25 use Psr\Log\LoggerInterface;
26 use Wikimedia\Timestamp\ConvertibleTimestamp;
52 ConvertibleTimestamp $ts,
54 LoggerInterface $logger
56 $pageLang = $parser->getTargetLanguage();
64 return $pageLang->formatNumNoSeparators( $ts->format(
'm' ) );
66 return $pageLang->formatNumNoSeparators( $ts->format(
'n' ) );
67 case 'currentmonthname':
68 return $pageLang->getMonthName( (
int)$ts->format(
'n' ) );
69 case 'currentmonthnamegen':
70 return $pageLang->getMonthNameGen( (
int)$ts->format(
'n' ) );
71 case 'currentmonthabbrev':
72 return $pageLang->getMonthAbbreviation( (
int)$ts->format(
'n' ) );
74 return $pageLang->formatNumNoSeparators( $ts->format(
'j' ) );
76 return $pageLang->formatNumNoSeparators( $ts->format(
'd' ) );
78 return $pageLang->formatNumNoSeparators( self::makeTsLocal( $svcOptions, $ts )->format(
'm' ) );
80 return $pageLang->formatNumNoSeparators( self::makeTsLocal( $svcOptions, $ts )->format(
'n' ) );
81 case 'localmonthname':
82 return $pageLang->getMonthName( (
int)self::makeTsLocal( $svcOptions, $ts )->format(
'n' ) );
83 case 'localmonthnamegen':
84 return $pageLang->getMonthNameGen( (
int)self::makeTsLocal( $svcOptions, $ts )->format(
'n' ) );
85 case 'localmonthabbrev':
86 return $pageLang->getMonthAbbreviation( (
int)self::makeTsLocal( $svcOptions, $ts )->format(
'n' ) );
88 return $pageLang->formatNumNoSeparators( self::makeTsLocal( $svcOptions, $ts )->format(
'j' ) );
90 return $pageLang->formatNumNoSeparators( self::makeTsLocal( $svcOptions, $ts )->format(
'd' ) );
100 case 'basepagenamee':
102 case 'talkpagenamee':
103 case 'subjectpagename':
104 case 'subjectpagenamee':
110 case 'revisionmonth':
111 case 'revisionmonth1':
113 case 'revisiontimestamp':
116 case 'namespacenumber':
120 case 'subjectspacee':
121 case 'cascadingsources':
122 # First argument of the corresponding parser function
123 # (second argument of the PHP implementation) is
126 # Note that for many of these {{FOO}} is subtly different
127 # from {{FOO:{{PAGENAME}}}}, so we can't pass $title here
128 # we have to explicitly use the "no arguments" form of the
129 # parser function by passing `null` to indicate a missing
130 # argument (which then defaults to the current page title).
131 return CoreParserFunctions::$id( $parser,
null );
134 case 'currentdayname':
135 return $pageLang->getWeekdayName( (
int)$ts->format(
'w' ) + 1 );
137 return $pageLang->formatNumNoSeparators( $ts->format(
'Y' ) );
139 return $pageLang->time( $ts->getTimestamp( TS_MW ),
false,
false );
141 return $pageLang->formatNumNoSeparators( $ts->format(
'H' ) );
145 return $pageLang->formatNum( (
int)$ts->format(
'W' ) );
147 return $pageLang->formatNum( $ts->format(
'w' ) );
149 return $pageLang->getWeekdayName(
150 (
int)self::makeTsLocal( $svcOptions, $ts )->format(
'w' ) + 1
153 return $pageLang->formatNumNoSeparators( self::makeTsLocal( $svcOptions, $ts )->format(
'Y' ) );
155 return $pageLang->time(
156 self::makeTsLocal( $svcOptions, $ts )->format(
'YmdHis' ),
161 return $pageLang->formatNumNoSeparators( self::makeTsLocal( $svcOptions, $ts )->format(
'H' ) );
165 return $pageLang->formatNum( (
int)self::makeTsLocal( $svcOptions, $ts )->format(
'W' ) );
167 return $pageLang->formatNum( self::makeTsLocal( $svcOptions, $ts )->format(
'w' ) );
168 case 'numberofarticles':
169 case 'numberoffiles':
170 case 'numberofusers':
171 case 'numberofactiveusers':
172 case 'numberofpages':
173 case 'numberofadmins':
174 case 'numberofedits':
175 # second argument is 'raw'; magic variables are "not raw"
176 return CoreParserFunctions::$id( $parser,
null );
177 case 'currenttimestamp':
178 return $ts->getTimestamp( TS_MW );
179 case 'localtimestamp':
180 return self::makeTsLocal( $svcOptions, $ts )->format(
'YmdHis' );
181 case 'currentversion':
184 return (
string)$svcOptions->
get( MainConfigNames::ArticlePath );
186 return (
string)$svcOptions->
get( MainConfigNames::Sitename );
188 return (
string)$svcOptions->
get( MainConfigNames::Server );
190 return (
string)$svcOptions->
get( MainConfigNames::ServerName );
192 return (
string)$svcOptions->
get( MainConfigNames::ScriptPath );
194 return (
string)$svcOptions->
get( MainConfigNames::StylePath );
195 case 'directionmark':
196 return $pageLang->getDirMark();
197 case 'contentlanguage':
200 return $pageLang->getCode();
214 private static function makeTsLocal( $svcOptions, $ts ) {
215 $localtimezone = $svcOptions->
get( MainConfigNames::Localtimezone );
216 $ts->setTimezone( $localtimezone );
Expansions of core magic variables, used by the parser.
static expand(Parser $parser, string $id, ConvertibleTimestamp $ts, ServiceOptions $svcOptions, LoggerInterface $logger)
Expand the magic variable given by $index.
A class containing constants representing the names of configuration variables.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
getRevisionSize()
Get the size of the revision.
getContentLanguage()
Get the content language that this Parser is using.
static getVersion( $flags='', $lang=null)
Return a string of the MediaWiki version with Git revision if available.