From: Wil Mahan Date: Tue, 21 Sep 2004 23:30:46 +0000 (+0000) Subject: Removing variableSubstitution broke passing magic variables as template X-Git-Tag: 1.5.0alpha1~1905 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=16fa7c34619a06d05065f0e02928bca94a04ad09;p=lhc%2Fweb%2Fwiklou.git Removing variableSubstitution broke passing magic variables as template 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. --- diff --git a/includes/Parser.php b/includes/Parser.php index 958f1a6ce4..1b91c8f96e 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -1576,6 +1576,9 @@ class Parser # 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 ); @@ -1590,6 +1593,33 @@ class Parser 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 === '' ) { @@ -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 ); @@ -2773,6 +2793,11 @@ function wfArgSubstitution( $matches ) { return $wgCurParser->argSubstitution( $matches ); } +function wfVariableSubstitution( $matches ) { + global $wgCurParser; + return $wgCurParser->variableSubstitution( $matches ); +} + /** * Return the total number of articles */