mediawiki-extensions-Parser.../ParserFunctions.php
Paul Copperman 3350ea8f2d Make ParserFunctions work with HipHop.
* When using HipHop, is_callable() returns false for objects which have only a __call() method instead of the requested one.
* Work around this by removing the ParserFunctions_HookStub hack.
* To retain the behavior that the code of ParserFunctions_body.php is only loaded when needed, turn it into a static class.
* Defer the registering of the ParserClearState hook until a relevant function is called.
2011-04-11 17:27:51 +00:00

96 lines
4.2 KiB
PHP

<?php
if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This file is a MediaWiki extension, it is not a valid entry point' );
}
/**
* CONFIGURATION
* 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.
*
* 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:
* MediaWiki wikitext with ParserFunctions.
*
* WARNING: enabling this may have an adverse impact on the sanity of your users.
* An alternative, saner solution for embedding complex text processing in
* MediaWiki templates can be found at: http://www.mediawiki.org/wiki/Extension:Lua
*/
$wgPFEnableStringFunctions = false;
/** REGISTRATION */
$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__,
'name' => 'ParserFunctions',
'version' => '1.4.0',
'url' => 'http://www.mediawiki.org/wiki/Extension:ParserFunctions',
'author' => array( 'Tim Starling', 'Robert Rohde', 'Ross McClure', 'Juraj Simlovic' ),
'descriptionmsg' => 'pfunc_desc',
);
$wgAutoloadClasses['ExtParserFunctions'] = dirname( __FILE__ ) . '/ParserFunctions_body.php';
$wgAutoloadClasses['ExprParser'] = dirname( __FILE__ ) . '/Expr.php';
$wgAutoloadClasses['ConvertParser'] = dirname( __FILE__ ) . '/Convert.php';
$wgExtensionMessagesFiles['ParserFunctions'] = dirname( __FILE__ ) . '/ParserFunctions.i18n.php';
$wgExtensionMessagesFiles['ParserFunctionsMagic'] = dirname( __FILE__ ) . '/ParserFunctions.i18n.magic.php';
$wgParserTestFiles[] = dirname( __FILE__ ) . "/funcsParserTests.txt";
$wgParserTestFiles[] = dirname( __FILE__ ) . "/stringFunctionTests.txt";
$wgParserTestFiles[] = dirname( __FILE__ ) . "/convertTests.txt";
$wgHooks['ParserFirstCallInit'][] = 'wfRegisterParserFunctions';
function wfRegisterParserFunctions( $parser ) {
global $wgPFEnableStringFunctions;
if ( defined( get_class( $parser ) . '::SFH_OBJECT_ARGS' ) ) {
// 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 );
} else {
$parser->setFunctionHook( 'if', 'ExtParserFunctions::ifHook' );
$parser->setFunctionHook( 'ifeq', 'ExtParserFunctions::ifeq' );
$parser->setFunctionHook( 'switch', 'ExtParserFunctions::switchHook' );
$parser->setFunctionHook( 'ifexist', 'ExtParserFunctions::ifexist' );
$parser->setFunctionHook( 'ifexpr', 'ExtParserFunctions::ifexpr' );
$parser->setFunctionHook( 'iferror', 'ExtParserFunctions::iferror' );
}
$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' );
$parser->setFunctionHook( 'convert', 'ExtParserFunctions::convert' );
// 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;
}