Merge "Type hint against LinkTarget in WatchedItemStore"
[lhc/web/wiklou.git] / includes / cache / localisation / LocalisationCache.php
index 788eec3..ffc7cd0 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,6 +199,7 @@ class LocalisationCache {
                global $wgCacheDirectory;
 
                $this->conf = $conf;
+               $this->logger = LoggerFactory::getInstance( 'localisation' );
 
                $directory = !empty( $conf['storeDirectory'] ) ? $conf['storeDirectory'] : $wgCacheDirectory;
                $storeArg = [];
@@ -226,8 +234,7 @@ class LocalisationCache {
                                        );
                        }
                }
-
-               wfDebugLog( 'caches', static::class . ": using store $storeClass" );
+               $this->logger->debug( static::class . ": using store $storeClass" );
 
                $this->store = new $storeClass( $storeArg );
                foreach ( [ 'manualRecache', 'forceRecache' ] as $var ) {
@@ -400,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" );
 
                        return true;
                }
@@ -410,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" );
 
                        return true;
                }
@@ -421,8 +428,8 @@ 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 " .
-                                       get_class( $dep ) . "\n" );
+                               $this->logger->debug( __METHOD__ . "($code): cache for $code expired due to " .
+                                       get_class( $dep ) );
 
                                return true;
                        }
@@ -589,7 +596,7 @@ class LocalisationCache {
                try {
                        $compiledRules = Evaluator::compile( $rules );
                } catch ( CLDRPluralRuleError $e ) {
-                       wfDebugLog( 'l10n', $e->getMessage() );
+                       $this->logger->debug( $e->getMessage() );
 
                        return [];
                }
@@ -829,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" );
                        $coreData['fallback'] = 'en';
                } else {
-                       wfDebug( __METHOD__ . ": got localisation for $code from source\n" );
+                       $this->logger->debug( __METHOD__ . ": got localisation for $code from source" );
 
                        # Merge primary localisation
                        foreach ( $data as $key => $value ) {
@@ -997,8 +1004,8 @@ class LocalisationCache {
                        $allData['list'][$key] = array_keys( $allData[$key] );
                }
                # Run hooks
-               $purgeBlobs = true;
-               Hooks::run( 'LocalisationCacheRecache', [ $this, $code, &$allData, &$purgeBlobs ] );
+               $unused = true; // Used to be $purgeBlobs, removed in 1.34
+               Hooks::run( 'LocalisationCacheRecache', [ $this, $code, &$allData, &$unused ] );
 
                if ( is_null( $allData['namespaceNames'] ) ) {
                        throw new MWException( __METHOD__ . ': Localisation data failed sanity check! ' .
@@ -1030,7 +1037,7 @@ class LocalisationCache {
                # Clear out the MessageBlobStore
                # HACK: If using a null (i.e. disabled) storage backend, we
                # can't write to the MessageBlobStore either
-               if ( $purgeBlobs && !$this->store instanceof LCStoreNull ) {
+               if ( !$this->store instanceof LCStoreNull ) {
                        $blobStore = MediaWikiServices::getInstance()->getResourceLoader()->getMessageBlobStore();
                        $blobStore->clear();
                }