37 use Wikimedia\RemexHtml\Tokenizer\Attributes;
38 use Wikimedia\RemexHtml\Tokenizer\PlainAttributes;
46 private const MAX_TTS = 900;
53 MainConfigNames::AllowDisplayTitle,
54 MainConfigNames::AllowSlowParserFunctions,
65 $options->assertRequiredOptions( self::REGISTER_OPTIONS );
66 $allowDisplayTitle = $options->get( MainConfigNames::AllowDisplayTitle );
67 $allowSlowParserFunctions = $options->get( MainConfigNames::AllowSlowParserFunctions );
69 # Syntax for arguments (see Parser::setFunctionHook):
70 # "name for lookup in localized magic words array",
72 # optional Parser::SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}}
73 # instead of {{#int:...}})
75 'ns',
'nse',
'urlencode',
'lcfirst',
'ucfirst',
'lc',
'uc',
76 'localurl',
'localurle',
'fullurl',
'fullurle',
'canonicalurl',
77 'canonicalurle',
'formatnum',
'grammar',
'gender',
'plural',
'bidi',
78 'numberingroup',
'language',
79 'padleft',
'padright',
'anchorencode',
'defaultsort',
'filepath',
80 'pagesincategory',
'pagesize',
'protectionlevel',
'protectionexpiry',
81 # The following are the "parser function" forms of magic
82 # variables defined in CoreMagicVariables. The no-args form will
83 # go through the magic variable code path (and be cached); the
84 # presence of arguments will cause the parser function form to
85 # be invoked. (Note that the actual implementation will pass
86 # a Parser object as first argument, in addition to the
87 # parser function parameters.)
89 # For this group, the first parameter to the parser function is
90 # "page title", and the no-args form (and the magic variable)
91 # defaults to "current page title".
92 'pagename',
'pagenamee',
93 'fullpagename',
'fullpagenamee',
94 'subpagename',
'subpagenamee',
95 'rootpagename',
'rootpagenamee',
96 'basepagename',
'basepagenamee',
97 'talkpagename',
'talkpagenamee',
98 'subjectpagename',
'subjectpagenamee',
99 'pageid',
'revisionid',
'revisionday',
100 'revisionday2',
'revisionmonth',
'revisionmonth1',
'revisionyear',
104 'namespace',
'namespacee',
'namespacenumber',
'talkspace',
'talkspacee',
105 'subjectspace',
'subjectspacee',
107 # More parser functions corresponding to CoreMagicVariables.
108 # For this group, the first parameter to the parser function is
109 # "raw" (uses the 'raw' format if present) and the no-args form
110 # (and the magic variable) defaults to 'not raw'.
111 'numberofarticles',
'numberoffiles',
113 'numberofactiveusers',
118 foreach ( $noHashFunctions as $func ) {
128 if ( $allowDisplayTitle ) {
131 [ __CLASS__,
'displaytitle' ],
135 if ( $allowSlowParserFunctions ) {
138 [ __CLASS__,
'pagesinnamespace' ],
150 public static function intFunction( $parser, $part1 =
'', ...$params ) {
151 if ( strval( $part1 ) !==
'' ) {
153 ->inLanguage( $parser->
getOptions()->getUserLangObj() );
154 return [ $message->plain(),
'noparse' => false ];
156 return [
'found' => false ];
167 public static function formatDate( $parser, $date, $defaultPref =
null ) {
169 $df = MediaWikiServices::getInstance()->getDateFormatterFactory()->get( $lang );
171 $date = trim( $date );
173 $pref = $parser->
getOptions()->getDateFormat();
177 if ( $pref ==
'default' && $defaultPref ) {
178 $pref = $defaultPref;
181 $date = $df->reformat( $pref, $date, [
'match-whole' ] );
185 public static function ns( $parser, $part1 =
'' ) {
186 if ( intval( $part1 ) || $part1 ==
"0" ) {
187 $index = intval( $part1 );
189 $index = $parser->
getContentLanguage()->getNsIndex( str_replace(
' ',
'_', $part1 ) );
191 if ( $index !==
false ) {
194 return [
'found' => false ];
198 public static function nse( $parser, $part1 =
'' ) {
200 if ( is_string( $ret ) ) {
201 $ret =
wfUrlencode( str_replace(
' ',
'_', $ret ) );
218 public static function urlencode( $parser, $s =
'', $arg =
null ) {
224 switch (
$magicWords->matchStartToEnd( $arg ??
'' ) ) {
227 $func =
'wfUrlencode';
228 $s = str_replace(
' ',
'_', $s );
233 $func =
'rawurlencode';
246 public static function lcfirst( $parser, $s =
'' ) {
250 public static function ucfirst( $parser, $s =
'' ) {
259 public static function lc( $parser, $s =
'' ) {
268 public static function uc( $parser, $s =
'' ) {
272 public static function localurl( $parser, $s =
'', $arg =
null ) {
276 public static function localurle( $parser, $s =
'', $arg =
null ) {
278 if ( !is_string( $temp ) ) {
281 return htmlspecialchars( $temp, ENT_COMPAT );
285 public static function fullurl( $parser, $s =
'', $arg =
null ) {
289 public static function fullurle( $parser, $s =
'', $arg =
null ) {
291 if ( !is_string( $temp ) ) {
294 return htmlspecialchars( $temp, ENT_COMPAT );
304 if ( !is_string( $temp ) ) {
307 return htmlspecialchars( $temp, ENT_COMPAT );
311 public static function urlFunction( $func, $s =
'', $arg =
null ) {
312 # Due to order of execution of a lot of bits, the values might be encoded
313 # before arriving here; if that's true, then the title can't be created
314 # and the variable will fail. If we can't get a decent title from the first
315 # attempt, url-decode and try for a second.
316 $title = Title::newFromText( $s ) ?? Title::newFromURL( urldecode( $s ) );
317 if ( $title !==
null ) {
318 # Convert NS_MEDIA -> NS_FILE
322 if ( $arg !==
null ) {
323 $text = $title->$func( $arg );
325 $text = $title->$func();
329 return [
'found' => false ];
339 public static function formatnum( $parser, $num =
'', $arg =
null ) {
346 $func = self::getLegacyFormatNum( $parser, $func );
349 $func = self::getLegacyFormatNum( $parser, $func );
360 private static function getLegacyFormatNum( $parser, $callback ) {
365 return static function ( $number ) use ( $parser, $callback ) {
366 $validNumberRe =
'(-(?=[\d\.]))?(\d+|(?=\.\d))(\.\d*)?([Ee][-+]?\d+)?';
368 !is_numeric( $number ) &&
369 $number !== (string)NAN &&
370 $number !== (
string)INF &&
371 $number !== (string)-INF
376 return preg_replace_callback(
"/{$validNumberRe}/",
static function ( $m ) use ( $callback ) {
377 return call_user_func( $callback, $m[0] );
380 return call_user_func( $callback, $number );
390 public static function grammar( $parser, $case =
'', $word =
'' ) {
401 public static function gender( $parser, $username, ...$forms ) {
403 if ( count( $forms ) === 0 ) {
405 } elseif ( count( $forms ) === 1 ) {
409 $username = trim( $username );
411 $userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
412 $gender = $userOptionsLookup->getDefaultOption(
'gender' );
415 $title = Title::newFromText( $username,
NS_USER );
422 $user = User::newFromName( $username );
423 $genderCache = MediaWikiServices::getInstance()->getGenderCache();
425 $gender = $genderCache->getGenderOf( $user, __METHOD__ );
426 } elseif ( $username ===
'' && $parser->
getOptions()->getInterfaceMessage() ) {
427 $gender = $genderCache->getGenderOf( $parser->
getOptions()->getUserIdentity(), __METHOD__ );
439 public static function plural( $parser, $text =
'', ...$forms ) {
441 settype( $text, ctype_digit( $text ) ?
'int' :
'float' );
451 public static function bidi( $parser, $text =
'' ) {
464 public static function displaytitle( $parser, $text =
'', $uarg =
'' ) {
465 $restrictDisplayTitle = MediaWikiServices::getInstance()->getMainConfig()
466 ->get( MainConfigNames::RestrictDisplayTitle );
471 [
'displaytitle_noerror',
'displaytitle_noreplace' ] );
484 $bad = [
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'div',
'blockquote',
'ol',
'ul',
'li',
'hr',
485 'table',
'tr',
'th',
'td',
'dl',
'dd',
'caption',
'p',
'ruby',
'rb',
'rt',
'rtc',
'rp',
'br' ];
488 if ( $restrictDisplayTitle ) {
491 $htmlTagsCallback =
static function ( Attributes $attr ): Attributes {
492 $decoded = $attr->getValues();
494 if ( isset( $decoded[
'style'] ) ) {
497 $decoded[
'style'] = Sanitizer::checkCss( $decoded[
'style'] );
499 if ( preg_match(
'/(display|user-select|visibility)\s*:/i', $decoded[
'style'] ) ) {
500 $decoded[
'style'] =
'/* attempt to bypass $wgRestrictDisplayTitle */';
504 return new PlainAttributes( $decoded );
507 $htmlTagsCallback =
null;
513 $text = Sanitizer::removeSomeTags( $text, [
514 'attrCallback' => $htmlTagsCallback,
515 'removeTags' => $bad,
517 $title = Title::newFromText( Sanitizer::stripAllTags( $text ) );
519 $filteredText = Sanitizer::decodeCharReferencesAndNormalize( $text );
521 if ( !$restrictDisplayTitle ||
522 ( $title instanceof
Title
526 $old = $parser->
getOutput()->getPageProperty(
'displaytitle' );
527 if ( $old ===
null || $arg !==
'displaytitle_noreplace' ) {
528 $parser->
getOutput()->setDisplayTitle( $text );
530 if ( $old !==
null && $old !== $text && !$arg ) {
533 return '<span class="error">' .
534 $parser->
msg(
'duplicate-displaytitle',
545 'restricted-displaytitle',
562 private static function matchAgainstMagicword(
565 $value = trim( strval( $value ) );
566 if ( $value ===
'' ) {
569 $mwObject = $magicWordFactory->
get( $magicword );
570 return $mwObject->matchStartToEnd( $value );
585 if ( $raw !==
null && $raw !==
'' ) {
586 if ( !$magicWordFactory ) {
587 $magicWordFactory = MediaWikiServices::getInstance()->getMagicWordFactory();
589 if ( self::matchAgainstMagicword( $magicWordFactory,
'rawsuffix', $raw ) ) {
593 return $language->formatNum( $num );
618 SiteStats::numberingroup(
'sysop' ),
630 SiteStats::pagesInNs( intval( $namespace ) ),
638 SiteStats::numberingroup( strtolower( $name ) ),
652 private static function makeTitle(
Parser $parser, ?
string $t ) {
657 $title = Title::newFromText(
$t );
670 public static function namespace( $parser, $title = null ) {
671 $t = self::makeTitle( $parser, $title );
675 return str_replace(
'_',
' ',
$t->getNsText() );
690 return self::namespace( $parser, $title );
693 public static function namespacee( $parser, $title =
null ) {
694 $t = self::makeTitle( $parser, $title );
702 $t = self::makeTitle( $parser, $title );
706 return (
string)
$t->getNamespace();
709 public static function talkspace( $parser, $title =
null ) {
710 $t = self::makeTitle( $parser, $title );
711 if (
$t ===
null || !
$t->canHaveTalkPage() ) {
714 return str_replace(
'_',
' ',
$t->getTalkNsText() );
717 public static function talkspacee( $parser, $title =
null ) {
718 $t = self::makeTitle( $parser, $title );
719 if (
$t ===
null || !
$t->canHaveTalkPage() ) {
726 $t = self::makeTitle( $parser, $title );
730 return str_replace(
'_',
' ',
$t->getSubjectNsText() );
734 $t = self::makeTitle( $parser, $title );
748 public static function pagename( $parser, $title =
null ) {
749 $t = self::makeTitle( $parser, $title );
756 public static function pagenamee( $parser, $title =
null ) {
757 $t = self::makeTitle( $parser, $title );
765 $t = self::makeTitle( $parser, $title );
773 $t = self::makeTitle( $parser, $title );
781 $t = self::makeTitle( $parser, $title );
789 $t = self::makeTitle( $parser, $title );
797 $t = self::makeTitle( $parser, $title );
805 $t = self::makeTitle( $parser, $title );
813 $t = self::makeTitle( $parser, $title );
821 $t = self::makeTitle( $parser, $title );
829 $t = self::makeTitle( $parser, $title );
830 if (
$t ===
null || !
$t->canHaveTalkPage() ) {
837 $t = self::makeTitle( $parser, $title );
838 if (
$t ===
null || !
$t->canHaveTalkPage() ) {
845 $t = self::makeTitle( $parser, $title );
853 $t = self::makeTitle( $parser, $title );
870 public static function pagesincategory( $parser, $name =
'', $arg1 =
'', $arg2 =
'' ) {
874 'pagesincategory_all',
875 'pagesincategory_pages',
876 'pagesincategory_subcats',
877 'pagesincategory_files'
893 $type =
'pagesincategory_all';
896 $title = Title::makeTitleSafe(
NS_CATEGORY, $name );
897 if ( !$title ) { # invalid title
900 $languageConverter = MediaWikiServices::getInstance()
901 ->getLanguageConverterFactory()
903 $languageConverter->findVariantLink( $name, $title,
true );
906 $name = $title->getDBkey();
908 if ( !isset( $cache[$name] ) ) {
909 $category = Category::newFromTitle( $title );
911 $allCount = $subcatCount = $fileCount = $pageCount = 0;
913 $allCount = $category->getMemberCount();
914 $subcatCount = $category->getSubcatCount();
915 $fileCount = $category->getFileCount();
916 $pageCount = $category->getPageCount( Category::COUNT_CONTENT_PAGES );
918 $cache[$name][
'pagesincategory_all'] = $allCount;
919 $cache[$name][
'pagesincategory_pages'] = $pageCount;
920 $cache[$name][
'pagesincategory_subcats'] = $subcatCount;
921 $cache[$name][
'pagesincategory_files'] = $fileCount;
924 $count = $cache[$name][$type];
937 public static function pagesize( $parser, $page =
'', $raw =
null ) {
938 $title = Title::newFromText( $page );
940 if ( !is_object( $title ) ) {
945 $rev = self::getCachedRevisionObject( $parser, $title, ParserOutputFlags::VARY_REVISION_SHA1 );
946 $length = $rev ? $rev->getSize() : 0;
947 if ( $length ===
null ) {
967 $titleObject = Title::newFromText( $title ) ?? $parser->
getTitle();
968 $restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore();
970 $restrictions = $restrictionStore->getRestrictions( $titleObject, strtolower( $type ) );
971 # RestrictionStore::getRestrictions returns an array, its possible it may have
972 # multiple values in the future
973 return implode(
',', $restrictions );
991 $titleObject = Title::newFromText( $title ) ?? $parser->
getTitle();
992 $restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore();
996 return $restrictionStore->getRestrictionExpiry( $titleObject, strtolower( $type ) ) ??
'';
1008 public static function language( $parser, $code =
'', $inLanguage =
'' ) {
1009 $code = strtolower( $code );
1010 $inLanguage = strtolower( $inLanguage );
1011 $lang = MediaWikiServices::getInstance()
1012 ->getLanguageNameUtils()
1013 ->getLanguageName( $code, $inLanguage );
1027 $parser, $string, $length, $padding =
'0', $direction = STR_PAD_RIGHT
1030 $lengthOfPadding = mb_strlen( $padding );
1031 if ( $lengthOfPadding == 0 ) {
1035 # The remaining length to add counts down to 0 as padding is added
1036 $length = min( (
int)$length, 500 ) - mb_strlen( $string );
1037 if ( $length <= 0 ) {
1042 # $finalPadding is just $padding repeated enough times so that
1043 # mb_strlen( $string ) + mb_strlen( $finalPadding ) == $length
1045 while ( $length > 0 ) {
1046 # If $length < $lengthofPadding, truncate $padding so we get the
1047 # exact length desired.
1048 $finalPadding .= mb_substr( $padding, 0, $length );
1049 $length -= $lengthOfPadding;
1052 if ( $direction == STR_PAD_LEFT ) {
1053 return $finalPadding . $string;
1055 return $string . $finalPadding;
1059 public static function padleft( $parser, $string =
'', $length = 0, $padding =
'0' ) {
1060 return self::pad( $parser, $string, $length, $padding, STR_PAD_LEFT );
1063 public static function padright( $parser, $string =
'', $length = 0, $padding =
'0' ) {
1064 return self::pad( $parser, $string, $length, $padding );
1075 return Sanitizer::safeEncodeAttribute( $section );
1078 public static function special( $parser, $text ) {
1079 [ $page, $subpage ] = MediaWikiServices::getInstance()->getSpecialPageFactory()->
1080 resolveAlias( $text );
1082 $title = SpecialPage::getTitleFor( $page, $subpage );
1083 return $title->getPrefixedText();
1086 $title = Title::makeTitleSafe(
NS_SPECIAL, $text );
1087 return $title ? $title->getPrefixedText() :
self::special( $parser,
'Badtitle' );
1092 return wfUrlencode( str_replace(
' ',
'_', self::special( $parser, $text ) ) );
1107 [
'defaultsort_noerror',
'defaultsort_noreplace' ] );
1111 $text = trim( $text );
1112 if ( strlen( $text ) == 0 ) {
1115 $old = $parser->
getOutput()->getPageProperty(
'defaultsort' );
1116 if ( $old ===
null || $arg !==
'defaultsort_noreplace' ) {
1117 $parser->
getOutput()->setPageProperty(
'defaultsort', $text );
1120 if ( $old ===
null || $old == $text || $arg ) {
1124 return '<span class="error">' .
1125 $parser->
msg(
'duplicate-defaultsort',
1145 public static function filepath( $parser, $name =
'', $argA =
'', $argB =
'' ) {
1146 $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name );
1148 if ( $argA ==
'nowiki' ) {
1155 $isNowiki = ( $argB ==
'nowiki' );
1159 $url =
$file->getFullUrl();
1162 if ( count( $parsedWidthParam ) ) {
1163 $mto =
$file->transform( $parsedWidthParam );
1165 if ( $mto && !$mto->isError() ) {
1171 return [ $url,
'nowiki' =>
true ];
1186 public static function tagObj( $parser, $frame, $args ) {
1187 if ( !count( $args ) ) {
1190 $tagName = strtolower( trim( $frame->expand( array_shift( $args ) ) ) );
1193 if ( count( $args ) ) {
1194 $inner = $frame->expand( array_shift( $args ), $processNowiki );
1200 foreach ( $args as $arg ) {
1201 $bits = $arg->splitArg();
1202 if ( strval( $bits[
'index'] ) ===
'' ) {
1204 $value = trim( $frame->expand( $bits[
'value'] ) );
1205 if ( preg_match(
'/^(?:["\'](.+)["\']|""|\'\')$/s', $value, $m ) ) {
1206 $value = $m[1] ??
'';
1208 $attributes[$name] = $value;
1213 if ( !in_array( $tagName, $stripList ) ) {
1216 foreach ( $attributes as $name => $value ) {
1217 $attrText .=
' ' . htmlspecialchars( $name ) .
1218 '="' . htmlspecialchars( $value, ENT_COMPAT ) .
'"';
1220 if ( $inner ===
null ) {
1221 return "<$tagName$attrText/>";
1223 return "<$tagName$attrText>$inner</$tagName>";
1229 'attributes' => $attributes,
1230 'close' =>
"</$tagName>",
1248 private static function getCachedRevisionObject( $parser, $title, $vary ) {
1253 $revisionRecord =
null;
1255 $isSelfReferential = $title->equals( $parser->
getTitle() );
1256 if ( $isSelfReferential ) {
1267 if ( $parserRevisionRecord && $parserRevisionRecord->isCurrent() ) {
1268 $revisionRecord = $parserRevisionRecord;
1273 if ( !$revisionRecord ) {
1282 if ( !$revisionRecord ) {
1284 $revisionRecord =
null;
1287 $parserOutput->addTemplate(
1289 $revisionRecord ? $revisionRecord->getPageId() : 0,
1290 $revisionRecord ? $revisionRecord->getId() : 0
1294 if ( $isSelfReferential ) {
1295 wfDebug( __METHOD__ .
": used current revision, setting $vary" );
1297 $parserOutput->setOutputFlag( $vary );
1298 if ( $vary === ParserOutputFlags::VARY_REVISION_SHA1 && $revisionRecord ) {
1300 $sha1 = $revisionRecord->getSha1();
1304 $parserOutput->setRevisionUsedSha1Base36( $sha1 );
1308 return $revisionRecord;
1318 public static function pageid( $parser, $title =
null ) {
1319 $t = self::makeTitle( $parser, $title );
1322 } elseif ( !
$t->canExist() ||
$t->isExternal() ) {
1331 $parserOutput->setOutputFlag( ParserOutputFlags::VARY_PAGE_ID );
1332 $id = $parser->
getTitle()->getArticleID();
1334 $parserOutput->setSpeculativePageIdUsed( $id );
1341 $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1342 $pdbk =
$t->getPrefixedDBkey();
1343 $id = $linkCache->getGoodLinkID( $pdbk );
1344 if ( $id != 0 || $linkCache->isBadLink( $pdbk ) ) {
1345 $parserOutput->addLink(
$t, $id );
1352 $id =
$t->getArticleID();
1353 $parserOutput->addLink(
$t, $id );
1369 $t = self::makeTitle( $parser, $title );
1370 if (
$t ===
null ) {
1374 $services = MediaWikiServices::getInstance();
1377 $services->getMainConfig()->get( MainConfigNames::MiserMode ) &&
1378 !$parser->
getOptions()->getInterfaceMessage() &&
1380 $services->getNamespaceInfo()->isSubject(
$t->getNamespace() )
1387 $parser->
getOutput()->setOutputFlag( ParserOutputFlags::VARY_REVISION_EXISTS );
1395 if (
$t->equals( $parser->
getTitle() ) && $title ===
null ) {
1398 $parser->
getOutput()->setOutputFlag( ParserOutputFlags::VARY_REVISION_ID );
1403 $id = $rev->getId();
1407 $id = $parser->
getOptions()->getSpeculativeRevId();
1409 $parser->
getOutput()->setSpeculativeRevIdUsed( $id );
1414 $rev = self::getCachedRevisionObject( $parser,
$t, ParserOutputFlags::VARY_REVISION_ID );
1415 return $rev ? $rev->getId() :
'';
1418 private static function getRevisionTimestampSubstring(
1431 if ( $title->equals( $parser->
getTitle() ) && !$parser->getOptions()->getInterfaceMessage() ) {
1446 if ( $resNow !== $resThen ) {
1449 $parser->
getOutput()->setOutputFlag( ParserOutputFlags::VARY_REVISION_TIMESTAMP );
1455 $rev = self::getCachedRevisionObject( $parser, $title, ParserOutputFlags::VARY_REVISION_TIMESTAMP );
1474 $t = self::makeTitle( $parser, $title );
1475 if (
$t ===
null ) {
1478 return strval( (
int)self::getRevisionTimestampSubstring(
1479 $parser,
$t, 6, 2, self::MAX_TTS
1491 $t = self::makeTitle( $parser, $title );
1492 if (
$t ===
null ) {
1495 return self::getRevisionTimestampSubstring(
1496 $parser,
$t, 6, 2, self::MAX_TTS
1508 $t = self::makeTitle( $parser, $title );
1509 if (
$t ===
null ) {
1512 return self::getRevisionTimestampSubstring(
1513 $parser,
$t, 4, 2, self::MAX_TTS
1525 $t = self::makeTitle( $parser, $title );
1526 if (
$t ===
null ) {
1529 return strval( (
int)self::getRevisionTimestampSubstring(
1530 $parser,
$t, 4, 2, self::MAX_TTS
1542 $t = self::makeTitle( $parser, $title );
1543 if (
$t ===
null ) {
1546 return self::getRevisionTimestampSubstring(
1547 $parser,
$t, 0, 4, self::MAX_TTS
1559 $t = self::makeTitle( $parser, $title );
1560 if (
$t ===
null ) {
1563 return self::getRevisionTimestampSubstring(
1564 $parser,
$t, 0, 14, self::MAX_TTS
1576 $t = self::makeTitle( $parser, $title );
1577 if (
$t ===
null ) {
1585 $parser->
getOutput()->setOutputFlag( ParserOutputFlags::VARY_USER );
1592 $rev = self::getCachedRevisionObject( $parser,
$t, ParserOutputFlags::VARY_USER );
1593 $user = ( $rev !== null ) ? $rev->getUser() :
null;
1594 return $user ? $user->getName() :
'';
1610 $titleObject = Title::newFromText( $title ) ?? $parser->
getTitle();
1611 $restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore();
1612 if ( $restrictionStore->areCascadeProtectionSourcesLoaded( $titleObject )
1616 $sources = $restrictionStore->getCascadeProtectionSources( $titleObject );
1617 $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
1618 foreach ( $sources[0] as $sourcePageIdentity ) {
1619 $names[] = $titleFormatter->getPrefixedText( $sourcePageIdentity );
1621 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,...
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.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
$magicWords
@phpcs-require-sorted-array
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 mwnamespace( $parser, $title=null)
Given a title, return the namespace name that would be given by the corresponding magic word.
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)
static bcp47( $code)
Get the normalised IANA language tag See unit test for examples.
A class containing constants representing the names of configuration variables.
Parent class for all special pages.
static plaintextParam( $plaintext)
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
addTrackingCategory( $msg)
getTargetLanguage()
Get the target language for the content being parsed.
getRevisionTimestamp()
Get the timestamp associated with the current revision, adjusted for the default server-local timesta...
getMagicWordFactory()
Get the MagicWordFactory that this Parser is using.
getRevisionUser()
Get the name of the user that edited the last revision.
isCurrentRevisionOfTitleCached(LinkTarget $link)
extensionSubstitution(array $params, PPFrame $frame, bool $processNowiki=false)
Return the text to be used for a given extension tag.
tagNeedsNowikiStrippedInTagPF(string $lowerTagName)
fetchCurrentRevisionRecordOfTitle(LinkTarget $link)
Fetch the current revision of a given title as a RevisionRecord.
setFunctionHook( $id, callable $callback, $flags=0)
Create a function, e.g.
getStripList()
Get a list of strippable XML-like elements.
getTargetLanguageConverter()
Shorthand for getting a Language Converter for Target language.
getContentLanguage()
Get the content language that this Parser is using.
guessSectionNameFromWikiText( $text)
Try to guess the section anchor name based on a wikitext fragment presumably extracted from a heading...
getRevisionId()
Get the ID of the revision we are parsing.
static parseWidthParam( $value, $parseHeight=true)
Parsed a width param of imagelink like 300px or 200x300px.
doQuotes( $text)
Helper function for handleAllQuotes()
incrementExpensiveFunctionCount()
markerSkipCallback( $s, callable $callback)
Call a callback function on all regions of the given text that are not inside strip markers,...
killMarkers( $text)
Remove any strip markers found in the given text.
msg(string $msg,... $args)
Helper function to correctly set the target language and title of a message based on the parser conte...
getRevisionRecordObject()
Get the revision record object for $this->mRevisionId.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.