--- Parser.php.bak 2007-08-10 19:20:40.000000000 +1000 +++ Parser.php 2007-09-04 17:18:47.000000000 +1000 @@ -128,6 +128,7 @@ $this->mFunctionHooks = array(); $this->mFunctionSynonyms = array( 0 => array(), 1 => array() ); $this->mFirstCall = true; + $this->mArgStack = array(); } /** @@ -295,9 +296,7 @@ $this->mRevisionTimestamp = null; } $this->setOutputType( OT_HTML ); - wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) ); - $text = $this->strip( $text, $this->mStripState ); - wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) ); + $text = $this->internalParse( $text ); $text = $this->mStripState->unstripGeneral( $text ); @@ -403,12 +402,7 @@ $this->setOutputType( OT_PREPROCESS ); $this->mOptions = $options; $this->mTitle = $title; - wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) ); - $text = $this->strip( $text, $this->mStripState ); - wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) ); - if ( $this->mOptions->getRemoveComments() ) { - $text = Sanitizer::removeHTMLcomments( $text ); - } + $text = $this->replaceVariables( $text ); $text = $this->mStripState->unstripBoth( $text ); wfProfileOut( __METHOD__ ); @@ -593,6 +587,15 @@ break; default: if( isset( $this->mTagHooks[$tagName] ) ) { + // replace template args in the parameter calls to custom parser tag hooks + $stack_depth = count( $this->mArgStack ); + foreach( $params as $index => $param ) { + $out = $this->replaceVariables( $param, $this->mArgStack[ $stack_depth - 1 ], true ); + $params[$index] = $out; + } + // replace template args in the content passed to custom parser tag hooks + $content = $this->replaceVariables( $content, $this->mArgStack[ $stack_depth - 1 ], true ); + // call custom parser tag hook $output = call_user_func_array( $this->mTagHooks[$tagName], array( $content, $params, $this ) ); } else { @@ -999,8 +1002,6 @@ $text = strtr( $text, array( '' => '', '' => '') ); $text = StringUtils::delimiterReplace( '', '', '', $text ); - $text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ) ); - $text = $this->replaceVariables( $text, $args ); // Tables need to come after variable replacement for things to work @@ -2775,16 +2776,30 @@ * @private */ function replaceVariables( $text, $args = array(), $argsOnly = false ) { - # Prevent too big inclusions - if( strlen( $text ) > $this->mOptions->getMaxIncludeSize() ) { - return $text; - } $fname = __METHOD__ /*. '-L' . count( $this->mArgStack )*/; wfProfileIn( $fname ); - + # This function is called recursively. To keep track of arguments we need a stack: array_push( $this->mArgStack, $args ); + + if( $this->ot['html'] || $this->ot['pre'] ) { + # Strip ,
, etc.
+			wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
+			$text = $this->strip( $text, $this->mStripState );
+			wfRunHooks( 'ParserAfterStrip', array( &$this, &$text, &$this->mStripState ) );
+			if ( $this->ot['html'] ) {
+				$text = Sanitizer::removeHTMLtags( $text, array( &$this, 'attributeStripCallback' ), $args );
+			} elseif ( $this->ot['pre'] && $this->mOptions->getRemoveComments() ) {
+				$text = Sanitizer::removeHTMLcomments( $text );
+			}
+		}
+		
+		# Prevent too big inclusions
+		if( strlen( $text ) > $this->mOptions->getMaxIncludeSize() ) {
+			array_pop( $this->mArgStack );
+			return $text;
+		}
 
 		$braceCallbacks = array();
 		if ( !$argsOnly ) {
@@ -3142,15 +3157,6 @@
 				$text = StringUtils::delimiterReplace( '', '', '', $text );
 				$text = strtr( $text, array( '' => '' , '' => '' ) );
 
-				if( $this->ot['html'] || $this->ot['pre'] ) {
-					# Strip , 
, etc.
-					$text = $this->strip( $text, $this->mStripState );
-					if ( $this->ot['html'] ) {
-						$text = Sanitizer::removeHTMLtags( $text, array( &$this, 'replaceVariables' ), $assocArgs );
-					} elseif ( $this->ot['pre'] && $this->mOptions->getRemoveComments() ) {
-						$text = Sanitizer::removeHTMLcomments( $text );
-					}
-				}
 				$text = $this->replaceVariables( $text, $assocArgs );
 
 				# If the template begins with a table or block-level