Merge "Deprecate $wgShowSQLErrors and $wgShowDBErrorBacktrace and make nonfunctional"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 25 Jul 2018 16:22:22 +0000 (16:22 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 25 Jul 2018 16:22:22 +0000 (16:22 +0000)
includes/cache/MessageCache.php
includes/diff/DifferenceEngine.php

index 59486e4..48aac7e 100644 (file)
@@ -592,13 +592,15 @@ class MessageCache {
                                                [ 'title' => $title, 'code' => $code ] );
                                        return;
                                }
-                               // Load the messages from the master DB to avoid race conditions
+                               // Reload messages from the database and pre-populate dc-local caches
+                               // as optimisation. Use the master DB to avoid race conditions.
                                $cache = $this->loadFromDB( $code, self::FOR_UPDATE );
                                // Check if an individual cache key should exist and update cache accordingly
                                $page = WikiPage::factory( Title::makeTitle( NS_MEDIAWIKI, $title ) );
                                $page->loadPageData( $page::READ_LATEST );
                                $text = $this->getMessageTextFromContent( $page->getContent() );
                                if ( is_string( $text ) && strlen( $text ) > $wgMaxMsgCacheEntrySize ) {
+                                       // Match logic of loadCachedMessagePageEntry()
                                        $this->wanCache->set(
                                                $this->bigMessageCacheKey( $cache['HASH'], $title ),
                                                ' ' . $text,
@@ -1037,6 +1039,8 @@ class MessageCache {
                                $title = Title::makeTitle( NS_MEDIAWIKI, $dbKey );
                                $revision = Revision::newKnownCurrent( $dbr, $title );
                                if ( !$revision ) {
+                                       // The wiki doesn't have a local override page. Cache absence with normal TTL.
+                                       // When overrides are created, self::replace() takes care of the cache.
                                        return '!NONEXISTENT';
                                }
                                $content = $revision->getContent();
@@ -1050,13 +1054,14 @@ class MessageCache {
                                        $message = null;
                                }
 
-                               if ( is_string( $message ) ) {
-                                       return ' ' . $message;
+                               if ( !is_string( $message ) ) {
+                                       // Revision failed to load Content, or Content is incompatible with wikitext.
+                                       // Possibly a temporary loading failure.
+                                       $ttl = 5;
+                                       return '!NONEXISTENT';
                                }
 
-                               $ttl = 5; // possibly a temporary loading failure
-
-                               return '!NONEXISTENT';
+                               return ' ' . $message;
                        }
                );
        }
index 1d9ad05..fbc3dd3 100644 (file)
@@ -36,19 +36,19 @@ class DifferenceEngine extends ContextSource {
         */
        const DIFF_VERSION = '1.12';
 
-       /** @var int */
+       /** @var int Revision ID or 0 for current */
        public $mOldid;
 
-       /** @var int */
+       /** @var int|string Revision ID or null for current or an alias such as 'next' */
        public $mNewid;
 
        private $mOldTags;
        private $mNewTags;
 
-       /** @var Content */
+       /** @var Content|null */
        public $mOldContent;
 
-       /** @var Content */
+       /** @var Content|null */
        public $mNewContent;
 
        /** @var Language */
@@ -60,10 +60,10 @@ class DifferenceEngine extends ContextSource {
        /** @var Title */
        public $mNewPage;
 
-       /** @var Revision */
+       /** @var Revision|null */
        public $mOldRev;
 
-       /** @var Revision */
+       /** @var Revision|null */
        public $mNewRev;
 
        /** @var bool Have the revisions IDs been loaded */
@@ -75,6 +75,13 @@ class DifferenceEngine extends ContextSource {
        /** @var int How many text blobs have been loaded, 0, 1 or 2? */
        public $mTextLoaded = 0;
 
+       /**
+        * Was the content overridden via setContent()?
+        * If the content was overridden, most internal state (e.g. mOldid or mOldRev) should be ignored.
+        * @var bool
+        */
+       protected $isContentOverridden = false;
+
        /** @var bool Was the diff fetched from cache? */
        public $mCacheHit = false;
 
@@ -1341,6 +1348,7 @@ class DifferenceEngine extends ContextSource {
 
                $this->mTextLoaded = 2;
                $this->mRevisionsLoaded = true;
+               $this->isContentOverridden = true;
        }
 
        /**
@@ -1420,11 +1428,11 @@ class DifferenceEngine extends ContextSource {
         * to false. This is impossible via ordinary user input, and is provided for
         * API convenience.
         *
-        * @return bool
+        * @return bool Whether both revisions were loaded successfully.
         */
        public function loadRevisionData() {
                if ( $this->mRevisionsLoaded ) {
-                       return true;
+                       return $this->isContentOverridden || $this->mNewRev && $this->mOldRev;
                }
 
                // Whether it succeeds or fails, we don't want to try again
@@ -1500,11 +1508,11 @@ class DifferenceEngine extends ContextSource {
        /**
         * Load the text of the revisions, as well as revision data.
         *
-        * @return bool
+        * @return bool Whether the content of both revisions could be loaded successfully.
         */
        public function loadText() {
                if ( $this->mTextLoaded == 2 ) {
-                       return true;
+                       return $this->loadRevisionData() && $this->mOldContent && $this->mNewContent;
                }
 
                // Whether it succeeds or fails, we don't want to try again
@@ -1535,11 +1543,11 @@ class DifferenceEngine extends ContextSource {
        /**
         * Load the text of the new revision, not the old one
         *
-        * @return bool
+        * @return bool Whether the content of the new revision could be loaded successfully.
         */
        public function loadNewText() {
                if ( $this->mTextLoaded >= 1 ) {
-                       return true;
+                       return $this->loadRevisionData();
                }
 
                $this->mTextLoaded = 1;