Documentation and type hinting.
[lhc/web/wiklou.git] / includes / LocalisationCache.php
index f81b9bf..9d00681 100644 (file)
@@ -81,21 +81,21 @@ class LocalisationCache {
         * All item keys
         */
        static public $allKeys = array(
-               'fallback', 'namespaceNames', 'mathNames', 'bookstoreList',
+               'fallback', 'namespaceNames', 'bookstoreList',
                'magicWords', 'messages', 'rtl', 'capitalizeAllNouns', 'digitTransformTable',
                'separatorTransformTable', 'fallback8bitEncoding', 'linkPrefixExtension',
                'defaultUserOptionOverrides', 'linkTrail', 'namespaceAliases',
                'dateFormats', 'datePreferences', 'datePreferenceMigrationMap',
                'defaultDateFormat', 'extraUserToggles', 'specialPageAliases',
-               'imageFiles', 'preloadedMessages',
+               'imageFiles', 'preloadedMessages', 'namespaceGenderAliases',
        );
 
        /**
         * Keys for items which consist of associative arrays, which may be merged
         * by a fallback sequence.
         */
-       static public $mergeableMapKeys = array( 'messages', 'namespaceNames', 'mathNames',
-               'dateFormats', 'defaultUserOptionOverrides', 'magicWords', 'imageFiles',
+       static public $mergeableMapKeys = array( 'messages', 'namespaceNames',
+               'dateFormats', 'defaultUserOptionOverrides', 'imageFiles',
                'preloadedMessages',
        );
 
@@ -117,6 +117,11 @@ class LocalisationCache {
         */
        static public $optionalMergeKeys = array( 'bookstoreList' );
 
+       /**
+        * Keys for items that are formatted like $magicWords
+        */
+       static public $magicWordKeys = array( 'magicWords' );
+
        /**
         * Keys for items where the subitems are stored in the backend separately.
         */
@@ -181,7 +186,8 @@ class LocalisationCache {
                                self::$mergeableMapKeys,
                                self::$mergeableListKeys,
                                self::$mergeableAliasListKeys,
-                               self::$optionalMergeKeys
+                               self::$optionalMergeKeys,
+                               self::$magicWordKeys
                        ) );
                }
                return isset( $this->mergeableKeys[$key] );
@@ -337,6 +343,12 @@ class LocalisationCache {
                }
                $this->initialisedLangs[$code] = true;
 
+               # If the code is of the wrong form for a Messages*.php file, do a shallow fallback
+               if ( !Language::isValidBuiltInCode( $code ) ) {
+                       $this->initShallowFallback( $code, 'en' );
+                       return;
+               }
+
                # Recache the data if necessary
                if ( !$this->manualRecache && $this->isExpired( $code ) ) {
                        if ( file_exists( Language::getMessagesFileName( $code ) ) ) {
@@ -426,6 +438,8 @@ class LocalisationCache {
                                        if ( isset( $value['inherit'] ) ) {
                                                unset( $value['inherit'] );
                                        }
+                               } elseif ( in_array( $key, self::$magicWordKeys ) ) {
+                                       $this->mergeMagicWords( $value, $fallbackValue );
                                }
                        }
                } else {
@@ -433,6 +447,20 @@ class LocalisationCache {
                }
        }
 
+       protected function mergeMagicWords( &$value, $fallbackValue ) {
+               foreach ( $fallbackValue as $magicName => $fallbackInfo ) {
+                       if ( !isset( $value[$magicName] ) ) {
+                               $value[$magicName] = $fallbackInfo;
+                       } else {
+                               $oldSynonyms = array_slice( $fallbackInfo, 1 );
+                               $newSynonyms = array_slice( $value[$magicName], 1 );
+                               $synonyms = array_values( array_unique( array_merge( 
+                                       $newSynonyms, $oldSynonyms ) ) );
+                               $value[$magicName] = array_merge( array( $fallbackInfo[0] ), $synonyms );
+                       }
+               }
+       }
+
        /**
         * Given an array mapping language code to localisation value, such as is
         * found in extension *.i18n.php files, iterate through a fallback sequence