Index: trunk/phase3/includes/parser/Parser.php |
— | — | @@ -436,12 +436,17 @@ |
437 | 437 | /** |
438 | 438 | * Recursive parser entry point that can be called from an extension tag |
439 | 439 | * hook. |
| 440 | + * |
| 441 | + * If $frame is not provided, then template variables (e.g., {{{1}}}) within $text are not expanded |
| 442 | + * |
| 443 | + * @param $text String: text extension wants to have parsed |
| 444 | + * @param PPFrame $frame: The frame to use for expanding any template variables |
440 | 445 | */ |
441 | | - function recursiveTagParse( $text ) { |
| 446 | + function recursiveTagParse( $text, $frame=false ) { |
442 | 447 | wfProfileIn( __METHOD__ ); |
443 | 448 | wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) ); |
444 | 449 | wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) ); |
445 | | - $text = $this->internalParse( $text, false ); |
| 450 | + $text = $this->internalParse( $text, false, $frame ); |
446 | 451 | wfProfileOut( __METHOD__ ); |
447 | 452 | return $text; |
448 | 453 | } |
— | — | @@ -862,7 +867,7 @@ |
863 | 868 | * |
864 | 869 | * @private |
865 | 870 | */ |
866 | | - function internalParse( $text, $isMain = true ) { |
| 871 | + function internalParse( $text, $isMain = true, $frame=false ) { |
867 | 872 | wfProfileIn( __METHOD__ ); |
868 | 873 | |
869 | 874 | $origText = $text; |
— | — | @@ -873,7 +878,22 @@ |
874 | 879 | return $text ; |
875 | 880 | } |
876 | 881 | |
877 | | - $text = $this->replaceVariables( $text ); |
| 882 | + // if $frame is provided, then use $frame for replacing any variables |
| 883 | + if ($frame) { |
| 884 | + // use frame depth to infer how include/noinclude tags should be handled |
| 885 | + // depth=0 means this is the top-level document; otherwise it's an included document |
| 886 | + if( !$frame->depth ) |
| 887 | + $flag = 0; |
| 888 | + else |
| 889 | + $flag = Parser::PTD_FOR_INCLUSION; |
| 890 | + $dom = $this->preprocessToDom( $text, $flag ); |
| 891 | + $text = $frame->expand( $dom ); |
| 892 | + } |
| 893 | + // if $frame is not provided, then use old-style replaceVariables |
| 894 | + else { |
| 895 | + $text = $this->replaceVariables( $text ); |
| 896 | + } |
| 897 | + |
878 | 898 | $text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ), false, array_keys( $this->mTransparentTagHooks ) ); |
879 | 899 | wfRunHooks( 'InternalParseBeforeLinks', array( &$this, &$text, &$this->mStripState ) ); |
880 | 900 | |
— | — | @@ -2277,7 +2297,7 @@ |
2278 | 2298 | * |
2279 | 2299 | * @private |
2280 | 2300 | */ |
2281 | | - function getVariableValue( $index ) { |
| 2301 | + function getVariableValue( $index, $frame=false ) { |
2282 | 2302 | global $wgContLang, $wgSitename, $wgServer, $wgServerName, $wgScriptPath; |
2283 | 2303 | |
2284 | 2304 | /** |
— | — | @@ -2500,7 +2520,7 @@ |
2501 | 2521 | return $wgContLanguageCode; |
2502 | 2522 | default: |
2503 | 2523 | $ret = null; |
2504 | | - if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret ) ) ) |
| 2524 | + if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret, &$frame ) ) ) |
2505 | 2525 | return $ret; |
2506 | 2526 | else |
2507 | 2527 | return null; |
— | — | @@ -2707,7 +2727,7 @@ |
2708 | 2728 | if ( !$found && $args->getLength() == 0 ) { |
2709 | 2729 | $id = $this->mVariables->matchStartToEnd( $part1 ); |
2710 | 2730 | if ( $id !== false ) { |
2711 | | - $text = $this->getVariableValue( $id ); |
| 2731 | + $text = $this->getVariableValue( $id, $frame ); |
2712 | 2732 | if (MagicWord::getCacheTTL($id)>-1) |
2713 | 2733 | $this->mOutput->mContainsOldMagic = true; |
2714 | 2734 | $found = true; |
— | — | @@ -3210,7 +3230,7 @@ |
3211 | 3231 | throw new MWException( "Tag hook for $name is not callable\n" ); |
3212 | 3232 | } |
3213 | 3233 | $output = call_user_func_array( $this->mTagHooks[$name], |
3214 | | - array( $content, $attributes, $this ) ); |
| 3234 | + array( $content, $attributes, $this, $frame ) ); |
3215 | 3235 | } elseif( isset( $this->mFunctionTagHooks[$name] ) ) { |
3216 | 3236 | list( $callback, $flags ) = $this->mFunctionTagHooks[$name]; |
3217 | 3237 | if( !is_callable( $callback ) ) |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -443,6 +443,8 @@ |
444 | 444 | at script execution, it now throws an exception |
445 | 445 | * Fixed EditFilterMerged hook so the hookError parameter serves a purpose |
446 | 446 | (analogous to EditFilter hook) |
| 447 | +* (bug 2257) Tag extensions can expand template parameters provided to the tag, |
| 448 | + by using a new parameter added to the recursiveTagParse function |
447 | 449 | |
448 | 450 | == API changes in 1.16 == |
449 | 451 | |