From: Conrad Irwin Date: Sat, 30 Jan 2010 12:46:16 +0000 (+0000) Subject: Fix for r61710. Changing subst: to subst:$1 would cause huge problems with localisation X-Git-Tag: 1.31.0-rc.0~38033 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=7dee03cbdff0dbea37da9b4b1dc216c15bccefe2;p=lhc%2Fweb%2Fwiklou.git Fix for r61710. Changing subst: to subst:$1 would cause huge problems with localisation instead add some proper functions to MagicWord.php to deal with the situation. --- diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 0913e6dd81..f159937be3 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -593,6 +593,21 @@ class MagicWordArray { return str_replace( "\\$1", "(.*?)", $this->getRegex() ); } + /** + * Get a regex for matching a prefix. Does not match parameters. + */ + function getRegexStart() { + $base = $this->getBaseRegex(); + $newRegex = array( '', '' ); + if ( $base[0] !== '' ) { + $newRegex[0] = str_replace( "\\$1", "", "/^(?:{$base[0]})/iuS" ); + } + if ( $base[1] !== '' ) { + $newRegex[1] = str_replace( "\\$1", "", "/^(?:{$base[1]})/S" ); + } + return $newRegex; + } + /** * Get an anchored regex for matching variables */ @@ -691,4 +706,24 @@ class MagicWordArray { } return $found; } + + /** + * Returns the magic word id removed from the start, or false + * does not match parameters. + */ + public function matchStartAndRemove( &$text ) { + $found = FALSE; + $regexes = $this->getRegexStart(); + foreach ( $regexes as $regex ) { + if ( $regex === '' ) { + continue; + } + preg_match_all( $regex, $text, $matches, PREG_SET_ORDER ); + foreach ( $matches as $m ) { + list( $found, $param ) = $this->parseMatch( $m ); + } + $text = preg_replace( $regex, '', $text ); + } + return $found; + } } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 3b2461573c..32ded4b2fa 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -2799,18 +2799,14 @@ class Parser wfProfileIn( __METHOD__.'-modifiers' ); if ( !$found ) { - $substMatch = $this->mSubsts->matchVariableStartToEnd( $part1 ); + $substMatch = $this->mSubsts->matchStartAndRemove( $part1 ); - # Possibilities for substMatch[0]: "subst", "safesubst" or FALSE + # Possibilities for substMatch: "subst", "safesubst" or FALSE # Whether to include depends also on whether we are in the pre-save-transform # - # safesubst || (subst && PST) => transclude (handled by if) - # (false && PST) || (subst && !PST) => return input (handled by else if) - # false && !PST => transclude (no handling needed here) - if ( $substMatch[0] && ( $this->ot['wiki'] || $substMatch[0] == 'safesubst' ) ) { - $part1 = $substMatch[1]; - - } else if ( $substMatch[0] xor $this->ot['wiki'] ) { + # safesubst || (subst && PST) || (false && !PST) => transclude (skip the if) + # (false && PST) || (subst && !PST) => return input (handled by if) + if ( $substMatch != 'safesubst' && ($substMatch == 'subst' xor $this->ot['wiki']) ) { $text = $frame->virtualBracketedImplode( '{{', '|', '}}', $titleWithSpaces, $args ); $isLocalObj = true; $found = true; diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index d588b049ec..af26491dcd 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -264,8 +264,8 @@ $magicWords = array( 'subjectpagename' => array( 1, 'SUBJECTPAGENAME', 'ARTICLEPAGENAME' ), 'subjectpagenamee' => array( 1, 'SUBJECTPAGENAMEE', 'ARTICLEPAGENAMEE' ), 'msg' => array( 0, 'MSG:' ), - 'subst' => array( 0, 'SUBST:$1' ), - 'safesubst' => array( 0, 'SAFESUBST:$1' ), + 'subst' => array( 0, 'SUBST:' ), + 'safesubst' => array( 0, 'SAFESUBST:' ), 'msgnw' => array( 0, 'MSGNW:' ), 'img_thumbnail' => array( 1, 'thumbnail', 'thumb' ), 'img_manualthumb' => array( 1, 'thumbnail=$1', 'thumb=$1'),