Normalize message name in Allmessages
authorGeoffrey Mon <geofbot@gmail.com>
Mon, 13 Jul 2015 16:35:11 +0000 (12:35 -0400)
committerGEOFBOT <geofbot@gmail.com>
Wed, 15 Jul 2015 20:47:15 +0000 (16:47 -0400)
* Normalize the message name returned by allmessages
* Separate message key normalization into
  MessageCache::normalizeKey()

Bug: T63894
Change-Id: I1d89fc73fea705243d390bab91255a635d8f9eee

includes/api/ApiQueryAllMessages.php
includes/cache/MessageCache.php

index cc884ec..152711f 100644 (file)
@@ -136,7 +136,11 @@ class ApiQueryAllMessages extends ApiQueryBase {
                        }
 
                        if ( !$skip ) {
-                               $a = array( 'name' => $message );
+                               $a = array(
+                                       'name' => $message,
+                                       'normalizedname' => MessageCache::normalizeKey( $message ),
+                               );
+
                                $args = array();
                                if ( isset( $params['args'] ) && count( $params['args'] ) != 0 ) {
                                        $args = $params['args'];
index 585fcd3..f63e0fb 100644 (file)
@@ -130,6 +130,23 @@ class MessageCache {
                self::$instance = null;
        }
 
+       /**
+        * Normalize message key input
+        *
+        * @param string $key Input message key to be normalized
+        * @return string Normalized message key
+        */
+       public static function normalizeKey( $key ) {
+               $lckey = strtr( $key, ' ', '_' );
+               if ( ord( $lckey ) < 128 ) {
+                       $lckey[0] = strtolower( $lckey[0] );
+               } else {
+                       $lckey = $wgContLang->lcfirst( $lckey );
+               }
+
+               return $lckey;
+       }
+
        /**
         * @param BagOStuff $memCached A cache instance. If none, fall back to CACHE_NONE.
         * @param bool $useDB
@@ -784,12 +801,7 @@ class MessageCache {
                }
 
                // Normalise title-case input (with some inlining)
-               $lckey = strtr( $key, ' ', '_' );
-               if ( ord( $lckey ) < 128 ) {
-                       $lckey[0] = strtolower( $lckey[0] );
-               } else {
-                       $lckey = $wgContLang->lcfirst( $lckey );
-               }
+               $lckey = MessageCache::normalizeKey( $key );
 
                Hooks::run( 'MessageCache::get', array( &$lckey ) );