LocalisationCache: Don't instantiate ResourceLoader
[lhc/web/wiklou.git] / includes / resourceloader / MessageBlobStore.php
index fca06c9..29dc866 100644 (file)
@@ -27,10 +27,13 @@ use Psr\Log\NullLogger;
 use Wikimedia\Rdbms\Database;
 
 /**
- * This class generates message blobs for use by ResourceLoader modules.
+ * This class generates message blobs for use by ResourceLoader.
  *
- * A message blob is a JSON object containing the interface messages for a certain module in
- * a certain language.
+ * A message blob is a JSON object containing the interface messages for a
+ * certain module in a certain language.
+ *
+ * @ingroup ResourceLoader
+ * @since 1.17
  */
 class MessageBlobStore implements LoggerAwareInterface {
 
@@ -54,6 +57,10 @@ class MessageBlobStore implements LoggerAwareInterface {
        public function __construct( ResourceLoader $rl, LoggerInterface $logger = null ) {
                $this->resourceloader = $rl;
                $this->logger = $logger ?: new NullLogger();
+
+               // NOTE: when changing this assignment, make sure the code in the instantiator for
+               // LocalisationCache which calls MessageBlobStore::clearGlobalCacheEntry() uses the
+               // same cache object.
                $this->wanCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
        }
 
@@ -166,10 +173,19 @@ class MessageBlobStore implements LoggerAwareInterface {
 
        /**
         * Invalidate cache keys for all known modules.
-        * Called by LocalisationCache after cache is regenerated.
         */
        public function clear() {
-               $cache = $this->wanCache;
+               self::clearGlobalCacheEntry( $this->wanCache );
+       }
+
+       /**
+        * Invalidate cache keys for all known modules.
+        *
+        * Called by LocalisationCache after cache is regenerated.
+        *
+        * @param WANObjectCache $cache
+        */
+       public static function clearGlobalCacheEntry( WANObjectCache $cache ) {
                // Disable hold-off because:
                // - LocalisationCache is populated by messages on-disk and don't have DB lag,
                //   thus there is no need for hold off. We only clear it after new localisation
@@ -224,7 +240,7 @@ class MessageBlobStore implements LoggerAwareInterface {
                        }
                }
 
-               $json = FormatJson::encode( (object)$messages );
+               $json = FormatJson::encode( (object)$messages, false, FormatJson::UTF8_OK );
                // @codeCoverageIgnoreStart
                if ( $json === false ) {
                        $this->logger->warning( 'Failed to encode message blob for {module} ({lang})', [