Removing variableSubstitution broke passing magic variables as template
authorWil Mahan <wmahan@users.mediawiki.org>
Tue, 21 Sep 2004 23:30:46 +0000 (23:30 +0000)
committerWil Mahan <wmahan@users.mediawiki.org>
Tue, 21 Sep 2004 23:30:46 +0000 (23:30 +0000)
parameters, so restore it. Instead, remove magic variable substitution
from braceSubstitution(), and modify variableSubstitution to handle magic
variables prefixed by SUBST in the pre-save transform.

includes/Parser.php

index 958f1a6..1b91c8f 100644 (file)
@@ -1576,6 +1576,9 @@ class Parser
                # PHP global rebinding syntax is a bit weird, need to use the GLOBALS array
                $GLOBALS['wgCurParser'] =& $this;
 
                # PHP global rebinding syntax is a bit weird, need to use the GLOBALS array
                $GLOBALS['wgCurParser'] =& $this;
 
+               # Variable substitution
+               $text = preg_replace_callback( "/{{([$titleChars]*?)}}/", 'wfVariableSubstitution', $text );
+               
                if ( $this->mOutputType == OT_HTML ) {
                        # Argument substitution
                        $text = preg_replace_callback( "/{{{([$titleChars]*?)}}}/", 'wfArgSubstitution', $text );
                if ( $this->mOutputType == OT_HTML ) {
                        # Argument substitution
                        $text = preg_replace_callback( "/{{{([$titleChars]*?)}}}/", 'wfArgSubstitution', $text );
@@ -1590,6 +1593,33 @@ class Parser
                return $text;
        }
 
                return $text;
        }
 
+       /**
+        * Replace magic variables
+        * @access private
+        */
+       function variableSubstitution( $matches ) {
+               if ( !$this->mVariables ) {
+                       $this->initialiseVariables();
+               }
+               $skip = false;
+               if ( $this->mOutputType == OT_WIKI ) {
+                       # Do only magic variables prefixed by SUBST
+                       $mwSubst =& MagicWord::get( MAG_SUBST );
+                       if (!$mwSubst->matchStartAndRemove( $matches[1] ))
+                               $skip = true;
+                       # Note that if we don't substitute the variable below,
+                       # we don't remove the {{subst:}} magic word, in case
+                       # it is a template rather than a magic variable.
+               }
+               if ( !$skip && array_key_exists( $matches[1], $this->mVariables ) ) {
+                       $text = $this->mVariables[$matches[1]];
+                       $this->mOutput->mContainsOldMagic = true;
+               } else {
+                       $text = $matches[0];
+               }
+               return $text;
+       }
+
        # Split template arguments
        function getTemplateArgs( $argsString ) {
                if ( $argsString === '' ) {
        # Split template arguments
        function getTemplateArgs( $argsString ) {
                if ( $argsString === '' ) {
@@ -1735,16 +1765,6 @@ class Parser
                        }
                }
 
                        }
                }
 
-               # Internal variables
-               if ( !$this->mVariables ) {
-                       $this->initialiseVariables();
-               }
-               if ( !$found && array_key_exists( $part1, $this->mVariables ) ) {
-                       $text = $this->mVariables[$part1];
-                       $found = true;
-                       $this->mOutput->mContainsOldMagic = true;
-               }
-
                # GRAMMAR
                if ( !$found && $argc == 1 ) {
                        $mwGrammar =& MagicWord::get( MAG_GRAMMAR );
                # GRAMMAR
                if ( !$found && $argc == 1 ) {
                        $mwGrammar =& MagicWord::get( MAG_GRAMMAR );
@@ -2773,6 +2793,11 @@ function wfArgSubstitution( $matches ) {
        return $wgCurParser->argSubstitution( $matches );
 }
 
        return $wgCurParser->argSubstitution( $matches );
 }
 
+function wfVariableSubstitution( $matches ) {
+       global $wgCurParser;
+       return $wgCurParser->variableSubstitution( $matches );
+}
+
 /**
  * Return the total number of articles
  */
 /**
  * Return the total number of articles
  */