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;
|
|
|
|
|
|
|
|
/** 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',
|
2013-01-06 19:26:26 +00:00
|
|
|
'version' => '1.5.1',
|
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
|
|
|
|
2010-10-02 22:36:34 +00:00
|
|
|
$wgAutoloadClasses['ExtParserFunctions'] = dirname( __FILE__ ) . '/ParserFunctions_body.php';
|
2011-01-27 17:34:37 +00:00
|
|
|
$wgAutoloadClasses['ExprParser'] = dirname( __FILE__ ) . '/Expr.php';
|
2012-12-07 03:01:35 +00:00
|
|
|
$wgAutoloadClasses['ExprError'] = dirname( __FILE__ ) . '/Expr.php';
|
2011-01-27 17:34:37 +00:00
|
|
|
|
2010-10-02 22:36:34 +00:00
|
|
|
$wgExtensionMessagesFiles['ParserFunctions'] = dirname( __FILE__ ) . '/ParserFunctions.i18n.php';
|
|
|
|
$wgExtensionMessagesFiles['ParserFunctionsMagic'] = dirname( __FILE__ ) . '/ParserFunctions.i18n.magic.php';
|
2007-11-29 10:42:48 +00:00
|
|
|
|
2008-11-30 03:15:22 +00:00
|
|
|
$wgParserTestFiles[] = dirname( __FILE__ ) . "/funcsParserTests.txt";
|
2010-07-09 21:11:54 +00:00
|
|
|
$wgParserTestFiles[] = dirname( __FILE__ ) . "/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
|
|
|
|
$parser->setFunctionHook( 'if', 'ExtParserFunctions::ifObj', SFH_OBJECT_ARGS );
|
|
|
|
$parser->setFunctionHook( 'ifeq', 'ExtParserFunctions::ifeqObj', SFH_OBJECT_ARGS );
|
|
|
|
$parser->setFunctionHook( 'switch', 'ExtParserFunctions::switchObj', SFH_OBJECT_ARGS );
|
|
|
|
$parser->setFunctionHook( 'ifexist', 'ExtParserFunctions::ifexistObj', SFH_OBJECT_ARGS );
|
|
|
|
$parser->setFunctionHook( 'ifexpr', 'ExtParserFunctions::ifexprObj', SFH_OBJECT_ARGS );
|
|
|
|
$parser->setFunctionHook( 'iferror', 'ExtParserFunctions::iferrorObj', 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( 'time', 'ExtParserFunctions::time' );
|
|
|
|
$parser->setFunctionHook( 'timel', 'ExtParserFunctions::localTime' );
|
|
|
|
$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 ) {
|
|
|
|
$files[] = dirname( __FILE__ ) . '/tests/ExpressionTest.php';
|
|
|
|
return true;
|
2012-12-07 23:51:27 +00:00
|
|
|
}
|