Index: includes/parser/Parser.php =================================================================== --- includes/parser/Parser.php (revision 49794) +++ includes/parser/Parser.php (working copy) @@ -436,12 +436,17 @@ /** * Recursive parser entry point that can be called from an extension tag * hook. + * + * If $frame is not provided, then template variables (e.g., {{{1}}}) within $text are not expanded + * + * @param $text String: text extension wants to have parsed + * @param PPFrame $frame: The frame to use for expanding any template variables */ - function recursiveTagParse( $text ) { + function recursiveTagParse( $text, $frame=false ) { wfProfileIn( __METHOD__ ); wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) ); wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) ); - $text = $this->internalParse( $text ); + $text = $this->internalParse( $text, $frame ); wfProfileOut( __METHOD__ ); return $text; } @@ -862,7 +867,7 @@ * * @private */ - function internalParse( $text ) { + function internalParse( $text, $frame=false ) { $isMain = true; wfProfileIn( __METHOD__ ); @@ -872,7 +877,22 @@ return $text ; } - $text = $this->replaceVariables( $text ); + // if $frame is provided, then use $frame for replacing any variables + if ($frame) { + // use frame depth to infer how include/noinclude tags should be handled + // depth=0 means this is the top-level document; otherwise it's an included document + if( !$frame->depth ) + $flag = 0; + else + $flag = Parser::PTD_FOR_INCLUSION; + $dom = $this->preprocessToDom( $text, $flag ); + $text = $frame->expand( $dom ); + } + // if $frame is not provided, then use old-style replaceVariables + else { + $text = $this->replaceVariables( $text ); + } + $text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ), false, array_keys( $this->mTransparentTagHooks ) ); wfRunHooks( 'InternalParseBeforeLinks', array( &$this, &$text, &$this->mStripState ) ); @@ -2315,7 +2335,7 @@ * * @private */ - function getVariableValue( $index ) { + function getVariableValue( $index, $frame ) { global $wgContLang, $wgSitename, $wgServer, $wgServerName, $wgScriptPath; /** @@ -2533,7 +2553,7 @@ return $wgContLanguageCode; default: $ret = null; - if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret ) ) ) + if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret, &$frame ) ) ) return $ret; else return null; @@ -2740,7 +2760,7 @@ if ( !$found && $args->getLength() == 0 ) { $id = $this->mVariables->matchStartToEnd( $part1 ); if ( $id !== false ) { - $text = $this->getVariableValue( $id ); + $text = $this->getVariableValue( $id, $frame ); if (MagicWord::getCacheTTL($id)>-1) $this->mOutput->mContainsOldMagic = true; $found = true; @@ -3242,7 +3262,7 @@ throw new MWException( "Tag hook for $name is not callable\n" ); } $output = call_user_func_array( $this->mTagHooks[$name], - array( $content, $attributes, $this ) ); + array( $content, $attributes, $this, $frame ) ); } else { $output = 'Invalid tag extension name: ' . htmlspecialchars( $name ) . '';