MediaWiki REL1_34
Hooks.php
Go to the documentation of this file.
1<?php
2
4
5use Parser;
6
7class Hooks {
8
16 public static function onParserTestGlobals( array &$globals ) {
17 $globals['wgPFEnableStringFunctions'] = true;
18 }
19
27 public static function onParserFirstCallInit( Parser $parser ) {
28 global $wgPFEnableStringFunctions;
29
30 // These functions accept DOM-style arguments
31 $class = ParserFunctions::class;
32 $parser->setFunctionHook( 'if', "$class::if", Parser::SFH_OBJECT_ARGS );
33 $parser->setFunctionHook( 'ifeq', "$class::ifeq", Parser::SFH_OBJECT_ARGS );
34 $parser->setFunctionHook( 'switch', "$class::switch", Parser::SFH_OBJECT_ARGS );
35 $parser->setFunctionHook( 'ifexist', "$class::ifexist", Parser::SFH_OBJECT_ARGS );
36 $parser->setFunctionHook( 'ifexpr', "$class::ifexpr", Parser::SFH_OBJECT_ARGS );
37 $parser->setFunctionHook( 'iferror', "$class::iferror", Parser::SFH_OBJECT_ARGS );
38 $parser->setFunctionHook( 'time', "$class::time", Parser::SFH_OBJECT_ARGS );
39 $parser->setFunctionHook( 'timel', "$class::localTime", Parser::SFH_OBJECT_ARGS );
40
41 $parser->setFunctionHook( 'expr', "$class::expr" );
42 $parser->setFunctionHook( 'rel2abs', "$class::rel2abs" );
43 $parser->setFunctionHook( 'titleparts', "$class::titleparts" );
44
45 // String Functions: enable if configured
46 if ( $wgPFEnableStringFunctions ) {
47 $parser->setFunctionHook( 'len', "$class::runLen" );
48 $parser->setFunctionHook( 'pos', "$class::runPos" );
49 $parser->setFunctionHook( 'rpos', "$class::runRPos" );
50 $parser->setFunctionHook( 'sub', "$class::runSub" );
51 $parser->setFunctionHook( 'count', "$class::runCount" );
52 $parser->setFunctionHook( 'replace', "$class::runReplace" );
53 $parser->setFunctionHook( 'explode', "$class::runExplode" );
54 $parser->setFunctionHook( 'urldecode', "$class::runUrlDecode" );
55 }
56 }
57
66 public static function onScribuntoExternalLibraries( $engine, array &$extraLibraries ) {
67 if ( $engine === 'lua' ) {
68 $extraLibraries['mw.ext.ParserFunctions'] = LuaLibrary::class;
69 }
70 }
71}
static onScribuntoExternalLibraries( $engine, array &$extraLibraries)
Registers ParserFunctions' lua function with Scribunto.
Definition Hooks.php:66
static onParserTestGlobals(array &$globals)
Enables string functions during parser tests.
Definition Hooks.php:16
static onParserFirstCallInit(Parser $parser)
Registers our parser functions with a fresh parser.
Definition Hooks.php:27
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
Definition Parser.php:74
setFunctionHook( $id, callable $callback, $flags=0)
Create a function, e.g.
Definition Parser.php:5283
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition ExprError.php:19