MediaWiki  master
CoreParserFunctions.php
Go to the documentation of this file.
1 <?php
27 
37  public static function register( $parser ) {
39 
40  # Syntax for arguments (see Parser::setFunctionHook):
41  # "name for lookup in localized magic words array",
42  # function callback,
43  # optional Parser::SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}}
44  # instead of {{#int:...}})
45  $noHashFunctions = [
46  'ns', 'nse', 'urlencode', 'lcfirst', 'ucfirst', 'lc', 'uc',
47  'localurl', 'localurle', 'fullurl', 'fullurle', 'canonicalurl',
48  'canonicalurle', 'formatnum', 'grammar', 'gender', 'plural', 'bidi',
49  'numberofpages', 'numberofusers', 'numberofactiveusers',
50  'numberofarticles', 'numberoffiles', 'numberofadmins',
51  'numberingroup', 'numberofedits', 'language',
52  'padleft', 'padright', 'anchorencode', 'defaultsort', 'filepath',
53  'pagesincategory', 'pagesize', 'protectionlevel', 'protectionexpiry',
54  'namespacee', 'namespacenumber', 'talkspace', 'talkspacee',
55  'subjectspace', 'subjectspacee', 'pagename', 'pagenamee',
56  'fullpagename', 'fullpagenamee', 'rootpagename', 'rootpagenamee',
57  'basepagename', 'basepagenamee', 'subpagename', 'subpagenamee',
58  'talkpagename', 'talkpagenamee', 'subjectpagename',
59  'subjectpagenamee', 'pageid', 'revisionid', 'revisionday',
60  'revisionday2', 'revisionmonth', 'revisionmonth1', 'revisionyear',
61  'revisiontimestamp', 'revisionuser', 'cascadingsources',
62  ];
63  foreach ( $noHashFunctions as $func ) {
64  $parser->setFunctionHook( $func, [ __CLASS__, $func ], Parser::SFH_NO_HASH );
65  }
66 
67  $parser->setFunctionHook(
68  'namespace',
69  [ __CLASS__, 'mwnamespace' ],
71  );
72  $parser->setFunctionHook( 'int', [ __CLASS__, 'intFunction' ], Parser::SFH_NO_HASH );
73  $parser->setFunctionHook( 'special', [ __CLASS__, 'special' ] );
74  $parser->setFunctionHook( 'speciale', [ __CLASS__, 'speciale' ] );
75  $parser->setFunctionHook( 'tag', [ __CLASS__, 'tagObj' ], Parser::SFH_OBJECT_ARGS );
76  $parser->setFunctionHook( 'formatdate', [ __CLASS__, 'formatDate' ] );
77 
78  if ( $wgAllowDisplayTitle ) {
79  $parser->setFunctionHook(
80  'displaytitle',
81  [ __CLASS__, 'displaytitle' ],
83  );
84  }
86  $parser->setFunctionHook(
87  'pagesinnamespace',
88  [ __CLASS__, 'pagesinnamespace' ],
90  );
91  }
92  }
93 
100  public static function intFunction( $parser, $part1 = '', ...$params ) {
101  if ( strval( $part1 ) !== '' ) {
102  $message = wfMessage( $part1, $params )
103  ->inLanguage( $parser->getOptions()->getUserLangObj() );
104  return [ $message->plain(), 'noparse' => false ];
105  } else {
106  return [ 'found' => false ];
107  }
108  }
109 
117  public static function formatDate( $parser, $date, $defaultPref = null ) {
118  $lang = $parser->getFunctionLang();
119  $df = MediaWikiServices::getInstance()->getDateFormatterFactory()->get( $lang );
120 
121  $date = trim( $date );
122 
123  $pref = $parser->getOptions()->getDateFormat();
124 
125  // Specify a different default date format other than the normal default
126  // if the user has 'default' for their setting
127  if ( $pref == 'default' && $defaultPref ) {
128  $pref = $defaultPref;
129  }
130 
131  $date = $df->reformat( $pref, $date, [ 'match-whole' ] );
132  return $date;
133  }
134 
135  public static function ns( $parser, $part1 = '' ) {
136  if ( intval( $part1 ) || $part1 == "0" ) {
137  $index = intval( $part1 );
138  } else {
139  $index = $parser->getContentLanguage()->getNsIndex( str_replace( ' ', '_', $part1 ) );
140  }
141  if ( $index !== false ) {
142  return $parser->getContentLanguage()->getFormattedNsText( $index );
143  } else {
144  return [ 'found' => false ];
145  }
146  }
147 
148  public static function nse( $parser, $part1 = '' ) {
149  $ret = self::ns( $parser, $part1 );
150  if ( is_string( $ret ) ) {
151  $ret = wfUrlencode( str_replace( ' ', '_', $ret ) );
152  }
153  return $ret;
154  }
155 
168  public static function urlencode( $parser, $s = '', $arg = null ) {
169  static $magicWords = null;
170  if ( $magicWords === null ) {
171  $magicWords =
172  $parser->getMagicWordFactory()->newArray( [ 'url_path', 'url_query', 'url_wiki' ] );
173  }
174  switch ( $magicWords->matchStartToEnd( $arg ) ) {
175  // Encode as though it's a wiki page, '_' for ' '.
176  case 'url_wiki':
177  $func = 'wfUrlencode';
178  $s = str_replace( ' ', '_', $s );
179  break;
180 
181  // Encode for an HTTP Path, '%20' for ' '.
182  case 'url_path':
183  $func = 'rawurlencode';
184  break;
185 
186  // Encode for HTTP query, '+' for ' '.
187  case 'url_query':
188  default:
189  $func = 'urlencode';
190  }
191  // See T105242, where the choice to kill markers and various
192  // other options were discussed.
193  return $func( $parser->killMarkers( $s ) );
194  }
195 
196  public static function lcfirst( $parser, $s = '' ) {
197  return $parser->getContentLanguage()->lcfirst( $s );
198  }
199 
200  public static function ucfirst( $parser, $s = '' ) {
201  return $parser->getContentLanguage()->ucfirst( $s );
202  }
203 
209  public static function lc( $parser, $s = '' ) {
210  return $parser->markerSkipCallback( $s, [ $parser->getContentLanguage(), 'lc' ] );
211  }
212 
218  public static function uc( $parser, $s = '' ) {
219  return $parser->markerSkipCallback( $s, [ $parser->getContentLanguage(), 'uc' ] );
220  }
221 
222  public static function localurl( $parser, $s = '', $arg = null ) {
223  return self::urlFunction( 'getLocalURL', $s, $arg );
224  }
225 
226  public static function localurle( $parser, $s = '', $arg = null ) {
227  $temp = self::urlFunction( 'getLocalURL', $s, $arg );
228  if ( !is_string( $temp ) ) {
229  return $temp;
230  } else {
231  return htmlspecialchars( $temp );
232  }
233  }
234 
235  public static function fullurl( $parser, $s = '', $arg = null ) {
236  return self::urlFunction( 'getFullURL', $s, $arg );
237  }
238 
239  public static function fullurle( $parser, $s = '', $arg = null ) {
240  $temp = self::urlFunction( 'getFullURL', $s, $arg );
241  if ( !is_string( $temp ) ) {
242  return $temp;
243  } else {
244  return htmlspecialchars( $temp );
245  }
246  }
247 
248  public static function canonicalurl( $parser, $s = '', $arg = null ) {
249  return self::urlFunction( 'getCanonicalURL', $s, $arg );
250  }
251 
252  public static function canonicalurle( $parser, $s = '', $arg = null ) {
253  $temp = self::urlFunction( 'getCanonicalURL', $s, $arg );
254  if ( !is_string( $temp ) ) {
255  return $temp;
256  } else {
257  return htmlspecialchars( $temp );
258  }
259  }
260 
261  public static function urlFunction( $func, $s = '', $arg = null ) {
263  # Due to order of execution of a lot of bits, the values might be encoded
264  # before arriving here; if that's true, then the title can't be created
265  # and the variable will fail. If we can't get a decent title from the first
266  # attempt, url-decode and try for a second.
267  if ( $title === null ) {
268  $title = Title::newFromURL( urldecode( $s ) );
269  }
270  if ( $title !== null ) {
271  # Convert NS_MEDIA -> NS_FILE
272  if ( $title->inNamespace( NS_MEDIA ) ) {
273  $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
274  }
275  if ( $arg !== null ) {
276  $text = $title->$func( $arg );
277  } else {
278  $text = $title->$func();
279  }
280  return $text;
281  } else {
282  return [ 'found' => false ];
283  }
284  }
285 
292  public static function formatnum( $parser, $num = '', $arg = null ) {
293  if ( self::matchAgainstMagicword( $parser->getMagicWordFactory(), 'rawsuffix', $arg ) ) {
294  $func = [ $parser->getFunctionLang(), 'parseFormattedNumber' ];
295  } elseif (
296  self::matchAgainstMagicword( $parser->getMagicWordFactory(), 'nocommafysuffix', $arg )
297  ) {
298  $func = [ $parser->getFunctionLang(), 'formatNumNoSeparators' ];
299  $func = self::getLegacyFormatNum( $parser, $func );
300  } else {
301  $func = [ $parser->getFunctionLang(), 'formatNum' ];
302  $func = self::getLegacyFormatNum( $parser, $func );
303  }
304  return $parser->markerSkipCallback( $num, $func );
305  }
306 
313  private static function getLegacyFormatNum( $parser, $callback ) {
314  // For historic reasons, the formatNum parser function will
315  // take arguments which are not actually formatted numbers,
316  // which then trigger deprecation warnings in Language::formatNum*.
317  // Instead emit a tracking category instead to allow linting.
318  return function ( $number ) use ( $parser, $callback ) {
319  $validNumberRe = '(-(?=[\d\.]))?(\d+|(?=\.\d))(\.\d*)?';
320  if ( !preg_match( "/^{$validNumberRe}$/", $number ) ) {
321  $parser->addTrackingCategory( 'nonnumeric-formatnum' );
322  }
323  return preg_replace_callback( "/{$validNumberRe}/", function ( $m ) use ( $callback ) {
324  return call_user_func( $callback, $m[0] );
325  }, $number );
326  };
327  }
328 
335  public static function grammar( $parser, $case = '', $word = '' ) {
336  $word = $parser->killMarkers( $word );
337  return $parser->getFunctionLang()->convertGrammar( $word, $case );
338  }
339 
346  public static function gender( $parser, $username, ...$forms ) {
347  // Some shortcuts to avoid loading user data unnecessarily
348  if ( count( $forms ) === 0 ) {
349  return '';
350  } elseif ( count( $forms ) === 1 ) {
351  return $forms[0];
352  }
353 
354  $username = trim( $username );
355 
356  $gender = User::getDefaultOption( 'gender' );
357 
358  // allow prefix and normalize (e.g. "&#42;foo" -> "*foo" ).
359  $title = Title::newFromText( $username, NS_USER );
360 
361  if ( $title && $title->inNamespace( NS_USER ) ) {
362  $username = $title->getText();
363  }
364 
365  // check parameter, or use the ParserOptions if in interface message
366  $user = User::newFromName( $username );
367  $genderCache = MediaWikiServices::getInstance()->getGenderCache();
368  if ( $user ) {
369  $gender = $genderCache->getGenderOf( $user, __METHOD__ );
370  } elseif ( $username === '' && $parser->getOptions()->getInterfaceMessage() ) {
371  $gender = $genderCache->getGenderOf( $parser->getOptions()->getUser(), __METHOD__ );
372  }
373  $ret = $parser->getFunctionLang()->gender( $gender, $forms );
374  return $ret;
375  }
376 
383  public static function plural( $parser, $text = '', ...$forms ) {
384  $text = $parser->getFunctionLang()->parseFormattedNumber( $text );
385  settype( $text, ctype_digit( $text ) ? 'int' : 'float' );
386  return $parser->getFunctionLang()->convertPlural( $text, $forms );
387  }
388 
394  public static function bidi( $parser, $text = '' ) {
395  return $parser->getFunctionLang()->embedBidi( $text );
396  }
397 
403  private static function getTargetLanguageConverter( Parser $parser ) : ILanguageConverter {
404  return MediaWikiServices::getInstance()->getLanguageConverterFactory()
405  ->getLanguageConverter( $parser->getTargetLanguage() );
406  }
407 
417  public static function displaytitle( $parser, $text = '', $uarg = '' ) {
419 
420  static $magicWords = null;
421  if ( $magicWords === null ) {
422  $magicWords = $parser->getMagicWordFactory()->newArray(
423  [ 'displaytitle_noerror', 'displaytitle_noreplace' ] );
424  }
425  $arg = $magicWords->matchStartToEnd( $uarg );
426 
427  // parse a limited subset of wiki markup (just the single quote items)
428  $text = $parser->doQuotes( $text );
429 
430  // remove stripped text (e.g. the UNIQ-QINU stuff) that was generated by tag extensions/whatever
431  $text = $parser->killMarkers( $text );
432 
433  // list of disallowed tags for DISPLAYTITLE
434  // these will be escaped even though they are allowed in normal wiki text
435  $bad = [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'blockquote', 'ol', 'ul', 'li', 'hr',
436  'table', 'tr', 'th', 'td', 'dl', 'dd', 'caption', 'p', 'ruby', 'rb', 'rt', 'rtc', 'rp', 'br' ];
437 
438  // disallow some styles that could be used to bypass $wgRestrictDisplayTitle
439  if ( $wgRestrictDisplayTitle ) {
440  $htmlTagsCallback = function ( &$params ) {
441  $decoded = Sanitizer::decodeTagAttributes( $params );
442 
443  if ( isset( $decoded['style'] ) ) {
444  // this is called later anyway, but we need it right now for the regexes below to be safe
445  // calling it twice doesn't hurt
446  $decoded['style'] = Sanitizer::checkCss( $decoded['style'] );
447 
448  if ( preg_match( '/(display|user-select|visibility)\s*:/i', $decoded['style'] ) ) {
449  $decoded['style'] = '/* attempt to bypass $wgRestrictDisplayTitle */';
450  }
451  }
452 
453  $params = Sanitizer::safeEncodeTagAttributes( $decoded );
454  };
455  } else {
456  $htmlTagsCallback = null;
457  }
458 
459  // only requested titles that normalize to the actual title are allowed through
460  // if $wgRestrictDisplayTitle is true (it is by default)
461  // mimic the escaping process that occurs in OutputPage::setPageTitle
463  $text,
464  $htmlTagsCallback,
465  [],
466  [],
467  $bad
468  ) );
470 
471  if ( !$wgRestrictDisplayTitle ||
472  ( $title instanceof Title
473  && !$title->hasFragment()
474  && $title->equals( $parser->getTitle() ) )
475  ) {
476  $old = $parser->mOutput->getProperty( 'displaytitle' );
477  if ( $old === false || $arg !== 'displaytitle_noreplace' ) {
478  $parser->mOutput->setDisplayTitle( $text );
479  }
480  if ( $old !== false && $old !== $text && !$arg ) {
481 
482  $converter = self::getTargetLanguageConverter( $parser );
483  return '<span class="error">' .
484  wfMessage( 'duplicate-displaytitle',
485  // Message should be parsed, but these params should only be escaped.
486  $converter->markNoConversion( wfEscapeWikiText( $old ) ),
487  $converter->markNoConversion( wfEscapeWikiText( $text ) )
488  )->inContentLanguage()->text() .
489  '</span>';
490  } else {
491  return '';
492  }
493  } else {
494  $parser->getOutput()->addWarning(
495  wfMessage( 'restricted-displaytitle',
496  // Message should be parsed, but this param should only be escaped.
497  wfEscapeWikiText( $text )
498  )->text()
499  );
500  $parser->addTrackingCategory( 'restricted-displaytitle-ignored' );
501  }
502  }
503 
513  private static function matchAgainstMagicword(
514  MagicWordFactory $magicWordFactory, $magicword, $value
515  ) {
516  $value = trim( strval( $value ) );
517  if ( $value === '' ) {
518  return false;
519  }
520  $mwObject = $magicWordFactory->get( $magicword );
521  return $mwObject->matchStartToEnd( $value );
522  }
523 
533  public static function formatRaw(
534  $num, $raw, $language, MagicWordFactory $magicWordFactory = null
535  ) {
536  if ( $raw !== null && !$magicWordFactory ) {
537  $magicWordFactory = MediaWikiServices::getInstance()->getMagicWordFactory();
538  }
539  if (
540  $raw !== null && self::matchAgainstMagicword( $magicWordFactory, 'rawsuffix', $raw )
541  ) {
542  return $num;
543  } else {
544  return $language->formatNum( $num );
545  }
546  }
547 
548  public static function numberofpages( $parser, $raw = null ) {
549  return self::formatRaw( SiteStats::pages(), $raw, $parser->getFunctionLang() );
550  }
551 
552  public static function numberofusers( $parser, $raw = null ) {
553  return self::formatRaw( SiteStats::users(), $raw, $parser->getFunctionLang() );
554  }
555 
556  public static function numberofactiveusers( $parser, $raw = null ) {
557  return self::formatRaw( SiteStats::activeUsers(), $raw, $parser->getFunctionLang() );
558  }
559 
560  public static function numberofarticles( $parser, $raw = null ) {
561  return self::formatRaw( SiteStats::articles(), $raw, $parser->getFunctionLang() );
562  }
563 
564  public static function numberoffiles( $parser, $raw = null ) {
565  return self::formatRaw( SiteStats::images(), $raw, $parser->getFunctionLang() );
566  }
567 
568  public static function numberofadmins( $parser, $raw = null ) {
569  return self::formatRaw(
570  SiteStats::numberingroup( 'sysop' ),
571  $raw,
572  $parser->getFunctionLang()
573  );
574  }
575 
576  public static function numberofedits( $parser, $raw = null ) {
577  return self::formatRaw( SiteStats::edits(), $raw, $parser->getFunctionLang() );
578  }
579 
580  public static function pagesinnamespace( $parser, $namespace = 0, $raw = null ) {
581  return self::formatRaw(
582  SiteStats::pagesInNs( intval( $namespace ) ),
583  $raw,
584  $parser->getFunctionLang()
585  );
586  }
587 
588  public static function numberingroup( $parser, $name = '', $raw = null ) {
589  return self::formatRaw(
590  SiteStats::numberingroup( strtolower( $name ) ),
591  $raw,
592  $parser->getFunctionLang()
593  );
594  }
595 
605  public static function mwnamespace( $parser, $title = null ) {
607  if ( $t === null ) {
608  return '';
609  }
610  return str_replace( '_', ' ', $t->getNsText() );
611  }
612 
613  public static function namespacee( $parser, $title = null ) {
615  if ( $t === null ) {
616  return '';
617  }
618  return wfUrlencode( $t->getNsText() );
619  }
620 
621  public static function namespacenumber( $parser, $title = null ) {
623  if ( $t === null ) {
624  return '';
625  }
626  return $t->getNamespace();
627  }
628 
629  public static function talkspace( $parser, $title = null ) {
631  if ( $t === null || !$t->canHaveTalkPage() ) {
632  return '';
633  }
634  return str_replace( '_', ' ', $t->getTalkNsText() );
635  }
636 
637  public static function talkspacee( $parser, $title = null ) {
639  if ( $t === null || !$t->canHaveTalkPage() ) {
640  return '';
641  }
642  return wfUrlencode( $t->getTalkNsText() );
643  }
644 
645  public static function subjectspace( $parser, $title = null ) {
647  if ( $t === null ) {
648  return '';
649  }
650  return str_replace( '_', ' ', $t->getSubjectNsText() );
651  }
652 
653  public static function subjectspacee( $parser, $title = null ) {
655  if ( $t === null ) {
656  return '';
657  }
658  return wfUrlencode( $t->getSubjectNsText() );
659  }
660 
668  public static function pagename( $parser, $title = null ) {
670  if ( $t === null ) {
671  return '';
672  }
673  return wfEscapeWikiText( $t->getText() );
674  }
675 
676  public static function pagenamee( $parser, $title = null ) {
678  if ( $t === null ) {
679  return '';
680  }
681  return wfEscapeWikiText( $t->getPartialURL() );
682  }
683 
684  public static function fullpagename( $parser, $title = null ) {
686  if ( $t === null || !$t->canHaveTalkPage() ) {
687  return '';
688  }
689  return wfEscapeWikiText( $t->getPrefixedText() );
690  }
691 
692  public static function fullpagenamee( $parser, $title = null ) {
694  if ( $t === null || !$t->canHaveTalkPage() ) {
695  return '';
696  }
697  return wfEscapeWikiText( $t->getPrefixedURL() );
698  }
699 
700  public static function subpagename( $parser, $title = null ) {
702  if ( $t === null ) {
703  return '';
704  }
705  return wfEscapeWikiText( $t->getSubpageText() );
706  }
707 
708  public static function subpagenamee( $parser, $title = null ) {
710  if ( $t === null ) {
711  return '';
712  }
713  return wfEscapeWikiText( $t->getSubpageUrlForm() );
714  }
715 
716  public static function rootpagename( $parser, $title = null ) {
718  if ( $t === null ) {
719  return '';
720  }
721  return wfEscapeWikiText( $t->getRootText() );
722  }
723 
724  public static function rootpagenamee( $parser, $title = null ) {
726  if ( $t === null ) {
727  return '';
728  }
729  return wfEscapeWikiText( wfUrlencode( str_replace( ' ', '_', $t->getRootText() ) ) );
730  }
731 
732  public static function basepagename( $parser, $title = null ) {
734  if ( $t === null ) {
735  return '';
736  }
737  return wfEscapeWikiText( $t->getBaseText() );
738  }
739 
740  public static function basepagenamee( $parser, $title = null ) {
742  if ( $t === null ) {
743  return '';
744  }
745  return wfEscapeWikiText( wfUrlencode( str_replace( ' ', '_', $t->getBaseText() ) ) );
746  }
747 
748  public static function talkpagename( $parser, $title = null ) {
750  if ( $t === null || !$t->canHaveTalkPage() ) {
751  return '';
752  }
753  return wfEscapeWikiText( $t->getTalkPage()->getPrefixedText() );
754  }
755 
756  public static function talkpagenamee( $parser, $title = null ) {
758  if ( $t === null || !$t->canHaveTalkPage() ) {
759  return '';
760  }
761  return wfEscapeWikiText( $t->getTalkPage()->getPrefixedURL() );
762  }
763 
764  public static function subjectpagename( $parser, $title = null ) {
766  if ( $t === null ) {
767  return '';
768  }
769  return wfEscapeWikiText( $t->getSubjectPage()->getPrefixedText() );
770  }
771 
772  public static function subjectpagenamee( $parser, $title = null ) {
774  if ( $t === null ) {
775  return '';
776  }
777  return wfEscapeWikiText( $t->getSubjectPage()->getPrefixedURL() );
778  }
779 
790  public static function pagesincategory( $parser, $name = '', $arg1 = null, $arg2 = null ) {
791  static $magicWords = null;
792  if ( $magicWords === null ) {
793  $magicWords = $parser->getMagicWordFactory()->newArray( [
794  'pagesincategory_all',
795  'pagesincategory_pages',
796  'pagesincategory_subcats',
797  'pagesincategory_files'
798  ] );
799  }
800  static $cache = [];
801 
802  // split the given option to its variable
803  if ( self::matchAgainstMagicword( $parser->getMagicWordFactory(), 'rawsuffix', $arg1 ) ) {
804  // {{pagesincategory:|raw[|type]}}
805  $raw = $arg1;
806  $type = $magicWords->matchStartToEnd( $arg2 );
807  } else {
808  // {{pagesincategory:[|type[|raw]]}}
809  $type = $magicWords->matchStartToEnd( $arg1 );
810  $raw = $arg2;
811  }
812  if ( !$type ) { // backward compatibility
813  $type = 'pagesincategory_all';
814  }
815 
817  if ( !$title ) { # invalid title
818  return self::formatRaw( 0, $raw, $parser->getFunctionLang() );
819  }
820  $languageConverter = MediaWikiServices::getInstance()
821  ->getLanguageConverterFactory()
822  ->getLanguageConverter( $parser->getContentLanguage() );
823  $languageConverter->findVariantLink( $name, $title, true );
824 
825  // Normalize name for cache
826  $name = $title->getDBkey();
827 
828  if ( !isset( $cache[$name] ) ) {
829  $category = Category::newFromTitle( $title );
830 
831  $allCount = $subcatCount = $fileCount = $pagesCount = 0;
832  if ( $parser->incrementExpensiveFunctionCount() ) {
833  // $allCount is the total number of cat members,
834  // not the count of how many members are normal pages.
835  $allCount = (int)$category->getPageCount();
836  $subcatCount = (int)$category->getSubcatCount();
837  $fileCount = (int)$category->getFileCount();
838  $pagesCount = $allCount - $subcatCount - $fileCount;
839  }
840  $cache[$name]['pagesincategory_all'] = $allCount;
841  $cache[$name]['pagesincategory_pages'] = $pagesCount;
842  $cache[$name]['pagesincategory_subcats'] = $subcatCount;
843  $cache[$name]['pagesincategory_files'] = $fileCount;
844  }
845 
846  $count = $cache[$name][$type];
847  return self::formatRaw( $count, $raw, $parser->getFunctionLang() );
848  }
849 
859  public static function pagesize( $parser, $page = '', $raw = null ) {
860  $title = Title::newFromText( $page );
861 
862  if ( !is_object( $title ) ) {
863  return self::formatRaw( 0, $raw, $parser->getFunctionLang() );
864  }
865 
866  // fetch revision from cache/database and return the value
867  $rev = self::getCachedRevisionObject( $parser, $title, 'vary-revision-sha1' );
868  $length = $rev ? $rev->getSize() : 0;
869  if ( $length === null ) {
870  // We've had bugs where rev_len was not being recorded for empty pages, see T135414
871  $length = 0;
872  }
873  return self::formatRaw( $length, $raw, $parser->getFunctionLang() );
874  }
875 
888  public static function protectionlevel( $parser, $type = '', $title = '' ) {
889  $titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
890  if ( $titleObject->areRestrictionsLoaded() || $parser->incrementExpensiveFunctionCount() ) {
891  $restrictions = $titleObject->getRestrictions( strtolower( $type ) );
892  # Title::getRestrictions returns an array, its possible it may have
893  # multiple values in the future
894  return implode( ',', $restrictions );
895  }
896  return '';
897  }
898 
911  public static function protectionexpiry( $parser, $type = '', $title = '' ) {
912  $titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
913  if ( $titleObject->areRestrictionsLoaded() || $parser->incrementExpensiveFunctionCount() ) {
914  $expiry = $titleObject->getRestrictionExpiry( strtolower( $type ) );
915  // getRestrictionExpiry() returns false on invalid type; trying to
916  // match protectionlevel() function that returns empty string instead
917  if ( $expiry === false ) {
918  $expiry = '';
919  }
920  return $expiry;
921  }
922  return '';
923  }
924 
932  public static function language( $parser, $code = '', $inLanguage = '' ) {
933  $code = strtolower( $code );
934  $inLanguage = strtolower( $inLanguage );
935  $lang = MediaWikiServices::getInstance()
936  ->getLanguageNameUtils()
937  ->getLanguageName( $code, $inLanguage );
938  return $lang !== '' ? $lang : LanguageCode::bcp47( $code );
939  }
940 
950  public static function pad(
951  $parser, $string, $length, $padding = '0', $direction = STR_PAD_RIGHT
952  ) {
953  $padding = $parser->killMarkers( $padding );
954  $lengthOfPadding = mb_strlen( $padding );
955  if ( $lengthOfPadding == 0 ) {
956  return $string;
957  }
958 
959  # The remaining length to add counts down to 0 as padding is added
960  $length = min( (int)$length, 500 ) - mb_strlen( $string );
961  if ( $length <= 0 ) {
962  // Nothing to add
963  return $string;
964  }
965 
966  # $finalPadding is just $padding repeated enough times so that
967  # mb_strlen( $string ) + mb_strlen( $finalPadding ) == $length
968  $finalPadding = '';
969  while ( $length > 0 ) {
970  # If $length < $lengthofPadding, truncate $padding so we get the
971  # exact length desired.
972  $finalPadding .= mb_substr( $padding, 0, $length );
973  $length -= $lengthOfPadding;
974  }
975 
976  if ( $direction == STR_PAD_LEFT ) {
977  return $finalPadding . $string;
978  } else {
979  return $string . $finalPadding;
980  }
981  }
982 
983  public static function padleft( $parser, $string = '', $length = 0, $padding = '0' ) {
984  return self::pad( $parser, $string, $length, $padding, STR_PAD_LEFT );
985  }
986 
987  public static function padright( $parser, $string = '', $length = 0, $padding = '0' ) {
988  return self::pad( $parser, $string, $length, $padding );
989  }
990 
996  public static function anchorencode( $parser, $text ) {
997  $text = $parser->killMarkers( $text );
998  $section = (string)substr( $parser->guessSectionNameFromWikiText( $text ), 1 );
999  return Sanitizer::safeEncodeAttribute( $section );
1000  }
1001 
1002  public static function special( $parser, $text ) {
1003  list( $page, $subpage ) = MediaWikiServices::getInstance()->getSpecialPageFactory()->
1004  resolveAlias( $text );
1005  if ( $page ) {
1006  $title = SpecialPage::getTitleFor( $page, $subpage );
1007  return $title->getPrefixedText();
1008  } else {
1009  // unknown special page, just use the given text as its title, if at all possible
1011  return $title ? $title->getPrefixedText() : self::special( $parser, 'Badtitle' );
1012  }
1013  }
1014 
1015  public static function speciale( $parser, $text ) {
1016  return wfUrlencode( str_replace( ' ', '_', self::special( $parser, $text ) ) );
1017  }
1018 
1027  public static function defaultsort( $parser, $text, $uarg = '' ) {
1028  static $magicWords = null;
1029  if ( $magicWords === null ) {
1030  $magicWords = $parser->getMagicWordFactory()->newArray(
1031  [ 'defaultsort_noerror', 'defaultsort_noreplace' ] );
1032  }
1033  $arg = $magicWords->matchStartToEnd( $uarg );
1034 
1035  $text = trim( $text );
1036  if ( strlen( $text ) == 0 ) {
1037  return '';
1038  }
1039  $old = $parser->getCustomDefaultSort();
1040  if ( $old === false || $arg !== 'defaultsort_noreplace' ) {
1041  $parser->setDefaultSort( $text );
1042  }
1043 
1044  if ( $old === false || $old == $text || $arg ) {
1045  return '';
1046  } else {
1047  $converter = $parser->getTargetLanguage()->getConverter();
1048  return '<span class="error">' .
1049  wfMessage( 'duplicate-defaultsort',
1050  // Message should be parsed, but these params should only be escaped.
1051  $converter->markNoConversion( wfEscapeWikiText( $old ) ),
1052  $converter->markNoConversion( wfEscapeWikiText( $text ) )
1053  )->inContentLanguage()->text() .
1054  '</span>';
1055  }
1056  }
1057 
1069  public static function filepath( $parser, $name = '', $argA = '', $argB = '' ) {
1070  $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name );
1071 
1072  if ( $argA == 'nowiki' ) {
1073  // {{filepath: | option [| size] }}
1074  $isNowiki = true;
1075  $parsedWidthParam = Parser::parseWidthParam( $argB );
1076  } else {
1077  // {{filepath: [| size [|option]] }}
1078  $parsedWidthParam = Parser::parseWidthParam( $argA );
1079  $isNowiki = ( $argB == 'nowiki' );
1080  }
1081 
1082  if ( $file ) {
1083  $url = $file->getFullUrl();
1084 
1085  // If a size is requested...
1086  if ( count( $parsedWidthParam ) ) {
1087  $mto = $file->transform( $parsedWidthParam );
1088  // ... and we can
1089  if ( $mto && !$mto->isError() ) {
1090  // ... change the URL to point to a thumbnail.
1091  $url = wfExpandUrl( $mto->getUrl(), PROTO_RELATIVE );
1092  }
1093  }
1094  if ( $isNowiki ) {
1095  return [ $url, 'nowiki' => true ];
1096  }
1097  return $url;
1098  } else {
1099  return '';
1100  }
1101  }
1102 
1110  public static function tagObj( $parser, $frame, $args ) {
1111  if ( !count( $args ) ) {
1112  return '';
1113  }
1114  $tagName = strtolower( trim( $frame->expand( array_shift( $args ) ) ) );
1115 
1116  if ( count( $args ) ) {
1117  $inner = $frame->expand( array_shift( $args ) );
1118  } else {
1119  $inner = null;
1120  }
1121 
1122  $attributes = [];
1123  foreach ( $args as $arg ) {
1124  $bits = $arg->splitArg();
1125  if ( strval( $bits['index'] ) === '' ) {
1126  $name = trim( $frame->expand( $bits['name'], PPFrame::STRIP_COMMENTS ) );
1127  $value = trim( $frame->expand( $bits['value'] ) );
1128  if ( preg_match( '/^(?:["\'](.+)["\']|""|\'\')$/s', $value, $m ) ) {
1129  $value = $m[1] ?? '';
1130  }
1131  $attributes[$name] = $value;
1132  }
1133  }
1134 
1135  $stripList = $parser->getStripList();
1136  if ( !in_array( $tagName, $stripList ) ) {
1137  // we can't handle this tag (at least not now), so just re-emit it as an ordinary tag
1138  $attrText = '';
1139  foreach ( $attributes as $name => $value ) {
1140  $attrText .= ' ' . htmlspecialchars( $name ) . '="' . htmlspecialchars( $value ) . '"';
1141  }
1142  if ( $inner === null ) {
1143  return "<$tagName$attrText/>";
1144  }
1145  return "<$tagName$attrText>$inner</$tagName>";
1146  }
1147 
1148  $params = [
1149  'name' => $tagName,
1150  'inner' => $inner,
1151  'attributes' => $attributes,
1152  'close' => "</$tagName>",
1153  ];
1154  return $parser->extensionSubstitution( $params, $frame );
1155  }
1156 
1170  private static function getCachedRevisionObject( $parser, $title, $vary ) {
1171  if ( !$title ) {
1172  return null;
1173  }
1174 
1175  $revisionRecord = null;
1176 
1177  $isSelfReferential = $title->equals( $parser->getTitle() );
1178  if ( $isSelfReferential ) {
1179  // Revision is for the same title that is currently being parsed. Only use the last
1180  // saved revision, regardless of Parser::getRevisionId() or fake revision injection
1181  // callbacks against the current title.
1182  $parserRevisionRecord = $parser->getRevisionRecordObject();
1183  if ( $parserRevisionRecord && $parserRevisionRecord->isCurrent() ) {
1184  $revisionRecord = $parserRevisionRecord;
1185  }
1186  }
1187 
1188  $parserOutput = $parser->getOutput();
1189  if ( !$revisionRecord ) {
1190  if (
1191  !$parser->isCurrentRevisionOfTitleCached( $title ) &&
1192  !$parser->incrementExpensiveFunctionCount()
1193  ) {
1194  return null; // not allowed
1195  }
1196  // Get the current revision, ignoring Parser::getRevisionId() being null/old
1197  $revisionRecord = $parser->fetchCurrentRevisionRecordOfTitle( $title );
1198  if ( !$revisionRecord ) {
1199  // Convert `false` error return to `null`
1200  $revisionRecord = null;
1201  }
1202  // Register dependency in templatelinks
1203  $parserOutput->addTemplate(
1204  $title,
1205  $revisionRecord ? $revisionRecord->getPageId() : 0,
1206  $revisionRecord ? $revisionRecord->getId() : 0
1207  );
1208  }
1209 
1210  if ( $isSelfReferential ) {
1211  wfDebug( __METHOD__ . ": used current revision, setting $vary" );
1212  // Upon page save, the result of the parser function using this might change
1213  $parserOutput->setFlag( $vary );
1214  if ( $vary === 'vary-revision-sha1' && $revisionRecord ) {
1215  try {
1216  $sha1 = $revisionRecord->getSha1();
1217  } catch ( RevisionAccessException $e ) {
1218  $sha1 = null;
1219  }
1220  $parserOutput->setRevisionUsedSha1Base36( $sha1 );
1221  }
1222  }
1223 
1224  return $revisionRecord;
1225  }
1226 
1234  public static function pageid( $parser, $title = null ) {
1236  if ( !$t ) {
1237  return '';
1238  } elseif ( !$t->canExist() || $t->isExternal() ) {
1239  return 0; // e.g. special page or interwiki link
1240  }
1241 
1242  $parserOutput = $parser->getOutput();
1243 
1244  if ( $t->equals( $parser->getTitle() ) ) {
1245  // Revision is for the same title that is currently being parsed.
1246  // Use the title from Parser in case a new page ID was injected into it.
1247  $parserOutput->setFlag( 'vary-page-id' );
1248  $id = $parser->getTitle()->getArticleID();
1249  if ( $id ) {
1250  $parserOutput->setSpeculativePageIdUsed( $id );
1251  }
1252 
1253  return $id;
1254  }
1255 
1256  // Check the link cache for the title
1257  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1258  $pdbk = $t->getPrefixedDBkey();
1259  $id = $linkCache->getGoodLinkID( $pdbk );
1260  if ( $id != 0 || $linkCache->isBadLink( $pdbk ) ) {
1261  $parserOutput->addLink( $t, $id );
1262 
1263  return $id;
1264  }
1265 
1266  // We need to load it from the DB, so mark expensive
1267  if ( $parser->incrementExpensiveFunctionCount() ) {
1268  $id = $t->getArticleID();
1269  $parserOutput->addLink( $t, $id );
1270 
1271  return $id;
1272  }
1273 
1274  return null;
1275  }
1276 
1284  public static function revisionid( $parser, $title = null ) {
1286  if ( $t === null ) {
1287  return '';
1288  }
1289 
1290  $services = MediaWikiServices::getInstance();
1291  if (
1292  $t->equals( $parser->getTitle() ) &&
1293  $services->getMainConfig()->get( 'MiserMode' ) &&
1294  !$parser->getOptions()->getInterfaceMessage() &&
1295  // @TODO: disallow this word on all namespaces (T235957)
1296  $services->getNamespaceInfo()->isSubject( $t->getNamespace() )
1297  ) {
1298  // Use a stub result instead of the actual revision ID in order to avoid
1299  // double parses on page save but still allow preview detection (T137900)
1300  if ( $parser->getRevisionId() || $parser->getOptions()->getSpeculativeRevId() ) {
1301  return '-';
1302  } else {
1303  $parser->getOutput()->setFlag( 'vary-revision-exists' );
1304  return '';
1305  }
1306  }
1307  // fetch revision from cache/database and return the value
1308  $rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-id' );
1309  return $rev ? $rev->getId() : '';
1310  }
1311 
1319  public static function revisionday( $parser, $title = null ) {
1321  if ( $t === null ) {
1322  return '';
1323  }
1324  // fetch revision from cache/database and return the value
1325  $rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
1326  return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'j' ) : '';
1327  }
1328 
1336  public static function revisionday2( $parser, $title = null ) {
1338  if ( $t === null ) {
1339  return '';
1340  }
1341  // fetch revision from cache/database and return the value
1342  $rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
1343  return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'd' ) : '';
1344  }
1345 
1353  public static function revisionmonth( $parser, $title = null ) {
1355  if ( $t === null ) {
1356  return '';
1357  }
1358  // fetch revision from cache/database and return the value
1359  $rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
1360  return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'm' ) : '';
1361  }
1362 
1370  public static function revisionmonth1( $parser, $title = null ) {
1372  if ( $t === null ) {
1373  return '';
1374  }
1375  // fetch revision from cache/database and return the value
1376  $rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
1377  return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'n' ) : '';
1378  }
1379 
1387  public static function revisionyear( $parser, $title = null ) {
1389  if ( $t === null ) {
1390  return '';
1391  }
1392  // fetch revision from cache/database and return the value
1393  $rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
1394  return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'Y' ) : '';
1395  }
1396 
1404  public static function revisiontimestamp( $parser, $title = null ) {
1406  if ( $t === null ) {
1407  return '';
1408  }
1409  // fetch revision from cache/database and return the value
1410  $rev = self::getCachedRevisionObject( $parser, $t, 'vary-revision-timestamp' );
1411  return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'YmdHis' ) : '';
1412  }
1413 
1421  public static function revisionuser( $parser, $title = null ) {
1423  if ( $t === null ) {
1424  return '';
1425  }
1426  // fetch revision from cache/database and return the value
1427  $rev = self::getCachedRevisionObject( $parser, $t, 'vary-user' );
1428  if ( $rev === null ) {
1429  return '';
1430  }
1431  $user = $rev->getUser();
1432  return $user ? $user->getName() : '';
1433  }
1434 
1447  public static function cascadingsources( $parser, $title = '' ) {
1448  $titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
1449  if ( $titleObject->areCascadeProtectionSourcesLoaded()
1450  || $parser->incrementExpensiveFunctionCount()
1451  ) {
1452  $names = [];
1453  $sources = $titleObject->getCascadeProtectionSources();
1454  foreach ( $sources[0] as $sourceTitle ) {
1455  $names[] = $sourceTitle->getPrefixedText();
1456  }
1457  return implode( '|', $names );
1458  }
1459  return '';
1460  }
1461 }
User\getDefaultOption
static getDefaultOption( $opt)
Get a given default option value.
Definition: User.php:1524
CoreParserFunctions\protectionexpiry
static protectionexpiry( $parser, $type='', $title='')
Returns the requested protection expiry for the current page.
Definition: CoreParserFunctions.php:911
SiteStats\articles
static articles()
Definition: SiteStats.php:103
Revision\RevisionAccessException
Exception representing a failure to look up a revision.
Definition: RevisionAccessException.php:34
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:328
PPFrame\STRIP_COMMENTS
const STRIP_COMMENTS
Definition: PPFrame.php:31
CoreParserFunctions\displaytitle
static displaytitle( $parser, $text='', $uarg='')
Override the title of the page when viewed, provided we've been given a title which will normalise to...
Definition: CoreParserFunctions.php:417
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:46
SiteStats\users
static users()
Definition: SiteStats.php:121
MagicWordFactory
A factory that stores information about MagicWords, and creates them on demand with caching.
Definition: MagicWordFactory.php:37
Sanitizer\stripAllTags
static stripAllTags( $html)
Take a fragment of (potentially invalid) HTML and return a version with any tags removed,...
Definition: Sanitizer.php:1574
SiteStats\activeUsers
static activeUsers()
Definition: SiteStats.php:130
CoreParserFunctions\pad
static pad( $parser, $string, $length, $padding='0', $direction=STR_PAD_RIGHT)
Unicode-safe str_pad with the restriction that $length is forced to be <= 500.
Definition: CoreParserFunctions.php:950
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:163
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
CoreParserFunctions\numberofactiveusers
static numberofactiveusers( $parser, $raw=null)
Definition: CoreParserFunctions.php:556
CoreParserFunctions\pageid
static pageid( $parser, $title=null)
Get the pageid of a specified page.
Definition: CoreParserFunctions.php:1234
Sanitizer\removeHTMLtags
static removeHTMLtags( $text, $processCallback=null, $args=[], $extratags=[], $removetags=[])
Cleans up HTML, removes dangerous tags and attributes, and removes HTML comments.
Definition: Sanitizer.php:239
CoreParserFunctions\talkpagename
static talkpagename( $parser, $title=null)
Definition: CoreParserFunctions.php:748
CoreParserFunctions\rootpagename
static rootpagename( $parser, $title=null)
Definition: CoreParserFunctions.php:716
true
return true
Definition: router.php:90
CoreParserFunctions\tagObj
static tagObj( $parser, $frame, $args)
Parser function to extension tag adaptor.
Definition: CoreParserFunctions.php:1110
CoreParserFunctions\pagesize
static pagesize( $parser, $page='', $raw=null)
Return the size of the given page, or 0 if it's nonexistent.
Definition: CoreParserFunctions.php:859
CoreParserFunctions\formatRaw
static formatRaw( $num, $raw, $language, MagicWordFactory $magicWordFactory=null)
Formats a number according to a language.
Definition: CoreParserFunctions.php:533
SiteStats\pages
static pages()
Definition: SiteStats.php:112
CoreParserFunctions\rootpagenamee
static rootpagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:724
CoreParserFunctions\protectionlevel
static protectionlevel( $parser, $type='', $title='')
Returns the requested protection level for the current page.
Definition: CoreParserFunctions.php:888
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:308
SiteStats\numberingroup
static numberingroup( $group)
Find the number of users in a given user group.
Definition: SiteStats.php:150
CoreParserFunctions\nse
static nse( $parser, $part1='')
Definition: CoreParserFunctions.php:148
NS_FILE
const NS_FILE
Definition: Defines.php:75
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
CoreParserFunctions\revisionmonth1
static revisionmonth1( $parser, $title=null)
Get the month from the last revision of a specified page.
Definition: CoreParserFunctions.php:1370
Parser\getTargetLanguage
getTargetLanguage()
Get the target language for the content being parsed.
Definition: Parser.php:1114
User\newFromName
static newFromName( $name, $validate='valid')
Definition: User.php:545
Sanitizer\safeEncodeTagAttributes
static safeEncodeTagAttributes( $assoc_array)
Build a partial tag string from an associative array of attribute names and values as returned by dec...
Definition: Sanitizer.php:1050
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1220
$s
$s
Definition: mergeMessageFileList.php:184
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:96
CoreParserFunctions\namespacenumber
static namespacenumber( $parser, $title=null)
Definition: CoreParserFunctions.php:621
CoreParserFunctions\talkspace
static talkspace( $parser, $title=null)
Definition: CoreParserFunctions.php:629
CoreParserFunctions\gender
static gender( $parser, $username,... $forms)
Definition: CoreParserFunctions.php:346
CoreParserFunctions\grammar
static grammar( $parser, $case='', $word='')
Definition: CoreParserFunctions.php:335
Parser\SFH_OBJECT_ARGS
const SFH_OBJECT_ARGS
Definition: Parser.php:94
CoreParserFunctions\defaultsort
static defaultsort( $parser, $text, $uarg='')
Definition: CoreParserFunctions.php:1027
CoreParserFunctions\revisionday
static revisionday( $parser, $title=null)
Get the day from the last revision of a specified page.
Definition: CoreParserFunctions.php:1319
CoreParserFunctions\pagename
static pagename( $parser, $title=null)
Functions to get and normalize pagenames, corresponding to the magic words of the same names.
Definition: CoreParserFunctions.php:668
SiteStats\images
static images()
Definition: SiteStats.php:139
CoreParserFunctions\revisionid
static revisionid( $parser, $title=null)
Get the id from the last revision of a specified page.
Definition: CoreParserFunctions.php:1284
CoreParserFunctions\talkspacee
static talkspacee( $parser, $title=null)
Definition: CoreParserFunctions.php:637
CoreParserFunctions\localurle
static localurle( $parser, $s='', $arg=null)
Definition: CoreParserFunctions.php:226
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:58
CoreParserFunctions\numberofpages
static numberofpages( $parser, $raw=null)
Definition: CoreParserFunctions.php:548
CoreParserFunctions\basepagenamee
static basepagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:740
Sanitizer\safeEncodeAttribute
static safeEncodeAttribute( $text)
Encode an attribute value for HTML tags, with extra armoring against further wiki processing.
Definition: Sanitizer.php:766
CoreParserFunctions\matchAgainstMagicword
static matchAgainstMagicword(MagicWordFactory $magicWordFactory, $magicword, $value)
Matches the given value against the value of given magic word.
Definition: CoreParserFunctions.php:513
CoreParserFunctions\revisionyear
static revisionyear( $parser, $title=null)
Get the year from the last revision of a specified page.
Definition: CoreParserFunctions.php:1387
CoreParserFunctions\mwnamespace
static mwnamespace( $parser, $title=null)
Given a title, return the namespace name that would be given by the corresponding magic word Note: fu...
Definition: CoreParserFunctions.php:605
$args
if( $line===false) $args
Definition: mcc.php:124
CoreParserFunctions\fullurle
static fullurle( $parser, $s='', $arg=null)
Definition: CoreParserFunctions.php:239
$title
$title
Definition: testCompression.php:38
CoreParserFunctions\numberofedits
static numberofedits( $parser, $raw=null)
Definition: CoreParserFunctions.php:576
CoreParserFunctions\revisionday2
static revisionday2( $parser, $title=null)
Get the day with leading zeros from the last revision of a specified page.
Definition: CoreParserFunctions.php:1336
CoreParserFunctions\fullurl
static fullurl( $parser, $s='', $arg=null)
Definition: CoreParserFunctions.php:235
CoreParserFunctions\ucfirst
static ucfirst( $parser, $s='')
Definition: CoreParserFunctions.php:200
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:591
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:83
CoreParserFunctions\fullpagenamee
static fullpagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:692
CoreParserFunctions\getLegacyFormatNum
static getLegacyFormatNum( $parser, $callback)
Definition: CoreParserFunctions.php:313
CoreParserFunctions\pagenamee
static pagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:676
CoreParserFunctions\ns
static ns( $parser, $part1='')
Definition: CoreParserFunctions.php:135
CoreParserFunctions\subjectpagename
static subjectpagename( $parser, $title=null)
Definition: CoreParserFunctions.php:764
CoreParserFunctions\language
static language( $parser, $code='', $inLanguage='')
Gives language names.
Definition: CoreParserFunctions.php:932
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:910
CoreParserFunctions\revisiontimestamp
static revisiontimestamp( $parser, $title=null)
Get the timestamp from the last revision of a specified page.
Definition: CoreParserFunctions.php:1404
CoreParserFunctions\bidi
static bidi( $parser, $text='')
Definition: CoreParserFunctions.php:394
Category\newFromTitle
static newFromTitle( $title)
Factory function.
Definition: Category.php:153
CoreParserFunctions\urlencode
static urlencode( $parser, $s='', $arg=null)
urlencodes a string according to one of three patterns: (T24474)
Definition: CoreParserFunctions.php:168
CoreParserFunctions\formatDate
static formatDate( $parser, $date, $defaultPref=null)
Definition: CoreParserFunctions.php:117
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:617
CoreParserFunctions\fullpagename
static fullpagename( $parser, $title=null)
Definition: CoreParserFunctions.php:684
SiteStats\pagesInNs
static pagesInNs( $ns)
Definition: SiteStats.php:201
MagicWordFactory\get
get( $id)
Factory: creates an object representing an ID.
Definition: MagicWordFactory.php:227
ILanguageConverter
The shared interface for all language converters.
Definition: ILanguageConverter.php:28
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:57
CoreParserFunctions\padleft
static padleft( $parser, $string='', $length=0, $padding='0')
Definition: CoreParserFunctions.php:983
CoreParserFunctions\padright
static padright( $parser, $string='', $length=0, $padding='0')
Definition: CoreParserFunctions.php:987
Title\newFromURL
static newFromURL( $url)
THIS IS NOT THE FUNCTION YOU WANT.
Definition: Title.php:413
CoreParserFunctions\revisionmonth
static revisionmonth( $parser, $title=null)
Get the month with leading zeros from the last revision of a specified page.
Definition: CoreParserFunctions.php:1353
CoreParserFunctions\getTargetLanguageConverter
static getTargetLanguageConverter(Parser $parser)
Shorthand for getting a Language Converter for Target language.
Definition: CoreParserFunctions.php:403
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1494
PROTO_RELATIVE
const PROTO_RELATIVE
Definition: Defines.php:210
CoreParserFunctions\subjectspacee
static subjectspacee( $parser, $title=null)
Definition: CoreParserFunctions.php:653
CoreParserFunctions\speciale
static speciale( $parser, $text)
Definition: CoreParserFunctions.php:1015
CoreParserFunctions\urlFunction
static urlFunction( $func, $s='', $arg=null)
Definition: CoreParserFunctions.php:261
CoreParserFunctions\lc
static lc( $parser, $s='')
Definition: CoreParserFunctions.php:209
CoreParserFunctions\subjectspace
static subjectspace( $parser, $title=null)
Definition: CoreParserFunctions.php:645
Parser
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
Definition: Parser.php:84
CoreParserFunctions\subjectpagenamee
static subjectpagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:772
Title
Represents a title within MediaWiki.
Definition: Title.php:41
CoreParserFunctions\numberofadmins
static numberofadmins( $parser, $raw=null)
Definition: CoreParserFunctions.php:568
CoreParserFunctions\cascadingsources
static cascadingsources( $parser, $title='')
Returns the sources of any cascading protection acting on a specified page.
Definition: CoreParserFunctions.php:1447
CoreParserFunctions\plural
static plural( $parser, $text='',... $forms)
Definition: CoreParserFunctions.php:383
$magicWords
$magicWords
Definition: MessagesAb.php:71
CoreParserFunctions\anchorencode
static anchorencode( $parser, $text)
Definition: CoreParserFunctions.php:996
$cache
$cache
Definition: mcc.php:33
CoreParserFunctions\uc
static uc( $parser, $s='')
Definition: CoreParserFunctions.php:218
CoreParserFunctions\special
static special( $parser, $text)
Definition: CoreParserFunctions.php:1002
CoreParserFunctions\subpagenamee
static subpagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:708
CoreParserFunctions\filepath
static filepath( $parser, $name='', $argA='', $argB='')
Usage {{filepath|300}}, {{filepath|nowiki}}, {{filepath|nowiki|300}} or {{filepath|300|nowiki}} or {{...
Definition: CoreParserFunctions.php:1069
CoreParserFunctions\namespacee
static namespacee( $parser, $title=null)
Definition: CoreParserFunctions.php:613
CoreParserFunctions\numberofarticles
static numberofarticles( $parser, $raw=null)
Definition: CoreParserFunctions.php:560
CoreParserFunctions\getCachedRevisionObject
static getCachedRevisionObject( $parser, $title, $vary)
Fetched the current revision of the given title and return this.
Definition: CoreParserFunctions.php:1170
LanguageCode\bcp47
static bcp47( $code)
Get the normalised IETF language tag See unit test for examples.
Definition: LanguageCode.php:175
CoreParserFunctions
Various core parser functions, registered in Parser::firstCallInit()
Definition: CoreParserFunctions.php:32
CoreParserFunctions\subpagename
static subpagename( $parser, $title=null)
Definition: CoreParserFunctions.php:700
NS_USER
const NS_USER
Definition: Defines.php:71
CoreParserFunctions\revisionuser
static revisionuser( $parser, $title=null)
Get the user from the last revision of a specified page.
Definition: CoreParserFunctions.php:1421
CoreParserFunctions\numberingroup
static numberingroup( $parser, $name='', $raw=null)
Definition: CoreParserFunctions.php:588
Sanitizer\normalizeCharReferences
static normalizeCharReferences( $text)
Ensure that any entities and character references are legal for XML and XHTML specifically.
Definition: Sanitizer.php:1127
Parser\SFH_NO_HASH
const SFH_NO_HASH
Definition: Parser.php:93
Sanitizer\decodeTagAttributes
static decodeTagAttributes( $text)
Return an associative array of attribute names and values from a partial tag string.
Definition: Sanitizer.php:1008
CoreParserFunctions\numberofusers
static numberofusers( $parser, $raw=null)
Definition: CoreParserFunctions.php:552
$t
$t
Definition: testCompression.php:74
CoreParserFunctions\pagesincategory
static pagesincategory( $parser, $name='', $arg1=null, $arg2=null)
Return the number of pages, files or subcats in the given category, or 0 if it's nonexistent.
Definition: CoreParserFunctions.php:790
$wgAllowSlowParserFunctions
$wgAllowSlowParserFunctions
Enable slow parser functions.
Definition: DefaultSettings.php:2396
CoreParserFunctions\numberoffiles
static numberoffiles( $parser, $raw=null)
Definition: CoreParserFunctions.php:564
Parser\parseWidthParam
static parseWidthParam( $value, $parseHeight=true)
Parsed a width param of imagelink like 300px or 200x300px.
Definition: Parser.php:6170
CoreParserFunctions\pagesinnamespace
static pagesinnamespace( $parser, $namespace=0, $raw=null)
Definition: CoreParserFunctions.php:580
$wgRestrictDisplayTitle
$wgRestrictDisplayTitle
For consistency, restrict DISPLAYTITLE to text that normalizes to the same canonical DB key.
Definition: DefaultSettings.php:4721
$wgAllowDisplayTitle
$wgAllowDisplayTitle
Allow DISPLAYTITLE to change title display.
Definition: DefaultSettings.php:4714
CoreParserFunctions\formatnum
static formatnum( $parser, $num='', $arg=null)
Definition: CoreParserFunctions.php:292
CoreParserFunctions\lcfirst
static lcfirst( $parser, $s='')
Definition: CoreParserFunctions.php:196
CoreParserFunctions\canonicalurl
static canonicalurl( $parser, $s='', $arg=null)
Definition: CoreParserFunctions.php:248
Sanitizer\checkCss
static checkCss( $value)
Pick apart some CSS and check it for forbidden or unsafe structures.
Definition: Sanitizer.php:632
MWTimestamp\getLocalInstance
static getLocalInstance( $ts=false)
Get a timestamp instance in the server local timezone ($wgLocaltimezone)
Definition: MWTimestamp.php:205
CoreParserFunctions\intFunction
static intFunction( $parser, $part1='',... $params)
Definition: CoreParserFunctions.php:100
SiteStats\edits
static edits()
Definition: SiteStats.php:94
CoreParserFunctions\basepagename
static basepagename( $parser, $title=null)
Definition: CoreParserFunctions.php:732
CoreParserFunctions\canonicalurle
static canonicalurle( $parser, $s='', $arg=null)
Definition: CoreParserFunctions.php:252
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:490
CoreParserFunctions\localurl
static localurl( $parser, $s='', $arg=null)
Definition: CoreParserFunctions.php:222
$type
$type
Definition: testCompression.php:52
CoreParserFunctions\talkpagenamee
static talkpagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:756