MediaWiki  master
CoreParserFunctions.php
Go to the documentation of this file.
1 <?php
28 
38  public static function register( $parser ) {
40 
41  # Syntax for arguments (see Parser::setFunctionHook):
42  # "name for lookup in localized magic words array",
43  # function callback,
44  # optional Parser::SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}}
45  # instead of {{#int:...}})
46  $noHashFunctions = [
47  'ns', 'nse', 'urlencode', 'lcfirst', 'ucfirst', 'lc', 'uc',
48  'localurl', 'localurle', 'fullurl', 'fullurle', 'canonicalurl',
49  'canonicalurle', 'formatnum', 'grammar', 'gender', 'plural', 'bidi',
50  'numberofpages', 'numberofusers', 'numberofactiveusers',
51  'numberofarticles', 'numberoffiles', 'numberofadmins',
52  'numberingroup', 'numberofedits', 'language',
53  'padleft', 'padright', 'anchorencode', 'defaultsort', 'filepath',
54  'pagesincategory', 'pagesize', 'protectionlevel', 'protectionexpiry',
55  'namespacee', 'namespacenumber', 'talkspace', 'talkspacee',
56  'subjectspace', 'subjectspacee', 'pagename', 'pagenamee',
57  'fullpagename', 'fullpagenamee', 'rootpagename', 'rootpagenamee',
58  'basepagename', 'basepagenamee', 'subpagename', 'subpagenamee',
59  'talkpagename', 'talkpagenamee', 'subjectpagename',
60  'subjectpagenamee', 'pageid', 'revisionid', 'revisionday',
61  'revisionday2', 'revisionmonth', 'revisionmonth1', 'revisionyear',
62  'revisiontimestamp', 'revisionuser', 'cascadingsources',
63  ];
64  foreach ( $noHashFunctions as $func ) {
65  $parser->setFunctionHook( $func, [ __CLASS__, $func ], Parser::SFH_NO_HASH );
66  }
67 
68  $parser->setFunctionHook(
69  'namespace',
70  [ __CLASS__, 'mwnamespace' ],
72  );
73  $parser->setFunctionHook( 'int', [ __CLASS__, 'intFunction' ], Parser::SFH_NO_HASH );
74  $parser->setFunctionHook( 'special', [ __CLASS__, 'special' ] );
75  $parser->setFunctionHook( 'speciale', [ __CLASS__, 'speciale' ] );
76  $parser->setFunctionHook( 'tag', [ __CLASS__, 'tagObj' ], Parser::SFH_OBJECT_ARGS );
77  $parser->setFunctionHook( 'formatdate', [ __CLASS__, 'formatDate' ] );
78 
79  if ( $wgAllowDisplayTitle ) {
80  $parser->setFunctionHook(
81  'displaytitle',
82  [ __CLASS__, 'displaytitle' ],
84  );
85  }
87  $parser->setFunctionHook(
88  'pagesinnamespace',
89  [ __CLASS__, 'pagesinnamespace' ],
91  );
92  }
93  }
94 
101  public static function intFunction( $parser, $part1 = '', ...$params ) {
102  if ( strval( $part1 ) !== '' ) {
103  $message = wfMessage( $part1, $params )
104  ->inLanguage( $parser->getOptions()->getUserLangObj() );
105  return [ $message->plain(), 'noparse' => false ];
106  } else {
107  return [ 'found' => false ];
108  }
109  }
110 
118  public static function formatDate( $parser, $date, $defaultPref = null ) {
119  $lang = $parser->getFunctionLang();
120  $df = MediaWikiServices::getInstance()->getDateFormatterFactory()->get( $lang );
121 
122  $date = trim( $date );
123 
124  $pref = $parser->getOptions()->getDateFormat();
125 
126  // Specify a different default date format other than the normal default
127  // if the user has 'default' for their setting
128  if ( $pref == 'default' && $defaultPref ) {
129  $pref = $defaultPref;
130  }
131 
132  $date = $df->reformat( $pref, $date, [ 'match-whole' ] );
133  return $date;
134  }
135 
136  public static function ns( $parser, $part1 = '' ) {
137  if ( intval( $part1 ) || $part1 == "0" ) {
138  $index = intval( $part1 );
139  } else {
140  $index = $parser->getContentLanguage()->getNsIndex( str_replace( ' ', '_', $part1 ) );
141  }
142  if ( $index !== false ) {
143  return $parser->getContentLanguage()->getFormattedNsText( $index );
144  } else {
145  return [ 'found' => false ];
146  }
147  }
148 
149  public static function nse( $parser, $part1 = '' ) {
150  $ret = self::ns( $parser, $part1 );
151  if ( is_string( $ret ) ) {
152  $ret = wfUrlencode( str_replace( ' ', '_', $ret ) );
153  }
154  return $ret;
155  }
156 
169  public static function urlencode( $parser, $s = '', $arg = null ) {
170  static $magicWords = null;
171  if ( $magicWords === null ) {
172  $magicWords =
173  $parser->getMagicWordFactory()->newArray( [ 'url_path', 'url_query', 'url_wiki' ] );
174  }
175  switch ( $magicWords->matchStartToEnd( $arg ) ) {
176  // Encode as though it's a wiki page, '_' for ' '.
177  case 'url_wiki':
178  $func = 'wfUrlencode';
179  $s = str_replace( ' ', '_', $s );
180  break;
181 
182  // Encode for an HTTP Path, '%20' for ' '.
183  case 'url_path':
184  $func = 'rawurlencode';
185  break;
186 
187  // Encode for HTTP query, '+' for ' '.
188  case 'url_query':
189  default:
190  $func = 'urlencode';
191  }
192  // See T105242, where the choice to kill markers and various
193  // other options were discussed.
194  return $func( $parser->killMarkers( $s ) );
195  }
196 
197  public static function lcfirst( $parser, $s = '' ) {
198  return $parser->getContentLanguage()->lcfirst( $s );
199  }
200 
201  public static function ucfirst( $parser, $s = '' ) {
202  return $parser->getContentLanguage()->ucfirst( $s );
203  }
204 
210  public static function lc( $parser, $s = '' ) {
211  return $parser->markerSkipCallback( $s, [ $parser->getContentLanguage(), 'lc' ] );
212  }
213 
219  public static function uc( $parser, $s = '' ) {
220  return $parser->markerSkipCallback( $s, [ $parser->getContentLanguage(), 'uc' ] );
221  }
222 
223  public static function localurl( $parser, $s = '', $arg = null ) {
224  return self::urlFunction( 'getLocalURL', $s, $arg );
225  }
226 
227  public static function localurle( $parser, $s = '', $arg = null ) {
228  $temp = self::urlFunction( 'getLocalURL', $s, $arg );
229  if ( !is_string( $temp ) ) {
230  return $temp;
231  } else {
232  return htmlspecialchars( $temp );
233  }
234  }
235 
236  public static function fullurl( $parser, $s = '', $arg = null ) {
237  return self::urlFunction( 'getFullURL', $s, $arg );
238  }
239 
240  public static function fullurle( $parser, $s = '', $arg = null ) {
241  $temp = self::urlFunction( 'getFullURL', $s, $arg );
242  if ( !is_string( $temp ) ) {
243  return $temp;
244  } else {
245  return htmlspecialchars( $temp );
246  }
247  }
248 
249  public static function canonicalurl( $parser, $s = '', $arg = null ) {
250  return self::urlFunction( 'getCanonicalURL', $s, $arg );
251  }
252 
253  public static function canonicalurle( $parser, $s = '', $arg = null ) {
254  $temp = self::urlFunction( 'getCanonicalURL', $s, $arg );
255  if ( !is_string( $temp ) ) {
256  return $temp;
257  } else {
258  return htmlspecialchars( $temp );
259  }
260  }
261 
262  public static function urlFunction( $func, $s = '', $arg = null ) {
264  # Due to order of execution of a lot of bits, the values might be encoded
265  # before arriving here; if that's true, then the title can't be created
266  # and the variable will fail. If we can't get a decent title from the first
267  # attempt, url-decode and try for a second.
268  if ( $title === null ) {
269  $title = Title::newFromURL( urldecode( $s ) );
270  }
271  if ( $title !== null ) {
272  # Convert NS_MEDIA -> NS_FILE
273  if ( $title->inNamespace( NS_MEDIA ) ) {
274  $title = Title::makeTitle( NS_FILE, $title->getDBkey() );
275  }
276  if ( $arg !== null ) {
277  $text = $title->$func( $arg );
278  } else {
279  $text = $title->$func();
280  }
281  return $text;
282  } else {
283  return [ 'found' => false ];
284  }
285  }
286 
293  public static function formatnum( $parser, $num = '', $arg = null ) {
294  if ( self::matchAgainstMagicword( $parser->getMagicWordFactory(), 'rawsuffix', $arg ) ) {
295  $func = [ $parser->getFunctionLang(), 'parseFormattedNumber' ];
296  } elseif (
297  self::matchAgainstMagicword( $parser->getMagicWordFactory(), 'nocommafysuffix', $arg )
298  ) {
299  $func = [ $parser->getFunctionLang(), 'formatNumNoSeparators' ];
300  $func = self::getLegacyFormatNum( $parser, $func );
301  } else {
302  $func = [ $parser->getFunctionLang(), 'formatNum' ];
303  $func = self::getLegacyFormatNum( $parser, $func );
304  }
305  return $parser->markerSkipCallback( $num, $func );
306  }
307 
314  private static function getLegacyFormatNum( $parser, $callback ) {
315  // For historic reasons, the formatNum parser function will
316  // take arguments which are not actually formatted numbers,
317  // which then trigger deprecation warnings in Language::formatNum*.
318  // Instead emit a tracking category instead to allow linting.
319  return static function ( $number ) use ( $parser, $callback ) {
320  $validNumberRe = '(-(?=[\d\.]))?(\d+|(?=\.\d))(\.\d*)?([Ee][-+]?\d+)?';
321  if (
322  !is_numeric( $number ) &&
323  $number !== (string)NAN &&
324  $number !== (string)INF &&
325  $number !== (string)-INF
326  ) {
327  $parser->addTrackingCategory( 'nonnumeric-formatnum' );
328  // Don't split on NAN/INF in the legacy case since they are
329  // likely to be found embedded inside non-numeric text.
330  return preg_replace_callback( "/{$validNumberRe}/", static function ( $m ) use ( $callback ) {
331  return call_user_func( $callback, $m[0] );
332  }, $number );
333  }
334  return call_user_func( $callback, $number );
335  };
336  }
337 
344  public static function grammar( $parser, $case = '', $word = '' ) {
345  $word = $parser->killMarkers( $word );
346  return $parser->getFunctionLang()->convertGrammar( $word, $case );
347  }
348 
355  public static function gender( $parser, $username, ...$forms ) {
356  // Some shortcuts to avoid loading user data unnecessarily
357  if ( count( $forms ) === 0 ) {
358  return '';
359  } elseif ( count( $forms ) === 1 ) {
360  return $forms[0];
361  }
362 
363  $username = trim( $username );
364 
365  $userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
366  $gender = $userOptionsLookup->getDefaultOption( 'gender' );
367 
368  // allow prefix and normalize (e.g. "&#42;foo" -> "*foo" ).
369  $title = Title::newFromText( $username, NS_USER );
370 
371  if ( $title && $title->inNamespace( NS_USER ) ) {
372  $username = $title->getText();
373  }
374 
375  // check parameter, or use the ParserOptions if in interface message
376  $user = User::newFromName( $username );
377  $genderCache = MediaWikiServices::getInstance()->getGenderCache();
378  if ( $user ) {
379  $gender = $genderCache->getGenderOf( $user, __METHOD__ );
380  } elseif ( $username === '' && $parser->getOptions()->getInterfaceMessage() ) {
381  $gender = $genderCache->getGenderOf( $parser->getOptions()->getUserIdentity(), __METHOD__ );
382  }
383  $ret = $parser->getFunctionLang()->gender( $gender, $forms );
384  return $ret;
385  }
386 
393  public static function plural( $parser, $text = '', ...$forms ) {
394  $text = $parser->getFunctionLang()->parseFormattedNumber( $text );
395  settype( $text, ctype_digit( $text ) ? 'int' : 'float' );
396  return $parser->getFunctionLang()->convertPlural( $text, $forms );
397  }
398 
404  public static function bidi( $parser, $text = '' ) {
405  return $parser->getFunctionLang()->embedBidi( $text );
406  }
407 
413  private static function getTargetLanguageConverter( Parser $parser ): ILanguageConverter {
414  return MediaWikiServices::getInstance()->getLanguageConverterFactory()
415  ->getLanguageConverter( $parser->getTargetLanguage() );
416  }
417 
427  public static function displaytitle( $parser, $text = '', $uarg = '' ) {
429 
430  static $magicWords = null;
431  if ( $magicWords === null ) {
432  $magicWords = $parser->getMagicWordFactory()->newArray(
433  [ 'displaytitle_noerror', 'displaytitle_noreplace' ] );
434  }
435  $arg = $magicWords->matchStartToEnd( $uarg );
436 
437  // parse a limited subset of wiki markup (just the single quote items)
438  $text = $parser->doQuotes( $text );
439 
440  // remove stripped text (e.g. the UNIQ-QINU stuff) that was generated by tag extensions/whatever
441  $text = $parser->killMarkers( $text );
442 
443  // list of disallowed tags for DISPLAYTITLE
444  // these will be escaped even though they are allowed in normal wiki text
445  $bad = [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'blockquote', 'ol', 'ul', 'li', 'hr',
446  'table', 'tr', 'th', 'td', 'dl', 'dd', 'caption', 'p', 'ruby', 'rb', 'rt', 'rtc', 'rp', 'br' ];
447 
448  // disallow some styles that could be used to bypass $wgRestrictDisplayTitle
449  if ( $wgRestrictDisplayTitle ) {
450  $htmlTagsCallback = static function ( &$params ) {
451  $decoded = Sanitizer::decodeTagAttributes( $params );
452 
453  if ( isset( $decoded['style'] ) ) {
454  // this is called later anyway, but we need it right now for the regexes below to be safe
455  // calling it twice doesn't hurt
456  $decoded['style'] = Sanitizer::checkCss( $decoded['style'] );
457 
458  if ( preg_match( '/(display|user-select|visibility)\s*:/i', $decoded['style'] ) ) {
459  $decoded['style'] = '/* attempt to bypass $wgRestrictDisplayTitle */';
460  }
461  }
462 
463  $params = Sanitizer::safeEncodeTagAttributes( $decoded );
464  };
465  } else {
466  $htmlTagsCallback = null;
467  }
468 
469  // only requested titles that normalize to the actual title are allowed through
470  // if $wgRestrictDisplayTitle is true (it is by default)
471  // mimic the escaping process that occurs in OutputPage::setPageTitle
473  $text,
474  $htmlTagsCallback,
475  [],
476  [],
477  $bad
478  ) );
480 
481  if ( !$wgRestrictDisplayTitle ||
482  ( $title instanceof Title
483  && !$title->hasFragment()
484  && $title->equals( $parser->getTitle() ) )
485  ) {
486  $old = $parser->getOutput()->getPageProperty( 'displaytitle' );
487  if ( $old === false || $arg !== 'displaytitle_noreplace' ) {
488  $parser->getOutput()->setDisplayTitle( $text );
489  }
490  if ( $old !== false && $old !== $text && !$arg ) {
491 
492  $converter = self::getTargetLanguageConverter( $parser );
493  return '<span class="error">' .
494  wfMessage( 'duplicate-displaytitle',
495  // Message should be parsed, but these params should only be escaped.
496  $converter->markNoConversion( wfEscapeWikiText( $old ) ),
497  $converter->markNoConversion( wfEscapeWikiText( $text ) )
498  )->inContentLanguage()->text() .
499  '</span>';
500  } else {
501  return '';
502  }
503  } else {
504  $parser->getOutput()->addWarningMsg(
505  'restricted-displaytitle',
506  // Message should be parsed, but this param should only be escaped.
507  Message::plaintextParam( $text )
508  );
509  $parser->addTrackingCategory( 'restricted-displaytitle-ignored' );
510  }
511  }
512 
522  private static function matchAgainstMagicword(
523  MagicWordFactory $magicWordFactory, $magicword, $value
524  ) {
525  $value = trim( strval( $value ) );
526  if ( $value === '' ) {
527  return false;
528  }
529  $mwObject = $magicWordFactory->get( $magicword );
530  return $mwObject->matchStartToEnd( $value );
531  }
532 
542  public static function formatRaw(
543  $num, $raw, $language, MagicWordFactory $magicWordFactory = null
544  ) {
545  if ( $raw !== null && !$magicWordFactory ) {
546  $magicWordFactory = MediaWikiServices::getInstance()->getMagicWordFactory();
547  }
548  if (
549  $raw !== null && self::matchAgainstMagicword( $magicWordFactory, 'rawsuffix', $raw )
550  ) {
551  return $num;
552  } else {
553  return $language->formatNum( $num );
554  }
555  }
556 
557  public static function numberofpages( $parser, $raw = null ) {
558  return self::formatRaw( SiteStats::pages(), $raw, $parser->getFunctionLang() );
559  }
560 
561  public static function numberofusers( $parser, $raw = null ) {
562  return self::formatRaw( SiteStats::users(), $raw, $parser->getFunctionLang() );
563  }
564 
565  public static function numberofactiveusers( $parser, $raw = null ) {
566  return self::formatRaw( SiteStats::activeUsers(), $raw, $parser->getFunctionLang() );
567  }
568 
569  public static function numberofarticles( $parser, $raw = null ) {
570  return self::formatRaw( SiteStats::articles(), $raw, $parser->getFunctionLang() );
571  }
572 
573  public static function numberoffiles( $parser, $raw = null ) {
574  return self::formatRaw( SiteStats::images(), $raw, $parser->getFunctionLang() );
575  }
576 
577  public static function numberofadmins( $parser, $raw = null ) {
578  return self::formatRaw(
579  SiteStats::numberingroup( 'sysop' ),
580  $raw,
581  $parser->getFunctionLang()
582  );
583  }
584 
585  public static function numberofedits( $parser, $raw = null ) {
586  return self::formatRaw( SiteStats::edits(), $raw, $parser->getFunctionLang() );
587  }
588 
589  public static function pagesinnamespace( $parser, $namespace = 0, $raw = null ) {
590  return self::formatRaw(
591  SiteStats::pagesInNs( intval( $namespace ) ),
592  $raw,
593  $parser->getFunctionLang()
594  );
595  }
596 
597  public static function numberingroup( $parser, $name = '', $raw = null ) {
598  return self::formatRaw(
599  SiteStats::numberingroup( strtolower( $name ) ),
600  $raw,
601  $parser->getFunctionLang()
602  );
603  }
604 
614  public static function mwnamespace( $parser, $title = null ) {
616  if ( $t === null ) {
617  return '';
618  }
619  return str_replace( '_', ' ', $t->getNsText() );
620  }
621 
622  public static function namespacee( $parser, $title = null ) {
624  if ( $t === null ) {
625  return '';
626  }
627  return wfUrlencode( $t->getNsText() );
628  }
629 
630  public static function namespacenumber( $parser, $title = null ) {
632  if ( $t === null ) {
633  return '';
634  }
635  return $t->getNamespace();
636  }
637 
638  public static function talkspace( $parser, $title = null ) {
640  if ( $t === null || !$t->canHaveTalkPage() ) {
641  return '';
642  }
643  return str_replace( '_', ' ', $t->getTalkNsText() );
644  }
645 
646  public static function talkspacee( $parser, $title = null ) {
648  if ( $t === null || !$t->canHaveTalkPage() ) {
649  return '';
650  }
651  return wfUrlencode( $t->getTalkNsText() );
652  }
653 
654  public static function subjectspace( $parser, $title = null ) {
656  if ( $t === null ) {
657  return '';
658  }
659  return str_replace( '_', ' ', $t->getSubjectNsText() );
660  }
661 
662  public static function subjectspacee( $parser, $title = null ) {
664  if ( $t === null ) {
665  return '';
666  }
667  return wfUrlencode( $t->getSubjectNsText() );
668  }
669 
677  public static function pagename( $parser, $title = null ) {
679  if ( $t === null ) {
680  return '';
681  }
682  return wfEscapeWikiText( $t->getText() );
683  }
684 
685  public static function pagenamee( $parser, $title = null ) {
687  if ( $t === null ) {
688  return '';
689  }
690  return wfEscapeWikiText( $t->getPartialURL() );
691  }
692 
693  public static function fullpagename( $parser, $title = null ) {
695  if ( $t === null || !$t->canHaveTalkPage() ) {
696  return '';
697  }
698  return wfEscapeWikiText( $t->getPrefixedText() );
699  }
700 
701  public static function fullpagenamee( $parser, $title = null ) {
703  if ( $t === null || !$t->canHaveTalkPage() ) {
704  return '';
705  }
706  return wfEscapeWikiText( $t->getPrefixedURL() );
707  }
708 
709  public static function subpagename( $parser, $title = null ) {
711  if ( $t === null ) {
712  return '';
713  }
714  return wfEscapeWikiText( $t->getSubpageText() );
715  }
716 
717  public static function subpagenamee( $parser, $title = null ) {
719  if ( $t === null ) {
720  return '';
721  }
722  return wfEscapeWikiText( $t->getSubpageUrlForm() );
723  }
724 
725  public static function rootpagename( $parser, $title = null ) {
727  if ( $t === null ) {
728  return '';
729  }
730  return wfEscapeWikiText( $t->getRootText() );
731  }
732 
733  public static function rootpagenamee( $parser, $title = null ) {
735  if ( $t === null ) {
736  return '';
737  }
738  return wfEscapeWikiText( wfUrlencode( str_replace( ' ', '_', $t->getRootText() ) ) );
739  }
740 
741  public static function basepagename( $parser, $title = null ) {
743  if ( $t === null ) {
744  return '';
745  }
746  return wfEscapeWikiText( $t->getBaseText() );
747  }
748 
749  public static function basepagenamee( $parser, $title = null ) {
751  if ( $t === null ) {
752  return '';
753  }
754  return wfEscapeWikiText( wfUrlencode( str_replace( ' ', '_', $t->getBaseText() ) ) );
755  }
756 
757  public static function talkpagename( $parser, $title = null ) {
759  if ( $t === null || !$t->canHaveTalkPage() ) {
760  return '';
761  }
762  return wfEscapeWikiText( $t->getTalkPage()->getPrefixedText() );
763  }
764 
765  public static function talkpagenamee( $parser, $title = null ) {
767  if ( $t === null || !$t->canHaveTalkPage() ) {
768  return '';
769  }
770  return wfEscapeWikiText( $t->getTalkPage()->getPrefixedURL() );
771  }
772 
773  public static function subjectpagename( $parser, $title = null ) {
775  if ( $t === null ) {
776  return '';
777  }
778  return wfEscapeWikiText( $t->getSubjectPage()->getPrefixedText() );
779  }
780 
781  public static function subjectpagenamee( $parser, $title = null ) {
783  if ( $t === null ) {
784  return '';
785  }
786  return wfEscapeWikiText( $t->getSubjectPage()->getPrefixedURL() );
787  }
788 
799  public static function pagesincategory( $parser, $name = '', $arg1 = null, $arg2 = null ) {
800  static $magicWords = null;
801  if ( $magicWords === null ) {
802  $magicWords = $parser->getMagicWordFactory()->newArray( [
803  'pagesincategory_all',
804  'pagesincategory_pages',
805  'pagesincategory_subcats',
806  'pagesincategory_files'
807  ] );
808  }
809  static $cache = [];
810 
811  // split the given option to its variable
812  if ( self::matchAgainstMagicword( $parser->getMagicWordFactory(), 'rawsuffix', $arg1 ) ) {
813  // {{pagesincategory:|raw[|type]}}
814  $raw = $arg1;
815  $type = $magicWords->matchStartToEnd( $arg2 );
816  } else {
817  // {{pagesincategory:[|type[|raw]]}}
818  $type = $magicWords->matchStartToEnd( $arg1 );
819  $raw = $arg2;
820  }
821  if ( !$type ) { // backward compatibility
822  $type = 'pagesincategory_all';
823  }
824 
826  if ( !$title ) { # invalid title
827  return self::formatRaw( 0, $raw, $parser->getFunctionLang() );
828  }
829  $languageConverter = MediaWikiServices::getInstance()
830  ->getLanguageConverterFactory()
831  ->getLanguageConverter( $parser->getContentLanguage() );
832  $languageConverter->findVariantLink( $name, $title, true );
833 
834  // Normalize name for cache
835  $name = $title->getDBkey();
836 
837  if ( !isset( $cache[$name] ) ) {
838  $category = Category::newFromTitle( $title );
839 
840  $allCount = $subcatCount = $fileCount = $pagesCount = 0;
841  if ( $parser->incrementExpensiveFunctionCount() ) {
842  // $allCount is the total number of cat members,
843  // not the count of how many members are normal pages.
844  $allCount = (int)$category->getPageCount();
845  $subcatCount = (int)$category->getSubcatCount();
846  $fileCount = (int)$category->getFileCount();
847  $pagesCount = $allCount - $subcatCount - $fileCount;
848  }
849  $cache[$name]['pagesincategory_all'] = $allCount;
850  $cache[$name]['pagesincategory_pages'] = $pagesCount;
851  $cache[$name]['pagesincategory_subcats'] = $subcatCount;
852  $cache[$name]['pagesincategory_files'] = $fileCount;
853  }
854 
855  $count = $cache[$name][$type];
856  return self::formatRaw( $count, $raw, $parser->getFunctionLang() );
857  }
858 
868  public static function pagesize( $parser, $page = '', $raw = null ) {
869  $title = Title::newFromText( $page );
870 
871  if ( !is_object( $title ) ) {
872  return self::formatRaw( 0, $raw, $parser->getFunctionLang() );
873  }
874 
875  // fetch revision from cache/database and return the value
876  $rev = self::getCachedRevisionObject( $parser, $title, ParserOutputFlags::VARY_REVISION_SHA1 );
877  $length = $rev ? $rev->getSize() : 0;
878  if ( $length === null ) {
879  // We've had bugs where rev_len was not being recorded for empty pages, see T135414
880  $length = 0;
881  }
882  return self::formatRaw( $length, $raw, $parser->getFunctionLang() );
883  }
884 
897  public static function protectionlevel( $parser, $type = '', $title = '' ) {
898  $titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
899  if ( $titleObject->areRestrictionsLoaded() || $parser->incrementExpensiveFunctionCount() ) {
900  $restrictions = $titleObject->getRestrictions( strtolower( $type ) );
901  # Title::getRestrictions returns an array, its possible it may have
902  # multiple values in the future
903  return implode( ',', $restrictions );
904  }
905  return '';
906  }
907 
920  public static function protectionexpiry( $parser, $type = '', $title = '' ) {
921  $titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
922  if ( $titleObject->areRestrictionsLoaded() || $parser->incrementExpensiveFunctionCount() ) {
923  $expiry = $titleObject->getRestrictionExpiry( strtolower( $type ) );
924  // getRestrictionExpiry() returns false on invalid type; trying to
925  // match protectionlevel() function that returns empty string instead
926  if ( $expiry === false ) {
927  $expiry = '';
928  }
929  return $expiry;
930  }
931  return '';
932  }
933 
941  public static function language( $parser, $code = '', $inLanguage = '' ) {
942  $code = strtolower( $code );
943  $inLanguage = strtolower( $inLanguage );
944  $lang = MediaWikiServices::getInstance()
945  ->getLanguageNameUtils()
946  ->getLanguageName( $code, $inLanguage );
947  return $lang !== '' ? $lang : LanguageCode::bcp47( $code );
948  }
949 
959  public static function pad(
960  $parser, $string, $length, $padding = '0', $direction = STR_PAD_RIGHT
961  ) {
962  $padding = $parser->killMarkers( $padding );
963  $lengthOfPadding = mb_strlen( $padding );
964  if ( $lengthOfPadding == 0 ) {
965  return $string;
966  }
967 
968  # The remaining length to add counts down to 0 as padding is added
969  $length = min( (int)$length, 500 ) - mb_strlen( $string );
970  if ( $length <= 0 ) {
971  // Nothing to add
972  return $string;
973  }
974 
975  # $finalPadding is just $padding repeated enough times so that
976  # mb_strlen( $string ) + mb_strlen( $finalPadding ) == $length
977  $finalPadding = '';
978  while ( $length > 0 ) {
979  # If $length < $lengthofPadding, truncate $padding so we get the
980  # exact length desired.
981  $finalPadding .= mb_substr( $padding, 0, $length );
982  $length -= $lengthOfPadding;
983  }
984 
985  if ( $direction == STR_PAD_LEFT ) {
986  return $finalPadding . $string;
987  } else {
988  return $string . $finalPadding;
989  }
990  }
991 
992  public static function padleft( $parser, $string = '', $length = 0, $padding = '0' ) {
993  return self::pad( $parser, $string, $length, $padding, STR_PAD_LEFT );
994  }
995 
996  public static function padright( $parser, $string = '', $length = 0, $padding = '0' ) {
997  return self::pad( $parser, $string, $length, $padding );
998  }
999 
1005  public static function anchorencode( $parser, $text ) {
1006  $text = $parser->killMarkers( $text );
1007  $section = (string)substr( $parser->guessSectionNameFromWikiText( $text ), 1 );
1008  return Sanitizer::safeEncodeAttribute( $section );
1009  }
1010 
1011  public static function special( $parser, $text ) {
1012  list( $page, $subpage ) = MediaWikiServices::getInstance()->getSpecialPageFactory()->
1013  resolveAlias( $text );
1014  if ( $page ) {
1015  $title = SpecialPage::getTitleFor( $page, $subpage );
1016  return $title->getPrefixedText();
1017  } else {
1018  // unknown special page, just use the given text as its title, if at all possible
1020  return $title ? $title->getPrefixedText() : self::special( $parser, 'Badtitle' );
1021  }
1022  }
1023 
1024  public static function speciale( $parser, $text ) {
1025  return wfUrlencode( str_replace( ' ', '_', self::special( $parser, $text ) ) );
1026  }
1027 
1036  public static function defaultsort( $parser, $text, $uarg = '' ) {
1037  static $magicWords = null;
1038  if ( $magicWords === null ) {
1039  $magicWords = $parser->getMagicWordFactory()->newArray(
1040  [ 'defaultsort_noerror', 'defaultsort_noreplace' ] );
1041  }
1042  $arg = $magicWords->matchStartToEnd( $uarg );
1043 
1044  $text = trim( $text );
1045  if ( strlen( $text ) == 0 ) {
1046  return '';
1047  }
1048  $old = $parser->getCustomDefaultSort();
1049  if ( $old === false || $arg !== 'defaultsort_noreplace' ) {
1050  $parser->setDefaultSort( $text );
1051  }
1052 
1053  if ( $old === false || $old == $text || $arg ) {
1054  return '';
1055  } else {
1056  $converter = $parser->getTargetLanguageConverter();
1057  return '<span class="error">' .
1058  wfMessage( 'duplicate-defaultsort',
1059  // Message should be parsed, but these params should only be escaped.
1060  $converter->markNoConversion( wfEscapeWikiText( $old ) ),
1061  $converter->markNoConversion( wfEscapeWikiText( $text ) )
1062  )->inContentLanguage()->text() .
1063  '</span>';
1064  }
1065  }
1066 
1078  public static function filepath( $parser, $name = '', $argA = '', $argB = '' ) {
1079  $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name );
1080 
1081  if ( $argA == 'nowiki' ) {
1082  // {{filepath: | option [| size] }}
1083  $isNowiki = true;
1084  $parsedWidthParam = Parser::parseWidthParam( $argB );
1085  } else {
1086  // {{filepath: [| size [|option]] }}
1087  $parsedWidthParam = Parser::parseWidthParam( $argA );
1088  $isNowiki = ( $argB == 'nowiki' );
1089  }
1090 
1091  if ( $file ) {
1092  $url = $file->getFullUrl();
1093 
1094  // If a size is requested...
1095  if ( count( $parsedWidthParam ) ) {
1096  $mto = $file->transform( $parsedWidthParam );
1097  // ... and we can
1098  if ( $mto && !$mto->isError() ) {
1099  // ... change the URL to point to a thumbnail.
1100  $url = wfExpandUrl( $mto->getUrl(), PROTO_RELATIVE );
1101  }
1102  }
1103  if ( $isNowiki ) {
1104  return [ $url, 'nowiki' => true ];
1105  }
1106  return $url;
1107  } else {
1108  return '';
1109  }
1110  }
1111 
1119  public static function tagObj( $parser, $frame, $args ) {
1120  if ( !count( $args ) ) {
1121  return '';
1122  }
1123  $tagName = strtolower( trim( $frame->expand( array_shift( $args ) ) ) );
1124 
1125  if ( count( $args ) ) {
1126  $inner = $frame->expand( array_shift( $args ) );
1127  } else {
1128  $inner = null;
1129  }
1130 
1131  $attributes = [];
1132  foreach ( $args as $arg ) {
1133  $bits = $arg->splitArg();
1134  if ( strval( $bits['index'] ) === '' ) {
1135  $name = trim( $frame->expand( $bits['name'], PPFrame::STRIP_COMMENTS ) );
1136  $value = trim( $frame->expand( $bits['value'] ) );
1137  if ( preg_match( '/^(?:["\'](.+)["\']|""|\'\')$/s', $value, $m ) ) {
1138  $value = $m[1] ?? '';
1139  }
1140  $attributes[$name] = $value;
1141  }
1142  }
1143 
1144  $stripList = $parser->getStripList();
1145  if ( !in_array( $tagName, $stripList ) ) {
1146  // we can't handle this tag (at least not now), so just re-emit it as an ordinary tag
1147  $attrText = '';
1148  foreach ( $attributes as $name => $value ) {
1149  $attrText .= ' ' . htmlspecialchars( $name ) . '="' . htmlspecialchars( $value ) . '"';
1150  }
1151  if ( $inner === null ) {
1152  return "<$tagName$attrText/>";
1153  }
1154  return "<$tagName$attrText>$inner</$tagName>";
1155  }
1156 
1157  $params = [
1158  'name' => $tagName,
1159  'inner' => $inner,
1160  'attributes' => $attributes,
1161  'close' => "</$tagName>",
1162  ];
1163  return $parser->extensionSubstitution( $params, $frame );
1164  }
1165 
1179  private static function getCachedRevisionObject( $parser, $title, $vary ) {
1180  if ( !$title ) {
1181  return null;
1182  }
1183 
1184  $revisionRecord = null;
1185 
1186  $isSelfReferential = $title->equals( $parser->getTitle() );
1187  if ( $isSelfReferential ) {
1188  // Revision is for the same title that is currently being parsed. Only use the last
1189  // saved revision, regardless of Parser::getRevisionId() or fake revision injection
1190  // callbacks against the current title.
1191  $parserRevisionRecord = $parser->getRevisionRecordObject();
1192  if ( $parserRevisionRecord && $parserRevisionRecord->isCurrent() ) {
1193  $revisionRecord = $parserRevisionRecord;
1194  }
1195  }
1196 
1197  $parserOutput = $parser->getOutput();
1198  if ( !$revisionRecord ) {
1199  if (
1200  !$parser->isCurrentRevisionOfTitleCached( $title ) &&
1201  !$parser->incrementExpensiveFunctionCount()
1202  ) {
1203  return null; // not allowed
1204  }
1205  // Get the current revision, ignoring Parser::getRevisionId() being null/old
1206  $revisionRecord = $parser->fetchCurrentRevisionRecordOfTitle( $title );
1207  if ( !$revisionRecord ) {
1208  // Convert `false` error return to `null`
1209  $revisionRecord = null;
1210  }
1211  // Register dependency in templatelinks
1212  $parserOutput->addTemplate(
1213  $title,
1214  $revisionRecord ? $revisionRecord->getPageId() : 0,
1215  $revisionRecord ? $revisionRecord->getId() : 0
1216  );
1217  }
1218 
1219  if ( $isSelfReferential ) {
1220  wfDebug( __METHOD__ . ": used current revision, setting $vary" );
1221  // Upon page save, the result of the parser function using this might change
1222  $parserOutput->setOutputFlag( $vary );
1223  if ( $vary === ParserOutputFlags::VARY_REVISION_SHA1 && $revisionRecord ) {
1224  try {
1225  $sha1 = $revisionRecord->getSha1();
1226  } catch ( RevisionAccessException $e ) {
1227  $sha1 = null;
1228  }
1229  $parserOutput->setRevisionUsedSha1Base36( $sha1 );
1230  }
1231  }
1232 
1233  return $revisionRecord;
1234  }
1235 
1243  public static function pageid( $parser, $title = null ) {
1245  if ( !$t ) {
1246  return '';
1247  } elseif ( !$t->canExist() || $t->isExternal() ) {
1248  return 0; // e.g. special page or interwiki link
1249  }
1250 
1251  $parserOutput = $parser->getOutput();
1252 
1253  if ( $t->equals( $parser->getTitle() ) ) {
1254  // Revision is for the same title that is currently being parsed.
1255  // Use the title from Parser in case a new page ID was injected into it.
1256  $parserOutput->setOutputFlag( ParserOutputFlags::VARY_PAGE_ID );
1257  $id = $parser->getTitle()->getArticleID();
1258  if ( $id ) {
1259  $parserOutput->setSpeculativePageIdUsed( $id );
1260  }
1261 
1262  return $id;
1263  }
1264 
1265  // Check the link cache for the title
1266  $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1267  $pdbk = $t->getPrefixedDBkey();
1268  $id = $linkCache->getGoodLinkID( $pdbk );
1269  if ( $id != 0 || $linkCache->isBadLink( $pdbk ) ) {
1270  $parserOutput->addLink( $t, $id );
1271 
1272  return $id;
1273  }
1274 
1275  // We need to load it from the DB, so mark expensive
1276  if ( $parser->incrementExpensiveFunctionCount() ) {
1277  $id = $t->getArticleID();
1278  $parserOutput->addLink( $t, $id );
1279 
1280  return $id;
1281  }
1282 
1283  return null;
1284  }
1285 
1293  public static function revisionid( $parser, $title = null ) {
1295  if ( $t === null ) {
1296  return '';
1297  }
1298 
1299  $services = MediaWikiServices::getInstance();
1300  if (
1301  $t->equals( $parser->getTitle() ) &&
1302  $services->getMainConfig()->get( 'MiserMode' ) &&
1303  !$parser->getOptions()->getInterfaceMessage() &&
1304  // @TODO: disallow this word on all namespaces (T235957)
1305  $services->getNamespaceInfo()->isSubject( $t->getNamespace() )
1306  ) {
1307  // Use a stub result instead of the actual revision ID in order to avoid
1308  // double parses on page save but still allow preview detection (T137900)
1309  if ( $parser->getRevisionId() || $parser->getOptions()->getSpeculativeRevId() ) {
1310  return '-';
1311  } else {
1312  $parser->getOutput()->setOutputFlag( ParserOutputFlags::VARY_REVISION_EXISTS );
1313  return '';
1314  }
1315  }
1316  // fetch revision from cache/database and return the value
1317  $rev = self::getCachedRevisionObject( $parser, $t, ParserOutputFlags::VARY_REVISION_ID );
1318  return $rev ? $rev->getId() : '';
1319  }
1320 
1328  public static function revisionday( $parser, $title = null ) {
1330  if ( $t === null ) {
1331  return '';
1332  }
1333  // fetch revision from cache/database and return the value
1334  $rev = self::getCachedRevisionObject( $parser, $t, ParserOutputFlags::VARY_REVISION_TIMESTAMP );
1335  return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'j' ) : '';
1336  }
1337 
1345  public static function revisionday2( $parser, $title = null ) {
1347  if ( $t === null ) {
1348  return '';
1349  }
1350  // fetch revision from cache/database and return the value
1351  $rev = self::getCachedRevisionObject( $parser, $t, ParserOutputFlags::VARY_REVISION_TIMESTAMP );
1352  return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'd' ) : '';
1353  }
1354 
1362  public static function revisionmonth( $parser, $title = null ) {
1364  if ( $t === null ) {
1365  return '';
1366  }
1367  // fetch revision from cache/database and return the value
1368  $rev = self::getCachedRevisionObject( $parser, $t, ParserOutputFlags::VARY_REVISION_TIMESTAMP );
1369  return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'm' ) : '';
1370  }
1371 
1379  public static function revisionmonth1( $parser, $title = null ) {
1381  if ( $t === null ) {
1382  return '';
1383  }
1384  // fetch revision from cache/database and return the value
1385  $rev = self::getCachedRevisionObject( $parser, $t, ParserOutputFlags::VARY_REVISION_TIMESTAMP );
1386  return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'n' ) : '';
1387  }
1388 
1396  public static function revisionyear( $parser, $title = null ) {
1398  if ( $t === null ) {
1399  return '';
1400  }
1401  // fetch revision from cache/database and return the value
1402  $rev = self::getCachedRevisionObject( $parser, $t, ParserOutputFlags::VARY_REVISION_TIMESTAMP );
1403  return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'Y' ) : '';
1404  }
1405 
1413  public static function revisiontimestamp( $parser, $title = null ) {
1415  if ( $t === null ) {
1416  return '';
1417  }
1418  // fetch revision from cache/database and return the value
1419  $rev = self::getCachedRevisionObject( $parser, $t, ParserOutputFlags::VARY_REVISION_TIMESTAMP );
1420  return $rev ? MWTimestamp::getLocalInstance( $rev->getTimestamp() )->format( 'YmdHis' ) : '';
1421  }
1422 
1430  public static function revisionuser( $parser, $title = null ) {
1432  if ( $t === null ) {
1433  return '';
1434  }
1435  // fetch revision from cache/database and return the value
1436  $rev = self::getCachedRevisionObject( $parser, $t, ParserOutputFlags::VARY_USER );
1437  if ( $rev === null ) {
1438  return '';
1439  }
1440  $user = $rev->getUser();
1441  return $user ? $user->getName() : '';
1442  }
1443 
1456  public static function cascadingsources( $parser, $title = '' ) {
1457  $titleObject = Title::newFromText( $title ) ?? $parser->getTitle();
1458  if ( $titleObject->areCascadeProtectionSourcesLoaded()
1459  || $parser->incrementExpensiveFunctionCount()
1460  ) {
1461  $names = [];
1462  $sources = $titleObject->getCascadeProtectionSources();
1463  foreach ( $sources[0] as $sourceTitle ) {
1464  $names[] = $sourceTitle->getPrefixedText();
1465  }
1466  return implode( '|', $names );
1467  }
1468  return '';
1469  }
1470 }
CoreParserFunctions\protectionexpiry
static protectionexpiry( $parser, $type='', $title='')
Returns the requested protection expiry for the current page.
Definition: CoreParserFunctions.php:920
SiteStats\articles
static articles()
Definition: SiteStats.php:103
MediaWiki\Revision\RevisionAccessException
Exception representing a failure to look up a revision.
Definition: RevisionAccessException.php:37
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:377
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:427
MediaWiki\Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
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:1576
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:959
Category\newFromTitle
static newFromTitle(PageIdentity $page)
Factory function.
Definition: Category.php:159
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:203
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:37
CoreParserFunctions\numberofactiveusers
static numberofactiveusers( $parser, $raw=null)
Definition: CoreParserFunctions.php:565
CoreParserFunctions\pageid
static pageid( $parser, $title=null)
Get the pageid of a specified page.
Definition: CoreParserFunctions.php:1243
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:240
CoreParserFunctions\talkpagename
static talkpagename( $parser, $title=null)
Definition: CoreParserFunctions.php:757
Parser\ParserOutputFlags
Definition: ParserOutputFlags.php:41
CoreParserFunctions\rootpagename
static rootpagename( $parser, $title=null)
Definition: CoreParserFunctions.php:725
true
return true
Definition: router.php:90
CoreParserFunctions\tagObj
static tagObj( $parser, $frame, $args)
Parser function to extension tag adaptor.
Definition: CoreParserFunctions.php:1119
CoreParserFunctions\pagesize
static pagesize( $parser, $page='', $raw=null)
Return the size of the given page, or 0 if it's nonexistent.
Definition: CoreParserFunctions.php:868
CoreParserFunctions\formatRaw
static formatRaw( $num, $raw, $language, MagicWordFactory $magicWordFactory=null)
Formats a number according to a language.
Definition: CoreParserFunctions.php:542
SiteStats\pages
static pages()
Definition: SiteStats.php:112
CoreParserFunctions\rootpagenamee
static rootpagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:733
CoreParserFunctions\protectionlevel
static protectionlevel( $parser, $type='', $title='')
Returns the requested protection level for the current page.
Definition: CoreParserFunctions.php:897
wfUrlencode
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
Definition: GlobalFunctions.php:292
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:149
$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:1379
Parser\getTargetLanguage
getTargetLanguage()
Get the target language for the content being parsed.
Definition: Parser.php:1147
User\newFromName
static newFromName( $name, $validate='valid')
Definition: User.php:595
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:1046
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1167
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:131
CoreParserFunctions\namespacenumber
static namespacenumber( $parser, $title=null)
Definition: CoreParserFunctions.php:630
CoreParserFunctions\talkspace
static talkspace( $parser, $title=null)
Definition: CoreParserFunctions.php:638
CoreParserFunctions\gender
static gender( $parser, $username,... $forms)
Definition: CoreParserFunctions.php:355
CoreParserFunctions\grammar
static grammar( $parser, $case='', $word='')
Definition: CoreParserFunctions.php:344
Parser\SFH_OBJECT_ARGS
const SFH_OBJECT_ARGS
Definition: Parser.php:95
CoreParserFunctions\defaultsort
static defaultsort( $parser, $text, $uarg='')
Definition: CoreParserFunctions.php:1036
CoreParserFunctions\revisionday
static revisionday( $parser, $title=null)
Get the day from the last revision of a specified page.
Definition: CoreParserFunctions.php:1328
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:677
SiteStats\images
static images()
Definition: SiteStats.php:139
NS_SPECIAL
const NS_SPECIAL
Definition: Defines.php:53
CoreParserFunctions\revisionid
static revisionid( $parser, $title=null)
Get the id from the last revision of a specified page.
Definition: CoreParserFunctions.php:1293
CoreParserFunctions\talkspacee
static talkspacee( $parser, $title=null)
Definition: CoreParserFunctions.php:646
CoreParserFunctions\localurle
static localurle( $parser, $s='', $arg=null)
Definition: CoreParserFunctions.php:227
PROTO_RELATIVE
const PROTO_RELATIVE
Definition: Defines.php:194
CoreParserFunctions\numberofpages
static numberofpages( $parser, $raw=null)
Definition: CoreParserFunctions.php:557
CoreParserFunctions\basepagenamee
static basepagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:749
Sanitizer\safeEncodeAttribute
static safeEncodeAttribute( $text)
Encode an attribute value for HTML tags, with extra armoring against further wiki processing.
Definition: Sanitizer.php:765
CoreParserFunctions\matchAgainstMagicword
static matchAgainstMagicword(MagicWordFactory $magicWordFactory, $magicword, $value)
Matches the given value against the value of given magic word.
Definition: CoreParserFunctions.php:522
CoreParserFunctions\revisionyear
static revisionyear( $parser, $title=null)
Get the year from the last revision of a specified page.
Definition: CoreParserFunctions.php:1396
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:614
$args
if( $line===false) $args
Definition: mcc.php:124
CoreParserFunctions\fullurle
static fullurle( $parser, $s='', $arg=null)
Definition: CoreParserFunctions.php:240
$title
$title
Definition: testCompression.php:38
CoreParserFunctions\numberofedits
static numberofedits( $parser, $raw=null)
Definition: CoreParserFunctions.php:585
CoreParserFunctions\revisionday2
static revisionday2( $parser, $title=null)
Get the day with leading zeros from the last revision of a specified page.
Definition: CoreParserFunctions.php:1345
CoreParserFunctions\fullurl
static fullurl( $parser, $s='', $arg=null)
Definition: CoreParserFunctions.php:236
CoreParserFunctions\ucfirst
static ucfirst( $parser, $s='')
Definition: CoreParserFunctions.php:201
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:648
CoreParserFunctions\fullpagenamee
static fullpagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:701
CoreParserFunctions\getLegacyFormatNum
static getLegacyFormatNum( $parser, $callback)
Definition: CoreParserFunctions.php:314
CoreParserFunctions\pagenamee
static pagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:685
CoreParserFunctions\ns
static ns( $parser, $part1='')
Definition: CoreParserFunctions.php:136
CoreParserFunctions\subjectpagename
static subjectpagename( $parser, $title=null)
Definition: CoreParserFunctions.php:773
CoreParserFunctions\language
static language( $parser, $code='', $inLanguage='')
Gives language names.
Definition: CoreParserFunctions.php:941
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:894
CoreParserFunctions\revisiontimestamp
static revisiontimestamp( $parser, $title=null)
Get the timestamp from the last revision of a specified page.
Definition: CoreParserFunctions.php:1413
CoreParserFunctions\bidi
static bidi( $parser, $text='')
Definition: CoreParserFunctions.php:404
CoreParserFunctions\urlencode
static urlencode( $parser, $s='', $arg=null)
urlencodes a string according to one of three patterns: (T24474)
Definition: CoreParserFunctions.php:169
CoreParserFunctions\formatDate
static formatDate( $parser, $date, $defaultPref=null)
Definition: CoreParserFunctions.php:118
Title\makeTitleSafe
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:674
CoreParserFunctions\fullpagename
static fullpagename( $parser, $title=null)
Definition: CoreParserFunctions.php:693
$s
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s
Definition: mergeMessageFileList.php:206
SiteStats\pagesInNs
static pagesInNs( $ns)
Definition: SiteStats.php:201
NS_MEDIA
const NS_MEDIA
Definition: Defines.php:52
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:29
Message\plaintextParam
static plaintextParam( $plaintext)
Definition: Message.php:1248
CoreParserFunctions\padleft
static padleft( $parser, $string='', $length=0, $padding='0')
Definition: CoreParserFunctions.php:992
CoreParserFunctions\padright
static padright( $parser, $string='', $length=0, $padding='0')
Definition: CoreParserFunctions.php:996
Title\newFromURL
static newFromURL( $url)
THIS IS NOT THE FUNCTION YOU WANT.
Definition: Title.php:474
CoreParserFunctions\revisionmonth
static revisionmonth( $parser, $title=null)
Get the month with leading zeros from the last revision of a specified page.
Definition: CoreParserFunctions.php:1362
CoreParserFunctions\getTargetLanguageConverter
static getTargetLanguageConverter(Parser $parser)
Shorthand for getting a Language Converter for Target language.
Definition: CoreParserFunctions.php:413
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1440
CoreParserFunctions\subjectspacee
static subjectspacee( $parser, $title=null)
Definition: CoreParserFunctions.php:662
CoreParserFunctions\speciale
static speciale( $parser, $text)
Definition: CoreParserFunctions.php:1024
NS_USER
const NS_USER
Definition: Defines.php:66
CoreParserFunctions\urlFunction
static urlFunction( $func, $s='', $arg=null)
Definition: CoreParserFunctions.php:262
CoreParserFunctions\lc
static lc( $parser, $s='')
Definition: CoreParserFunctions.php:210
CoreParserFunctions\subjectspace
static subjectspace( $parser, $title=null)
Definition: CoreParserFunctions.php:654
Parser
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
Definition: Parser.php:91
CoreParserFunctions\subjectpagenamee
static subjectpagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:781
$userOptionsLookup
UserOptionsLookup $userOptionsLookup
Definition: ApiWatchlistTrait.php:33
Title
Represents a title within MediaWiki.
Definition: Title.php:47
CoreParserFunctions\numberofadmins
static numberofadmins( $parser, $raw=null)
Definition: CoreParserFunctions.php:577
CoreParserFunctions\cascadingsources
static cascadingsources( $parser, $title='')
Returns the sources of any cascading protection acting on a specified page.
Definition: CoreParserFunctions.php:1456
CoreParserFunctions\plural
static plural( $parser, $text='',... $forms)
Definition: CoreParserFunctions.php:393
$magicWords
$magicWords
@phpcs-require-sorted-array
Definition: MessagesAb.php:73
CoreParserFunctions\anchorencode
static anchorencode( $parser, $text)
Definition: CoreParserFunctions.php:1005
$cache
$cache
Definition: mcc.php:33
CoreParserFunctions\uc
static uc( $parser, $s='')
Definition: CoreParserFunctions.php:219
CoreParserFunctions\special
static special( $parser, $text)
Definition: CoreParserFunctions.php:1011
CoreParserFunctions\subpagenamee
static subpagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:717
CoreParserFunctions\filepath
static filepath( $parser, $name='', $argA='', $argB='')
Usage {{filepath|300}}, {{filepath|nowiki}}, {{filepath|nowiki|300}} or {{filepath|300|nowiki}} or {{...
Definition: CoreParserFunctions.php:1078
CoreParserFunctions\namespacee
static namespacee( $parser, $title=null)
Definition: CoreParserFunctions.php:622
CoreParserFunctions\numberofarticles
static numberofarticles( $parser, $raw=null)
Definition: CoreParserFunctions.php:569
CoreParserFunctions\getCachedRevisionObject
static getCachedRevisionObject( $parser, $title, $vary)
Fetched the current revision of the given title and return this.
Definition: CoreParserFunctions.php:1179
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 every Parser.
Definition: CoreParserFunctions.php:33
NS_CATEGORY
const NS_CATEGORY
Definition: Defines.php:78
CoreParserFunctions\subpagename
static subpagename( $parser, $title=null)
Definition: CoreParserFunctions.php:709
CoreParserFunctions\revisionuser
static revisionuser( $parser, $title=null)
Get the user from the last revision of a specified page.
Definition: CoreParserFunctions.php:1430
CoreParserFunctions\numberingroup
static numberingroup( $parser, $name='', $raw=null)
Definition: CoreParserFunctions.php:597
Sanitizer\normalizeCharReferences
static normalizeCharReferences( $text)
Ensure that any entities and character references are legal for XML and XHTML specifically.
Definition: Sanitizer.php:1123
Parser\SFH_NO_HASH
const SFH_NO_HASH
Definition: Parser.php:94
Sanitizer\decodeTagAttributes
static decodeTagAttributes( $text)
Return an associative array of attribute names and values from a partial tag string.
Definition: Sanitizer.php:1004
CoreParserFunctions\numberofusers
static numberofusers( $parser, $raw=null)
Definition: CoreParserFunctions.php:561
$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:799
$wgAllowSlowParserFunctions
$wgAllowSlowParserFunctions
Enable slow parser functions.
Definition: DefaultSettings.php:2662
NS_FILE
const NS_FILE
Definition: Defines.php:70
CoreParserFunctions\numberoffiles
static numberoffiles( $parser, $raw=null)
Definition: CoreParserFunctions.php:573
Parser\parseWidthParam
static parseWidthParam( $value, $parseHeight=true)
Parsed a width param of imagelink like 300px or 200x300px.
Definition: Parser.php:6289
CoreParserFunctions\pagesinnamespace
static pagesinnamespace( $parser, $namespace=0, $raw=null)
Definition: CoreParserFunctions.php:589
$wgRestrictDisplayTitle
$wgRestrictDisplayTitle
For consistency, restrict DISPLAYTITLE to text that normalizes to the same canonical DB key.
Definition: DefaultSettings.php:5057
$wgAllowDisplayTitle
$wgAllowDisplayTitle
Allow DISPLAYTITLE to change title display.
Definition: DefaultSettings.php:5050
CoreParserFunctions\formatnum
static formatnum( $parser, $num='', $arg=null)
Definition: CoreParserFunctions.php:293
CoreParserFunctions\lcfirst
static lcfirst( $parser, $s='')
Definition: CoreParserFunctions.php:197
CoreParserFunctions\canonicalurl
static canonicalurl( $parser, $s='', $arg=null)
Definition: CoreParserFunctions.php:249
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:173
CoreParserFunctions\intFunction
static intFunction( $parser, $part1='',... $params)
Definition: CoreParserFunctions.php:101
SiteStats\edits
static edits()
Definition: SiteStats.php:94
CoreParserFunctions\basepagename
static basepagename( $parser, $title=null)
Definition: CoreParserFunctions.php:741
CoreParserFunctions\canonicalurle
static canonicalurle( $parser, $s='', $arg=null)
Definition: CoreParserFunctions.php:253
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:474
CoreParserFunctions\localurl
static localurl( $parser, $s='', $arg=null)
Definition: CoreParserFunctions.php:223
$type
$type
Definition: testCompression.php:52
CoreParserFunctions\talkpagenamee
static talkpagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:765