Followup r94995: add hooks.txt entries for the new hooks
[lhc/web/wiklou.git] / includes / LocalisationCache.php
index 36867c8..b20db32 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-define( 'MW_LC_VERSION', 1 );
+define( 'MW_LC_VERSION', 2 );
 
 /**
  * Class for caching the contents of localisation files, Messages*.php
@@ -84,7 +84,7 @@ class LocalisationCache {
                'fallback', 'namespaceNames', 'bookstoreList',
                'magicWords', 'messages', 'rtl', 'capitalizeAllNouns', 'digitTransformTable',
                'separatorTransformTable', 'fallback8bitEncoding', 'linkPrefixExtension',
-               'defaultUserOptionOverrides', 'linkTrail', 'namespaceAliases',
+               'linkTrail', 'namespaceAliases',
                'dateFormats', 'datePreferences', 'datePreferenceMigrationMap',
                'defaultDateFormat', 'extraUserToggles', 'specialPageAliases',
                'imageFiles', 'preloadedMessages', 'namespaceGenderAliases',
@@ -95,8 +95,7 @@ class LocalisationCache {
         * by a fallback sequence.
         */
        static public $mergeableMapKeys = array( 'messages', 'namespaceNames',
-               'dateFormats', 'defaultUserOptionOverrides', 'imageFiles',
-               'preloadedMessages',
+               'dateFormats', 'imageFiles', 'preloadedMessages',
        );
 
        /**
@@ -130,13 +129,14 @@ class LocalisationCache {
        /**
         * Keys which are loaded automatically by initLanguage()
         */
-       static public $preloadedKeys = array( 'dateFormats', 'namespaceNames',
-               'defaultUserOptionOverrides' );
+       static public $preloadedKeys = array( 'dateFormats', 'namespaceNames' );
 
        /**
         * Constructor.
         * For constructor parameters, see the documentation in DefaultSettings.php
         * for $wgLocalisationCacheConf.
+        *
+        * @param $conf Array
         */
        function __construct( $conf ) {
                global $wgCacheDirectory;
@@ -485,7 +485,6 @@ class LocalisationCache {
         * and save it to the persistent cache store and the process cache
         */
        public function recache( $code ) {
-               static $recursionGuard = array();
                global $wgExtensionMessagesFiles, $wgExtensionAliasesFiles;
                wfProfileIn( __METHOD__ );
 
@@ -522,27 +521,27 @@ class LocalisationCache {
                        $coreData['fallback'] = $code === 'en' ? false : 'en';
                }
 
-               if ( $coreData['fallback'] !== false ) {
-                       # Guard against circular references
-                       if ( isset( $recursionGuard[$code] ) ) {
-                               throw new MWException( "Error: Circular fallback reference in language code $code" );
+               if ( $coreData['fallback'] === false ) {
+                       $coreData['fallbackSequence'] = array();
+               } else {
+                       $coreData['fallbackSequence'] = array_map( 'trim', explode( ',', $coreData['fallback'] ) );
+                       $len = count( $coreData['fallbackSequence'] );
+                       # Ensure that the sequence ends at en
+                       if ( $coreData['fallbackSequence'][$len - 1] !== 'en' ) {
+                               $coreData['fallbackSequence'][] = 'en';
                        }
-                       $recursionGuard[$code] = true;
 
                        # Load the fallback localisation item by item and merge it
-                       $deps = array_merge( $deps, $this->getItem( $coreData['fallback'], 'deps' ) );
-                       foreach ( self::$allKeys as $key ) {
-                               if ( is_null( $coreData[$key] ) || $this->isMergeableKey( $key ) ) {
-                                       $fallbackValue = $this->getItem( $coreData['fallback'], $key );
-                                       $this->mergeItem( $key, $coreData[$key], $fallbackValue );
+                       foreach ( $coreData['fallbackSequence'] as $fallback ) {
+                               $deps = array_merge( $deps, $this->getItem( $fallback, 'deps' ) );
+                               foreach ( self::$allKeys as $key ) {
+                                       if ( is_null( $coreData[$key] ) || $this->isMergeableKey( $key ) ) {
+                                               $fallbackValue = $this->getItem( $fallback, $key );
+                                               $this->mergeItem( $key, $coreData[$key], $fallbackValue );
+                                       }
                                }
                        }
-                       $fallbackSequence = $this->getItem( $coreData['fallback'], 'fallbackSequence' );
-                       array_unshift( $fallbackSequence, $coreData['fallback'] );
-                       $coreData['fallbackSequence'] = $fallbackSequence;
-                       unset( $recursionGuard[$code] );
-               } else {
-                       $coreData['fallbackSequence'] = array();
+                       
                }
                $codeSequence = array_merge( array( $code ), $coreData['fallbackSequence'] );
 
@@ -600,11 +599,6 @@ class LocalisationCache {
                # Decouple the reference to prevent accidental damage
                unset($page);
 
-               # Fix broken defaultUserOptionOverrides
-               if ( !is_array( $allData['defaultUserOptionOverrides'] ) ) {
-                       $allData['defaultUserOptionOverrides'] = array();
-               }
-
                # Set the list keys
                $allData['list'] = array();
                foreach ( self::$splitKeys as $key ) {
@@ -614,11 +608,6 @@ class LocalisationCache {
                # Run hooks
                wfRunHooks( 'LocalisationCacheRecache', array( $this, $code, &$allData ) );
 
-               if ( is_null( $allData['defaultUserOptionOverrides'] ) ) {
-                       throw new MWException( __METHOD__.': Localisation data failed sanity check! ' .
-                               'Check that your languages/messages/MessagesEn.php file is intact.' );
-               }
-
                # Set the preload key
                $allData['preload'] = $this->buildPreload( $allData );
 
@@ -879,7 +868,7 @@ class LCStore_CDB implements LCStore {
 
        public function startWrite( $code ) {
                if ( !file_exists( $this->directory ) ) {
-                       if ( !wfMkdirParents( $this->directory ) ) {
+                       if ( !wfMkdirParents( $this->directory, null, __METHOD__ ) ) {
                                throw new MWException( "Unable to create the localisation store " .
                                        "directory \"{$this->directory}\"" );
                        }