38use Wikimedia\RemexHtml\Tokenizer\Attributes;
39use Wikimedia\RemexHtml\Tokenizer\PlainAttributes;
47 private const MAX_TTS = 900;
54 MainConfigNames::AllowDisplayTitle,
55 MainConfigNames::AllowSlowParserFunctions,
66 $options->assertRequiredOptions( self::REGISTER_OPTIONS );
67 $allowDisplayTitle = $options->get( MainConfigNames::AllowDisplayTitle );
68 $allowSlowParserFunctions = $options->get( MainConfigNames::AllowSlowParserFunctions );
70 # Syntax for arguments (see Parser::setFunctionHook):
71 # "name for lookup in localized magic words array",
73 # optional Parser::SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}}
74 # instead of {{#int:...}})
76 'ns',
'nse',
'urlencode',
'lcfirst',
'ucfirst',
'lc',
'uc',
77 'localurl',
'localurle',
'fullurl',
'fullurle',
'canonicalurl',
78 'canonicalurle',
'formatnum',
'grammar',
'gender',
'plural',
'bidi',
79 'numberingroup',
'language',
80 'padleft',
'padright',
'anchorencode',
'defaultsort',
'filepath',
81 'pagesincategory',
'pagesize',
'protectionlevel',
'protectionexpiry',
82 # The following are the "parser function" forms of magic
83 # variables defined in CoreMagicVariables. The no-args form will
84 # go through the magic variable code path (and be cached); the
85 # presence of arguments will cause the parser function form to
86 # be invoked. (Note that the actual implementation will pass
87 # a Parser object as first argument, in addition to the
88 # parser function parameters.)
90 # For this group, the first parameter to the parser function is
91 # "page title", and the no-args form (and the magic variable)
92 # defaults to "current page title".
93 'pagename',
'pagenamee',
94 'fullpagename',
'fullpagenamee',
95 'subpagename',
'subpagenamee',
96 'rootpagename',
'rootpagenamee',
97 'basepagename',
'basepagenamee',
98 'talkpagename',
'talkpagenamee',
99 'subjectpagename',
'subjectpagenamee',
100 'pageid',
'revisionid',
'revisionday',
101 'revisionday2',
'revisionmonth',
'revisionmonth1',
'revisionyear',
105 'namespace',
'namespacee',
'namespacenumber',
'talkspace',
'talkspacee',
106 'subjectspace',
'subjectspacee',
108 # More parser functions corresponding to CoreMagicVariables.
109 # For this group, the first parameter to the parser function is
110 # "raw" (uses the 'raw' format if present) and the no-args form
111 # (and the magic variable) defaults to 'not raw'.
112 'numberofarticles',
'numberoffiles',
114 'numberofactiveusers',
119 foreach ( $noHashFunctions as $func ) {
120 $parser->
setFunctionHook( $func, [ __CLASS__, $func ], Parser::SFH_NO_HASH );
123 $parser->
setFunctionHook(
'int', [ __CLASS__,
'intFunction' ], Parser::SFH_NO_HASH );
126 $parser->
setFunctionHook(
'tag', [ __CLASS__,
'tagObj' ], Parser::SFH_OBJECT_ARGS );
129 if ( $allowDisplayTitle ) {
132 [ __CLASS__,
'displaytitle' ],
136 if ( $allowSlowParserFunctions ) {
139 [ __CLASS__,
'pagesinnamespace' ],
152 if ( strval( $part1 ) !==
'' ) {
154 ->inLanguage( $parser->
getOptions()->getUserLangObj() );
155 return [ $message->plain(),
'noparse' => false ];
157 return [
'found' => false ];
168 public static function formatDate( $parser, $date, $defaultPref =
null ) {
170 $df = MediaWikiServices::getInstance()->getDateFormatterFactory()->get( $lang );
172 $date = trim( $date );
174 $pref = $parser->
getOptions()->getDateFormat();
178 if ( $pref ==
'default' && $defaultPref ) {
179 $pref = $defaultPref;
182 $date = $df->reformat( $pref, $date, [
'match-whole' ] );
186 public static function ns( $parser, $part1 =
'' ) {
187 if ( intval( $part1 ) || $part1 ==
"0" ) {
188 $index = intval( $part1 );
190 $index = $parser->
getContentLanguage()->getNsIndex( str_replace(
' ',
'_', $part1 ) );
192 if ( $index !==
false ) {
195 return [
'found' => false ];
199 public static function nse( $parser, $part1 =
'' ) {
200 $ret = self::ns( $parser, $part1 );
201 if ( is_string( $ret ) ) {
202 $ret =
wfUrlencode( str_replace(
' ',
'_', $ret ) );
219 public static function urlencode( $parser, $s =
'', $arg =
null ) {
225 switch (
$magicWords->matchStartToEnd( $arg ??
'' ) ) {
228 $func =
'wfUrlencode';
229 $s = str_replace(
' ',
'_', $s );
234 $func =
'rawurlencode';
247 public static function lcfirst( $parser, $s =
'' ) {
251 public static function ucfirst( $parser, $s =
'' ) {
260 public static function lc( $parser, $s =
'' ) {
269 public static function uc( $parser, $s =
'' ) {
273 public static function localurl( $parser, $s =
'', $arg =
null ) {
274 return self::urlFunction(
'getLocalURL', $s, $arg );
277 public static function localurle( $parser, $s =
'', $arg =
null ) {
278 $temp = self::urlFunction(
'getLocalURL', $s, $arg );
279 if ( !is_string( $temp ) ) {
282 return htmlspecialchars( $temp, ENT_COMPAT );
286 public static function fullurl( $parser, $s =
'', $arg =
null ) {
287 return self::urlFunction(
'getFullURL', $s, $arg );
290 public static function fullurle( $parser, $s =
'', $arg =
null ) {
291 $temp = self::urlFunction(
'getFullURL', $s, $arg );
292 if ( !is_string( $temp ) ) {
295 return htmlspecialchars( $temp, ENT_COMPAT );
300 return self::urlFunction(
'getCanonicalURL', $s, $arg );
304 $temp = self::urlFunction(
'getCanonicalURL', $s, $arg );
305 if ( !is_string( $temp ) ) {
308 return htmlspecialchars( $temp, ENT_COMPAT );
312 public static function urlFunction( $func, $s =
'', $arg =
null ) {
313 # Due to order of execution of a lot of bits, the values might be encoded
314 # before arriving here; if that's true, then the title can't be created
315 # and the variable will fail. If we can't get a decent title from the first
316 # attempt, url-decode and try for a second.
317 $title = Title::newFromText( $s ) ?? Title::newFromURL( urldecode( $s ) );
318 if ( $title !==
null ) {
319 # Convert NS_MEDIA -> NS_FILE
323 if ( $arg !==
null ) {
324 $text = $title->$func( $arg );
326 $text = $title->$func();
330 return [
'found' => false ];
340 public static function formatnum( $parser, $num =
'', $arg =
null ) {
347 $func = self::getLegacyFormatNum( $parser, $func );
350 $func = self::getLegacyFormatNum( $parser, $func );
361 private static function getLegacyFormatNum( $parser, $callback ) {
366 return static function ( $number ) use ( $parser, $callback ) {
367 $validNumberRe =
'(-(?=[\d\.]))?(\d+|(?=\.\d))(\.\d*)?([Ee][-+]?\d+)?';
369 !is_numeric( $number ) &&
370 $number !== (string)NAN &&
371 $number !== (
string)INF &&
372 $number !== (string)-INF
377 return preg_replace_callback(
"/{$validNumberRe}/",
static function ( $m ) use ( $callback ) {
378 return call_user_func( $callback, $m[0] );
381 return call_user_func( $callback, $number );
391 public static function grammar( $parser, $case =
'', $word =
'' ) {
402 public static function gender( $parser, $username, ...$forms ) {
404 if ( count( $forms ) === 0 ) {
406 } elseif ( count( $forms ) === 1 ) {
410 $username = trim( $username );
412 $userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
413 $gender = $userOptionsLookup->getDefaultOption(
'gender' );
416 $title = Title::newFromText( $username,
NS_USER );
423 $user = User::newFromName( $username );
424 $genderCache = MediaWikiServices::getInstance()->getGenderCache();
426 $gender = $genderCache->getGenderOf( $user, __METHOD__ );
427 } elseif ( $username ===
'' && $parser->
getOptions()->getInterfaceMessage() ) {
428 $gender = $genderCache->getGenderOf( $parser->
getOptions()->getUserIdentity(), __METHOD__ );
440 public static function plural( $parser, $text =
'', ...$forms ) {
442 settype( $text, ctype_digit( $text ) ?
'int' :
'float' );
452 public static function bidi( $parser, $text =
'' ) {
465 public static function displaytitle( $parser, $text =
'', $uarg =
'' ) {
466 $restrictDisplayTitle = MediaWikiServices::getInstance()->getMainConfig()
467 ->get( MainConfigNames::RestrictDisplayTitle );
472 [
'displaytitle_noerror',
'displaytitle_noreplace' ] );
485 $bad = [
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'div',
'blockquote',
'ol',
'ul',
'li',
'hr',
486 'table',
'tr',
'th',
'td',
'dl',
'dd',
'caption',
'p',
'ruby',
'rb',
'rt',
'rtc',
'rp',
'br' ];
489 if ( $restrictDisplayTitle ) {
492 $htmlTagsCallback =
static function ( Attributes $attr ): Attributes {
493 $decoded = $attr->getValues();
495 if ( isset( $decoded[
'style'] ) ) {
498 $decoded[
'style'] = Sanitizer::checkCss( $decoded[
'style'] );
500 if ( preg_match(
'/(display|user-select|visibility)\s*:/i', $decoded[
'style'] ) ) {
501 $decoded[
'style'] =
'/* attempt to bypass $wgRestrictDisplayTitle */';
505 return new PlainAttributes( $decoded );
508 $htmlTagsCallback =
null;
514 $text = Sanitizer::removeSomeTags( $text, [
515 'attrCallback' => $htmlTagsCallback,
516 'removeTags' => $bad,
518 $title = Title::newFromText( Sanitizer::stripAllTags( $text ) );
520 $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
522 if ( !$restrictDisplayTitle ||
523 ( $title instanceof
Title
527 $old = $parser->
getOutput()->getPageProperty(
'displaytitle' );
528 if ( $old ===
null || $arg !==
'displaytitle_noreplace' ) {
529 $parser->
getOutput()->setDisplayTitle( $text );
531 if ( $old !==
null && $old !== $text && !$arg ) {
534 return '<span class="error">' .
535 $parser->
msg(
'duplicate-displaytitle',
546 'restricted-displaytitle',
548 Message::plaintextParam( $filteredText )
563 private static function matchAgainstMagicword(
566 $value = trim( strval( $value ) );
567 if ( $value ===
'' ) {
570 $mwObject = $magicWordFactory->
get( $magicword );
571 return $mwObject->matchStartToEnd( $value );
586 if ( $raw !==
null && $raw !==
'' ) {
587 if ( !$magicWordFactory ) {
588 $magicWordFactory = MediaWikiServices::getInstance()->getMagicWordFactory();
590 if ( self::matchAgainstMagicword( $magicWordFactory,
'rawsuffix', $raw ) ) {
594 return $language->formatNum( $num );
598 return self::formatRaw( SiteStats::pages(), $raw, $parser->
getTargetLanguage() );
602 return self::formatRaw( SiteStats::users(), $raw, $parser->
getTargetLanguage() );
606 return self::formatRaw( SiteStats::activeUsers(), $raw, $parser->
getTargetLanguage() );
610 return self::formatRaw( SiteStats::articles(), $raw, $parser->
getTargetLanguage() );
614 return self::formatRaw( SiteStats::images(), $raw, $parser->
getTargetLanguage() );
618 return self::formatRaw(
619 SiteStats::numberingroup(
'sysop' ),
626 return self::formatRaw( SiteStats::edits(), $raw, $parser->
getTargetLanguage() );
630 return self::formatRaw(
631 SiteStats::pagesInNs( intval( $namespace ) ),
638 return self::formatRaw(
639 SiteStats::numberingroup( strtolower( $name ) ),
653 private static function makeTitle(
Parser $parser, ?
string $t ) {
658 $title = Title::newFromText( $t );
671 public static function namespace( $parser, $title = null ) {
672 $t = self::makeTitle( $parser, $title );
676 return str_replace(
'_',
' ', $t->getNsText() );
679 public static function namespacee( $parser, $title =
null ) {
680 $t = self::makeTitle( $parser, $title );
688 $t = self::makeTitle( $parser, $title );
692 return (
string)$t->getNamespace();
695 public static function talkspace( $parser, $title =
null ) {
696 $t = self::makeTitle( $parser, $title );
697 if ( $t ===
null || !$t->canHaveTalkPage() ) {
700 return str_replace(
'_',
' ', $t->getTalkNsText() );
703 public static function talkspacee( $parser, $title =
null ) {
704 $t = self::makeTitle( $parser, $title );
705 if ( $t ===
null || !$t->canHaveTalkPage() ) {
712 $t = self::makeTitle( $parser, $title );
716 return str_replace(
'_',
' ', $t->getSubjectNsText() );
720 $t = self::makeTitle( $parser, $title );
734 public static function pagename( $parser, $title =
null ) {
735 $t = self::makeTitle( $parser, $title );
742 public static function pagenamee( $parser, $title =
null ) {
743 $t = self::makeTitle( $parser, $title );
751 $t = self::makeTitle( $parser, $title );
759 $t = self::makeTitle( $parser, $title );
767 $t = self::makeTitle( $parser, $title );
775 $t = self::makeTitle( $parser, $title );
783 $t = self::makeTitle( $parser, $title );
791 $t = self::makeTitle( $parser, $title );
799 $t = self::makeTitle( $parser, $title );
807 $t = self::makeTitle( $parser, $title );
815 $t = self::makeTitle( $parser, $title );
816 if ( $t ===
null || !$t->canHaveTalkPage() ) {
823 $t = self::makeTitle( $parser, $title );
824 if ( $t ===
null || !$t->canHaveTalkPage() ) {
831 $t = self::makeTitle( $parser, $title );
839 $t = self::makeTitle( $parser, $title );
856 public static function pagesincategory( $parser, $name =
'', $arg1 =
'', $arg2 =
'' ) {
860 'pagesincategory_all',
861 'pagesincategory_pages',
862 'pagesincategory_subcats',
863 'pagesincategory_files'
879 $type =
'pagesincategory_all';
882 $title = Title::makeTitleSafe(
NS_CATEGORY, $name );
883 if ( !$title ) { # invalid title
886 $languageConverter = MediaWikiServices::getInstance()
887 ->getLanguageConverterFactory()
889 $languageConverter->findVariantLink( $name, $title,
true );
892 $name = $title->getDBkey();
894 if ( !isset( $cache[$name] ) ) {
895 $category = Category::newFromTitle( $title );
897 $allCount = $subcatCount = $fileCount = $pageCount = 0;
899 $allCount = $category->getMemberCount();
900 $subcatCount = $category->getSubcatCount();
901 $fileCount = $category->getFileCount();
902 $pageCount = $category->getPageCount( Category::COUNT_CONTENT_PAGES );
904 $cache[$name][
'pagesincategory_all'] = $allCount;
905 $cache[$name][
'pagesincategory_pages'] = $pageCount;
906 $cache[$name][
'pagesincategory_subcats'] = $subcatCount;
907 $cache[$name][
'pagesincategory_files'] = $fileCount;
910 $count = $cache[$name][$type];
923 public static function pagesize( $parser, $page =
'', $raw =
null ) {
924 $title = Title::newFromText( $page );
926 if ( !is_object( $title ) || $title->isExternal() ) {
931 $rev = self::getCachedRevisionObject( $parser, $title, ParserOutputFlags::VARY_REVISION_SHA1 );
932 $length = $rev ? $rev->getSize() : 0;
933 if ( $length ===
null ) {
953 $titleObject = Title::newFromText( $title ) ?? $parser->
getTitle();
954 $restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore();
956 $restrictions = $restrictionStore->getRestrictions( $titleObject, strtolower( $type ) );
957 # RestrictionStore::getRestrictions returns an array, its possible it may have
958 # multiple values in the future
959 return implode(
',', $restrictions );
977 $titleObject = Title::newFromText( $title ) ?? $parser->
getTitle();
978 $restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore();
982 return $restrictionStore->getRestrictionExpiry( $titleObject, strtolower( $type ) ) ??
'';
994 public static function language( $parser, $code =
'', $inLanguage =
'' ) {
995 $code = strtolower( $code );
996 $inLanguage = strtolower( $inLanguage );
997 $lang = MediaWikiServices::getInstance()
998 ->getLanguageNameUtils()
999 ->getLanguageName( $code, $inLanguage );
1000 return $lang !==
'' ? $lang : LanguageCode::bcp47( $code );
1013 $parser, $string, $length, $padding =
'0', $direction = STR_PAD_RIGHT
1016 $lengthOfPadding = mb_strlen( $padding );
1017 if ( $lengthOfPadding == 0 ) {
1021 # The remaining length to add counts down to 0 as padding is added
1022 $length = min( (
int)$length, 500 ) - mb_strlen( $string );
1023 if ( $length <= 0 ) {
1028 # $finalPadding is just $padding repeated enough times so that
1029 # mb_strlen( $string ) + mb_strlen( $finalPadding ) == $length
1031 while ( $length > 0 ) {
1032 # If $length < $lengthofPadding, truncate $padding so we get the
1033 # exact length desired.
1034 $finalPadding .= mb_substr( $padding, 0, $length );
1035 $length -= $lengthOfPadding;
1038 if ( $direction == STR_PAD_LEFT ) {
1039 return $finalPadding . $string;
1041 return $string . $finalPadding;
1045 public static function padleft( $parser, $string =
'', $length = 0, $padding =
'0' ) {
1046 return self::pad( $parser, $string, $length, $padding, STR_PAD_LEFT );
1049 public static function padright( $parser, $string =
'', $length = 0, $padding =
'0' ) {
1050 return self::pad( $parser, $string, $length, $padding );
1061 return Sanitizer::safeEncodeAttribute( $section );
1064 public static function special( $parser, $text ) {
1065 [ $page, $subpage ] = MediaWikiServices::getInstance()->getSpecialPageFactory()->
1066 resolveAlias( $text );
1068 $title = SpecialPage::getTitleFor( $page, $subpage );
1069 return $title->getPrefixedText();
1072 $title = Title::makeTitleSafe(
NS_SPECIAL, $text );
1073 return $title ? $title->getPrefixedText() : self::special( $parser,
'Badtitle' );
1078 return wfUrlencode( str_replace(
' ',
'_', self::special( $parser, $text ) ) );
1093 [
'defaultsort_noerror',
'defaultsort_noreplace' ] );
1097 $text = trim( $text );
1098 if ( strlen( $text ) == 0 ) {
1101 $old = $parser->
getOutput()->getPageProperty(
'defaultsort' );
1102 if ( $old ===
null || $arg !==
'defaultsort_noreplace' ) {
1103 $parser->
getOutput()->setPageProperty(
'defaultsort', $text );
1106 if ( $old ===
null || $old == $text || $arg ) {
1110 return '<span class="error">' .
1111 $parser->
msg(
'duplicate-defaultsort',
1131 public static function filepath( $parser, $name =
'', $argA =
'', $argB =
'' ) {
1132 $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name );
1134 if ( $argA ==
'nowiki' ) {
1137 $parsedWidthParam = Parser::parseWidthParam( $argB );
1140 $parsedWidthParam = Parser::parseWidthParam( $argA );
1141 $isNowiki = ( $argB ==
'nowiki' );
1145 $url = $file->getFullUrl();
1148 if ( count( $parsedWidthParam ) ) {
1149 $mto = $file->transform( $parsedWidthParam );
1151 if ( $mto && !$mto->isError() ) {
1157 return [ $url,
'nowiki' => true ];
1172 public static function tagObj( $parser, $frame, $args ) {
1173 if ( !count( $args ) ) {
1176 $tagName = strtolower( trim( $frame->expand( array_shift( $args ) ) ) );
1179 if ( count( $args ) ) {
1180 $inner = $frame->expand( array_shift( $args ), $processNowiki );
1186 foreach ( $args as $arg ) {
1187 $bits = $arg->splitArg();
1188 if ( strval( $bits[
'index'] ) ===
'' ) {
1189 $name = trim( $frame->expand( $bits[
'name'], PPFrame::STRIP_COMMENTS ) );
1190 $value = trim( $frame->expand( $bits[
'value'] ) );
1191 if ( preg_match(
'/^(?:["\'](.+)["\']|""|\'\')$/s', $value, $m ) ) {
1192 $value = $m[1] ??
'';
1194 $attributes[$name] = $value;
1199 if ( !in_array( $tagName, $stripList ) ) {
1202 foreach ( $attributes as $name => $value ) {
1203 $attrText .=
' ' . htmlspecialchars( $name ) .
1204 '="' . htmlspecialchars( $value, ENT_COMPAT ) .
'"';
1206 if ( $inner ===
null ) {
1207 return "<$tagName$attrText/>";
1209 return "<$tagName$attrText>$inner</$tagName>";
1215 'attributes' => $attributes,
1216 'close' =>
"</$tagName>",
1234 private static function getCachedRevisionObject( $parser, $title, $vary ) {
1239 $revisionRecord =
null;
1241 $isSelfReferential = $title->equals( $parser->
getTitle() );
1242 if ( $isSelfReferential ) {
1253 if ( $parserRevisionRecord && $parserRevisionRecord->isCurrent() ) {
1254 $revisionRecord = $parserRevisionRecord;
1259 if ( !$revisionRecord ) {
1268 if ( !$revisionRecord ) {
1270 $revisionRecord =
null;
1273 $parserOutput->addTemplate(
1275 $revisionRecord ? $revisionRecord->getPageId() : 0,
1276 $revisionRecord ? $revisionRecord->getId() : 0
1280 if ( $isSelfReferential ) {
1281 wfDebug( __METHOD__ .
": used current revision, setting $vary" );
1283 $parserOutput->setOutputFlag( $vary );
1284 if ( $vary === ParserOutputFlags::VARY_REVISION_SHA1 && $revisionRecord ) {
1286 $sha1 = $revisionRecord->getSha1();
1290 $parserOutput->setRevisionUsedSha1Base36( $sha1 );
1294 return $revisionRecord;
1304 public static function pageid( $parser, $title =
null ) {
1305 $t = self::makeTitle( $parser, $title );
1308 } elseif ( !$t->canExist() || $t->isExternal() ) {
1314 if ( $t->equals( $parser->
getTitle() ) ) {
1317 $parserOutput->setOutputFlag( ParserOutputFlags::VARY_PAGE_ID );
1318 $id = $parser->
getTitle()->getArticleID();
1320 $parserOutput->setSpeculativePageIdUsed( $id );
1327 $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1328 $pdbk = $t->getPrefixedDBkey();
1329 $id = $linkCache->getGoodLinkID( $pdbk );
1330 if ( $id != 0 || $linkCache->isBadLink( $pdbk ) ) {
1331 $parserOutput->addLink( $t, $id );
1338 $id = $t->getArticleID();
1339 $parserOutput->addLink( $t, $id );
1355 $t = self::makeTitle( $parser, $title );
1356 if ( $t ===
null || $t->isExternal() ) {
1360 $services = MediaWikiServices::getInstance();
1362 $t->equals( $parser->
getTitle() ) &&
1363 $services->getMainConfig()->get( MainConfigNames::MiserMode ) &&
1364 !$parser->
getOptions()->getInterfaceMessage() &&
1366 $services->getNamespaceInfo()->isSubject( $t->getNamespace() )
1373 $parser->
getOutput()->setOutputFlag( ParserOutputFlags::VARY_REVISION_EXISTS );
1381 if ( $t->equals( $parser->
getTitle() ) && $title ===
null ) {
1384 $parser->
getOutput()->setOutputFlag( ParserOutputFlags::VARY_REVISION_ID );
1389 $id = $rev->getId();
1393 $id = $parser->
getOptions()->getSpeculativeRevId();
1395 $parser->
getOutput()->setSpeculativeRevIdUsed( $id );
1400 $rev = self::getCachedRevisionObject( $parser, $t, ParserOutputFlags::VARY_REVISION_ID );
1401 return $rev ? $rev->getId() :
'';
1404 private static function getRevisionTimestampSubstring(
1417 if ( $title->equals( $parser->
getTitle() ) && !$parser->getOptions()->getInterfaceMessage() ) {
1432 if ( $resNow !== $resThen ) {
1435 $parser->
getOutput()->setOutputFlag( ParserOutputFlags::VARY_REVISION_TIMESTAMP );
1441 $rev = self::getCachedRevisionObject( $parser, $title, ParserOutputFlags::VARY_REVISION_TIMESTAMP );
1460 $t = self::makeTitle( $parser, $title );
1461 if ( $t ===
null || $t->isExternal() ) {
1464 return strval( (
int)self::getRevisionTimestampSubstring(
1465 $parser, $t, 6, 2, self::MAX_TTS
1477 $t = self::makeTitle( $parser, $title );
1478 if ( $t ===
null || $t->isExternal() ) {
1481 return self::getRevisionTimestampSubstring(
1482 $parser, $t, 6, 2, self::MAX_TTS
1494 $t = self::makeTitle( $parser, $title );
1495 if ( $t ===
null || $t->isExternal() ) {
1498 return self::getRevisionTimestampSubstring(
1499 $parser, $t, 4, 2, self::MAX_TTS
1511 $t = self::makeTitle( $parser, $title );
1512 if ( $t ===
null || $t->isExternal() ) {
1515 return strval( (
int)self::getRevisionTimestampSubstring(
1516 $parser, $t, 4, 2, self::MAX_TTS
1528 $t = self::makeTitle( $parser, $title );
1529 if ( $t ===
null || $t->isExternal() ) {
1532 return self::getRevisionTimestampSubstring(
1533 $parser, $t, 0, 4, self::MAX_TTS
1545 $t = self::makeTitle( $parser, $title );
1546 if ( $t ===
null || $t->isExternal() ) {
1549 return self::getRevisionTimestampSubstring(
1550 $parser, $t, 0, 14, self::MAX_TTS
1562 $t = self::makeTitle( $parser, $title );
1563 if ( $t ===
null || $t->isExternal() ) {
1569 if ( $t->equals( $parser->
getTitle() ) ) {
1571 $parser->
getOutput()->setOutputFlag( ParserOutputFlags::VARY_USER );
1578 $rev = self::getCachedRevisionObject( $parser, $t, ParserOutputFlags::VARY_USER );
1579 $user = ( $rev !== null ) ? $rev->getUser() :
null;
1580 return $user ? $user->getName() :
'';
1596 $titleObject = Title::newFromText( $title ) ?? $parser->
getTitle();
1597 $restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore();
1598 if ( $restrictionStore->areCascadeProtectionSourcesLoaded( $titleObject )
1602 $sources = $restrictionStore->getCascadeProtectionSources( $titleObject );
1603 $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
1604 foreach ( $sources[0] as $sourcePageIdentity ) {
1605 $names[] = $titleFormatter->getPrefixedText( $sourcePageIdentity );
1607 return implode(
'|', $names );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL using $wgServer (or one of its alternatives).
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
$magicWords
@phpcs-require-sorted-array
array $params
The job parameters.
if(!defined('MW_SETUP_CALLBACK'))
Various core parser functions, registered in every Parser.
static language( $parser, $code='', $inLanguage='')
Gives language names.
static numberingroup( $parser, $name='', $raw=null)
static rootpagename( $parser, $title=null)
static localurl( $parser, $s='', $arg=null)
static formatnum( $parser, $num='', $arg=null)
static ns( $parser, $part1='')
static protectionexpiry( $parser, $type='', $title='')
Returns the requested protection expiry for the current page.
static pagenamee( $parser, $title=null)
static padleft( $parser, $string='', $length=0, $padding='0')
static fullurle( $parser, $s='', $arg=null)
static revisionmonth( $parser, $title=null)
Get the month with leading zeros from the last revision of a specified page.
static fullpagename( $parser, $title=null)
static revisionid( $parser, $title=null)
Get the id from the last revision of a specified page.
static pagesinnamespace( $parser, $namespace=0, $raw=null)
static numberofusers( $parser, $raw=null)
static special( $parser, $text)
static nse( $parser, $part1='')
static pagesize( $parser, $page='', $raw=null)
Return the size of the given page, or 0 if it's nonexistent.
static canonicalurl( $parser, $s='', $arg=null)
static basepagenamee( $parser, $title=null)
static subjectspacee( $parser, $title=null)
static numberofedits( $parser, $raw=null)
static numberoffiles( $parser, $raw=null)
static ucfirst( $parser, $s='')
static basepagename( $parser, $title=null)
static gender( $parser, $username,... $forms)
static numberofpages( $parser, $raw=null)
static lcfirst( $parser, $s='')
static urlFunction( $func, $s='', $arg=null)
static plural( $parser, $text='',... $forms)
static formatRaw( $num, $raw, $language, MagicWordFactory $magicWordFactory=null)
Formats a number according to a language.
static talkspacee( $parser, $title=null)
static bidi( $parser, $text='')
static revisionuser( $parser, $title=null)
Get the user from the last revision of a specified page.
static anchorencode( $parser, $text)
static subjectpagenamee( $parser, $title=null)
static namespacee( $parser, $title=null)
static subjectpagename( $parser, $title=null)
static filepath( $parser, $name='', $argA='', $argB='')
Usage {{filepath|300}}, {{filepath|nowiki}}, {{filepath|nowiki|300}} or {{filepath|300|nowiki}} or {{...
static padright( $parser, $string='', $length=0, $padding='0')
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.
static canonicalurle( $parser, $s='', $arg=null)
static cascadingsources( $parser, $title='')
Returns the sources of any cascading protection acting on a specified page.
static numberofactiveusers( $parser, $raw=null)
static displaytitle( $parser, $text='', $uarg='')
Override the title of the page when viewed, provided we've been given a title which will normalise to...
static pageid( $parser, $title=null)
Get the pageid of a specified page.
static formatDate( $parser, $date, $defaultPref=null)
static urlencode( $parser, $s='', $arg=null)
urlencodes a string according to one of three patterns: (T24474)
static grammar( $parser, $case='', $word='')
static subpagenamee( $parser, $title=null)
static tagObj( $parser, $frame, $args)
Parser function to extension tag adaptor.
static revisionmonth1( $parser, $title=null)
Get the month from the last revision of a specified page.
static rootpagenamee( $parser, $title=null)
static protectionlevel( $parser, $type='', $title='')
Returns the requested protection level for the current page.
static namespacenumber( $parser, $title=null)
static revisionday( $parser, $title=null)
Get the day from the last revision of a specified page.
static subjectspace( $parser, $title=null)
static lc( $parser, $s='')
static pagesincategory( $parser, $name='', $arg1='', $arg2='')
Return the number of pages, files or subcats in the given category, or 0 if it's nonexistent.
static talkpagename( $parser, $title=null)
static fullurl( $parser, $s='', $arg=null)
static pagename( $parser, $title=null)
Functions to get and normalize pagenames, corresponding to the magic words of the same names.
static intFunction( $parser, $part1='',... $params)
static numberofadmins( $parser, $raw=null)
static numberofarticles( $parser, $raw=null)
static revisionyear( $parser, $title=null)
Get the year from the last revision of a specified page.
static revisionday2( $parser, $title=null)
Get the day with leading zeros from the last revision of a specified page.
static uc( $parser, $s='')
static talkpagenamee( $parser, $title=null)
static revisiontimestamp( $parser, $title=null)
Get the timestamp from the last revision of a specified page.
static subpagename( $parser, $title=null)
static localurle( $parser, $s='', $arg=null)
static defaultsort( $parser, $text, $uarg='')
static fullpagenamee( $parser, $title=null)
static talkspace( $parser, $title=null)
static speciale( $parser, $text)
A class containing constants representing the names of configuration variables.
Parent class for all special pages.