35 use Wikimedia\RemexHtml\Tokenizer\Attributes;
36 use Wikimedia\RemexHtml\Tokenizer\PlainAttributes;
44 private const MAX_TTS = 900;
51 MainConfigNames::AllowDisplayTitle,
52 MainConfigNames::AllowSlowParserFunctions,
64 $options->assertRequiredOptions( self::REGISTER_OPTIONS );
65 $allowDisplayTitle = $options->get( MainConfigNames::AllowDisplayTitle );
66 $allowSlowParserFunctions = $options->get( MainConfigNames::AllowSlowParserFunctions );
68 # Syntax for arguments (see Parser::setFunctionHook):
69 # "name for lookup in localized magic words array",
71 # optional Parser::SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}}
72 # instead of {{#int:...}})
74 'ns',
'nse',
'urlencode',
'lcfirst',
'ucfirst',
'lc',
'uc',
75 'localurl',
'localurle',
'fullurl',
'fullurle',
'canonicalurl',
76 'canonicalurle',
'formatnum',
'grammar',
'gender',
'plural',
'bidi',
77 'numberingroup',
'language',
78 'padleft',
'padright',
'anchorencode',
'defaultsort',
'filepath',
79 'pagesincategory',
'pagesize',
'protectionlevel',
'protectionexpiry',
80 # The following are the "parser function" forms of magic
81 # variables defined in CoreMagicVariables. The no-args form will
82 # go through the magic variable code path (and be cached); the
83 # presence of arguments will cause the parser function form to
84 # be invoked. (Note that the actual implementation will pass
85 # a Parser object as first argument, in addition to the
86 # parser function parameters.)
88 # For this group, the first parameter to the parser function is
89 # "page title", and the no-args form (and the magic variable)
90 # defaults to "current page title".
91 'pagename',
'pagenamee',
92 'fullpagename',
'fullpagenamee',
93 'subpagename',
'subpagenamee',
94 'rootpagename',
'rootpagenamee',
95 'basepagename',
'basepagenamee',
96 'talkpagename',
'talkpagenamee',
97 'subjectpagename',
'subjectpagenamee',
98 'pageid',
'revisionid',
'revisionday',
99 'revisionday2',
'revisionmonth',
'revisionmonth1',
'revisionyear',
103 'namespace',
'namespacee',
'namespacenumber',
'talkspace',
'talkspacee',
104 'subjectspace',
'subjectspacee',
106 # More parser functions corresponding to CoreMagicVariables.
107 # For this group, the first parameter to the parser function is
108 # "raw" (uses the 'raw' format if present) and the no-args form
109 # (and the magic variable) defaults to 'not raw'.
110 'numberofarticles',
'numberoffiles',
112 'numberofactiveusers',
117 foreach ( $noHashFunctions as $func ) {
127 if ( $allowDisplayTitle ) {
130 [ __CLASS__,
'displaytitle' ],
134 if ( $allowSlowParserFunctions ) {
137 [ __CLASS__,
'pagesinnamespace' ],
149 public static function intFunction( $parser, $part1 =
'', ...$params ) {
150 if ( strval( $part1 ) !==
'' ) {
152 ->inLanguage( $parser->
getOptions()->getUserLangObj() );
153 return [ $message->plain(),
'noparse' => false ];
155 return [
'found' => false ];
166 public static function formatDate( $parser, $date, $defaultPref =
null ) {
168 $df = MediaWikiServices::getInstance()->getDateFormatterFactory()->get(
$lang );
170 $date = trim( $date );
172 $pref = $parser->
getOptions()->getDateFormat();
176 if ( $pref ==
'default' && $defaultPref ) {
177 $pref = $defaultPref;
180 $date = $df->reformat( $pref, $date, [
'match-whole' ] );
184 public static function ns( $parser, $part1 =
'' ) {
185 if ( intval( $part1 ) || $part1 ==
"0" ) {
186 $index = intval( $part1 );
188 $index = $parser->
getContentLanguage()->getNsIndex( str_replace(
' ',
'_', $part1 ) );
190 if ( $index !==
false ) {
193 return [
'found' => false ];
197 public static function nse( $parser, $part1 =
'' ) {
199 if ( is_string( $ret ) ) {
200 $ret =
wfUrlencode( str_replace(
' ',
'_', $ret ) );
217 public static function urlencode( $parser, $s =
'', $arg =
null ) {
223 switch (
$magicWords->matchStartToEnd( $arg ??
'' ) ) {
226 $func =
'wfUrlencode';
227 $s = str_replace(
' ',
'_', $s );
232 $func =
'rawurlencode';
245 public static function lcfirst( $parser, $s =
'' ) {
249 public static function ucfirst( $parser, $s =
'' ) {
258 public static function lc( $parser, $s =
'' ) {
267 public static function uc( $parser, $s =
'' ) {
271 public static function localurl( $parser, $s =
'', $arg =
null ) {
275 public static function localurle( $parser, $s =
'', $arg =
null ) {
277 if ( !is_string( $temp ) ) {
280 return htmlspecialchars( $temp, ENT_COMPAT );
284 public static function fullurl( $parser, $s =
'', $arg =
null ) {
288 public static function fullurle( $parser, $s =
'', $arg =
null ) {
290 if ( !is_string( $temp ) ) {
293 return htmlspecialchars( $temp, ENT_COMPAT );
303 if ( !is_string( $temp ) ) {
306 return htmlspecialchars( $temp, ENT_COMPAT );
310 public static function urlFunction( $func, $s =
'', $arg =
null ) {
311 # Due to order of execution of a lot of bits, the values might be encoded
312 # before arriving here; if that's true, then the title can't be created
313 # and the variable will fail. If we can't get a decent title from the first
314 # attempt, url-decode and try for a second.
315 $title = Title::newFromText( $s ) ?? Title::newFromURL( urldecode( $s ) );
317 # Convert NS_MEDIA -> NS_FILE
321 if ( $arg !==
null ) {
322 $text =
$title->$func( $arg );
328 return [
'found' => false ];
338 public static function formatnum( $parser, $num =
'', $arg =
null ) {
345 $func = self::getLegacyFormatNum( $parser, $func );
348 $func = self::getLegacyFormatNum( $parser, $func );
359 private static function getLegacyFormatNum( $parser, $callback ) {
364 return static function ( $number ) use ( $parser, $callback ) {
365 $validNumberRe =
'(-(?=[\d\.]))?(\d+|(?=\.\d))(\.\d*)?([Ee][-+]?\d+)?';
367 !is_numeric( $number ) &&
368 $number !== (string)NAN &&
369 $number !== (
string)INF &&
370 $number !== (string)-INF
375 return preg_replace_callback(
"/{$validNumberRe}/",
static function ( $m ) use ( $callback ) {
376 return call_user_func( $callback, $m[0] );
379 return call_user_func( $callback, $number );
389 public static function grammar( $parser, $case =
'', $word =
'' ) {
400 public static function gender( $parser, $username, ...$forms ) {
402 if ( count( $forms ) === 0 ) {
404 } elseif ( count( $forms ) === 1 ) {
408 $username = trim( $username );
410 $userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
411 $gender = $userOptionsLookup->getDefaultOption(
'gender' );
417 $username =
$title->getText();
422 $genderCache = MediaWikiServices::getInstance()->getGenderCache();
424 $gender = $genderCache->getGenderOf( $user, __METHOD__ );
425 } elseif ( $username ===
'' && $parser->
getOptions()->getInterfaceMessage() ) {
426 $gender = $genderCache->getGenderOf( $parser->
getOptions()->getUserIdentity(), __METHOD__ );
438 public static function plural( $parser, $text =
'', ...$forms ) {
440 settype( $text, ctype_digit( $text ) ?
'int' :
'float' );
450 public static function bidi( $parser, $text =
'' ) {
463 public static function displaytitle( $parser, $text =
'', $uarg =
'' ) {
464 $restrictDisplayTitle = MediaWikiServices::getInstance()->getMainConfig()
465 ->get( MainConfigNames::RestrictDisplayTitle );
470 [
'displaytitle_noerror',
'displaytitle_noreplace' ] );
483 $bad = [
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'div',
'blockquote',
'ol',
'ul',
'li',
'hr',
484 'table',
'tr',
'th',
'td',
'dl',
'dd',
'caption',
'p',
'ruby',
'rb',
'rt',
'rtc',
'rp',
'br' ];
487 if ( $restrictDisplayTitle ) {
490 $htmlTagsCallback =
static function ( Attributes $attr ): Attributes {
491 $decoded = $attr->getValues();
493 if ( isset( $decoded[
'style'] ) ) {
498 if ( preg_match(
'/(display|user-select|visibility)\s*:/i', $decoded[
'style'] ) ) {
499 $decoded[
'style'] =
'/* attempt to bypass $wgRestrictDisplayTitle */';
503 return new PlainAttributes( $decoded );
506 $htmlTagsCallback =
null;
513 'attrCallback' => $htmlTagsCallback,
514 'removeTags' => $bad,
520 if ( !$restrictDisplayTitle ||
525 $old = $parser->
getOutput()->getPageProperty(
'displaytitle' );
526 if ( $old ===
null || $arg !==
'displaytitle_noreplace' ) {
527 $parser->
getOutput()->setDisplayTitle( $text );
529 if ( $old !==
null && $old !== $text && !$arg ) {
532 return '<span class="error">' .
533 $parser->
msg(
'duplicate-displaytitle',
544 'restricted-displaytitle',
561 private static function matchAgainstMagicword(
564 $value = trim( strval( $value ) );
565 if ( $value ===
'' ) {
568 $mwObject = $magicWordFactory->
get( $magicword );
569 return $mwObject->matchStartToEnd( $value );
584 if ( $raw !==
null && $raw !==
'' ) {
585 if ( !$magicWordFactory ) {
586 $magicWordFactory = MediaWikiServices::getInstance()->getMagicWordFactory();
588 if ( self::matchAgainstMagicword( $magicWordFactory,
'rawsuffix', $raw ) ) {
592 return $language->formatNum( $num );
617 SiteStats::numberingroup(
'sysop' ),
629 SiteStats::pagesInNs( intval( $namespace ) ),
637 SiteStats::numberingroup( strtolower( $name ) ),
651 private static function makeTitle(
Parser $parser, ?
string $t ) {
669 public static function namespace( $parser,
$title = null ) {
674 return str_replace(
'_',
' ',
$t->getNsText() );
689 return self::namespace( $parser,
$title );
693 $t = self::makeTitle( $parser,
$title );
701 $t = self::makeTitle( $parser,
$title );
705 return (
string)
$t->getNamespace();
709 $t = self::makeTitle( $parser,
$title );
710 if (
$t ===
null || !
$t->canHaveTalkPage() ) {
713 return str_replace(
'_',
' ',
$t->getTalkNsText() );
717 $t = self::makeTitle( $parser,
$title );
718 if (
$t ===
null || !
$t->canHaveTalkPage() ) {
725 $t = self::makeTitle( $parser,
$title );
729 return str_replace(
'_',
' ',
$t->getSubjectNsText() );
733 $t = self::makeTitle( $parser,
$title );
748 $t = self::makeTitle( $parser,
$title );
756 $t = self::makeTitle( $parser,
$title );
764 $t = self::makeTitle( $parser,
$title );
772 $t = self::makeTitle( $parser,
$title );
780 $t = self::makeTitle( $parser,
$title );
788 $t = self::makeTitle( $parser,
$title );
796 $t = self::makeTitle( $parser,
$title );
804 $t = self::makeTitle( $parser,
$title );
812 $t = self::makeTitle( $parser,
$title );
820 $t = self::makeTitle( $parser,
$title );
828 $t = self::makeTitle( $parser,
$title );
829 if (
$t ===
null || !
$t->canHaveTalkPage() ) {
836 $t = self::makeTitle( $parser,
$title );
837 if (
$t ===
null || !
$t->canHaveTalkPage() ) {
844 $t = self::makeTitle( $parser,
$title );
852 $t = self::makeTitle( $parser,
$title );
869 public static function pagesincategory( $parser, $name =
'', $arg1 =
'', $arg2 =
'' ) {
873 'pagesincategory_all',
874 'pagesincategory_pages',
875 'pagesincategory_subcats',
876 'pagesincategory_files'
892 $type =
'pagesincategory_all';
896 if ( !
$title ) { # invalid title
899 $languageConverter = MediaWikiServices::getInstance()
900 ->getLanguageConverterFactory()
902 $languageConverter->findVariantLink( $name,
$title,
true );
905 $name =
$title->getDBkey();
907 if ( !isset( $cache[$name] ) ) {
908 $category = Category::newFromTitle(
$title );
910 $allCount = $subcatCount = $fileCount = $pageCount = 0;
912 $allCount = $category->getMemberCount();
913 $subcatCount = $category->getSubcatCount();
914 $fileCount = $category->getFileCount();
915 $pageCount = $category->getPageCount( Category::COUNT_CONTENT_PAGES );
917 $cache[$name][
'pagesincategory_all'] = $allCount;
918 $cache[$name][
'pagesincategory_pages'] = $pageCount;
919 $cache[$name][
'pagesincategory_subcats'] = $subcatCount;
920 $cache[$name][
'pagesincategory_files'] = $fileCount;
923 $count = $cache[$name][
$type];
936 public static function pagesize( $parser, $page =
'', $raw =
null ) {
937 $title = Title::newFromText( $page );
939 if ( !is_object(
$title ) ) {
944 $rev = self::getCachedRevisionObject( $parser,
$title, ParserOutputFlags::VARY_REVISION_SHA1 );
945 $length = $rev ? $rev->getSize() : 0;
946 if ( $length ===
null ) {
966 $titleObject = Title::newFromText(
$title ) ?? $parser->
getTitle();
967 $restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore();
969 $restrictions = $restrictionStore->getRestrictions( $titleObject, strtolower(
$type ) );
970 # RestrictionStore::getRestrictions returns an array, its possible it may have
971 # multiple values in the future
972 return implode(
',', $restrictions );
990 $titleObject = Title::newFromText(
$title ) ?? $parser->
getTitle();
991 $restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore();
995 return $restrictionStore->getRestrictionExpiry( $titleObject, strtolower(
$type ) ) ??
'';
1007 public static function language( $parser, $code =
'', $inLanguage =
'' ) {
1008 $code = strtolower( $code );
1009 $inLanguage = strtolower( $inLanguage );
1010 $lang = MediaWikiServices::getInstance()
1011 ->getLanguageNameUtils()
1012 ->getLanguageName( $code, $inLanguage );
1026 $parser, $string, $length, $padding =
'0', $direction = STR_PAD_RIGHT
1029 $lengthOfPadding = mb_strlen( $padding );
1030 if ( $lengthOfPadding == 0 ) {
1034 # The remaining length to add counts down to 0 as padding is added
1035 $length = min( (
int)$length, 500 ) - mb_strlen( $string );
1036 if ( $length <= 0 ) {
1041 # $finalPadding is just $padding repeated enough times so that
1042 # mb_strlen( $string ) + mb_strlen( $finalPadding ) == $length
1044 while ( $length > 0 ) {
1045 # If $length < $lengthofPadding, truncate $padding so we get the
1046 # exact length desired.
1047 $finalPadding .= mb_substr( $padding, 0, $length );
1048 $length -= $lengthOfPadding;
1051 if ( $direction == STR_PAD_LEFT ) {
1052 return $finalPadding . $string;
1054 return $string . $finalPadding;
1058 public static function padleft( $parser, $string =
'', $length = 0, $padding =
'0' ) {
1059 return self::pad( $parser, $string, $length, $padding, STR_PAD_LEFT );
1062 public static function padright( $parser, $string =
'', $length = 0, $padding =
'0' ) {
1063 return self::pad( $parser, $string, $length, $padding );
1077 public static function special( $parser, $text ) {
1078 [ $page, $subpage ] = MediaWikiServices::getInstance()->getSpecialPageFactory()->
1079 resolveAlias( $text );
1082 return $title->getPrefixedText();
1091 return wfUrlencode( str_replace(
' ',
'_', self::special( $parser, $text ) ) );
1106 [
'defaultsort_noerror',
'defaultsort_noreplace' ] );
1110 $text = trim( $text );
1111 if ( strlen( $text ) == 0 ) {
1114 $old = $parser->
getOutput()->getPageProperty(
'defaultsort' );
1115 if ( $old ===
null || $arg !==
'defaultsort_noreplace' ) {
1116 $parser->
getOutput()->setPageProperty(
'defaultsort', $text );
1119 if ( $old ===
null || $old == $text || $arg ) {
1123 return '<span class="error">' .
1124 $parser->
msg(
'duplicate-defaultsort',
1144 public static function filepath( $parser, $name =
'', $argA =
'', $argB =
'' ) {
1145 $file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $name );
1147 if ( $argA ==
'nowiki' ) {
1154 $isNowiki = ( $argB ==
'nowiki' );
1158 $url =
$file->getFullUrl();
1161 if ( count( $parsedWidthParam ) ) {
1162 $mto =
$file->transform( $parsedWidthParam );
1164 if ( $mto && !$mto->isError() ) {
1170 return [ $url,
'nowiki' =>
true ];
1185 public static function tagObj( $parser, $frame, $args ) {
1186 if ( !count( $args ) ) {
1189 $tagName = strtolower( trim( $frame->expand( array_shift( $args ) ) ) );
1192 if ( count( $args ) ) {
1193 $inner = $frame->expand( array_shift( $args ), $processNowiki );
1199 foreach ( $args as $arg ) {
1200 $bits = $arg->splitArg();
1201 if ( strval( $bits[
'index'] ) ===
'' ) {
1203 $value = trim( $frame->expand( $bits[
'value'] ) );
1204 if ( preg_match(
'/^(?:["\'](.+)["\']|""|\'\')$/s', $value, $m ) ) {
1205 $value = $m[1] ??
'';
1207 $attributes[$name] = $value;
1212 if ( !in_array( $tagName, $stripList ) ) {
1215 foreach ( $attributes as $name => $value ) {
1216 $attrText .=
' ' . htmlspecialchars( $name ) .
1217 '="' . htmlspecialchars( $value, ENT_COMPAT ) .
'"';
1219 if ( $inner ===
null ) {
1220 return "<$tagName$attrText/>";
1222 return "<$tagName$attrText>$inner</$tagName>";
1228 'attributes' => $attributes,
1229 'close' =>
"</$tagName>",
1247 private static function getCachedRevisionObject( $parser,
$title, $vary ) {
1252 $revisionRecord =
null;
1255 if ( $isSelfReferential ) {
1266 if ( $parserRevisionRecord && $parserRevisionRecord->isCurrent() ) {
1267 $revisionRecord = $parserRevisionRecord;
1272 if ( !$revisionRecord ) {
1281 if ( !$revisionRecord ) {
1283 $revisionRecord =
null;
1286 $parserOutput->addTemplate(
1288 $revisionRecord ? $revisionRecord->getPageId() : 0,
1289 $revisionRecord ? $revisionRecord->getId() : 0
1293 if ( $isSelfReferential ) {
1294 wfDebug( __METHOD__ .
": used current revision, setting $vary" );
1296 $parserOutput->setOutputFlag( $vary );
1297 if ( $vary === ParserOutputFlags::VARY_REVISION_SHA1 && $revisionRecord ) {
1299 $sha1 = $revisionRecord->getSha1();
1303 $parserOutput->setRevisionUsedSha1Base36( $sha1 );
1307 return $revisionRecord;
1318 $t = self::makeTitle( $parser,
$title );
1321 } elseif ( !
$t->canExist() ||
$t->isExternal() ) {
1330 $parserOutput->setOutputFlag( ParserOutputFlags::VARY_PAGE_ID );
1331 $id = $parser->
getTitle()->getArticleID();
1333 $parserOutput->setSpeculativePageIdUsed( $id );
1340 $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1341 $pdbk =
$t->getPrefixedDBkey();
1342 $id = $linkCache->getGoodLinkID( $pdbk );
1343 if ( $id != 0 || $linkCache->isBadLink( $pdbk ) ) {
1344 $parserOutput->addLink(
$t, $id );
1351 $id =
$t->getArticleID();
1352 $parserOutput->addLink(
$t, $id );
1368 $t = self::makeTitle( $parser,
$title );
1369 if (
$t ===
null ) {
1373 $services = MediaWikiServices::getInstance();
1376 $services->getMainConfig()->get( MainConfigNames::MiserMode ) &&
1377 !$parser->
getOptions()->getInterfaceMessage() &&
1379 $services->getNamespaceInfo()->isSubject(
$t->getNamespace() )
1386 $parser->
getOutput()->setOutputFlag( ParserOutputFlags::VARY_REVISION_EXISTS );
1397 $parser->
getOutput()->setOutputFlag( ParserOutputFlags::VARY_REVISION_ID );
1402 $id = $rev->getId();
1406 $id = $parser->
getOptions()->getSpeculativeRevId();
1408 $parser->
getOutput()->setSpeculativeRevIdUsed( $id );
1413 $rev = self::getCachedRevisionObject( $parser,
$t, ParserOutputFlags::VARY_REVISION_ID );
1414 return $rev ? $rev->getId() :
'';
1417 private static function getRevisionTimestampSubstring(
1430 if (
$title->equals( $parser->
getTitle() ) && !$parser->getOptions()->getInterfaceMessage() ) {
1445 if ( $resNow !== $resThen ) {
1448 $parser->
getOutput()->setOutputFlag( ParserOutputFlags::VARY_REVISION_TIMESTAMP );
1454 $rev = self::getCachedRevisionObject( $parser,
$title, ParserOutputFlags::VARY_REVISION_TIMESTAMP );
1473 $t = self::makeTitle( $parser,
$title );
1474 if (
$t ===
null ) {
1477 return strval( (
int)self::getRevisionTimestampSubstring(
1478 $parser,
$t, 6, 2, self::MAX_TTS
1490 $t = self::makeTitle( $parser,
$title );
1491 if (
$t ===
null ) {
1494 return self::getRevisionTimestampSubstring(
1495 $parser,
$t, 6, 2, self::MAX_TTS
1507 $t = self::makeTitle( $parser,
$title );
1508 if (
$t ===
null ) {
1511 return self::getRevisionTimestampSubstring(
1512 $parser,
$t, 4, 2, self::MAX_TTS
1524 $t = self::makeTitle( $parser,
$title );
1525 if (
$t ===
null ) {
1528 return strval( (
int)self::getRevisionTimestampSubstring(
1529 $parser,
$t, 4, 2, self::MAX_TTS
1541 $t = self::makeTitle( $parser,
$title );
1542 if (
$t ===
null ) {
1545 return self::getRevisionTimestampSubstring(
1546 $parser,
$t, 0, 4, self::MAX_TTS
1558 $t = self::makeTitle( $parser,
$title );
1559 if (
$t ===
null ) {
1562 return self::getRevisionTimestampSubstring(
1563 $parser,
$t, 0, 14, self::MAX_TTS
1575 $t = self::makeTitle( $parser,
$title );
1576 if (
$t ===
null ) {
1584 $parser->
getOutput()->setOutputFlag( ParserOutputFlags::VARY_USER );
1591 $rev = self::getCachedRevisionObject( $parser,
$t, ParserOutputFlags::VARY_USER );
1592 $user = ( $rev !== null ) ? $rev->getUser() :
null;
1593 return $user ? $user->getName() :
'';
1609 $titleObject = Title::newFromText(
$title ) ?? $parser->
getTitle();
1610 $restrictionStore = MediaWikiServices::getInstance()->getRestrictionStore();
1611 if ( $restrictionStore->areCascadeProtectionSourcesLoaded( $titleObject )
1615 $sources = $restrictionStore->getCascadeProtectionSources( $titleObject );
1616 $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
1617 foreach ( $sources[0] as $sourcePageIdentity ) {
1618 $names[] = $titleFormatter->getPrefixedText( $sourcePageIdentity );
1620 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.
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.
static checkCss( $value)
Pick apart some CSS and check it for forbidden or unsafe structures.
static removeSomeTags(string $text, array $options=[])
Cleans up HTML, removes dangerous tags and attributes, and removes HTML comments; the result will alw...
static stripAllTags( $html)
Take a fragment of (potentially invalid) HTML and return a version with any tags removed,...
static decodeCharReferencesAndNormalize( $text)
Decode any character references, numeric or named entities, in the next and normalize the resulting s...
static safeEncodeAttribute( $text)
Encode an attribute value for HTML tags, with extra armoring against further wiki processing.
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,...
static newFromName( $name, $validate='valid')
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
if(!isset( $args[0])) $lang