r55682 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55681‎ | r55682 | r55683 >
Date:06:37, 30 August 2009
Author:nephele
Status:resolved (Comments)
Tags:
Comment:
(bug 2257) Add a $frame parameter to recursiveTagParse so tag extensions can expand template parameters
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -436,12 +436,17 @@
437437 /**
438438 * Recursive parser entry point that can be called from an extension tag
439439 * 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
440445 */
441 - function recursiveTagParse( $text ) {
 446+ function recursiveTagParse( $text, $frame=false ) {
442447 wfProfileIn( __METHOD__ );
443448 wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
444449 wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
445 - $text = $this->internalParse( $text, false );
 450+ $text = $this->internalParse( $text, false, $frame );
446451 wfProfileOut( __METHOD__ );
447452 return $text;
448453 }
@@ -862,7 +867,7 @@
863868 *
864869 * @private
865870 */
866 - function internalParse( $text, $isMain = true ) {
 871+ function internalParse( $text, $isMain = true, $frame=false ) {
867872 wfProfileIn( __METHOD__ );
868873
869874 $origText = $text;
@@ -873,7 +878,22 @@
874879 return $text ;
875880 }
876881
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+
878898 $text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ), false, array_keys( $this->mTransparentTagHooks ) );
879899 wfRunHooks( 'InternalParseBeforeLinks', array( &$this, &$text, &$this->mStripState ) );
880900
@@ -2277,7 +2297,7 @@
22782298 *
22792299 * @private
22802300 */
2281 - function getVariableValue( $index ) {
 2301+ function getVariableValue( $index, $frame=false ) {
22822302 global $wgContLang, $wgSitename, $wgServer, $wgServerName, $wgScriptPath;
22832303
22842304 /**
@@ -2500,7 +2520,7 @@
25012521 return $wgContLanguageCode;
25022522 default:
25032523 $ret = null;
2504 - if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret ) ) )
 2524+ if ( wfRunHooks( 'ParserGetVariableValueSwitch', array( &$this, &$this->mVarCache, &$index, &$ret, &$frame ) ) )
25052525 return $ret;
25062526 else
25072527 return null;
@@ -2707,7 +2727,7 @@
27082728 if ( !$found && $args->getLength() == 0 ) {
27092729 $id = $this->mVariables->matchStartToEnd( $part1 );
27102730 if ( $id !== false ) {
2711 - $text = $this->getVariableValue( $id );
 2731+ $text = $this->getVariableValue( $id, $frame );
27122732 if (MagicWord::getCacheTTL($id)>-1)
27132733 $this->mOutput->mContainsOldMagic = true;
27142734 $found = true;
@@ -3210,7 +3230,7 @@
32113231 throw new MWException( "Tag hook for $name is not callable\n" );
32123232 }
32133233 $output = call_user_func_array( $this->mTagHooks[$name],
3214 - array( $content, $attributes, $this ) );
 3234+ array( $content, $attributes, $this, $frame ) );
32153235 } elseif( isset( $this->mFunctionTagHooks[$name] ) ) {
32163236 list( $callback, $flags ) = $this->mFunctionTagHooks[$name];
32173237 if( !is_callable( $callback ) )
Index: trunk/phase3/RELEASE-NOTES
@@ -443,6 +443,8 @@
444444 at script execution, it now throws an exception
445445 * Fixed EditFilterMerged hook so the hookError parameter serves a purpose
446446 (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
447449
448450 == API changes in 1.16 ==
449451

Follow-up revisions

RevisionCommit summaryAuthorDate
r55996Update hooks.txt for r55682catrope19:29, 7 September 2009
r62416Deprecate old undocumented workaround to bug 2257 (setTransparentTagHook)conrad02:22, 13 February 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r11339ported fix for bug 2257 heremagnus_manske12:58, 13 October 2005
r11349Reverting patch for bug 2257 for now:...vibber20:32, 13 October 2005

Comments

#Comment by 😂 (talk | contribs)   11:34, 30 August 2009

Needs to update hooks.txt

Status & tagging log