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 static function ( $number ) use ( $parser, $callback ) {
319  $validNumberRe = '(-(?=[\d\.]))?(\d+|(?=\.\d))(\.\d*)?([Ee][-+]?\d+)?';
320  if (
321  !is_numeric( $number ) &&
322  $number !== (string)NAN &&
323  $number !== (string)INF &&
324  $number !== (string)-INF
325  ) {
326  $parser->addTrackingCategory( 'nonnumeric-formatnum' );
327  // Don't split on NAN/INF in the legacy case since they are
328  // likely to be found embedded inside non-numeric text.
329  return preg_replace_callback( "/{$validNumberRe}/", static function ( $m ) use ( $callback ) {
330  return call_user_func( $callback, $m[0] );
331  }, $number );
332  }
333  return call_user_func( $callback, $number );
334  };
335  }
336 
343  public static function grammar( $parser, $case = '', $word = '' ) {
344  $word = $parser->killMarkers( $word );
345  return $parser->getFunctionLang()->convertGrammar( $word, $case );
346  }
347 
354  public static function gender( $parser, $username, ...$forms ) {
355  // Some shortcuts to avoid loading user data unnecessarily
356  if ( count( $forms ) === 0 ) {
357  return '';
358  } elseif ( count( $forms ) === 1 ) {
359  return $forms[0];
360  }
361 
362  $username = trim( $username );
363 
364  $userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
365  $gender = $userOptionsLookup->getDefaultOption( 'gender' );
366 
367  // allow prefix and normalize (e.g. "&#42;foo" -> "*foo" ).
368  $title = Title::newFromText( $username, NS_USER );
369 
370  if ( $title && $title->inNamespace( NS_USER ) ) {
371  $username = $title->getText();
372  }
373 
374  // check parameter, or use the ParserOptions if in interface message
375  $user = User::newFromName( $username );
376  $genderCache = MediaWikiServices::getInstance()->getGenderCache();
377  if ( $user ) {
378  $gender = $genderCache->getGenderOf( $user, __METHOD__ );
379  } elseif ( $username === '' && $parser->getOptions()->getInterfaceMessage() ) {
380  $gender = $genderCache->getGenderOf( $parser->getOptions()->getUserIdentity(), __METHOD__ );
381  }
382  $ret = $parser->getFunctionLang()->gender( $gender, $forms );
383  return $ret;
384  }
385 
392  public static function plural( $parser, $text = '', ...$forms ) {
393  $text = $parser->getFunctionLang()->parseFormattedNumber( $text );
394  settype( $text, ctype_digit( $text ) ? 'int' : 'float' );
395  return $parser->getFunctionLang()->convertPlural( $text, $forms );
396  }
397 
403  public static function bidi( $parser, $text = '' ) {
404  return $parser->getFunctionLang()->embedBidi( $text );
405  }
406 
412  private static function getTargetLanguageConverter( Parser $parser ): ILanguageConverter {
413  return MediaWikiServices::getInstance()->getLanguageConverterFactory()
414  ->getLanguageConverter( $parser->getTargetLanguage() );
415  }
416 
426  public static function displaytitle( $parser, $text = '', $uarg = '' ) {
428 
429  static $magicWords = null;
430  if ( $magicWords === null ) {
431  $magicWords = $parser->getMagicWordFactory()->newArray(
432  [ 'displaytitle_noerror', 'displaytitle_noreplace' ] );
433  }
434  $arg = $magicWords->matchStartToEnd( $uarg );
435 
436  // parse a limited subset of wiki markup (just the single quote items)
437  $text = $parser->doQuotes( $text );
438 
439  // remove stripped text (e.g. the UNIQ-QINU stuff) that was generated by tag extensions/whatever
440  $text = $parser->killMarkers( $text );
441 
442  // list of disallowed tags for DISPLAYTITLE
443  // these will be escaped even though they are allowed in normal wiki text
444  $bad = [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'blockquote', 'ol', 'ul', 'li', 'hr',
445  'table', 'tr', 'th', 'td', 'dl', 'dd', 'caption', 'p', 'ruby', 'rb', 'rt', 'rtc', 'rp', 'br' ];
446 
447  // disallow some styles that could be used to bypass $wgRestrictDisplayTitle
448  if ( $wgRestrictDisplayTitle ) {
449  $htmlTagsCallback = static function ( &$params ) {
450  $decoded = Sanitizer::decodeTagAttributes( $params );
451 
452  if ( isset( $decoded['style'] ) ) {
453  // this is called later anyway, but we need it right now for the regexes below to be safe
454  // calling it twice doesn't hurt
455  $decoded['style'] = Sanitizer::checkCss( $decoded['style'] );
456 
457  if ( preg_match( '/(display|user-select|visibility)\s*:/i', $decoded['style'] ) ) {
458  $decoded['style'] = '/* attempt to bypass $wgRestrictDisplayTitle */';
459  }
460  }
461 
462  $params = Sanitizer::safeEncodeTagAttributes( $decoded );
463  };
464  } else {
465  $htmlTagsCallback = null;
466  }
467 
468  // only requested titles that normalize to the actual title are allowed through
469  // if $wgRestrictDisplayTitle is true (it is by default)
470  // mimic the escaping process that occurs in OutputPage::setPageTitle
472  $text,
473  $htmlTagsCallback,
474  [],
475  [],
476  $bad
477  ) );
479 
480  if ( !$wgRestrictDisplayTitle ||
481  ( $title instanceof Title
482  && !$title->hasFragment()
483  && $title->equals( $parser->getTitle() ) )
484  ) {
485  $old = $parser->getOutput()->getProperty( 'displaytitle' );
486  if ( $old === false || $arg !== 'displaytitle_noreplace' ) {
487  $parser->getOutput()->setDisplayTitle( $text );
488  }
489  if ( $old !== false && $old !== $text && !$arg ) {
490 
491  $converter = self::getTargetLanguageConverter( $parser );
492  return '<span class="error">' .
493  wfMessage( 'duplicate-displaytitle',
494  // Message should be parsed, but these params should only be escaped.
495  $converter->markNoConversion( wfEscapeWikiText( $old ) ),
496  $converter->markNoConversion( wfEscapeWikiText( $text ) )
497  )->inContentLanguage()->text() .
498  '</span>';
499  } else {
500  return '';
501  }
502  } else {
503  $parser->getOutput()->addWarning(
504  wfMessage( 'restricted-displaytitle',
505  // Message should be parsed, but this param should only be escaped.
506  wfEscapeWikiText( $text )
507  )->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, '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->getTargetLanguage()->getConverter();
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->setFlag( $vary );
1223  if ( $vary === '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->setFlag( '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()->setFlag( 'vary-revision-exists' );
1313  return '';
1314  }
1315  }
1316  // fetch revision from cache/database and return the value
1317  $rev = self::getCachedRevisionObject( $parser, $t, '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, '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, '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, '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, '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, '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, '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, '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:383
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:426
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:1577
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:193
$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
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:148
$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:1156
User\newFromName
static newFromName( $name, $validate='valid')
Definition: User.php:606
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:1047
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1186
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:107
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:354
CoreParserFunctions\grammar
static grammar( $parser, $case='', $word='')
Definition: CoreParserFunctions.php:343
Parser\SFH_OBJECT_ARGS
const SFH_OBJECT_ARGS
Definition: Parser.php:96
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:226
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:766
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:239
$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: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:651
CoreParserFunctions\fullpagenamee
static fullpagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:701
CoreParserFunctions\getLegacyFormatNum
static getLegacyFormatNum( $parser, $callback)
Definition: CoreParserFunctions.php:313
CoreParserFunctions\pagenamee
static pagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:685
CoreParserFunctions\ns
static ns( $parser, $part1='')
Definition: CoreParserFunctions.php:135
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:403
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:677
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
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:480
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:412
wfEscapeWikiText
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
Definition: GlobalFunctions.php:1459
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:261
CoreParserFunctions\lc
static lc( $parser, $s='')
Definition: CoreParserFunctions.php:209
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:48
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:392
$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:218
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:32
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:1124
Parser\SFH_NO_HASH
const SFH_NO_HASH
Definition: Parser.php:95
Sanitizer\decodeTagAttributes
static decodeTagAttributes( $text)
Return an associative array of attribute names and values from a partial tag string.
Definition: Sanitizer.php:1005
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:2644
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:6279
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:5047
$wgAllowDisplayTitle
$wgAllowDisplayTitle
Allow DISPLAYTITLE to change title display.
Definition: DefaultSettings.php:5040
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:633
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:100
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:252
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:222
$type
$type
Definition: testCompression.php:52
CoreParserFunctions\talkpagenamee
static talkpagenamee( $parser, $title=null)
Definition: CoreParserFunctions.php:765