Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
Hooks | |
0.00% |
0 / 34 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
onParserTestGlobals | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onParserFirstCallInit | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\ParserFunctions; |
4 | |
5 | use MediaWiki\Cache\LinkCache; |
6 | use MediaWiki\Config\Config; |
7 | use MediaWiki\HookContainer\HookContainer; |
8 | use MediaWiki\Languages\LanguageConverterFactory; |
9 | use MediaWiki\Languages\LanguageFactory; |
10 | use MediaWiki\Languages\LanguageNameUtils; |
11 | use MediaWiki\Parser\Parser; |
12 | use MediaWiki\SpecialPage\SpecialPageFactory; |
13 | use RepoGroup; |
14 | |
15 | class Hooks implements |
16 | \MediaWiki\Hook\ParserFirstCallInitHook, |
17 | \MediaWiki\Hook\ParserTestGlobalsHook |
18 | { |
19 | private Config $config; |
20 | private ParserFunctions $parserFunctions; |
21 | |
22 | public function __construct( |
23 | Config $config, |
24 | HookContainer $hookContainer, |
25 | LanguageConverterFactory $languageConverterFactory, |
26 | LanguageFactory $languageFactory, |
27 | LanguageNameUtils $languageNameUtils, |
28 | LinkCache $linkCache, |
29 | RepoGroup $repoGroup, |
30 | SpecialPageFactory $specialPageFactory |
31 | ) { |
32 | $this->config = $config; |
33 | $this->parserFunctions = new ParserFunctions( |
34 | $config, |
35 | $hookContainer, |
36 | $languageConverterFactory, |
37 | $languageFactory, |
38 | $languageNameUtils, |
39 | $linkCache, |
40 | $repoGroup, |
41 | $specialPageFactory |
42 | ); |
43 | } |
44 | |
45 | /** |
46 | * Enables string functions during parser tests. |
47 | * |
48 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserTestGlobals |
49 | * |
50 | * @param array &$globals |
51 | */ |
52 | public function onParserTestGlobals( &$globals ) { |
53 | $globals['wgPFEnableStringFunctions'] = true; |
54 | } |
55 | |
56 | /** |
57 | * Registers our parser functions with a fresh parser. |
58 | * |
59 | * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserFirstCallInit |
60 | * |
61 | * @param Parser $parser |
62 | */ |
63 | public function onParserFirstCallInit( $parser ) { |
64 | // These functions accept DOM-style arguments |
65 | $parser->setFunctionHook( 'if', [ $this->parserFunctions, 'if' ], Parser::SFH_OBJECT_ARGS ); |
66 | $parser->setFunctionHook( 'ifeq', [ $this->parserFunctions, 'ifeq' ], Parser::SFH_OBJECT_ARGS ); |
67 | $parser->setFunctionHook( 'switch', [ $this->parserFunctions, 'switch' ], Parser::SFH_OBJECT_ARGS ); |
68 | $parser->setFunctionHook( 'ifexist', [ $this->parserFunctions, 'ifexist' ], Parser::SFH_OBJECT_ARGS ); |
69 | $parser->setFunctionHook( 'ifexpr', [ $this->parserFunctions, 'ifexpr' ], Parser::SFH_OBJECT_ARGS ); |
70 | $parser->setFunctionHook( 'iferror', [ $this->parserFunctions, 'iferror' ], Parser::SFH_OBJECT_ARGS ); |
71 | $parser->setFunctionHook( 'time', [ $this->parserFunctions, 'time' ], Parser::SFH_OBJECT_ARGS ); |
72 | $parser->setFunctionHook( 'timel', [ $this->parserFunctions, 'localTime' ], Parser::SFH_OBJECT_ARGS ); |
73 | $parser->setFunctionHook( 'timef', [ $this->parserFunctions, 'timef' ], Parser::SFH_OBJECT_ARGS ); |
74 | $parser->setFunctionHook( 'timefl', [ $this->parserFunctions, 'timefl' ], Parser::SFH_OBJECT_ARGS ); |
75 | |
76 | $parser->setFunctionHook( 'expr', [ $this->parserFunctions, 'expr' ] ); |
77 | $parser->setFunctionHook( 'rel2abs', [ $this->parserFunctions, 'rel2abs' ] ); |
78 | $parser->setFunctionHook( 'titleparts', [ $this->parserFunctions, 'titleparts' ] ); |
79 | |
80 | // String Functions: enable if configured |
81 | if ( $this->config->get( 'PFEnableStringFunctions' ) ) { |
82 | $parser->setFunctionHook( 'len', [ $this->parserFunctions, 'runLen' ] ); |
83 | $parser->setFunctionHook( 'pos', [ $this->parserFunctions, 'runPos' ] ); |
84 | $parser->setFunctionHook( 'rpos', [ $this->parserFunctions, 'runRPos' ] ); |
85 | $parser->setFunctionHook( 'sub', [ $this->parserFunctions, 'runSub' ] ); |
86 | $parser->setFunctionHook( 'count', [ $this->parserFunctions, 'runCount' ] ); |
87 | $parser->setFunctionHook( 'replace', [ $this->parserFunctions, 'runReplace' ] ); |
88 | $parser->setFunctionHook( 'explode', [ $this->parserFunctions, 'runExplode' ] ); |
89 | $parser->setFunctionHook( 'urldecode', [ $this->parserFunctions, 'runUrlDecode' ] ); |
90 | } |
91 | } |
92 | } |