Merge "resourceloader: ResourceLoaderGetConfigVars is passed skin"
[lhc/web/wiklou.git] / includes / cache / MessageCache.php
index 4e0d0a7..5ada42f 100644 (file)
@@ -52,6 +52,13 @@ class MessageCache {
         */
        protected $cache;
 
+       /**
+        * Map of (lowercase message key => index) for all software defined messages
+        *
+        * @var array
+        */
+       protected $overridable;
+
        /**
         * @var bool[] Map of (language code => boolean)
         */
@@ -191,6 +198,7 @@ class MessageCache {
                                // either.
                                $po = ParserOptions::newFromAnon();
                                $po->setAllowUnsafeRawHtml( false );
+                               $po->setTidy( true );
                                return $po;
                        }
 
@@ -199,6 +207,8 @@ class MessageCache {
                        // from malicious sources. As a precaution, disable
                        // the <html> parser tag when parsing messages.
                        $this->mParserOptions->setAllowUnsafeRawHtml( false );
+                       // For the same reason, tidy the output!
+                       $this->mParserOptions->setTidy( true );
                }
 
                return $this->mParserOptions;
@@ -258,6 +268,8 @@ class MessageCache {
                        return true;
                }
 
+               $this->overridable = array_flip( Language::getMessageKeysFor( $code ) );
+
                # 8 lines of code just to say (once) that message cache is disabled
                if ( $this->mDisable ) {
                        static $shownDisabled = false;
@@ -504,7 +516,7 @@ class MessageCache {
                foreach ( $res as $row ) {
                        $name = $this->contLang->lcfirst( $row->page_title );
                        // Include entries/stubs for all keys in $mostused in adaptive mode
-                       if ( $wgAdaptiveMessageCache || isset( $overridable[$name] ) ) {
+                       if ( $wgAdaptiveMessageCache || $this->isMainCacheable( $name, $overridable ) ) {
                                $cache[$row->page_title] = '!TOO BIG';
                        }
                        // At least include revision ID so page changes are reflected in the hash
@@ -526,7 +538,7 @@ class MessageCache {
                foreach ( $res as $row ) {
                        $name = $this->contLang->lcfirst( $row->page_title );
                        // Include entries/stubs for all keys in $mostused in adaptive mode
-                       if ( $wgAdaptiveMessageCache || isset( $overridable[$name] ) ) {
+                       if ( $wgAdaptiveMessageCache || $this->isMainCacheable( $name, $overridable ) ) {
                                $text = Revision::getRevisionText( $row );
                                if ( $text === false ) {
                                        // Failed to fetch data; possible ES errors?
@@ -562,6 +574,17 @@ class MessageCache {
                return $cache;
        }
 
+       /**
+        * @param string $name Message name with lowercase first letter
+        * @param array $overridable Map of (key => unused) for software-defined messages
+        * @return bool
+        */
+       private function isMainCacheable( $name, array $overridable ) {
+               // 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 );
+       }
+
        /**
         * Updates cache as necessary when message page is changed
         *
@@ -1029,14 +1052,19 @@ class MessageCache {
                                $this->cache->getField( $code, 'HASH' )
                        );
                } else {
-                       // Message page does not exist or does not override a software message.
-                       // Load the message page, utilizing the individual message cache.
-                       $entry = $this->loadCachedMessagePageEntry(
-                               $title,
-                               $code,
-                               $this->cache->getField( $code, 'HASH' )
-                       );
-                       if ( substr( $entry, 0, 1 ) !== ' ' ) {
+                       // Message page either does not exist or does not override a software message
+                       $name = $this->contLang->lcfirst( $title );
+                       if ( !$this->isMainCacheable( $name, $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.
+                               $entry = $this->loadCachedMessagePageEntry(
+                                       $title,
+                                       $code,
+                                       $this->cache->getField( $code, 'HASH' )
+                               );
+                       }
+                       if ( $entry === null || substr( $entry, 0, 1 ) !== ' ' ) {
                                // Message does not have a MediaWiki page definition; try hook handlers
                                $message = false;
                                Hooks::run( 'MessagesPreLoad', [ $title, &$message, $code ] );