2007-01-05 02:13:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
|
|
|
die( 'This file is a MediaWiki extension, it is not a valid entry point' );
|
|
|
|
}
|
|
|
|
|
2009-06-05 09:53:05 +00:00
|
|
|
/**
|
2010-10-02 22:36:34 +00:00
|
|
|
* CONFIGURATION
|
2009-06-05 09:53:05 +00:00
|
|
|
* These variables may be overridden in LocalSettings.php after you include the
|
|
|
|
* extension file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines the maximum length of a string that string functions are allowed to operate on
|
|
|
|
* Prevention against denial of service by string function abuses.
|
|
|
|
*/
|
|
|
|
$wgPFStringLengthLimit = 1000;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable string functions.
|
|
|
|
*
|
2010-10-02 22:36:34 +00:00
|
|
|
* Set this to true if you want your users to be able to implement their own
|
|
|
|
* parsers in the ugliest, most inefficient programming language known to man:
|
2009-06-05 09:53:05 +00:00
|
|
|
* MediaWiki wikitext with ParserFunctions.
|
|
|
|
*
|
|
|
|
* WARNING: enabling this may have an adverse impact on the sanity of your users.
|
2010-10-02 22:36:34 +00:00
|
|
|
* An alternative, saner solution for embedding complex text processing in
|
2014-02-07 15:33:48 +00:00
|
|
|
* MediaWiki templates can be found at: http://www.mediawiki.org/wiki/Extension:Scribunto
|
2009-06-05 09:53:05 +00:00
|
|
|
*/
|
|
|
|
$wgPFEnableStringFunctions = false;
|
|
|
|
|
2014-02-18 11:40:55 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-06-21 18:49:27 +00:00
|
|
|
if ( isset( $wgWikimediaJenkinsCI ) && $wgWikimediaJenkinsCI === true ) {
|
|
|
|
$wgPFEnableStringFunctions = true;
|
2014-02-18 11:40:55 +00:00
|
|
|
}
|
|
|
|
|
2009-06-05 09:53:05 +00:00
|
|
|
/** REGISTRATION */
|
2007-01-07 13:57:35 +00:00
|
|
|
$wgExtensionCredits['parserhook'][] = array(
|
2009-04-26 05:22:33 +00:00
|
|
|
'path' => __FILE__,
|
2008-07-09 17:46:09 +00:00
|
|
|
'name' => 'ParserFunctions',
|
2014-03-28 11:15:51 +00:00
|
|
|
'version' => '1.6.0',
|
2011-12-13 23:49:33 +00:00
|
|
|
'url' => 'https://www.mediawiki.org/wiki/Extension:ParserFunctions',
|
2010-10-02 22:36:34 +00:00
|
|
|
'author' => array( 'Tim Starling', 'Robert Rohde', 'Ross McClure', 'Juraj Simlovic' ),
|
2008-02-05 18:52:55 +00:00
|
|
|
'descriptionmsg' => 'pfunc_desc',
|
2007-01-07 13:57:35 +00:00
|
|
|
);
|
2007-01-05 02:13:39 +00:00
|
|
|
|
2014-03-28 11:15:51 +00:00
|
|
|
$wgAutoloadClasses['ExtParserFunctions'] = __DIR__ . '/ParserFunctions_body.php';
|
|
|
|
$wgAutoloadClasses['ExprParser'] = __DIR__ . '/Expr.php';
|
|
|
|
$wgAutoloadClasses['ExprError'] = __DIR__ . '/Expr.php';
|
2014-04-08 16:04:32 +00:00
|
|
|
$wgAutoloadClasses['Scribunto_LuaParserFunctionsLibrary'] = __DIR__ . '/ParserFunctions.library.php';
|
2011-01-27 17:34:37 +00:00
|
|
|
|
2014-03-28 11:15:51 +00:00
|
|
|
$wgMessagesDirs['ParserFunctions'] = __DIR__ . '/i18n';
|
|
|
|
$wgExtensionMessagesFiles['ParserFunctionsMagic'] = __DIR__ . '/ParserFunctions.i18n.magic.php';
|
2007-11-29 10:42:48 +00:00
|
|
|
|
2014-03-28 11:15:51 +00:00
|
|
|
$wgParserTestFiles[] = __DIR__ . "/funcsParserTests.txt";
|
|
|
|
$wgParserTestFiles[] = __DIR__ . "/stringFunctionTests.txt";
|
2008-10-27 17:56:58 +00:00
|
|
|
|
2011-04-11 17:27:51 +00:00
|
|
|
$wgHooks['ParserFirstCallInit'][] = 'wfRegisterParserFunctions';
|
|
|
|
|
2011-11-16 13:22:03 +00:00
|
|
|
/**
|
|
|
|
* @param $parser Parser
|
|
|
|
* @return bool
|
|
|
|
*/
|
2011-04-11 17:27:51 +00:00
|
|
|
function wfRegisterParserFunctions( $parser ) {
|
2012-09-06 14:32:52 +00:00
|
|
|
global $wgPFEnableStringFunctions;
|
2011-04-11 17:27:51 +00:00
|
|
|
|
2011-12-19 00:38:10 +00:00
|
|
|
// These functions accept DOM-style arguments
|
2014-11-18 18:47:12 +00:00
|
|
|
$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 );
|
2009-05-26 00:43:34 +00:00
|
|
|
|
2011-04-11 17:27:51 +00:00
|
|
|
$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' );
|
2009-05-26 00:43:34 +00:00
|
|
|
}
|
2007-01-05 02:13:39 +00:00
|
|
|
|
2011-04-11 17:27:51 +00:00
|
|
|
return true;
|
2007-01-05 02:13:39 +00:00
|
|
|
}
|
2012-12-07 02:00:29 +00:00
|
|
|
|
|
|
|
$wgHooks['UnitTestsList'][] = 'wfParserFunctionsTests';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $files array
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function wfParserFunctionsTests( &$files ) {
|
2014-03-28 11:15:51 +00:00
|
|
|
$files[] = __DIR__ . '/tests/ExpressionTest.php';
|
2012-12-07 02:00:29 +00:00
|
|
|
return true;
|
2012-12-07 23:51:27 +00:00
|
|
|
}
|
2014-04-08 16:04:32 +00:00
|
|
|
|
|
|
|
$wgHooks['ScribuntoExternalLibraries'][] = function( $engine, array &$extraLibraries ) {
|
|
|
|
if( $engine == 'lua' ) {
|
|
|
|
$extraLibraries['mw.ext.ParserFunctions'] = 'Scribunto_LuaParserFunctionsLibrary';
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|