Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ParserFunctionsHooks | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
onParserFirstCallInit | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments; |
4 | |
5 | use MediaWiki\MediaWikiServices; |
6 | use MediaWiki\Parser\Parser; |
7 | |
8 | /** |
9 | * Class that consumes parser-functions related hooks. |
10 | */ |
11 | class ParserFunctionsHooks implements \MediaWiki\Hook\ParserFirstCallInitHook { |
12 | /** |
13 | * @param Parser $parser |
14 | */ |
15 | public function onParserFirstCallInit( $parser ) { |
16 | $parser->setFunctionHook( 'mentor', static function ( Parser $parser, $username ) { |
17 | // Do not use dependency injection here. MentorManager's service wiring |
18 | // tries to read the context language, which fails when sessions are disabled, |
19 | // such as in ResourceLoader callbacks. Having this hook depending on MentorManager |
20 | // would cause an error every time the parser gets initialized in a ResourceLoader callback, |
21 | // which is sometimes done for messages parsing. |
22 | |
23 | // Accessing the service container late means this would happen only if {{#mentor}} |
24 | // is actually used in a ResourceLoader callback, which should not happen. |
25 | |
26 | return HomepageParserFunctions::mentorRender( |
27 | MediaWikiServices::getInstance()->getUserFactory(), |
28 | GrowthExperimentsServices::wrap( |
29 | MediaWikiServices::getInstance() |
30 | )->getMentorManager(), |
31 | $parser, |
32 | $username |
33 | ); |
34 | } ); |
35 | } |
36 | } |