* @file
*/
use MediaWiki\Linker\LinkTarget;
+use MediaWiki\MediaWikiServices;
/**
* @todo document
const DELETED_USER = 4;
const DELETED_RESTRICTED = 8;
const SUPPRESSED_USER = 12; // convenience
+ const SUPPRESSED_ALL = 15; // convenience
// Audience options for accessors
const FOR_PUBLIC = 1;
const FOR_THIS_USER = 2;
const RAW = 3;
+ const TEXT_CACHE_GROUP = 'revisiontext:10'; // process cache name and max key count
+
/**
* Load a page revision from a given revision ID number.
* Returns null if no such revision can be found.
* to the $audience parameter
*
* @deprecated since 1.21, use getContent() instead
- * @todo Replace usage in core
* @return string
*/
public function getText( $audience = self::FOR_PUBLIC, User $user = null ) {
- ContentHandler::deprecated( __METHOD__, '1.21' );
+ wfDeprecated( __METHOD__, '1.21' );
$content = $this->getContent( $audience, $user );
return ContentHandler::getContentText( $content ); # returns the raw content text, if applicable
}
/**
- * Fetch original serialized data without regard for view restrictions
+ * Get original serialized data (without checking view restrictions)
*
* @since 1.21
* @return string
*/
public function getSerializedData() {
if ( $this->mText === null ) {
+ // Revision is immutable. Load on demand.
$this->mText = $this->loadText();
}
*/
protected function getContentInternal() {
if ( $this->mContent === null ) {
- // Revision is immutable. Load on demand:
- if ( $this->mText === null ) {
- $this->mText = $this->loadText();
- }
+ $text = $this->getSerializedData();
- if ( $this->mText !== null && $this->mText !== false ) {
+ if ( $text !== null && $text !== false ) {
// Unserialize content
$handler = $this->getContentHandler();
$format = $this->getContentFormat();
- $this->mContent = $handler->unserializeContent( $this->mText, $format );
+ $this->mContent = $handler->unserializeContent( $text, $format );
}
}
public function insertOn( $dbw ) {
global $wgDefaultExternalStore, $wgContentHandlerUseDB;
+ // We're inserting a new revision, so we have to use master anyway.
+ // If it's a null revision, it may have references to rows that
+ // are not in the replica yet (the text row).
+ $this->mQueryFlags |= self::READ_LATEST;
+
// Not allowed to have rev_page equal to 0, false, etc.
if ( !$this->mPage ) {
$title = $this->getTitle();
*
* @return string|bool The revision's text, or false on failure
*/
- protected function loadText() {
- // Caching may be beneficial for massive use of external storage
+ private function loadText() {
global $wgRevisionCacheExpiry;
- static $processCache = null;
- if ( !$processCache ) {
- $processCache = new MapCacheLRU( 10 );
+ $cache = ObjectCache::getMainWANInstance();
+ if ( $cache->getQoS( $cache::ATTR_EMULATION ) <= $cache::QOS_EMULATION_SQL ) {
+ // Do not cache RDBMs blobs in...the RDBMs store
+ $ttl = $cache::TTL_UNCACHEABLE;
+ } else {
+ $ttl = $wgRevisionCacheExpiry ?: $cache::TTL_UNCACHEABLE;
}
- $cache = ObjectCache::getMainWANInstance();
- $textId = $this->getTextId();
- $key = wfMemcKey( 'revisiontext', 'textid', $textId );
+ // No negative caching; negative hits on text rows may be due to corrupted replica DBs
+ return $cache->getWithSetCallback(
+ $cache->makeKey( 'revisiontext', 'textid', $this->getTextId() ),
+ $ttl,
+ function () {
+ return $this->fetchText();
+ },
+ [ 'pcGroup' => self::TEXT_CACHE_GROUP, 'pcTTL' => $cache::TTL_PROC_LONG ]
+ );
+ }
- if ( $wgRevisionCacheExpiry ) {
- if ( $processCache->has( $key ) ) {
- return $processCache->get( $key );
- }
- $text = $cache->get( $key );
- if ( is_string( $text ) ) {
- $processCache->set( $key, $text );
- return $text;
- }
- }
+ private function fetchText() {
+ $textId = $this->getTextId();
// If we kept data for lazy extraction, use it now...
if ( $this->mTextRow !== null ) {
$row = null;
}
+ // Callers doing updates will pass in READ_LATEST as usual. Since the text/blob tables
+ // do not normally get rows changed around, set READ_LATEST_IMMUTABLE in those cases.
+ $flags = $this->mQueryFlags;
+ $flags |= DBAccessObjectUtils::hasFlags( $flags, self::READ_LATEST )
+ ? self::READ_LATEST_IMMUTABLE
+ : 0;
+
+ list( $index, $options, $fallbackIndex, $fallbackOptions ) =
+ DBAccessObjectUtils::getDBOptions( $flags );
+
if ( !$row ) {
// Text data is immutable; check replica DBs first.
- $dbr = wfGetDB( DB_REPLICA );
- $row = $dbr->selectRow( 'text',
+ $row = wfGetDB( $index )->selectRow(
+ 'text',
[ 'old_text', 'old_flags' ],
[ 'old_id' => $textId ],
- __METHOD__ );
+ __METHOD__,
+ $options
+ );
}
- // Fallback to the master in case of replica DB lag. Also use FOR UPDATE if it was
- // used to fetch this revision to avoid missing the row due to REPEATABLE-READ.
- $forUpdate = ( $this->mQueryFlags & self::READ_LOCKING == self::READ_LOCKING );
- if ( !$row && ( $forUpdate || wfGetLB()->getServerCount() > 1 ) ) {
- $dbw = wfGetDB( DB_MASTER );
- $row = $dbw->selectRow( 'text',
+ // Fallback to DB_MASTER in some cases if the row was not found
+ if ( !$row && $fallbackIndex !== null ) {
+ // Use FOR UPDATE if it was used to fetch this revision. This avoids missing the row
+ // due to REPEATABLE-READ. Also fallback to the master if READ_LATEST is provided.
+ $row = wfGetDB( $fallbackIndex )->selectRow(
+ 'text',
[ 'old_text', 'old_flags' ],
[ 'old_id' => $textId ],
__METHOD__,
- $forUpdate ? [ 'FOR UPDATE' ] : [] );
+ $fallbackOptions
+ );
}
if ( !$row ) {
wfDebugLog( 'Revision', "No blob for text row '$textId' (revision {$this->getId()})." );
}
- # No negative caching -- negative hits on text rows may be due to corrupted replica DB servers
- if ( $wgRevisionCacheExpiry && $text !== false ) {
- $processCache->set( $key, $text );
- $cache->set( $key, $text, $wgRevisionCacheExpiry );
- }
-
- return $text;
+ return is_string( $text ) ? $text : false;
}
/**
* @since 1.28
*/
public static function newKnownCurrent( IDatabase $db, $pageId, $revId ) {
- $cache = ObjectCache::getMainWANInstance();
+ $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
return $cache->getWithSetCallback(
// Page/rev IDs passed in from DB to reflect history merges
$cache->makeGlobalKey( 'revision', $db->getWikiID(), $pageId, $revId ),