*Border should explicitly be 0
[lhc/web/wiklou.git] / includes / MessageCache.php
index 2f40897..99fc2f5 100644 (file)
@@ -74,6 +74,18 @@ class MessageCache {
                }
 
                if ( $wgLocalMessageCacheSerialized ) {
+                       // Check to see if the file has the hash specified
+                       $localHash = fread( $file, 32 );
+                       if ( $hash === $localHash ) {
+                               // All good, get the rest of it
+                               $serialized = '';
+                               while ( !feof( $file ) ) {
+                                       $serialized .= fread( $file, 100000 );
+                               }
+                               $this->setCache( unserialize( $serialized ) );
+                       }
+                       fclose( $file );
+               } else {
                        $localHash=substr(fread($file,40),8);
                        fclose($file);
                        if ($hash!=$localHash) {
@@ -82,15 +94,6 @@ class MessageCache {
 
                        require("$wgLocalMessageCache/messages-" . wfWikiID());
                        $this->setCache( $this->mCache);
-               } else {
-                       // Check to see if the file has the hash specified
-                       $localHash = fread( $file, 32 );
-                       if ( $hash === $localHash ) {
-                               // All good, get the rest of it
-                               $serialized = fread( $file, 20000000 );
-                               $this->setCache( unserialize( $serialized ) );
-                       }
-                       fclose( $file );
                }
        }
 
@@ -121,7 +124,7 @@ class MessageCache {
        }
 
        function loadFromScript( $hash ) {
-               trigger_error( 'Use of ' . __METHOD__ . ' is deprecated', E_USER_NOTICE );
+               wfDeprecated( __METHOD__ );
                $this->loadFromLocal( $hash );
        }
        
@@ -348,7 +351,6 @@ class MessageCache {
                wfProfileIn( __METHOD__ );
                $this->lock();
                $this->load();
-               $parserMemc->delete(wfMemcKey('sidebar'));
                if ( is_array( $this->mCache ) ) {
                        if ( $text === false ) {
                                # Article was deleted
@@ -376,6 +378,7 @@ class MessageCache {
                        }
                }
                $this->unlock();
+               $parserMemc->delete(wfMemcKey('sidebar'));
                wfProfileOut( __METHOD__ );
        }
 
@@ -637,7 +640,8 @@ class MessageCache {
        }
 
        /**
-        * Get the extension messages for a specific language
+        * Get the extension messages for a specific language. Only English, interface
+        * and content language are guaranteed to be loaded.
         *
         * @param string $lang The messages language, English by default
         */
@@ -692,11 +696,27 @@ class MessageCache {
         * Load messages from a given file
         */
        function loadMessagesFile( $filename ) {
+               global $wgLang, $wgContLang;
                $messages = $magicWords = false;
                require( $filename );
 
-               if ( $messages !== false ) {
-                       $this->addMessagesByLang( $messages );
+               /*
+                * Load only languages that are usually used, and merge all fallbacks,
+                * except English.
+                */
+               $langs = array_unique( array( 'en', $wgContLang->getCode(), $wgLang->getCode() ) );
+               foreach( $langs as $code ) {
+                       $fbcode = $code;
+                       $mergedMessages = array();
+                       do {
+                               if ( isset($messages[$fbcode]) ) {
+                                       $mergedMessages += $messages[$fbcode];
+                               }
+                               $fbcode = Language::getFallbackfor( $fbcode );
+                       } while( $fbcode && $fbcode !== 'en' );
+
+                       if ( !empty($mergedMessages) )
+                               $this->addMessages( $mergedMessages, $code );
                }
 
                if ( $magicWords !== false ) {