Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
72.93% |
590 / 809 |
|
34.78% |
32 / 92 |
CRAP | |
0.00% |
0 / 1 |
| CoreParserFunctions | |
73.02% |
590 / 808 |
|
34.78% |
32 / 92 |
2184.22 | |
0.00% |
0 / 1 |
| register | |
91.07% |
51 / 56 |
|
0.00% |
0 / 1 |
4.01 | |||
| intFunction | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
2.03 | |||
| formatDate | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
| ns | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
4.07 | |||
| nse | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| urlencode | |
86.67% |
13 / 15 |
|
0.00% |
0 / 1 |
6.09 | |||
| lcfirst | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| ucfirst | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| lc | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| uc | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| localurl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| localurle | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| fullurl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fullurle | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| canonicalurl | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| canonicalurle | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| urlFunction | |
66.67% |
6 / 9 |
|
0.00% |
0 / 1 |
4.59 | |||
| formatnum | |
80.00% |
20 / 25 |
|
0.00% |
0 / 1 |
6.29 | |||
| getLegacyFormatNum | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
5 | |||
| grammar | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| gender | |
77.78% |
14 / 18 |
|
0.00% |
0 / 1 |
8.70 | |||
| plural | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| formal | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| bidi | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| displaytitle | |
78.95% |
45 / 57 |
|
0.00% |
0 / 1 |
17.10 | |||
| matchAgainstMagicword | |
60.00% |
3 / 5 |
|
0.00% |
0 / 1 |
2.26 | |||
| formatRaw | |
33.33% |
2 / 6 |
|
0.00% |
0 / 1 |
12.41 | |||
| numberofpages | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| numberofusers | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| numberofactiveusers | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| numberofarticles | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| numberoffiles | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| numberofadmins | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| numberofedits | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| pagesinnamespace | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| numberingroup | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| makeTitle | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| namespace | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| namespacee | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| namespacenumber | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| talkspace | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
3.14 | |||
| talkspacee | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
3.14 | |||
| subjectspace | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| subjectspacee | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| pagename | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| pagenamee | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| fullpagename | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| fullpagenamee | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| subpagename | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| subpagenamee | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| rootpagename | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| rootpagenamee | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| basepagename | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| basepagenamee | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| talkpagename | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
| talkpagenamee | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
3.14 | |||
| subjectpagename | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| subjectpagenamee | |
80.00% |
4 / 5 |
|
0.00% |
0 / 1 |
2.03 | |||
| pagesincategory | |
44.74% |
17 / 38 |
|
0.00% |
0 / 1 |
15.27 | |||
| pagesize | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
5.05 | |||
| protectionlevel | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| protectionexpiry | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| language | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
| dir | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
6 | |||
| bcp47 | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| pad | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
5.01 | |||
| padleft | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| padright | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| anchorencode | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| special | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
| speciale | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| defaultsort | |
55.00% |
11 / 20 |
|
0.00% |
0 / 1 |
13.83 | |||
| categorysort | |
88.89% |
16 / 18 |
|
0.00% |
0 / 1 |
4.02 | |||
| filepath | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
56 | |||
| tagObj | |
73.81% |
31 / 42 |
|
0.00% |
0 / 1 |
13.17 | |||
| getCachedRevisionObject | |
83.33% |
25 / 30 |
|
0.00% |
0 / 1 |
16.04 | |||
| pageid | |
43.48% |
10 / 23 |
|
0.00% |
0 / 1 |
23.63 | |||
| revisionid | |
60.00% |
15 / 25 |
|
0.00% |
0 / 1 |
32.38 | |||
| getRevisionTimestampSubstring | |
77.78% |
14 / 18 |
|
0.00% |
0 / 1 |
6.40 | |||
| revisionday | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| revisionday2 | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| revisionmonth | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| revisionmonth1 | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| revisionyear | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| revisiontimestamp | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
3 | |||
| revisionuser | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
6 | |||
| cascadingsources | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
| contentmodel | |
85.00% |
17 / 20 |
|
0.00% |
0 / 1 |
7.17 | |||
| isbn | |
96.30% |
26 / 27 |
|
0.00% |
0 / 1 |
2 | |||
| interwikilink | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
5 | |||
| interlanguagelink | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
6 | |||
| getTitleValueSafe | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Parser functions provided by MediaWiki core |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | * @ingroup Parser |
| 8 | */ |
| 9 | |
| 10 | namespace MediaWiki\Parser; |
| 11 | |
| 12 | use InvalidArgumentException; |
| 13 | use MediaWiki\Category\Category; |
| 14 | use MediaWiki\Config\ServiceOptions; |
| 15 | use MediaWiki\Content\ContentHandler; |
| 16 | use MediaWiki\Language\Language; |
| 17 | use MediaWiki\Language\LanguageCode; |
| 18 | use MediaWiki\Language\LanguageNameUtils; |
| 19 | use MediaWiki\MainConfigNames; |
| 20 | use MediaWiki\MediaWikiServices; |
| 21 | use MediaWiki\Revision\RevisionAccessException; |
| 22 | use MediaWiki\Revision\RevisionRecord; |
| 23 | use MediaWiki\SiteStats\SiteStats; |
| 24 | use MediaWiki\SpecialPage\SpecialPage; |
| 25 | use MediaWiki\Title\Title; |
| 26 | use MediaWiki\Title\TitleValue; |
| 27 | use MediaWiki\User\User; |
| 28 | use Wikimedia\Bcp47Code\Bcp47CodeValue; |
| 29 | use Wikimedia\HtmlArmor\HtmlArmor; |
| 30 | use Wikimedia\RemexHtml\Tokenizer\Attributes; |
| 31 | use Wikimedia\RemexHtml\Tokenizer\PlainAttributes; |
| 32 | use Wikimedia\Timestamp\TimestampFormat as TS; |
| 33 | |
| 34 | /** |
| 35 | * Various core parser functions, registered in every Parser |
| 36 | * @ingroup Parser |
| 37 | */ |
| 38 | class CoreParserFunctions { |
| 39 | /** @var int Assume that no output will later be saved this many seconds after parsing */ |
| 40 | private const MAX_TTS = 900; |
| 41 | |
| 42 | /** |
| 43 | * @internal |
| 44 | */ |
| 45 | public const REGISTER_OPTIONS = [ |
| 46 | // See documentation for the corresponding config options |
| 47 | MainConfigNames::AllowDisplayTitle, |
| 48 | MainConfigNames::AllowSlowParserFunctions, |
| 49 | ]; |
| 50 | |
| 51 | /** |
| 52 | * @param Parser $parser |
| 53 | * @param ServiceOptions $options |
| 54 | * |
| 55 | * @return void |
| 56 | * @internal |
| 57 | */ |
| 58 | public static function register( Parser $parser, ServiceOptions $options ) { |
| 59 | $options->assertRequiredOptions( self::REGISTER_OPTIONS ); |
| 60 | $allowDisplayTitle = $options->get( MainConfigNames::AllowDisplayTitle ); |
| 61 | $allowSlowParserFunctions = $options->get( MainConfigNames::AllowSlowParserFunctions ); |
| 62 | |
| 63 | # Syntax for arguments (see Parser::setFunctionHook): |
| 64 | # "name for lookup in localized magic words array", |
| 65 | # function callback, |
| 66 | # optional Parser::SFH_NO_HASH to omit the hash from calls (e.g. {{int:...}} |
| 67 | # instead of {{#int:...}}) |
| 68 | $noHashFunctions = [ |
| 69 | 'ns', 'nse', 'urlencode', 'lcfirst', 'ucfirst', 'lc', 'uc', |
| 70 | 'localurl', 'localurle', 'fullurl', 'fullurle', 'canonicalurl', |
| 71 | 'canonicalurle', 'formatnum', 'grammar', 'gender', 'plural', 'formal', |
| 72 | 'bidi', 'numberingroup', 'language', |
| 73 | 'padleft', 'padright', 'anchorencode', 'defaultsort', 'categorysort', 'filepath', |
| 74 | 'pagesincategory', 'pagesize', 'protectionlevel', 'protectionexpiry', |
| 75 | # The following are the "parser function" forms of magic |
| 76 | # variables defined in CoreMagicVariables. The no-args form will |
| 77 | # go through the magic variable code path (and be cached); the |
| 78 | # presence of arguments will cause the parser function form to |
| 79 | # be invoked. (Note that the actual implementation will pass |
| 80 | # a Parser object as first argument, in addition to the |
| 81 | # parser function parameters.) |
| 82 | |
| 83 | # For this group, the first parameter to the parser function is |
| 84 | # "page title", and the no-args form (and the magic variable) |
| 85 | # defaults to "current page title". |
| 86 | 'pagename', 'pagenamee', |