From 16fa7c34619a06d05065f0e02928bca94a04ad09 Mon Sep 17 00:00:00 2001 From: Wil Mahan Date: Tue, 21 Sep 2004 23:30:46 +0000 Subject: [PATCH] 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. --- includes/Parser.php | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) 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 */ -- 2.20.1