summaryrefslogtreecommitdiff
path: root/extensions/ParserFunctions/ParserFunctions.hooks.php
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:30:02 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-05-01 15:30:02 -0400
commit1de335ad3f395ca6861085393ba366a9e3fb4a0d (patch)
treef1fdd326034e05177596851be6a7127615d81498 /extensions/ParserFunctions/ParserFunctions.hooks.php
parent9c75fa8ff6d4d38ef552c00fef5969fb154765e8 (diff)
parentf6d65e533c62f6deb21342d4901ece24497b433e (diff)
Merge commit 'f6d65'
# Conflicts: # skins/ArchLinux/ArchLinux.php
Diffstat (limited to 'extensions/ParserFunctions/ParserFunctions.hooks.php')
-rw-r--r--extensions/ParserFunctions/ParserFunctions.hooks.php68
1 files changed, 68 insertions, 0 deletions
diff --git a/extensions/ParserFunctions/ParserFunctions.hooks.php b/extensions/ParserFunctions/ParserFunctions.hooks.php
new file mode 100644
index 00000000..bac580c0
--- /dev/null
+++ b/extensions/ParserFunctions/ParserFunctions.hooks.php
@@ -0,0 +1,68 @@
+<?php
+
+class ParserFunctionsHooks {
+
+ /**
+ * Enable string functions, when running Wikimedia Jenkins unit tests.
+ *
+ * Running Jenkins unit tests without setting $wgPFEnableStringFunctions = true;
+ * will cause all the parser tests for string functions to be skipped.
+ */
+ public static function onRegistration() {
+ if ( isset( $GLOBALS['wgWikimediaJenkinsCI'] ) && $GLOBALS['wgWikimediaJenkinsCI'] === true ) {
+ $GLOBALS['wgPFEnableStringFunctions'] = true;
+ }
+ }
+
+ /**
+ * @param $parser Parser
+ * @return bool
+ */
+ public static function onParserFirstCallInit( $parser ) {
+ global $wgPFEnableStringFunctions;
+
+ // These functions accept DOM-style arguments
+ $parser->setFunctionHook( 'if', 'ExtParserFunctions::ifObj', Parser::SFH_OBJECT_ARGS );
+ $parser->setFunctionHook( 'ifeq', 'ExtParserFunctions::ifeqObj', Parser::SFH_OBJECT_ARGS );
+ $parser->setFunctionHook( 'switch', 'ExtParserFunctions::switchObj', Parser::SFH_OBJECT_ARGS );
+ $parser->setFunctionHook( 'ifexist', 'ExtParserFunctions::ifexistObj', Parser::SFH_OBJECT_ARGS );
+ $parser->setFunctionHook( 'ifexpr', 'ExtParserFunctions::ifexprObj', Parser::SFH_OBJECT_ARGS );
+ $parser->setFunctionHook( 'iferror', 'ExtParserFunctions::iferrorObj', Parser::SFH_OBJECT_ARGS );
+ $parser->setFunctionHook( 'time', 'ExtParserFunctions::timeObj', Parser::SFH_OBJECT_ARGS );
+ $parser->setFunctionHook( 'timel', 'ExtParserFunctions::localTimeObj', Parser::SFH_OBJECT_ARGS );
+
+ $parser->setFunctionHook( 'expr', 'ExtParserFunctions::expr' );
+ $parser->setFunctionHook( 'rel2abs', 'ExtParserFunctions::rel2abs' );
+ $parser->setFunctionHook( 'titleparts', 'ExtParserFunctions::titleparts' );
+
+ // String Functions
+ if ( $wgPFEnableStringFunctions ) {
+ $parser->setFunctionHook( 'len', 'ExtParserFunctions::runLen' );
+ $parser->setFunctionHook( 'pos', 'ExtParserFunctions::runPos' );
+ $parser->setFunctionHook( 'rpos', 'ExtParserFunctions::runRPos' );
+ $parser->setFunctionHook( 'sub', 'ExtParserFunctions::runSub' );
+ $parser->setFunctionHook( 'count', 'ExtParserFunctions::runCount' );
+ $parser->setFunctionHook( 'replace', 'ExtParserFunctions::runReplace' );
+ $parser->setFunctionHook( 'explode', 'ExtParserFunctions::runExplode' );
+ $parser->setFunctionHook( 'urldecode', 'ExtParserFunctions::runUrlDecode' );
+ }
+
+ return true;
+ }
+
+ /**
+ * @param $files array
+ * @return bool
+ */
+ public static function onUnitTestsList( &$files ) {
+ $files[] = __DIR__ . '/tests/ExpressionTest.php';
+ return true;
+ }
+
+ public static function onScribuntoExternalLibraries( $engine, array &$extraLibraries ) {
+ if ( $engine == 'lua' ) {
+ $extraLibraries['mw.ext.ParserFunctions'] = 'Scribunto_LuaParserFunctionsLibrary';
+ }
+ return true;
+ }
+}