From: Alexandre Emsenhuber Date: Sun, 14 Aug 2011 20:22:52 +0000 (+0000) Subject: Added Parser::recursivePreprocess(); like preprocess() but doesn't call startParse... X-Git-Tag: 1.31.0-rc.0~28268 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/modifier.php?a=commitdiff_plain;h=76478abafeed68698524281d6e9aee02ece9533d;p=lhc%2Fweb%2Fwiklou.git Added Parser::recursivePreprocess(); like preprocess() but doesn't call startParse() so that it can be used inside a parse operation using the same context without having to mess with other functions Simple use case (PHP 5.3+) that will work show the expand text passed to a tag: $wgHooks['ParserFirstCallInit'][] = function( $parser ) { $parser->setHook( 'preprocess', function( $text, $attr, $parser, $frame ) { return $parser->recursivePreprocess( $text, $frame ); } ); return true; }; --- diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 63891702ca..8fe153c31d 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -510,6 +510,22 @@ class Parser { return $text; } + /** + * Recursive parser entry point that can be called from an extension tag + * hook. + * + * @param $text String: text to be expanded + * @param $frame PPFrame: The frame to use for expanding any template variables + * @return String + */ + public function recursivePreprocess( $text, $frame = false ) { + wfProfileIn( __METHOD__ ); + $text = $this->replaceVariables( $text, $frame ); + $text = $this->mStripState->unstripBoth( $text ); + wfProfileOut( __METHOD__ ); + return $text; + } + /** * Process the wikitext for the ?preload= feature. (bug 5210) *