Fix return type of MessageCache::getMsgFromNamespace for existing
authorTyler Anthony Romeo <tylerromeo@gmail.com>
Fri, 17 May 2013 12:10:31 +0000 (12:10 +0000)
committerTim Starling <tstarling@wikimedia.org>
Tue, 11 Jun 2013 22:48:05 +0000 (08:48 +1000)
Functions expect the message cache to return a string if a message
exists, even empty, and false if it does not exist. This adds casting
to the substr() function, which would return false for existing
messages that were just blank.

Bug: 14176
Change-Id: Id91914a3701fe53f1e2e894824512489392c628b

RELEASE-NOTES-1.22
includes/cache/MessageCache.php

index 4f33548..38b2cbd 100644 (file)
@@ -143,6 +143,9 @@ production.
 * (bug 48294) API: Fix chunk upload async mode.
 * (bug 46749) Broken files tracking category removed from pages if an image
   with that name is uploaded.
+* (bug 14176) System messages that are empty were previously incorrectly treated
+  as non-existent, causing a fallback to the default. This stopped users from
+  overriding system messages to make them blank.
 
 === API changes in 1.22 ===
 * (bug 46626) xmldoublequote parameter was removed. Because of a bug, the
index 7dc8d05..fcefc06 100644 (file)
@@ -865,14 +865,16 @@ class MessageCache {
         *
         * @param string $title Message cache key with initial uppercase letter.
         * @param string $code Code denoting the language to try.
-        * @return string|bool False on failure
+        * @return string|bool The message, or false iff it does not exist or on error
         */
        function getMsgFromNamespace( $title, $code ) {
                $this->load( $code );
                if ( isset( $this->mCache[$code][$title] ) ) {
                        $entry = $this->mCache[$code][$title];
                        if ( substr( $entry, 0, 1 ) === ' ' ) {
-                               return substr( $entry, 1 );
+                               // The message exists, so make sure a string
+                               // is returned.
+                               return (string)substr( $entry, 1 );
                        } elseif ( $entry === '!NONEXISTENT' ) {
                                return false;
                        } elseif ( $entry === '!TOO BIG' ) {
@@ -895,7 +897,9 @@ class MessageCache {
                if ( $entry ) {
                        if ( substr( $entry, 0, 1 ) === ' ' ) {
                                $this->mCache[$code][$title] = $entry;
-                               return substr( $entry, 1 );
+                               // The message exists, so make sure a string
+                               // is returned.
+                               return (string)substr( $entry, 1 );
                        } elseif ( $entry === '!NONEXISTENT' ) {
                                $this->mCache[$code][$title] = '!NONEXISTENT';
                                return false;