MessageCache: Fix isMainCacheable() logic for non-content languages
[lhc/web/wiklou.git] / includes / cache / MessageCache.php
index 157d88e..a8bcfc6 100644 (file)
@@ -217,7 +217,7 @@ class MessageCache {
        /**
         * Try to load the cache from APC.
         *
-        * @param string $code Optional language code, see documenation of load().
+        * @param string $code Optional language code, see documentation of load().
         * @return array|bool The cache array, or false if not in cache.
         */
        protected function getLocalCache( $code ) {
@@ -342,7 +342,7 @@ class MessageCache {
                                        } elseif ( $hashVolatile ) {
                                                # DB results are replica DB lag prone until the holdoff TTL passes.
                                                # By then, updates should be reflected in loadFromDBWithLock().
-                                               # One thread renerates the cache while others use old values.
+                                               # One thread regenerates the cache while others use old values.
                                                $where[] = 'global cache is expired/volatile';
                                                $staleCache = $cache;
                                        } else {
@@ -379,7 +379,7 @@ class MessageCache {
                                        break;
                                } elseif ( $loadStatus === 'cantacquire' ) {
                                        # Wait for the other thread to finish, then retry. Normally,
-                                       # the memcached get() will then yeild the other thread's result.
+                                       # the memcached get() will then yield the other thread's result.
                                        $where[] = 'waited for other thread to complete';
                                        $this->getReentrantScopedLock( $cacheKey );
                                } else {
@@ -525,9 +525,8 @@ class MessageCache {
                        __METHOD__ . "($code)-big"
                );
                foreach ( $res as $row ) {
-                       $name = $this->contLang->lcfirst( $row->page_title );
                        // Include entries/stubs for all keys in $mostused in adaptive mode
-                       if ( $wgAdaptiveMessageCache || $this->isMainCacheable( $name, $overridable ) ) {
+                       if ( $wgAdaptiveMessageCache || $this->isMainCacheable( $row->page_title, $overridable ) ) {
                                $cache[$row->page_title] = '!TOO BIG';
                        }
                        // At least include revision ID so page changes are reflected in the hash
@@ -549,9 +548,8 @@ class MessageCache {
                        $revQuery['joins']
                );
                foreach ( $res as $row ) {
-                       $name = $this->contLang->lcfirst( $row->page_title );
                        // Include entries/stubs for all keys in $mostused in adaptive mode
-                       if ( $wgAdaptiveMessageCache || $this->isMainCacheable( $name, $overridable ) ) {
+                       if ( $wgAdaptiveMessageCache || $this->isMainCacheable( $row->page_title, $overridable ) ) {
                                try {
                                        $rev = $revisionStore->newRevisionFromRow( $row );
                                        $content = $rev->getContent( MediaWiki\Revision\SlotRecord::MAIN );
@@ -592,14 +590,17 @@ class MessageCache {
        }
 
        /**
-        * @param string $name Message name with lowercase first letter
+        * @param string $name Message name (possibly with /code suffix)
         * @param array $overridable Map of (key => unused) for software-defined messages
         * @return bool
         */
        private function isMainCacheable( $name, array $overridable ) {
+               // Convert first letter to lowercase, and strip /code suffix
+               $name = $this->contLang->lcfirst( $name );
+               $msg = preg_replace( '/\/[a-z0-9-]{2,}$/', '', $name );
                // Include common conversion table pages. This also avoids problems with
                // Installer::parse() bailing out due to disallowed DB queries (T207979).
-               return ( isset( $overridable[$name] ) || strpos( $name, 'conversiontable/' ) === 0 );
+               return ( isset( $overridable[$msg] ) || strpos( $name, 'conversiontable/' ) === 0 );
        }
 
        /**
@@ -718,8 +719,7 @@ class MessageCache {
                $this->wanCache->touchCheckKey( $this->getCheckKey( $code ) );
 
                // Purge the messages in the message blob store and fire any hook handlers
-               $resourceloader = RequestContext::getMain()->getOutput()->getResourceLoader();
-               $blobStore = $resourceloader->getMessageBlobStore();
+               $blobStore = MediaWikiServices::getInstance()->getResourceLoader()->getMessageBlobStore();
                foreach ( $replacements as list( $title, $msg ) ) {
                        $blobStore->updateMessage( $this->contLang->lcfirst( $msg ) );
                        Hooks::run( 'MessageCacheReplace', [ $title, $newTextByTitle[$title] ] );
@@ -1070,8 +1070,7 @@ class MessageCache {
                        );
                } else {
                        // Message page either does not exist or does not override a software message
-                       $name = $this->contLang->lcfirst( $title );
-                       if ( !$this->isMainCacheable( $name, $this->overridable ) ) {
+                       if ( !$this->isMainCacheable( $title, $this->overridable ) ) {
                                // Message page does not override any software-defined message. A custom
                                // message might be defined to have content or settings specific to the wiki.
                                // Load the message page, utilizing the individual message cache as needed.
@@ -1203,18 +1202,18 @@ class MessageCache {
         * @return Parser
         */
        public function getParser() {
-               global $wgParser, $wgParserConf;
-
-               if ( !$this->mParser && isset( $wgParser ) ) {
+               global $wgParserConf;
+               if ( !$this->mParser ) {
+                       $parser = MediaWikiServices::getInstance()->getParser();
                        # Do some initialisation so that we don't have to do it twice
-                       $wgParser->firstCallInit();
+                       $parser->firstCallInit();
                        # Clone it and store it
                        $class = $wgParserConf['class'];
                        if ( $class == ParserDiffTest::class ) {
                                # Uncloneable
                                $this->mParser = new $class( $wgParserConf );
                        } else {
-                               $this->mParser = clone $wgParser;
+                               $this->mParser = clone $parser;
                        }
                }