[ '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,
$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();
$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;
}
);
}
*/
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 */
/** @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 */
/** @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;
$this->mTextLoaded = 2;
$this->mRevisionsLoaded = true;
+ $this->isContentOverridden = true;
}
/**
* 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
/**
* 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
/**
* 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;