Index: trunk/phase3/includes/Parser.php |
— | — | @@ -1576,6 +1576,9 @@ |
1577 | 1577 | # PHP global rebinding syntax is a bit weird, need to use the GLOBALS array |
1578 | 1578 | $GLOBALS['wgCurParser'] =& $this; |
1579 | 1579 | |
| 1580 | + # Variable substitution |
| 1581 | + $text = preg_replace_callback( "/{{([$titleChars]*?)}}/", 'wfVariableSubstitution', $text ); |
| 1582 | + |
1580 | 1583 | if ( $this->mOutputType == OT_HTML ) { |
1581 | 1584 | # Argument substitution |
1582 | 1585 | $text = preg_replace_callback( "/{{{([$titleChars]*?)}}}/", 'wfArgSubstitution', $text ); |
— | — | @@ -1590,6 +1593,33 @@ |
1591 | 1594 | return $text; |
1592 | 1595 | } |
1593 | 1596 | |
| 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 | + |
1594 | 1624 | # Split template arguments |
1595 | 1625 | function getTemplateArgs( $argsString ) { |
1596 | 1626 | if ( $argsString === '' ) { |
— | — | @@ -1735,16 +1765,6 @@ |
1736 | 1766 | } |
1737 | 1767 | } |
1738 | 1768 | |
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 | | - |
1749 | 1769 | # GRAMMAR |
1750 | 1770 | if ( !$found && $argc == 1 ) { |
1751 | 1771 | $mwGrammar =& MagicWord::get( MAG_GRAMMAR ); |
— | — | @@ -2773,6 +2793,11 @@ |
2774 | 2794 | return $wgCurParser->argSubstitution( $matches ); |
2775 | 2795 | } |
2776 | 2796 | |
| 2797 | +function wfVariableSubstitution( $matches ) { |
| 2798 | + global $wgCurParser; |
| 2799 | + return $wgCurParser->variableSubstitution( $matches ); |
| 2800 | +} |
| 2801 | + |
2777 | 2802 | /** |
2778 | 2803 | * Return the total number of articles |
2779 | 2804 | */ |