Merge "Title: Title::getSubpage should not lose the interwiki prefix"
[lhc/web/wiklou.git] / includes / cache / localisation / LocalisationCache.php
index db0f380..c4a7e89 100644 (file)
@@ -22,6 +22,7 @@
 
 use CLDRPluralRuleParser\Evaluator;
 use CLDRPluralRuleParser\Error as CLDRPluralRuleError;
+use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\MediaWikiServices;
 
 /**
@@ -69,6 +70,11 @@ class LocalisationCache {
         */
        private $store;
 
+       /**
+        * @var \Psr\Log\LoggerInterface
+        */
+       private $logger;
+
        /**
         * A 2-d associative array, code/key, where presence indicates that the item
         * is loaded. Value arbitrary.
@@ -108,14 +114,15 @@ class LocalisationCache {
         */
        public static $allKeys = [
                'fallback', 'namespaceNames', 'bookstoreList',
-               'magicWords', 'messages', 'rtl', 'capitalizeAllNouns', 'digitTransformTable',
-               'separatorTransformTable', 'minimumGroupingDigits',
-               'fallback8bitEncoding', 'linkPrefixExtension',
-               'linkTrail', 'linkPrefixCharset', 'namespaceAliases',
-               'dateFormats', 'datePreferences', 'datePreferenceMigrationMap',
-               'defaultDateFormat', 'extraUserToggles', 'specialPageAliases',
-               'imageFiles', 'preloadedMessages', 'namespaceGenderAliases',
-               'digitGroupingPattern', 'pluralRules', 'pluralRuleTypes', 'compiledPluralRules',
+               'magicWords', 'messages', 'rtl', 'capitalizeAllNouns',
+               'digitTransformTable', 'separatorTransformTable',
+               'minimumGroupingDigits', 'fallback8bitEncoding',
+               'linkPrefixExtension', 'linkTrail', 'linkPrefixCharset',
+               'namespaceAliases', 'dateFormats', 'datePreferences',
+               'datePreferenceMigrationMap', 'defaultDateFormat',
+               'specialPageAliases', 'imageFiles', 'preloadedMessages',
+               'namespaceGenderAliases', 'digitGroupingPattern', 'pluralRules',
+               'pluralRuleTypes', 'compiledPluralRules',
        ];
 
        /**
@@ -129,7 +136,7 @@ class LocalisationCache {
        /**
         * Keys for items which are a numbered array.
         */
-       public static $mergeableListKeys = [ 'extraUserToggles' ];
+       public static $mergeableListKeys = [];
 
        /**
         * Keys for items which contain an array of arrays of equivalent aliases
@@ -192,7 +199,12 @@ class LocalisationCache {
                global $wgCacheDirectory;
 
                $this->conf = $conf;
-               $storeConf = [];
+               $this->logger = LoggerFactory::getInstance( 'localisation' );
+
+               $directory = !empty( $conf['storeDirectory'] ) ? $conf['storeDirectory'] : $wgCacheDirectory;
+               $storeArg = [];
+               $storeArg['directory'] = $directory;
+
                if ( !empty( $conf['storeClass'] ) ) {
                        $storeClass = $conf['storeClass'];
                } else {
@@ -203,20 +215,17 @@ class LocalisationCache {
                                        break;
                                case 'db':
                                        $storeClass = LCStoreDB::class;
-                                       $storeConf['server'] = $conf['storeServer'] ?? [];
+                                       $storeArg['server'] = $conf['storeServer'] ?? [];
                                        break;
                                case 'array':
                                        $storeClass = LCStoreStaticArray::class;
                                        break;
                                case 'detect':
-                                       if ( !empty( $conf['storeDirectory'] ) ) {
-                                               $storeClass = LCStoreCDB::class;
-                                       } elseif ( $wgCacheDirectory ) {
-                                               $storeConf['directory'] = $wgCacheDirectory;
+                                       if ( $directory ) {
                                                $storeClass = LCStoreCDB::class;
                                        } else {
                                                $storeClass = LCStoreDB::class;
-                                               $storeConf['server'] = $conf['storeServer'] ?? [];
+                                               $storeArg['server'] = $conf['storeServer'] ?? [];
                                        }
                                        break;
                                default:
@@ -225,13 +234,9 @@ class LocalisationCache {
                                        );
                        }
                }
+               $this->logger->debug( static::class . ": using store $storeClass" );
 
-               wfDebugLog( 'caches', static::class . ": using store $storeClass" );
-               if ( !empty( $conf['storeDirectory'] ) ) {
-                       $storeConf['directory'] = $conf['storeDirectory'];
-               }
-
-               $this->store = new $storeClass( $storeConf );
+               $this->store = new $storeClass( $storeArg );
                foreach ( [ 'manualRecache', 'forceRecache' ] as $var ) {
                        if ( isset( $conf[$var] ) ) {
                                $this->$var = $conf[$var];
@@ -402,7 +407,7 @@ class LocalisationCache {
         */
        public function isExpired( $code ) {
                if ( $this->forceRecache && !isset( $this->recachedLangs[$code] ) ) {
-                       wfDebug( __METHOD__ . "($code): forced reload\n" );
+                       $this->logger->debug( __METHOD__ . "($code): forced reload\n" );
 
                        return true;
                }
@@ -412,7 +417,7 @@ class LocalisationCache {
                $preload = $this->store->get( $code, 'preload' );
                // Different keys may expire separately for some stores
                if ( $deps === null || $keys === null || $preload === null ) {
-                       wfDebug( __METHOD__ . "($code): cache missing, need to make one\n" );
+                       $this->logger->debug( __METHOD__ . "($code): cache missing, need to make one\n" );
 
                        return true;
                }
@@ -423,7 +428,7 @@ class LocalisationCache {
                        // anymore (e.g. uninstalled extensions)
                        // When this happens, always expire the cache
                        if ( !$dep instanceof CacheDependency || $dep->isExpired() ) {
-                               wfDebug( __METHOD__ . "($code): cache for $code expired due to " .
+                               $this->logger->debug( __METHOD__ . "($code): cache for $code expired due to " .
                                        get_class( $dep ) . "\n" );
 
                                return true;
@@ -591,7 +596,7 @@ class LocalisationCache {
                try {
                        $compiledRules = Evaluator::compile( $rules );
                } catch ( CLDRPluralRuleError $e ) {
-                       wfDebugLog( 'l10n', $e->getMessage() );
+                       $this->logger->debug( $e->getMessage() );
 
                        return [];
                }
@@ -831,10 +836,10 @@ class LocalisationCache {
                # Load the primary localisation from the source file
                $data = $this->readSourceFilesAndRegisterDeps( $code, $deps );
                if ( $data === false ) {
-                       wfDebug( __METHOD__ . ": no localisation file for $code, using fallback to en\n" );
+                       $this->logger->debug( __METHOD__ . ": no localisation file for $code, using fallback to en\n" );
                        $coreData['fallback'] = 'en';
                } else {
-                       wfDebug( __METHOD__ . ": got localisation for $code from source\n" );
+                       $this->logger->debug( __METHOD__ . ": got localisation for $code from source\n" );
 
                        # Merge primary localisation
                        foreach ( $data as $key => $value ) {