Fix for r61710. Changing subst: to subst:$1 would cause huge problems with localisation
authorConrad Irwin <conrad@users.mediawiki.org>
Sat, 30 Jan 2010 12:46:16 +0000 (12:46 +0000)
committerConrad Irwin <conrad@users.mediawiki.org>
Sat, 30 Jan 2010 12:46:16 +0000 (12:46 +0000)
instead add some proper functions to MagicWord.php to deal with the situation.

includes/MagicWord.php
includes/parser/Parser.php
languages/messages/MessagesEn.php

index 0913e6d..f159937 100644 (file)
@@ -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;
+       }
 }
index 3b24615..32ded4b 100644 (file)
@@ -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;
index d588b04..af26491 100644 (file)
@@ -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'),