MediaWiki  1.33.0
Hooks.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Parser;
6 
7 class 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::ifObj", Parser::SFH_OBJECT_ARGS );
33  $parser->setFunctionHook( 'ifeq', "$class::ifeqObj", Parser::SFH_OBJECT_ARGS );
34  $parser->setFunctionHook( 'switch', "$class::switchObj", Parser::SFH_OBJECT_ARGS );
35  $parser->setFunctionHook( 'ifexist', "$class::ifexistObj", Parser::SFH_OBJECT_ARGS );
36  $parser->setFunctionHook( 'ifexpr', "$class::ifexprObj", Parser::SFH_OBJECT_ARGS );
37  $parser->setFunctionHook( 'iferror', "$class::iferrorObj", Parser::SFH_OBJECT_ARGS );
38  $parser->setFunctionHook( 'time', "$class::timeObj", Parser::SFH_OBJECT_ARGS );
39  $parser->setFunctionHook( 'timel', "$class::localTimeObj", 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 }
SFH_OBJECT_ARGS
const SFH_OBJECT_ARGS
Definition: Defines.php:198
MediaWiki\Extensions\ParserFunctions\Hooks\onParserTestGlobals
static onParserTestGlobals(array &$globals)
Enables string functions during parser tests.
Definition: Hooks.php:16
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWiki\Extensions\ParserFunctions\Hooks
Definition: Hooks.php:7
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$parser
see documentation in includes Linker php for Linker::makeImageLink or false for current used if you return false $parser
Definition: hooks.txt:1802
$engine
the value to return A Title object or null for latest all implement SearchIndexField $engine
Definition: hooks.txt:2901
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
MediaWiki\Extensions\ParserFunctions
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
Definition: ExprError.php:19
MediaWiki\Extensions\ParserFunctions\Hooks\onScribuntoExternalLibraries
static onScribuntoExternalLibraries( $engine, array &$extraLibraries)
Registers ParserFunctions' lua function with Scribunto.
Definition: Hooks.php:66
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
MediaWiki\Extensions\ParserFunctions\Hooks\onParserFirstCallInit
static onParserFirstCallInit(Parser $parser)
Registers our parser functions with a fresh parser.
Definition: Hooks.php:27