| 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 |
|
| 20 |
|
| 21 |
private $config; |
| 22 |
|
| 23 |
|
| 24 |
private $parserFunctions; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public function __construct( |
| 37 |
Config $config, |
| 38 |
HookContainer $hookContainer, |
| 39 |
LanguageConverterFactory $languageConverterFactory, |
| 40 |
LanguageFactory $languageFactory, |
| 41 |
LanguageNameUtils $languageNameUtils, |
| 42 |
LinkCache $linkCache, |
| 43 |
RepoGroup $repoGroup, |
| 44 |
SpecialPageFactory $specialPageFactory |
| 45 |
) { |
| 46 |
$this->config = $config; |
| 47 |
$this->parserFunctions = new ParserFunctions( |
| 48 |
$config, |
| 49 |
$hookContainer, |
| 50 |
$languageConverterFactory, |
| 51 |
$languageFactory, |
| 52 |
$languageNameUtils, |
| 53 |
$linkCache, |
| 54 |
$repoGroup, |
| 55 |
$specialPageFactory |
| 56 |
); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public function onParserTestGlobals( &$globals ) { |
| 67 |
$globals['wgPFEnableStringFunctions'] = true; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
public function onParserFirstCallInit( $parser ) { |
| 78 |
|
| 79 |
$parser->setFunctionHook( 'if', [ $this->parserFunctions, 'if' ], Parser::SFH_OBJECT_ARGS ); |
| 80 |
$parser->setFunctionHook( 'ifeq', [ $this->parserFunctions, 'ifeq' ], Parser::SFH_OBJECT_ARGS ); |
| 81 |
$parser->setFunctionHook( 'switch', [ $this->parserFunctions, 'switch' ], Parser::SFH_OBJECT_ARGS ); |
| 82 |
$parser->setFunctionHook( 'ifexist', [ $this->parserFunctions, 'ifexist' ], Parser::SFH_OBJECT_ARGS ); |
| 83 |
$parser->setFunctionHook( 'ifexpr', [ $this->parserFunctions, 'ifexpr' ], Parser::SFH_OBJECT_ARGS ); |
| 84 |
$parser->setFunctionHook( 'iferror', [ $this->parserFunctions, 'iferror' ], Parser::SFH_OBJECT_ARGS ); |
| 85 |
$parser->setFunctionHook( 'time', [ $this->parserFunctions, 'time' ], Parser::SFH_OBJECT_ARGS ); |
| 86 |
$parser->setFunctionHook( 'timel', [ $this->parserFunctions, 'localTime' ], Parser::SFH_OBJECT_ARGS ); |
| 87 |
$parser->setFunctionHook( 'timef', [ $this->parserFunctions, 'timef' ], Parser::SFH_OBJECT_ARGS ); |
| 88 |
$parser->setFunctionHook( 'timefl', [ $this->parserFunctions, 'timefl' ], Parser::SFH_OBJECT_ARGS ); |
| 89 |
|
| 90 |
$parser->setFunctionHook( 'expr', [ $this->parserFunctions, 'expr' ] ); |
| 91 |
$parser->setFunctionHook( 'rel2abs', [ $this->parserFunctions, 'rel2abs' ] ); |
| 92 |
$parser->setFunctionHook( 'titleparts', [ $this->parserFunctions, 'titleparts' ] ); |
| 93 |
|
| 94 |
|
| 95 |
if ( $this->config->get( 'PFEnableStringFunctions' ) ) { |
| 96 |
$parser->setFunctionHook( 'len', [ $this->parserFunctions, 'runLen' ] ); |
| 97 |
$parser->setFunctionHook( 'pos', [ $this->parserFunctions, 'runPos' ] ); |
| 98 |
$parser->setFunctionHook( 'rpos', [ $this->parserFunctions, 'runRPos' ] ); |
| 99 |
$parser->setFunctionHook( 'sub', [ $this->parserFunctions, 'runSub' ] ); |
| 100 |
$parser->setFunctionHook( 'count', [ $this->parserFunctions, 'runCount' ] ); |
| 101 |
$parser->setFunctionHook( 'replace', [ $this->parserFunctions, 'runReplace' ] ); |
| 102 |
$parser->setFunctionHook( 'explode', [ $this->parserFunctions, 'runExplode' ] ); |
| 103 |
$parser->setFunctionHook( 'urldecode', [ $this->parserFunctions, 'runUrlDecode' ] ); |
| 104 |
} |
| 105 |
} |
| 106 |
} |