From 76478abafeed68698524281d6e9aee02ece9533d Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sun, 14 Aug 2011 20:22:52 +0000 Subject: [PATCH] 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; }; --- includes/parser/Parser.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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) * -- 2.20.1