r5369 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r5368‎ | r5369 | r5370 >
Date:23:30, 21 September 2004
Author:wmahan
Status:old
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Parser.php
@@ -1576,6 +1576,9 @@
15771577 # PHP global rebinding syntax is a bit weird, need to use the GLOBALS array
15781578 $GLOBALS['wgCurParser'] =& $this;
15791579
 1580+ # Variable substitution
 1581+ $text = preg_replace_callback( "/{{([$titleChars]*?)}}/", 'wfVariableSubstitution', $text );
 1582+
15801583 if ( $this->mOutputType == OT_HTML ) {
15811584 # Argument substitution
15821585 $text = preg_replace_callback( "/{{{([$titleChars]*?)}}}/", 'wfArgSubstitution', $text );
@@ -1590,6 +1593,33 @@
15911594 return $text;
15921595 }
15931596
 1597+ /**
 1598+ * Replace magic variables
 1599+ * @access private
 1600+ */
 1601+ function variableSubstitution( $matches ) {
 1602+ if ( !$this->mVariables ) {
 1603+ $this->initialiseVariables();
 1604+ }
 1605+ $skip = false;
 1606+ if ( $this->mOutputType == OT_WIKI ) {
 1607+ # Do only magic variables prefixed by SUBST
 1608+ $mwSubst =& MagicWord::get( MAG_SUBST );
 1609+ if (!$mwSubst->matchStartAndRemove( $matches[1] ))
 1610+ $skip = true;
 1611+ # Note that if we don't substitute the variable below,
 1612+ # we don't remove the {{subst:}} magic word, in case
 1613+ # it is a template rather than a magic variable.
 1614+ }
 1615+ if ( !$skip && array_key_exists( $matches[1], $this->mVariables ) ) {
 1616+ $text = $this->mVariables[$matches[1]];
 1617+ $this->mOutput->mContainsOldMagic = true;
 1618+ } else {
 1619+ $text = $matches[0];
 1620+ }
 1621+ return $text;
 1622+ }
 1623+
15941624 # Split template arguments
15951625 function getTemplateArgs( $argsString ) {
15961626 if ( $argsString === '' ) {
@@ -1735,16 +1765,6 @@
17361766 }
17371767 }
17381768
1739 - # Internal variables
1740 - if ( !$this->mVariables ) {
1741 - $this->initialiseVariables();
1742 - }
1743 - if ( !$found && array_key_exists( $part1, $this->mVariables ) ) {
1744 - $text = $this->mVariables[$part1];
1745 - $found = true;
1746 - $this->mOutput->mContainsOldMagic = true;
1747 - }
1748 -
17491769 # GRAMMAR
17501770 if ( !$found && $argc == 1 ) {
17511771 $mwGrammar =& MagicWord::get( MAG_GRAMMAR );
@@ -2773,6 +2793,11 @@
27742794 return $wgCurParser->argSubstitution( $matches );
27752795 }
27762796
 2797+function wfVariableSubstitution( $matches ) {
 2798+ global $wgCurParser;
 2799+ return $wgCurParser->variableSubstitution( $matches );
 2800+}
 2801+
27772802 /**
27782803 * Return the total number of articles
27792804 */

Status & tagging log