(follow-up r96767) Make {{DEFAULTSORT:..|noerror}} and noreplace i18n-izable.
authorBrian Wolff <bawolff@users.mediawiki.org>
Sun, 11 Sep 2011 20:32:58 +0000 (20:32 +0000)
committerBrian Wolff <bawolff@users.mediawiki.org>
Sun, 11 Sep 2011 20:32:58 +0000 (20:32 +0000)
Hopefully i did this right. I've never added a magic word before...

includes/parser/CoreParserFunctions.php
languages/messages/MessagesEn.php

index 54800bd..fec8351 100644 (file)
@@ -678,24 +678,27 @@ class CoreParserFunctions {
        /**
         * @param $parser Parser
         * @param $text String The sortkey to use
-        * @param $arg String Either "noreplace" or "noerror"
+        * @param $uarg String Either "noreplace" or "noerror" (in en)
         *   both suppress errors, and noreplace does nothing if
         *   a default sortkey already exists.
         * @return string
         */
-       public static function defaultsort( $parser, $text, $arg = '' ) {
+       public static function defaultsort( $parser, $text, $uarg = '' ) {
+               static $magicWords = null;
+               if ( is_null( $magicWords ) ) {
+                       $magicWords = new MagicWordArray( array( 'defaultsort_noerror', 'defaultsort_noreplace' ) );
+               }
+               $arg = $magicWords->matchStartToEnd( $uarg );
+
                $text = trim( $text );
-               $arg = trim( strtolower( $arg ) );
                if( strlen( $text ) == 0 )
                        return '';
                $old = $parser->getCustomDefaultSort();
-               if ( $old === false || $arg !== 'noreplace' ) {
+               if ( $old === false || $arg !== 'defaultsort_noreplace' ) {
                        $parser->setDefaultSort( $text );
                }
 
-               if( $old === false || $old == $text || $arg === 'noreplace'
-                       || $arg === 'noerror' )
-               {
+               if( $old === false || $old == $text || $arg ) {
                        return '';
                } else {
                        return( '<span class="error">' .
index b50aeb8..a563be7 100644 (file)
@@ -350,6 +350,8 @@ $magicWords = array(
        'url_path'               => array( 0,    'PATH' ),
        'url_wiki'               => array( 0,    'WIKI' ),
        'url_query'              => array( 0,    'QUERY' ),
+       'defaultsort_noerror'    => array( 0,    'noerror' ),
+       'defaultsort_noreplace'  => array( 0,    'noreplace' ),
 );
 
 /**