Added Parser::recursivePreprocess(); like preprocess() but doesn't call startParse...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sun, 14 Aug 2011 20:22:52 +0000 (20:22 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Sun, 14 Aug 2011 20:22:52 +0000 (20:22 +0000)
Simple use case (PHP 5.3+) that will work show the expand text passed to a <preprocess> tag:
$wgHooks['ParserFirstCallInit'][] = function( $parser ) {
$parser->setHook( 'preprocess', function( $text, $attr, $parser, $frame ) {
return $parser->recursivePreprocess( $text, $frame );
} );
return true;
};

includes/parser/Parser.php

index 6389170..8fe153c 100644 (file)
@@ -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)
         *