3 * Service for looking up page revisions.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * Attribution notice: when this file was created, much of its content was taken
21 * from the Revision.php file as present in release 1.30. Refer to the history
22 * of that file for original authorship.
27 namespace MediaWiki\Storage
;
31 use CommentStoreComment
;
34 use DBAccessObjectUtils
;
37 use InvalidArgumentException
;
40 use MediaWiki\Linker\LinkTarget
;
41 use MediaWiki\User\UserIdentity
;
42 use MediaWiki\User\UserIdentityValue
;
45 use MWUnknownContentModelException
;
46 use Psr\Log\LoggerAwareInterface
;
47 use Psr\Log\LoggerInterface
;
48 use Psr\Log\NullLogger
;
55 use Wikimedia\Assert\Assert
;
56 use Wikimedia\Rdbms\Database
;
57 use Wikimedia\Rdbms\DBConnRef
;
58 use Wikimedia\Rdbms\IDatabase
;
59 use Wikimedia\Rdbms\LoadBalancer
;
62 * Service for looking up page revisions.
66 * @note This was written to act as a drop-in replacement for the corresponding
67 * static methods in Revision.
70 implements IDBAccessObject
, RevisionFactory
, RevisionLookup
, LoggerAwareInterface
{
72 const ROW_CACHE_KEY
= 'revision-row-1.29';
87 private $contentHandlerUseDB = true;
92 private $loadBalancer;
102 private $commentStore;
105 * @var ActorMigration
107 private $actorMigration;
110 * @var LoggerInterface
115 * @var NameTableStore
117 private $contentModelStore;
120 * @var NameTableStore
122 private $slotRoleStore;
124 /** @var int One of the MIGRATION_* constants */
125 private $mcrMigrationStage;
128 * @todo $blobStore should be allowed to be any BlobStore!
130 * @param LoadBalancer $loadBalancer
131 * @param SqlBlobStore $blobStore
132 * @param WANObjectCache $cache
133 * @param CommentStore $commentStore
134 * @param NameTableStore $contentModelStore
135 * @param NameTableStore $slotRoleStore
136 * @param int $migrationStage
137 * @param ActorMigration $actorMigration
138 * @param bool|string $wikiId
140 public function __construct(
141 LoadBalancer
$loadBalancer,
142 SqlBlobStore
$blobStore,
143 WANObjectCache
$cache,
144 CommentStore
$commentStore,
145 NameTableStore
$contentModelStore,
146 NameTableStore
$slotRoleStore,
148 ActorMigration
$actorMigration,
151 Assert
::parameterType( 'string|boolean', $wikiId, '$wikiId' );
152 Assert
::parameterType( 'integer', $migrationStage, '$migrationStage' );
154 $this->loadBalancer
= $loadBalancer;
155 $this->blobStore
= $blobStore;
156 $this->cache
= $cache;
157 $this->commentStore
= $commentStore;
158 $this->contentModelStore
= $contentModelStore;
159 $this->slotRoleStore
= $slotRoleStore;
160 $this->mcrMigrationStage
= $migrationStage;
161 $this->actorMigration
= $actorMigration;
162 $this->wikiId
= $wikiId;
163 $this->logger
= new NullLogger();
166 public function setLogger( LoggerInterface
$logger ) {
167 $this->logger
= $logger;
171 * @return bool Whether the store is read-only
173 public function isReadOnly() {
174 return $this->blobStore
->isReadOnly();
180 public function getContentHandlerUseDB() {
181 return $this->contentHandlerUseDB
;
185 * @param bool $contentHandlerUseDB
186 * @throws MWException
188 public function setContentHandlerUseDB( $contentHandlerUseDB ) {
189 if ( !$contentHandlerUseDB && $this->mcrMigrationStage
> MIGRATION_OLD
) {
190 throw new MWException(
191 'Content model must be stored in the database for multi content revision migration.'
194 $this->contentHandlerUseDB
= $contentHandlerUseDB;
198 * @return LoadBalancer
200 private function getDBLoadBalancer() {
201 return $this->loadBalancer
;
205 * @param int $mode DB_MASTER or DB_REPLICA
209 private function getDBConnection( $mode ) {
210 $lb = $this->getDBLoadBalancer();
211 return $lb->getConnection( $mode, [], $this->wikiId
);
215 * @param IDatabase $connection
217 private function releaseDBConnection( IDatabase
$connection ) {
218 $lb = $this->getDBLoadBalancer();
219 $lb->reuseConnection( $connection );
223 * @param int $mode DB_MASTER or DB_REPLICA
227 private function getDBConnectionRef( $mode ) {
228 $lb = $this->getDBLoadBalancer();
229 return $lb->getConnectionRef( $mode, [], $this->wikiId
);
233 * Determines the page Title based on the available information.
235 * MCR migration note: this corresponds to Revision::getTitle
237 * @note this method should be private, external use should be avoided!
239 * @param int|null $pageId
240 * @param int|null $revId
241 * @param int $queryFlags
244 * @throws RevisionAccessException
246 public function getTitle( $pageId, $revId, $queryFlags = self
::READ_NORMAL
) {
247 if ( !$pageId && !$revId ) {
248 throw new InvalidArgumentException( '$pageId and $revId cannot both be 0 or null' );
251 // This method recalls itself with READ_LATEST if READ_NORMAL doesn't get us a Title
252 // So ignore READ_LATEST_IMMUTABLE flags and handle the fallback logic in this method
253 if ( DBAccessObjectUtils
::hasFlags( $queryFlags, self
::READ_LATEST_IMMUTABLE
) ) {
254 $queryFlags = self
::READ_NORMAL
;
257 $canUseTitleNewFromId = ( $pageId !== null && $pageId > 0 && $this->wikiId
=== false );
258 list( $dbMode, $dbOptions ) = DBAccessObjectUtils
::getDBOptions( $queryFlags );
259 $titleFlags = ( $dbMode == DB_MASTER ? Title
::GAID_FOR_UPDATE
: 0 );
261 // Loading by ID is best, but Title::newFromID does not support that for foreign IDs.
262 if ( $canUseTitleNewFromId ) {
263 // TODO: better foreign title handling (introduce TitleFactory)
264 $title = Title
::newFromID( $pageId, $titleFlags );
270 // rev_id is defined as NOT NULL, but this revision may not yet have been inserted.
271 $canUseRevId = ( $revId !== null && $revId > 0 );
273 if ( $canUseRevId ) {
274 $dbr = $this->getDBConnectionRef( $dbMode );
275 // @todo: Title::getSelectFields(), or Title::getQueryInfo(), or something like that
276 $row = $dbr->selectRow(
277 [ 'revision', 'page' ],
286 [ 'rev_id' => $revId ],
289 [ 'page' => [ 'JOIN', 'page_id=rev_page' ] ]
292 // TODO: better foreign title handling (introduce TitleFactory)
293 return Title
::newFromRow( $row );
297 // If we still don't have a title, fallback to master if that wasn't already happening.
298 if ( $dbMode !== DB_MASTER
) {
299 $title = $this->getTitle( $pageId, $revId, self
::READ_LATEST
);
302 __METHOD__
. ' fell back to READ_LATEST and got a Title.',
303 [ 'trace' => wfBacktrace() ]
309 throw new RevisionAccessException(
310 "Could not determine title for page ID $pageId and revision ID $revId"
315 * @param mixed $value
316 * @param string $name
318 * @throws IncompleteRevisionException if $value is null
319 * @return mixed $value, if $value is not null
321 private function failOnNull( $value, $name ) {
322 if ( $value === null ) {
323 throw new IncompleteRevisionException(
324 "$name must not be " . var_export( $value, true ) . "!"
332 * @param mixed $value
333 * @param string $name
335 * @throws IncompleteRevisionException if $value is empty
336 * @return mixed $value, if $value is not null
338 private function failOnEmpty( $value, $name ) {
339 if ( $value === null ||
$value === 0 ||
$value === '' ) {
340 throw new IncompleteRevisionException(
341 "$name must not be " . var_export( $value, true ) . "!"
349 * Insert a new revision into the database, returning the new revision record
350 * on success and dies horribly on failure.
352 * MCR migration note: this replaces Revision::insertOn
354 * @param RevisionRecord $rev
355 * @param IDatabase $dbw (master connection)
357 * @throws InvalidArgumentException
358 * @return RevisionRecord the new revision record.
360 public function insertRevisionOn( RevisionRecord
$rev, IDatabase
$dbw ) {
361 // TODO: pass in a DBTransactionContext instead of a database connection.
362 $this->checkDatabaseWikiId( $dbw );
364 $slotRoles = $rev->getSlotRoles();
366 // Make sure the main slot is always provided throughout migration
367 if ( !in_array( 'main', $slotRoles ) ) {
368 throw new InvalidArgumentException(
369 'main slot must be provided'
373 // While inserting into the old schema make sure only the main slot is allowed.
374 // TODO: support extra slots in MIGRATION_WRITE_BOTH mode!
375 if ( $this->mcrMigrationStage
<= MIGRATION_WRITE_BOTH
&& $slotRoles !== [ 'main' ] ) {
376 throw new InvalidArgumentException(
377 'Only the main slot is supported with MCR migration mode <= MIGRATION_WRITE_BOTH!'
382 $this->failOnNull( $rev->getSize(), 'size field' );
383 $this->failOnEmpty( $rev->getSha1(), 'sha1 field' );
384 $this->failOnEmpty( $rev->getTimestamp(), 'timestamp field' );
385 $comment = $this->failOnNull( $rev->getComment( RevisionRecord
::RAW
), 'comment' );
386 $user = $this->failOnNull( $rev->getUser( RevisionRecord
::RAW
), 'user' );
387 $this->failOnNull( $user->getId(), 'user field' );
388 $this->failOnEmpty( $user->getName(), 'user_text field' );
390 // TODO: we shouldn't need an actual Title here.
391 $title = Title
::newFromLinkTarget( $rev->getPageAsLinkTarget() );
392 $pageId = $this->failOnEmpty( $rev->getPageId(), 'rev_page field' ); // check this early
394 $parentId = $rev->getParentId() === null
395 ?
$this->getPreviousRevisionId( $dbw, $rev )
396 : $rev->getParentId();
398 /** @var RevisionRecord $rev */
399 $rev = $dbw->doAtomicSection(
401 function ( IDatabase
$dbw, $fname ) use (
409 return $this->insertRevisionInternal(
422 Assert
::postcondition( $rev->getId() > 0, 'revision must have an ID' );
423 Assert
::postcondition( $rev->getPageId() > 0, 'revision must have a page ID' );
424 Assert
::postcondition(
425 $rev->getComment( RevisionRecord
::RAW
) !== null,
426 'revision must have a comment'
428 Assert
::postcondition(
429 $rev->getUser( RevisionRecord
::RAW
) !== null,
430 'revision must have a user'
433 // Trigger exception if the main slot is missing.
434 // Technically, this could go away with MIGRATION_NEW: while
435 // calling code may require a main slot to exist, RevisionStore
436 // really should not know or care about that requirement.
437 $rev->getSlot( 'main', RevisionRecord
::RAW
);
439 foreach ( $slotRoles as $role ) {
440 $slot = $rev->getSlot( $role, RevisionRecord
::RAW
);
441 Assert
::postcondition(
442 $slot->getContent() !== null,
443 $role . ' slot must have content'
445 Assert
::postcondition(
446 $slot->hasRevision(),
447 $role . ' slot must have a revision associated'
451 Hooks
::run( 'RevisionRecordInserted', [ $rev ] );
453 // TODO: deprecate in 1.32!
454 $legacyRevision = new Revision( $rev );
455 Hooks
::run( 'RevisionInsertComplete', [ &$legacyRevision, null, null ] );
460 private function insertRevisionInternal(
464 CommentStoreComment
$comment,
469 $slotRoles = $rev->getSlotRoles();
471 $revisionRow = $this->insertRevisionRowOn(
478 $revisionId = $revisionRow['rev_id'];
481 BlobStore
::PAGE_HINT
=> $pageId,
482 BlobStore
::REVISION_HINT
=> $revisionId,
483 BlobStore
::PARENT_HINT
=> $parentId,
487 foreach ( $slotRoles as $role ) {
488 $slot = $rev->getSlot( $role, RevisionRecord
::RAW
);
490 if ( $slot->hasRevision() ) {
491 // If the SlotRecord already has a revision ID set, this means it already exists
492 // in the database, and should already belong to the current revision.
493 // TODO: properly abort transaction if the assertion fails!
495 $slot->getRevision() === $revisionId,
496 'slot role ' . $slot->getRole(),
497 'Existing slot should belong to revision '
498 . $revisionId . ', but belongs to revision ' . $slot->getRevision() . '!'
501 // Slot exists, nothing to do, move along.
502 // This happens when restoring archived revisions.
504 $newSlots[$role] = $slot;
506 // Write the main slot's text ID to the revision table for backwards compatibility
507 if ( $slot->getRole() === 'main' && $this->mcrMigrationStage
<= MIGRATION_WRITE_BOTH
) {
508 $blobAddress = $slot->getAddress();
509 $this->updateRevisionTextId( $dbw, $revisionId, $blobAddress );
512 $newSlots[$role] = $this->insertSlotOn( $dbw, $revisionId, $slot, $title, $blobHints );
516 $this->insertIpChangesRow( $dbw, $user, $rev, $revisionId );
518 $rev = new RevisionStoreRecord(
522 (object)$revisionRow,
523 new RevisionSlots( $newSlots ),
531 * @param IDatabase $dbw
532 * @param int $revisionId
533 * @param string &$blobAddress (may change!)
535 private function updateRevisionTextId( IDatabase
$dbw, $revisionId, &$blobAddress ) {
536 $textId = $this->blobStore
->getTextIdFromAddress( $blobAddress );
538 throw new LogicException(
539 'Blob address not supported in 1.29 database schema: ' . $blobAddress
543 // getTextIdFromAddress() is free to insert something into the text table, so $textId
544 // may be a new value, not anything already contained in $blobAddress.
545 $blobAddress = SqlBlobStore
::makeAddressFromTextId( $textId );
549 [ 'rev_text_id' => $textId ],
550 [ 'rev_id' => $revisionId ],
556 * @param IDatabase $dbw
557 * @param int $revisionId
558 * @param SlotRecord $protoSlot
559 * @param Title $title
560 * @param array $blobHints See the BlobStore::XXX_HINT constants
563 private function insertSlotOn(
566 SlotRecord
$protoSlot,
568 array $blobHints = []
570 if ( $protoSlot->hasAddress() ) {
571 $blobAddress = $protoSlot->getAddress();
573 $blobAddress = $this->storeContentBlob( $protoSlot, $title, $blobHints );
576 // Write the main slot's text ID to the revision table for backwards compatibility
577 if ( $protoSlot->getRole() === 'main' && $this->mcrMigrationStage
<= MIGRATION_WRITE_BOTH
) {
578 $this->updateRevisionTextId( $dbw, $revisionId, $blobAddress );
581 if ( $this->mcrMigrationStage
>= MIGRATION_WRITE_BOTH
) {
582 if ( $protoSlot->hasContentId() ) {
583 $contentId = $protoSlot->getContentId();
585 $contentId = $this->insertContentRowOn( $protoSlot, $dbw, $blobAddress );
588 $this->insertSlotRowOn( $protoSlot, $dbw, $revisionId, $contentId );
593 $savedSlot = SlotRecord
::newSaved(
604 * Insert IP revision into ip_changes for use when querying for a range.
605 * @param IDatabase $dbw
607 * @param RevisionRecord $rev
608 * @param int $revisionId
610 private function insertIpChangesRow(
616 if ( $user->getId() === 0 && IP
::isValid( $user->getName() ) ) {
618 'ipc_rev_id' => $revisionId,
619 'ipc_rev_timestamp' => $dbw->timestamp( $rev->getTimestamp() ),
620 'ipc_hex' => IP
::toHex( $user->getName() ),
622 $dbw->insert( 'ip_changes', $ipcRow, __METHOD__
);
627 * @param IDatabase $dbw
628 * @param RevisionRecord $rev
629 * @param Title $title
630 * @param int $parentId
632 * @return array a revision table row
634 * @throws MWException
635 * @throws MWUnknownContentModelException
637 private function insertRevisionRowOn(
643 $revisionRow = $this->getBaseRevisionRow( $dbw, $rev, $title, $parentId );
645 list( $commentFields, $commentCallback ) =
646 $this->commentStore
->insertWithTempTable(
649 $rev->getComment( RevisionRecord
::RAW
)
651 $revisionRow +
= $commentFields;
653 list( $actorFields, $actorCallback ) =
654 $this->actorMigration
->getInsertValuesWithTempTable(
657 $rev->getUser( RevisionRecord
::RAW
)
659 $revisionRow +
= $actorFields;
661 $dbw->insert( 'revision', $revisionRow, __METHOD__
);
663 if ( !isset( $revisionRow['rev_id'] ) ) {
664 // only if auto-increment was used
665 $revisionRow['rev_id'] = intval( $dbw->insertId() );
668 $commentCallback( $revisionRow['rev_id'] );
669 $actorCallback( $revisionRow['rev_id'], $revisionRow );
675 * @param IDatabase $dbw
676 * @param RevisionRecord $rev
677 * @param Title $title
678 * @param int $parentId
680 * @return array [ 0 => array $revisionRow, 1 => callable ]
681 * @throws MWException
682 * @throws MWUnknownContentModelException
684 private function getBaseRevisionRow(
690 // Record the edit in revisions
692 'rev_page' => $rev->getPageId(),
693 'rev_parent_id' => $parentId,
694 'rev_minor_edit' => $rev->isMinor() ?
1 : 0,
695 'rev_timestamp' => $dbw->timestamp( $rev->getTimestamp() ),
696 'rev_deleted' => $rev->getVisibility(),
697 'rev_len' => $rev->getSize(),
698 'rev_sha1' => $rev->getSha1(),
701 if ( $rev->getId() !== null ) {
702 // Needed to restore revisions with their original ID
703 $revisionRow['rev_id'] = $rev->getId();
706 if ( $this->mcrMigrationStage
<= MIGRATION_WRITE_BOTH
) {
707 // In non MCR more this IF section will relate to the main slot
708 $mainSlot = $rev->getSlot( 'main' );
709 $model = $mainSlot->getModel();
710 $format = $mainSlot->getFormat();
712 // MCR migration note: rev_content_model and rev_content_format will go away
713 if ( $this->contentHandlerUseDB
) {
714 $defaultModel = ContentHandler
::getDefaultModelFor( $title );
715 $defaultFormat = ContentHandler
::getForModelID( $defaultModel )->getDefaultFormat();
717 $revisionRow['rev_content_model'] = ( $model === $defaultModel ) ?
null : $model;
718 $revisionRow['rev_content_format'] = ( $format === $defaultFormat ) ?
null : $format;
726 * @param SlotRecord $slot
727 * @param Title $title
728 * @param array $blobHints See the BlobStore::XXX_HINT constants
730 * @throws MWException
731 * @return string the blob address
733 private function storeContentBlob(
736 array $blobHints = []
738 $content = $slot->getContent();
739 $format = $content->getDefaultFormat();
740 $model = $content->getModel();
742 $this->checkContent( $content, $title );
744 return $this->blobStore
->storeBlob(
745 $content->serialize( $format ),
746 // These hints "leak" some information from the higher abstraction layer to
747 // low level storage to allow for optimization.
751 BlobStore
::DESIGNATION_HINT
=> 'page-content',
752 BlobStore
::ROLE_HINT
=> $slot->getRole(),
753 BlobStore
::SHA1_HINT
=> $slot->getSha1(),
754 BlobStore
::MODEL_HINT
=> $model,
755 BlobStore
::FORMAT_HINT
=> $format,
762 * @param SlotRecord $slot
763 * @param IDatabase $dbw
764 * @param int $revisionId
765 * @param int $contentId
767 private function insertSlotRowOn( SlotRecord
$slot, IDatabase
$dbw, $revisionId, $contentId ) {
769 'slot_revision_id' => $revisionId,
770 'slot_role_id' => $this->slotRoleStore
->acquireId( $slot->getRole() ),
771 'slot_content_id' => $contentId,
772 // If the slot has a specific origin use that ID, otherwise use the ID of the revision
773 // that we just inserted.
774 'slot_origin' => $slot->hasOrigin() ?
$slot->getOrigin() : $revisionId,
776 $dbw->insert( 'slots', $slotRow, __METHOD__
);
780 * @param SlotRecord $slot
781 * @param IDatabase $dbw
782 * @param string $blobAddress
783 * @return int content row ID
785 private function insertContentRowOn( SlotRecord
$slot, IDatabase
$dbw, $blobAddress ) {
787 'content_size' => $slot->getSize(),
788 'content_sha1' => $slot->getSha1(),
789 'content_model' => $this->contentModelStore
->acquireId( $slot->getModel() ),
790 'content_address' => $blobAddress,
792 $dbw->insert( 'content', $contentRow, __METHOD__
);
793 return intval( $dbw->insertId() );
797 * MCR migration note: this corresponds to Revision::checkContentModel
799 * @param Content $content
800 * @param Title $title
802 * @throws MWException
803 * @throws MWUnknownContentModelException
805 private function checkContent( Content
$content, Title
$title ) {
806 // Note: may return null for revisions that have not yet been inserted
808 $model = $content->getModel();
809 $format = $content->getDefaultFormat();
810 $handler = $content->getContentHandler();
814 if ( !$handler->isSupportedFormat( $format ) ) {
815 throw new MWException( "Can't use format $format with content model $model on $name" );
818 if ( !$this->contentHandlerUseDB
) {
819 // if $wgContentHandlerUseDB is not set,
820 // all revisions must use the default content model and format.
822 $defaultModel = ContentHandler
::getDefaultModelFor( $title );
823 $defaultHandler = ContentHandler
::getForModelID( $defaultModel );
824 $defaultFormat = $defaultHandler->getDefaultFormat();
826 if ( $model != $defaultModel ) {
827 throw new MWException( "Can't save non-default content model with "
828 . "\$wgContentHandlerUseDB disabled: model is $model, "
829 . "default for $name is $defaultModel"
833 if ( $format != $defaultFormat ) {
834 throw new MWException( "Can't use non-default content format with "
835 . "\$wgContentHandlerUseDB disabled: format is $format, "
836 . "default for $name is $defaultFormat"
841 if ( !$content->isValid() ) {
842 throw new MWException(
843 "New content for $name is not valid! Content model is $model"
849 * Create a new null-revision for insertion into a page's
850 * history. This will not re-save the text, but simply refer
851 * to the text from the previous version.
853 * Such revisions can for instance identify page rename
854 * operations and other such meta-modifications.
856 * @note: This method grabs a FOR UPDATE lock on the relevant row of the page table,
857 * to prevent a new revision from being inserted before the null revision has been written
860 * MCR migration note: this replaces Revision::newNullRevision
862 * @todo Introduce newFromParentRevision(). newNullRevision can then be based on that
865 * @param IDatabase $dbw used for obtaining the lock on the page table row
866 * @param Title $title Title of the page to read from
867 * @param CommentStoreComment $comment RevisionRecord's summary
868 * @param bool $minor Whether the revision should be considered as minor
869 * @param User $user The user to attribute the revision to
871 * @return RevisionRecord|null RevisionRecord or null on error
873 public function newNullRevision(
876 CommentStoreComment
$comment,
880 $this->checkDatabaseWikiId( $dbw );
882 // T51581: Lock the page table row to ensure no other process
883 // is adding a revision to the page at the same time.
884 // Avoid locking extra tables, compare T191892.
885 $pageLatest = $dbw->selectField(
888 [ 'page_id' => $title->getArticleID() ],
893 if ( !$pageLatest ) {
897 // Fetch the actual revision row, without locking all extra tables.
898 $oldRevision = $this->loadRevisionFromId( $dbw, $pageLatest );
900 // Construct the new revision
901 $timestamp = wfTimestampNow(); // TODO: use a callback, so we can override it for testing.
902 $newRevision = MutableRevisionRecord
::newFromParentRevision( $oldRevision );
904 $newRevision->setComment( $comment );
905 $newRevision->setUser( $user );
906 $newRevision->setTimestamp( $timestamp );
907 $newRevision->setMinorEdit( $minor );
913 * MCR migration note: this replaces Revision::isUnpatrolled
915 * @todo This is overly specific, so move or kill this method.
917 * @param RevisionRecord $rev
919 * @return int Rcid of the unpatrolled row, zero if there isn't one
921 public function getRcIdIfUnpatrolled( RevisionRecord
$rev ) {
922 $rc = $this->getRecentChange( $rev );
923 if ( $rc && $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_UNPATROLLED
) {
924 return $rc->getAttribute( 'rc_id' );
931 * Get the RC object belonging to the current revision, if there's one
933 * MCR migration note: this replaces Revision::getRecentChange
935 * @todo move this somewhere else?
937 * @param RevisionRecord $rev
938 * @param int $flags (optional) $flags include:
939 * IDBAccessObject::READ_LATEST: Select the data from the master
941 * @return null|RecentChange
943 public function getRecentChange( RevisionRecord
$rev, $flags = 0 ) {
944 $dbr = $this->getDBConnection( DB_REPLICA
);
946 list( $dbType, ) = DBAccessObjectUtils
::getDBOptions( $flags );
948 $userIdentity = $rev->getUser( RevisionRecord
::RAW
);
950 if ( !$userIdentity ) {
951 // If the revision has no user identity, chances are it never went
952 // into the database, and doesn't have an RC entry.
956 // TODO: Select by rc_this_oldid alone - but as of Nov 2017, there is no index on that!
957 $actorWhere = $this->actorMigration
->getWhere( $dbr, 'rc_user', $rev->getUser(), false );
958 $rc = RecentChange
::newFromConds(
960 $actorWhere['conds'],
961 'rc_timestamp' => $dbr->timestamp( $rev->getTimestamp() ),
962 'rc_this_oldid' => $rev->getId()
968 $this->releaseDBConnection( $dbr );
970 // XXX: cache this locally? Glue it to the RevisionRecord?
975 * Maps fields of the archive row to corresponding revision rows.
977 * @param object $archiveRow
979 * @return object a revision row object, corresponding to $archiveRow.
981 private static function mapArchiveFields( $archiveRow ) {
983 // keep with ar prefix:
986 // not the same suffix:
987 'ar_page_id' => 'rev_page',
988 'ar_rev_id' => 'rev_id',
991 'ar_text_id' => 'rev_text_id',
992 'ar_timestamp' => 'rev_timestamp',
993 'ar_user_text' => 'rev_user_text',
994 'ar_user' => 'rev_user',
995 'ar_actor' => 'rev_actor',
996 'ar_minor_edit' => 'rev_minor_edit',
997 'ar_deleted' => 'rev_deleted',
998 'ar_len' => 'rev_len',
999 'ar_parent_id' => 'rev_parent_id',
1000 'ar_sha1' => 'rev_sha1',
1001 'ar_comment' => 'rev_comment',
1002 'ar_comment_cid' => 'rev_comment_cid',
1003 'ar_comment_id' => 'rev_comment_id',
1004 'ar_comment_text' => 'rev_comment_text',
1005 'ar_comment_data' => 'rev_comment_data',
1006 'ar_comment_old' => 'rev_comment_old',
1007 'ar_content_format' => 'rev_content_format',
1008 'ar_content_model' => 'rev_content_model',
1011 $revRow = new stdClass();
1012 foreach ( $fieldMap as $arKey => $revKey ) {
1013 if ( property_exists( $archiveRow, $arKey ) ) {
1014 $revRow->$revKey = $archiveRow->$arKey;
1022 * Constructs a RevisionRecord for the revisions main slot, based on the MW1.29 schema.
1024 * @param object|array $row Either a database row or an array
1025 * @param int $queryFlags for callbacks
1026 * @param Title $title
1028 * @return SlotRecord The main slot, extracted from the MW 1.29 style row.
1029 * @throws MWException
1031 private function emulateMainSlot_1_29( $row, $queryFlags, Title
$title ) {
1032 $mainSlotRow = new stdClass();
1033 $mainSlotRow->role_name
= 'main';
1034 $mainSlotRow->model_name
= null;
1035 $mainSlotRow->slot_revision_id
= null;
1036 $mainSlotRow->content_address
= null;
1042 if ( is_object( $row ) ) {
1043 if ( $this->mcrMigrationStage
>= MIGRATION_NEW
) {
1044 // Don't emulate from a row when using the new schema.
1045 // Emulating from an array is still OK.
1046 throw new LogicException( 'Can\'t emulate the main slot when using MCR schema.' );
1050 if ( !isset( $row->rev_id
) && ( isset( $row->ar_user
) ||
isset( $row->ar_actor
) ) ) {
1051 $row = $this->mapArchiveFields( $row );
1054 if ( isset( $row->rev_text_id
) && $row->rev_text_id
> 0 ) {
1055 $mainSlotRow->content_address
= SqlBlobStore
::makeAddressFromTextId(
1060 // This is used by null-revisions
1061 $mainSlotRow->slot_origin
= isset( $row->slot_origin
)
1062 ?
intval( $row->slot_origin
)
1065 if ( isset( $row->old_text
) ) {
1066 // this happens when the text-table gets joined directly, in the pre-1.30 schema
1067 $blobData = isset( $row->old_text
) ?
strval( $row->old_text
) : null;
1068 // Check against selects that might have not included old_flags
1069 if ( !property_exists( $row, 'old_flags' ) ) {
1070 throw new InvalidArgumentException( 'old_flags was not set in $row' );
1072 $blobFlags = ( $row->old_flags
=== null ) ?
'' : $row->old_flags
;
1075 $mainSlotRow->slot_revision_id
= intval( $row->rev_id
);
1077 $mainSlotRow->content_size
= isset( $row->rev_len
) ?
intval( $row->rev_len
) : null;
1078 $mainSlotRow->content_sha1
= isset( $row->rev_sha1
) ?
strval( $row->rev_sha1
) : null;
1079 $mainSlotRow->model_name
= isset( $row->rev_content_model
)
1080 ?
strval( $row->rev_content_model
)
1082 // XXX: in the future, we'll probably always use the default format, and drop content_format
1083 $mainSlotRow->format_name
= isset( $row->rev_content_format
)
1084 ?
strval( $row->rev_content_format
)
1086 } elseif ( is_array( $row ) ) {
1087 $mainSlotRow->slot_revision_id
= isset( $row['id'] ) ?
intval( $row['id'] ) : null;
1089 $mainSlotRow->slot_origin
= isset( $row['slot_origin'] )
1090 ?
intval( $row['slot_origin'] )
1092 $mainSlotRow->content_address
= isset( $row['text_id'] )
1093 ? SqlBlobStore
::makeAddressFromTextId( intval( $row['text_id'] ) )
1095 $mainSlotRow->content_size
= isset( $row['len'] ) ?
intval( $row['len'] ) : null;
1096 $mainSlotRow->content_sha1
= isset( $row['sha1'] ) ?
strval( $row['sha1'] ) : null;
1098 $mainSlotRow->model_name
= isset( $row['content_model'] )
1099 ?
strval( $row['content_model'] ) : null; // XXX: must be a string!
1100 // XXX: in the future, we'll probably always use the default format, and drop content_format
1101 $mainSlotRow->format_name
= isset( $row['content_format'] )
1102 ?
strval( $row['content_format'] ) : null;
1103 $blobData = isset( $row['text'] ) ?
rtrim( strval( $row['text'] ) ) : null;
1104 // XXX: If the flags field is not set then $blobFlags should be null so that no
1105 // decoding will happen. An empty string will result in default decodings.
1106 $blobFlags = isset( $row['flags'] ) ?
trim( strval( $row['flags'] ) ) : null;
1108 // if we have a Content object, override mText and mContentModel
1109 if ( !empty( $row['content'] ) ) {
1110 if ( !( $row['content'] instanceof Content
) ) {
1111 throw new MWException( 'content field must contain a Content object.' );
1114 /** @var Content $content */
1115 $content = $row['content'];
1116 $handler = $content->getContentHandler();
1118 $mainSlotRow->model_name
= $content->getModel();
1120 // XXX: in the future, we'll probably always use the default format.
1121 if ( $mainSlotRow->format_name
=== null ) {
1122 $mainSlotRow->format_name
= $handler->getDefaultFormat();
1126 throw new MWException( 'Revision constructor passed invalid row format.' );
1129 // With the old schema, the content changes with every revision,
1130 // except for null-revisions.
1131 if ( !isset( $mainSlotRow->slot_origin
) ) {
1132 $mainSlotRow->slot_origin
= $mainSlotRow->slot_revision_id
;
1135 if ( $mainSlotRow->model_name
=== null ) {
1136 $mainSlotRow->model_name
= function ( SlotRecord
$slot ) use ( $title ) {
1137 // TODO: MCR: consider slot role in getDefaultModelFor()! Use LinkTarget!
1138 // TODO: MCR: deprecate $title->getModel().
1139 return ContentHandler
::getDefaultModelFor( $title );
1144 // XXX: We should perhaps fail if $blobData is null and $mainSlotRow->content_address
1145 // is missing, but "empty revisions" with no content are used in some edge cases.
1147 $content = function ( SlotRecord
$slot )
1148 use ( $blobData, $blobFlags, $queryFlags, $mainSlotRow )
1150 return $this->loadSlotContent(
1154 $mainSlotRow->format_name
,
1160 // NOTE: this callback will be looped through RevisionSlot::newInherited(), allowing
1161 // the inherited slot to have the same content_id as the original slot. In that case,
1162 // $slot will be the inherited slot, while $mainSlotRow still refers to the original slot.
1163 $mainSlotRow->slot_content_id
=
1164 function ( SlotRecord
$slot ) use ( $queryFlags, $mainSlotRow ) {
1165 list( $dbMode, ) = DBAccessObjectUtils
::getDBOptions( $queryFlags );
1166 $db = $this->getDBConnectionRef( $dbMode );
1167 return $this->findSlotContentId( $db, $mainSlotRow->slot_revision_id
, 'main' );
1170 return new SlotRecord( $mainSlotRow, $content );
1174 * Loads a Content object based on a slot row.
1176 * This method does not call $slot->getContent(), and may be used as a callback
1177 * called by $slot->getContent().
1179 * MCR migration note: this roughly corresponds to Revision::getContentInternal
1181 * @param SlotRecord $slot The SlotRecord to load content for
1182 * @param string|null $blobData The content blob, in the form indicated by $blobFlags
1183 * @param string|null $blobFlags Flags indicating how $blobData needs to be processed.
1184 * Use null if no processing should happen. That is in constrast to the empty string,
1185 * which causes the blob to be decoded according to the configured legacy encoding.
1186 * @param string|null $blobFormat MIME type indicating how $dataBlob is encoded
1187 * @param int $queryFlags
1189 * @throws RevisionAccessException
1192 private function loadSlotContent(
1199 if ( $blobData !== null ) {
1200 Assert
::parameterType( 'string', $blobData, '$blobData' );
1201 Assert
::parameterType( 'string|null', $blobFlags, '$blobFlags' );
1203 $cacheKey = $slot->hasAddress() ?
$slot->getAddress() : null;
1205 if ( $blobFlags === null ) {
1206 // No blob flags, so use the blob verbatim.
1209 $data = $this->blobStore
->expandBlob( $blobData, $blobFlags, $cacheKey );
1210 if ( $data === false ) {
1211 throw new RevisionAccessException(
1212 "Failed to expand blob data using flags $blobFlags (key: $cacheKey)"
1218 $address = $slot->getAddress();
1220 $data = $this->blobStore
->getBlob( $address, $queryFlags );
1221 } catch ( BlobAccessException
$e ) {
1222 throw new RevisionAccessException(
1223 "Failed to load data blob from $address: " . $e->getMessage(), 0, $e
1228 // Unserialize content
1229 $handler = ContentHandler
::getForModelID( $slot->getModel() );
1231 $content = $handler->unserializeContent( $data, $blobFormat );
1236 * Load a page revision from a given revision ID number.
1237 * Returns null if no such revision can be found.
1239 * MCR migration note: this replaces Revision::newFromId
1242 * IDBAccessObject::READ_LATEST: Select the data from the master
1243 * IDBAccessObject::READ_LOCKING : Select & lock the data from the master
1246 * @param int $flags (optional)
1247 * @return RevisionRecord|null
1249 public function getRevisionById( $id, $flags = 0 ) {
1250 return $this->newRevisionFromConds( [ 'rev_id' => intval( $id ) ], $flags );
1254 * Load either the current, or a specified, revision
1255 * that's attached to a given link target. If not attached
1256 * to that link target, will return null.
1258 * MCR migration note: this replaces Revision::newFromTitle
1261 * IDBAccessObject::READ_LATEST: Select the data from the master
1262 * IDBAccessObject::READ_LOCKING : Select & lock the data from the master
1264 * @param LinkTarget $linkTarget
1265 * @param int $revId (optional)
1266 * @param int $flags Bitfield (optional)
1267 * @return RevisionRecord|null
1269 public function getRevisionByTitle( LinkTarget
$linkTarget, $revId = 0, $flags = 0 ) {
1271 'page_namespace' => $linkTarget->getNamespace(),
1272 'page_title' => $linkTarget->getDBkey()
1275 // Use the specified revision ID.
1276 // Note that we use newRevisionFromConds here because we want to retry
1277 // and fall back to master if the page is not found on a replica.
1278 // Since the caller supplied a revision ID, we are pretty sure the revision is
1279 // supposed to exist, so we should try hard to find it.
1280 $conds['rev_id'] = $revId;
1281 return $this->newRevisionFromConds( $conds, $flags );
1283 // Use a join to get the latest revision.
1284 // Note that we don't use newRevisionFromConds here because we don't want to retry
1285 // and fall back to master. The assumption is that we only want to force the fallback
1286 // if we are quite sure the revision exists because the caller supplied a revision ID.
1287 // If the page isn't found at all on a replica, it probably simply does not exist.
1288 $db = $this->getDBConnection( ( $flags & self
::READ_LATEST
) ? DB_MASTER
: DB_REPLICA
);
1290 $conds[] = 'rev_id=page_latest';
1291 $rev = $this->loadRevisionFromConds( $db, $conds, $flags );
1293 $this->releaseDBConnection( $db );
1299 * Load either the current, or a specified, revision
1300 * that's attached to a given page ID.
1301 * Returns null if no such revision can be found.
1303 * MCR migration note: this replaces Revision::newFromPageId
1306 * IDBAccessObject::READ_LATEST: Select the data from the master (since 1.20)
1307 * IDBAccessObject::READ_LOCKING : Select & lock the data from the master
1309 * @param int $pageId
1310 * @param int $revId (optional)
1311 * @param int $flags Bitfield (optional)
1312 * @return RevisionRecord|null
1314 public function getRevisionByPageId( $pageId, $revId = 0, $flags = 0 ) {
1315 $conds = [ 'page_id' => $pageId ];
1317 // Use the specified revision ID.
1318 // Note that we use newRevisionFromConds here because we want to retry
1319 // and fall back to master if the page is not found on a replica.
1320 // Since the caller supplied a revision ID, we are pretty sure the revision is
1321 // supposed to exist, so we should try hard to find it.
1322 $conds['rev_id'] = $revId;
1323 return $this->newRevisionFromConds( $conds, $flags );
1325 // Use a join to get the latest revision.
1326 // Note that we don't use newRevisionFromConds here because we don't want to retry
1327 // and fall back to master. The assumption is that we only want to force the fallback
1328 // if we are quite sure the revision exists because the caller supplied a revision ID.
1329 // If the page isn't found at all on a replica, it probably simply does not exist.
1330 $db = $this->getDBConnection( ( $flags & self
::READ_LATEST
) ? DB_MASTER
: DB_REPLICA
);
1332 $conds[] = 'rev_id=page_latest';
1333 $rev = $this->loadRevisionFromConds( $db, $conds, $flags );
1335 $this->releaseDBConnection( $db );
1341 * Load the revision for the given title with the given timestamp.
1342 * WARNING: Timestamps may in some circumstances not be unique,
1343 * so this isn't the best key to use.
1345 * MCR migration note: this replaces Revision::loadFromTimestamp
1347 * @param Title $title
1348 * @param string $timestamp
1349 * @return RevisionRecord|null
1351 public function getRevisionByTimestamp( $title, $timestamp ) {
1352 $db = $this->getDBConnection( DB_REPLICA
);
1353 return $this->newRevisionFromConds(
1355 'rev_timestamp' => $db->timestamp( $timestamp ),
1356 'page_namespace' => $title->getNamespace(),
1357 'page_title' => $title->getDBkey()
1365 * @param int $revId The revision to load slots for.
1366 * @param int $queryFlags
1368 * @return SlotRecord[]
1370 private function loadSlotRecords( $revId, $queryFlags ) {
1371 $revQuery = self
::getSlotsQueryInfo( [ 'content' ] );
1373 list( $dbMode, $dbOptions ) = DBAccessObjectUtils
::getDBOptions( $queryFlags );
1374 $db = $this->getDBConnectionRef( $dbMode );
1377 $revQuery['tables'],
1378 $revQuery['fields'],
1380 'slot_revision_id' => $revId,
1389 foreach ( $res as $row ) {
1390 $contentCallback = function ( SlotRecord
$slot ) use ( $queryFlags, $row ) {
1391 return $this->loadSlotContent( $slot, null, null, null, $queryFlags );
1394 $slots[$row->role_name
] = new SlotRecord( $row, $contentCallback );
1397 if ( !isset( $slots['main'] ) ) {
1398 throw new RevisionAccessException(
1399 'Main slot of revision ' . $revId . ' not found in database!'
1407 * Factory method for RevisionSlots.
1409 * @note If other code has a need to construct RevisionSlots objects, this should be made
1410 * public, since RevisionSlots instances should not be constructed directly.
1413 * @param object $revisionRow
1414 * @param int $queryFlags
1415 * @param Title $title
1417 * @return RevisionSlots
1418 * @throws MWException
1420 private function newRevisionSlots(
1426 if ( $this->mcrMigrationStage
< MIGRATION_NEW
) {
1427 // TODO: in MIGRATION_WRITE_BOTH, we could use the old and the new method:
1428 // e.g. call emulateMainSlot_1_29() if loadSlotRecords() fails.
1430 $mainSlot = $this->emulateMainSlot_1_29( $revisionRow, $queryFlags, $title );
1431 $slots = new RevisionSlots( [ 'main' => $mainSlot ] );
1433 // XXX: do we need the same kind of caching here
1434 // that getKnownCurrentRevision uses (if $revId == page_latest?)
1436 $slots = new RevisionSlots( function () use( $revId, $queryFlags ) {
1437 return $this->loadSlotRecords( $revId, $queryFlags );
1445 * Make a fake revision object from an archive table row. This is queried
1446 * for permissions or even inserted (as in Special:Undelete)
1448 * MCR migration note: this replaces Revision::newFromArchiveRow
1450 * @param object $row
1451 * @param int $queryFlags
1452 * @param Title|null $title
1453 * @param array $overrides associative array with fields of $row to override. This may be
1454 * used e.g. to force the parent revision ID or page ID. Keys in the array are fields
1455 * names from the archive table without the 'ar_' prefix, i.e. use 'parent_id' to
1456 * override ar_parent_id.
1458 * @return RevisionRecord
1459 * @throws MWException
1461 public function newRevisionFromArchiveRow(
1464 Title
$title = null,
1465 array $overrides = []
1467 Assert
::parameterType( 'object', $row, '$row' );
1469 // check second argument, since Revision::newFromArchiveRow had $overrides in that spot.
1470 Assert
::parameterType( 'integer', $queryFlags, '$queryFlags' );
1472 if ( !$title && isset( $overrides['title'] ) ) {
1473 if ( !( $overrides['title'] instanceof Title
) ) {
1474 throw new MWException( 'title field override must contain a Title object.' );
1477 $title = $overrides['title'];
1480 if ( !isset( $title ) ) {
1481 if ( isset( $row->ar_namespace
) && isset( $row->ar_title
) ) {
1482 $title = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
1484 throw new InvalidArgumentException(
1485 'A Title or ar_namespace and ar_title must be given'
1490 foreach ( $overrides as $key => $value ) {
1492 $row->$field = $value;
1496 $user = User
::newFromAnyId(
1497 $row->ar_user ??
null,
1498 $row->ar_user_text ??
null,
1499 $row->ar_actor ??
null
1501 } catch ( InvalidArgumentException
$ex ) {
1502 wfWarn( __METHOD__
. ': ' . $ex->getMessage() );
1503 $user = new UserIdentityValue( 0, '', 0 );
1506 $comment = $this->commentStore
1507 // Legacy because $row may have come from self::selectFields()
1508 ->getCommentLegacy( $this->getDBConnection( DB_REPLICA
), 'ar_comment', $row, true );
1510 $slots = $this->newRevisionSlots( $row->ar_rev_id
, $row, $queryFlags, $title );
1512 return new RevisionArchiveRecord( $title, $user, $comment, $row, $slots, $this->wikiId
);
1516 * @see RevisionFactory::newRevisionFromRow
1518 * MCR migration note: this replaces Revision::newFromRow
1520 * @param object $row
1521 * @param int $queryFlags
1522 * @param Title|null $title
1524 * @return RevisionRecord
1526 public function newRevisionFromRow( $row, $queryFlags = 0, Title
$title = null ) {
1527 Assert
::parameterType( 'object', $row, '$row' );
1530 $pageId = $row->rev_page ??
0; // XXX: also check page_id?
1531 $revId = $row->rev_id ??
0;
1533 $title = $this->getTitle( $pageId, $revId, $queryFlags );
1536 if ( !isset( $row->page_latest
) ) {
1537 $row->page_latest
= $title->getLatestRevID();
1538 if ( $row->page_latest
=== 0 && $title->exists() ) {
1539 wfWarn( 'Encountered title object in limbo: ID ' . $title->getArticleID() );
1544 $user = User
::newFromAnyId(
1545 $row->rev_user ??
null,
1546 $row->rev_user_text ??
null,
1547 $row->rev_actor ??
null
1549 } catch ( InvalidArgumentException
$ex ) {
1550 wfWarn( __METHOD__
. ': ' . $ex->getMessage() );
1551 $user = new UserIdentityValue( 0, '', 0 );
1554 $comment = $this->commentStore
1555 // Legacy because $row may have come from self::selectFields()
1556 ->getCommentLegacy( $this->getDBConnection( DB_REPLICA
), 'rev_comment', $row, true );
1558 $slots = $this->newRevisionSlots( $row->rev_id
, $row, $queryFlags, $title );
1560 return new RevisionStoreRecord( $title, $user, $comment, $row, $slots, $this->wikiId
);
1564 * Constructs a new MutableRevisionRecord based on the given associative array following
1565 * the MW1.29 convention for the Revision constructor.
1567 * MCR migration note: this replaces Revision::newFromRow
1569 * @param array $fields
1570 * @param int $queryFlags
1571 * @param Title|null $title
1573 * @return MutableRevisionRecord
1574 * @throws MWException
1575 * @throws RevisionAccessException
1577 public function newMutableRevisionFromArray(
1582 if ( !$title && isset( $fields['title'] ) ) {
1583 if ( !( $fields['title'] instanceof Title
) ) {
1584 throw new MWException( 'title field must contain a Title object.' );
1587 $title = $fields['title'];
1591 $pageId = $fields['page'] ??
0;
1592 $revId = $fields['id'] ??
0;
1594 $title = $this->getTitle( $pageId, $revId, $queryFlags );
1597 if ( !isset( $fields['page'] ) ) {
1598 $fields['page'] = $title->getArticleID( $queryFlags );
1601 // if we have a content object, use it to set the model and type
1602 if ( !empty( $fields['content'] ) ) {
1603 if ( !( $fields['content'] instanceof Content
) && !is_array( $fields['content'] ) ) {
1604 throw new MWException(
1605 'content field must contain a Content object or an array of Content objects.'
1610 if ( !empty( $fields['text_id'] ) ) {
1611 if ( $this->mcrMigrationStage
>= MIGRATION_NEW
) {
1612 throw new MWException( "Cannot use text_id field with MCR schema" );
1615 if ( !empty( $fields['content'] ) ) {
1616 throw new MWException(
1617 "Text already stored in external store (id {$fields['text_id']}), " .
1618 "can't specify content object"
1624 isset( $fields['comment'] )
1625 && !( $fields['comment'] instanceof CommentStoreComment
)
1627 $commentData = $fields['comment_data'] ??
null;
1629 if ( $fields['comment'] instanceof Message
) {
1630 $fields['comment'] = CommentStoreComment
::newUnsavedComment(
1635 $commentText = trim( strval( $fields['comment'] ) );
1636 $fields['comment'] = CommentStoreComment
::newUnsavedComment(
1643 $revision = new MutableRevisionRecord( $title, $this->wikiId
);
1644 $this->initializeMutableRevisionFromArray( $revision, $fields );
1646 if ( isset( $fields['content'] ) && is_array( $fields['content'] ) ) {
1647 foreach ( $fields['content'] as $role => $content ) {
1648 $revision->setContent( $role, $content );
1651 $mainSlot = $this->emulateMainSlot_1_29( $fields, $queryFlags, $title );
1652 $revision->setSlot( $mainSlot );
1659 * @param MutableRevisionRecord $record
1660 * @param array $fields
1662 private function initializeMutableRevisionFromArray(
1663 MutableRevisionRecord
$record,
1666 /** @var UserIdentity $user */
1669 if ( isset( $fields['user'] ) && ( $fields['user'] instanceof UserIdentity
) ) {
1670 $user = $fields['user'];
1673 $user = User
::newFromAnyId(
1674 $fields['user'] ??
null,
1675 $fields['user_text'] ??
null,
1676 $fields['actor'] ??
null
1678 } catch ( InvalidArgumentException
$ex ) {
1684 $record->setUser( $user );
1687 $timestamp = isset( $fields['timestamp'] )
1688 ?
strval( $fields['timestamp'] )
1689 : wfTimestampNow(); // TODO: use a callback, so we can override it for testing.
1691 $record->setTimestamp( $timestamp );
1693 if ( isset( $fields['page'] ) ) {
1694 $record->setPageId( intval( $fields['page'] ) );
1697 if ( isset( $fields['id'] ) ) {
1698 $record->setId( intval( $fields['id'] ) );
1700 if ( isset( $fields['parent_id'] ) ) {
1701 $record->setParentId( intval( $fields['parent_id'] ) );
1704 if ( isset( $fields['sha1'] ) ) {
1705 $record->setSha1( $fields['sha1'] );
1707 if ( isset( $fields['size'] ) ) {
1708 $record->setSize( intval( $fields['size'] ) );
1711 if ( isset( $fields['minor_edit'] ) ) {
1712 $record->setMinorEdit( intval( $fields['minor_edit'] ) !== 0 );
1714 if ( isset( $fields['deleted'] ) ) {
1715 $record->setVisibility( intval( $fields['deleted'] ) );
1718 if ( isset( $fields['comment'] ) ) {
1719 Assert
::parameterType(
1720 CommentStoreComment
::class,
1724 $record->setComment( $fields['comment'] );
1729 * Load a page revision from a given revision ID number.
1730 * Returns null if no such revision can be found.
1732 * MCR migration note: this corresponds to Revision::loadFromId
1734 * @note direct use is deprecated!
1735 * @todo remove when unused! there seem to be no callers of Revision::loadFromId
1737 * @param IDatabase $db
1740 * @return RevisionRecord|null
1742 public function loadRevisionFromId( IDatabase
$db, $id ) {
1743 return $this->loadRevisionFromConds( $db, [ 'rev_id' => intval( $id ) ] );
1747 * Load either the current, or a specified, revision
1748 * that's attached to a given page. If not attached
1749 * to that page, will return null.
1751 * MCR migration note: this replaces Revision::loadFromPageId
1753 * @note direct use is deprecated!
1754 * @todo remove when unused!
1756 * @param IDatabase $db
1757 * @param int $pageid
1759 * @return RevisionRecord|null
1761 public function loadRevisionFromPageId( IDatabase
$db, $pageid, $id = 0 ) {
1762 $conds = [ 'rev_page' => intval( $pageid ), 'page_id' => intval( $pageid ) ];
1764 $conds['rev_id'] = intval( $id );
1766 $conds[] = 'rev_id=page_latest';
1768 return $this->loadRevisionFromConds( $db, $conds );
1772 * Load either the current, or a specified, revision
1773 * that's attached to a given page. If not attached
1774 * to that page, will return null.
1776 * MCR migration note: this replaces Revision::loadFromTitle
1778 * @note direct use is deprecated!
1779 * @todo remove when unused!
1781 * @param IDatabase $db
1782 * @param Title $title
1785 * @return RevisionRecord|null
1787 public function loadRevisionFromTitle( IDatabase
$db, $title, $id = 0 ) {
1789 $matchId = intval( $id );
1791 $matchId = 'page_latest';
1794 return $this->loadRevisionFromConds(
1798 'page_namespace' => $title->getNamespace(),
1799 'page_title' => $title->getDBkey()
1807 * Load the revision for the given title with the given timestamp.
1808 * WARNING: Timestamps may in some circumstances not be unique,
1809 * so this isn't the best key to use.
1811 * MCR migration note: this replaces Revision::loadFromTimestamp
1813 * @note direct use is deprecated! Use getRevisionFromTimestamp instead!
1814 * @todo remove when unused!
1816 * @param IDatabase $db
1817 * @param Title $title
1818 * @param string $timestamp
1819 * @return RevisionRecord|null
1821 public function loadRevisionFromTimestamp( IDatabase
$db, $title, $timestamp ) {
1822 return $this->loadRevisionFromConds( $db,
1824 'rev_timestamp' => $db->timestamp( $timestamp ),
1825 'page_namespace' => $title->getNamespace(),
1826 'page_title' => $title->getDBkey()
1834 * Given a set of conditions, fetch a revision
1836 * This method should be used if we are pretty sure the revision exists.
1837 * Unless $flags has READ_LATEST set, this method will first try to find the revision
1838 * on a replica before hitting the master database.
1840 * MCR migration note: this corresponds to Revision::newFromConds
1842 * @param array $conditions
1843 * @param int $flags (optional)
1844 * @param Title $title
1846 * @return RevisionRecord|null
1848 private function newRevisionFromConds( $conditions, $flags = 0, Title
$title = null ) {
1849 $db = $this->getDBConnection( ( $flags & self
::READ_LATEST
) ? DB_MASTER
: DB_REPLICA
);
1850 $rev = $this->loadRevisionFromConds( $db, $conditions, $flags, $title );
1851 $this->releaseDBConnection( $db );
1853 $lb = $this->getDBLoadBalancer();
1855 // Make sure new pending/committed revision are visibile later on
1856 // within web requests to certain avoid bugs like T93866 and T94407.
1858 && !( $flags & self
::READ_LATEST
)
1859 && $lb->getServerCount() > 1
1860 && $lb->hasOrMadeRecentMasterChanges()
1862 $flags = self
::READ_LATEST
;
1863 $db = $this->getDBConnection( DB_MASTER
);
1864 $rev = $this->loadRevisionFromConds( $db, $conditions, $flags, $title );
1865 $this->releaseDBConnection( $db );
1872 * Given a set of conditions, fetch a revision from
1873 * the given database connection.
1875 * MCR migration note: this corresponds to Revision::loadFromConds
1877 * @param IDatabase $db
1878 * @param array $conditions
1879 * @param int $flags (optional)
1880 * @param Title $title
1882 * @return RevisionRecord|null
1884 private function loadRevisionFromConds(
1890 $row = $this->fetchRevisionRowFromConds( $db, $conditions, $flags );
1892 $rev = $this->newRevisionFromRow( $row, $flags, $title );
1901 * Throws an exception if the given database connection does not belong to the wiki this
1902 * RevisionStore is bound to.
1904 * @param IDatabase $db
1905 * @throws MWException
1907 private function checkDatabaseWikiId( IDatabase
$db ) {
1908 $storeWiki = $this->wikiId
;
1909 $dbWiki = $db->getDomainID();
1911 if ( $dbWiki === $storeWiki ) {
1915 // XXX: we really want the default database ID...
1916 $storeWiki = $storeWiki ?
: wfWikiID();
1917 $dbWiki = $dbWiki ?
: wfWikiID();
1919 if ( $dbWiki === $storeWiki ) {
1923 // HACK: counteract encoding imposed by DatabaseDomain
1924 $storeWiki = str_replace( '?h', '-', $storeWiki );
1925 $dbWiki = str_replace( '?h', '-', $dbWiki );
1927 if ( $dbWiki === $storeWiki ) {
1931 throw new MWException( "RevisionStore for $storeWiki "
1932 . "cannot be used with a DB connection for $dbWiki" );
1936 * Given a set of conditions, return a row with the
1937 * fields necessary to build RevisionRecord objects.
1939 * MCR migration note: this corresponds to Revision::fetchFromConds
1941 * @param IDatabase $db
1942 * @param array $conditions
1943 * @param int $flags (optional)
1945 * @return object|false data row as a raw object
1947 private function fetchRevisionRowFromConds( IDatabase
$db, $conditions, $flags = 0 ) {
1948 $this->checkDatabaseWikiId( $db );
1950 $revQuery = $this->getQueryInfo( [ 'page', 'user' ] );
1952 if ( ( $flags & self
::READ_LOCKING
) == self
::READ_LOCKING
) {
1953 $options[] = 'FOR UPDATE';
1955 return $db->selectRow(
1956 $revQuery['tables'],
1957 $revQuery['fields'],
1966 * Finds the ID of a content row for a given revision and slot role.
1967 * This can be used to re-use content rows even while the content ID
1968 * is still missing from SlotRecords, in MIGRATION_WRITE_BOTH mode.
1970 * @todo remove after MCR schema migration is complete.
1972 * @param IDatabase $db
1974 * @param string $role
1978 private function findSlotContentId( IDatabase
$db, $revId, $role ) {
1979 if ( $this->mcrMigrationStage
< MIGRATION_WRITE_BOTH
) {
1984 $roleId = $this->slotRoleStore
->getId( $role );
1986 'slot_revision_id' => $revId,
1987 'slot_role_id' => $roleId,
1990 $contentId = $db->selectField( 'slots', 'slot_content_id', $conditions, __METHOD__
);
1992 return $contentId ?
: null;
1993 } catch ( NameTableAccessException
$ex ) {
1994 // If the role is missing from the slot_roles table,
1995 // the corresponding row in slots cannot exist.
2001 * Return the tables, fields, and join conditions to be selected to create
2002 * a new RevisionStoreRecord object.
2004 * MCR migration note: this replaces Revision::getQueryInfo
2006 * If the format of fields returned changes in any way then the cache key provided by
2007 * self::getRevisionRowCacheKey should be updated.
2011 * @param array $options Any combination of the following strings
2012 * - 'page': Join with the page table, and select fields to identify the page
2013 * - 'user': Join with the user table, and select the user name
2014 * - 'text': Join with the text table, and select fields to load page text. This
2015 * option is deprecated in MW 1.32 with MCR migration stage MIGRATION_WRITE_BOTH,
2016 * and disallowed with MIGRATION_MEW.
2018 * @return array With three keys:
2019 * - tables: (string[]) to include in the `$table` to `IDatabase->select()`
2020 * - fields: (string[]) to include in the `$vars` to `IDatabase->select()`
2021 * - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
2023 public function getQueryInfo( $options = [] ) {
2030 $ret['tables'][] = 'revision';
2031 $ret['fields'] = array_merge( $ret['fields'], [
2042 $commentQuery = $this->commentStore
->getJoin( 'rev_comment' );
2043 $ret['tables'] = array_merge( $ret['tables'], $commentQuery['tables'] );
2044 $ret['fields'] = array_merge( $ret['fields'], $commentQuery['fields'] );
2045 $ret['joins'] = array_merge( $ret['joins'], $commentQuery['joins'] );
2047 $actorQuery = $this->actorMigration
->getJoin( 'rev_user' );
2048 $ret['tables'] = array_merge( $ret['tables'], $actorQuery['tables'] );
2049 $ret['fields'] = array_merge( $ret['fields'], $actorQuery['fields'] );
2050 $ret['joins'] = array_merge( $ret['joins'], $actorQuery['joins'] );
2052 if ( $this->mcrMigrationStage
< MIGRATION_NEW
) {
2053 $ret['fields'][] = 'rev_text_id';
2055 if ( $this->contentHandlerUseDB
) {
2056 $ret['fields'][] = 'rev_content_format';
2057 $ret['fields'][] = 'rev_content_model';
2061 if ( in_array( 'page', $options, true ) ) {
2062 $ret['tables'][] = 'page';
2063 $ret['fields'] = array_merge( $ret['fields'], [
2071 $ret['joins']['page'] = [ 'INNER JOIN', [ 'page_id = rev_page' ] ];
2074 if ( in_array( 'user', $options, true ) ) {
2075 $ret['tables'][] = 'user';
2076 $ret['fields'] = array_merge( $ret['fields'], [
2079 $u = $actorQuery['fields']['rev_user'];
2080 $ret['joins']['user'] = [ 'LEFT JOIN', [ "$u != 0", "user_id = $u" ] ];
2083 if ( in_array( 'text', $options, true ) ) {
2084 if ( $this->mcrMigrationStage
=== MIGRATION_NEW
) {
2085 throw new InvalidArgumentException( 'text table can no longer be joined directly' );
2086 } elseif ( $this->mcrMigrationStage
>= MIGRATION_WRITE_BOTH
) {
2087 wfDeprecated( __METHOD__
. ' with `text` option', '1.32' );
2090 $ret['tables'][] = 'text';
2091 $ret['fields'] = array_merge( $ret['fields'], [
2095 $ret['joins']['text'] = [ 'INNER JOIN', [ 'rev_text_id=old_id' ] ];
2102 * Return the tables, fields, and join conditions to be selected to create
2107 * @param array $options Any combination of the following strings
2108 * - 'content': Join with the content table, and select content meta-data fields
2110 * @return array With three keys:
2111 * - tables: (string[]) to include in the `$table` to `IDatabase->select()`
2112 * - fields: (string[]) to include in the `$vars` to `IDatabase->select()`
2113 * - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
2115 public function getSlotsQueryInfo( $options = [] ) {
2122 if ( $this->mcrMigrationStage
< MIGRATION_NEW
) {
2123 $db = $this->getDBConnectionRef( DB_REPLICA
);
2124 $ret['tables']['slots'] = 'revision';
2126 $ret['fields']['slot_revision_id'] = 'slots.rev_id';
2127 $ret['fields']['slot_content_id'] = 'NULL';
2128 $ret['fields']['slot_origin'] = 'slots.rev_id';
2129 $ret['fields']['role_name'] = $db->addQuotes( 'main' );
2131 if ( in_array( 'content', $options, true ) ) {
2132 $ret['fields']['content_size'] = 'slots.rev_len';
2133 $ret['fields']['content_sha1'] = 'slots.rev_sha1';
2134 $ret['fields']['content_address']
2135 = $db->buildConcat( [ $db->addQuotes( 'tt:' ), 'slots.rev_text_id' ] );
2137 if ( $this->contentHandlerUseDB
) {
2138 $ret['fields']['model_name'] = 'slots.rev_content_model';
2140 $ret['fields']['model_name'] = 'NULL';
2144 // XXX: in MIGRATION_WRITE_BOTH mode, emulate *and* select - using a UNION?
2145 // See Anomie's idea at <https://gerrit.wikimedia.org/r/c/416465/
2146 // 8..10/includes/Storage/RevisionStore.php#2113>
2148 $ret['tables'][] = 'slots';
2149 $ret['tables'][] = 'slot_roles';
2150 $ret['fields'] = array_merge( $ret['fields'], [
2156 $ret['joins']['slot_roles'] = [ 'INNER JOIN', [ 'slot_role_id = role_id' ] ];
2158 if ( in_array( 'content', $options, true ) ) {
2159 $ret['tables'][] = 'content';
2160 $ret['tables'][] = 'content_models';
2161 $ret['fields'] = array_merge( $ret['fields'], [
2167 $ret['joins']['content'] = [ 'INNER JOIN', [ 'slot_content_id = content_id' ] ];
2168 $ret['joins']['content_models'] = [ 'INNER JOIN', [ 'content_model = model_id' ] ];
2176 * Return the tables, fields, and join conditions to be selected to create
2177 * a new RevisionArchiveRecord object.
2179 * MCR migration note: this replaces Revision::getArchiveQueryInfo
2183 * @return array With three keys:
2184 * - tables: (string[]) to include in the `$table` to `IDatabase->select()`
2185 * - fields: (string[]) to include in the `$vars` to `IDatabase->select()`
2186 * - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
2188 public function getArchiveQueryInfo() {
2189 $commentQuery = $this->commentStore
->getJoin( 'ar_comment' );
2190 $actorQuery = $this->actorMigration
->getJoin( 'ar_user' );
2192 'tables' => [ 'archive' ] +
$commentQuery['tables'] +
$actorQuery['tables'],
2205 ] +
$commentQuery['fields'] +
$actorQuery['fields'],
2206 'joins' => $commentQuery['joins'] +
$actorQuery['joins'],
2209 if ( $this->mcrMigrationStage
< MIGRATION_NEW
) {
2210 $ret['fields'][] = 'ar_text_id';
2212 if ( $this->contentHandlerUseDB
) {
2213 $ret['fields'][] = 'ar_content_format';
2214 $ret['fields'][] = 'ar_content_model';
2222 * Do a batched query for the sizes of a set of revisions.
2224 * MCR migration note: this replaces Revision::getParentLengths
2226 * @param int[] $revIds
2227 * @return int[] associative array mapping revision IDs from $revIds to the nominal size
2228 * of the corresponding revision.
2230 public function getRevisionSizes( array $revIds ) {
2231 return $this->listRevisionSizes( $this->getDBConnection( DB_REPLICA
), $revIds );
2235 * Do a batched query for the sizes of a set of revisions.
2237 * MCR migration note: this replaces Revision::getParentLengths
2239 * @deprecated use RevisionStore::getRevisionSizes instead.
2241 * @param IDatabase $db
2242 * @param int[] $revIds
2243 * @return int[] associative array mapping revision IDs from $revIds to the nominal size
2244 * of the corresponding revision.
2246 public function listRevisionSizes( IDatabase
$db, array $revIds ) {
2247 $this->checkDatabaseWikiId( $db );
2251 return $revLens; // empty
2256 [ 'rev_id', 'rev_len' ],
2257 [ 'rev_id' => $revIds ],
2261 foreach ( $res as $row ) {
2262 $revLens[$row->rev_id
] = intval( $row->rev_len
);
2269 * Get previous revision for this title
2271 * MCR migration note: this replaces Revision::getPrevious
2273 * @param RevisionRecord $rev
2274 * @param Title $title if known (optional)
2276 * @return RevisionRecord|null
2278 public function getPreviousRevision( RevisionRecord
$rev, Title
$title = null ) {
2279 if ( $title === null ) {
2280 $title = $this->getTitle( $rev->getPageId(), $rev->getId() );
2282 $prev = $title->getPreviousRevisionID( $rev->getId() );
2284 return $this->getRevisionByTitle( $title, $prev );
2290 * Get next revision for this title
2292 * MCR migration note: this replaces Revision::getNext
2294 * @param RevisionRecord $rev
2295 * @param Title $title if known (optional)
2297 * @return RevisionRecord|null
2299 public function getNextRevision( RevisionRecord
$rev, Title
$title = null ) {
2300 if ( $title === null ) {
2301 $title = $this->getTitle( $rev->getPageId(), $rev->getId() );
2303 $next = $title->getNextRevisionID( $rev->getId() );
2305 return $this->getRevisionByTitle( $title, $next );
2311 * Get previous revision Id for this page_id
2312 * This is used to populate rev_parent_id on save
2314 * MCR migration note: this corresponds to Revision::getPreviousRevisionId
2316 * @param IDatabase $db
2317 * @param RevisionRecord $rev
2321 private function getPreviousRevisionId( IDatabase
$db, RevisionRecord
$rev ) {
2322 $this->checkDatabaseWikiId( $db );
2324 if ( $rev->getPageId() === null ) {
2327 # Use page_latest if ID is not given
2328 if ( !$rev->getId() ) {
2329 $prevId = $db->selectField(
2330 'page', 'page_latest',
2331 [ 'page_id' => $rev->getPageId() ],
2335 $prevId = $db->selectField(
2336 'revision', 'rev_id',
2337 [ 'rev_page' => $rev->getPageId(), 'rev_id < ' . $rev->getId() ],
2339 [ 'ORDER BY' => 'rev_id DESC' ]
2342 return intval( $prevId );
2346 * Get rev_timestamp from rev_id, without loading the rest of the row
2348 * MCR migration note: this replaces Revision::getTimestampFromId
2350 * @param Title $title
2353 * @return string|bool False if not found
2355 public function getTimestampFromId( $title, $id, $flags = 0 ) {
2356 $db = $this->getDBConnection(
2357 ( $flags & IDBAccessObject
::READ_LATEST
) ? DB_MASTER
: DB_REPLICA
2360 $conds = [ 'rev_id' => $id ];
2361 $conds['rev_page'] = $title->getArticleID();
2362 $timestamp = $db->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
2364 $this->releaseDBConnection( $db );
2365 return ( $timestamp !== false ) ?
wfTimestamp( TS_MW
, $timestamp ) : false;
2369 * Get count of revisions per page...not very efficient
2371 * MCR migration note: this replaces Revision::countByPageId
2373 * @param IDatabase $db
2374 * @param int $id Page id
2377 public function countRevisionsByPageId( IDatabase
$db, $id ) {
2378 $this->checkDatabaseWikiId( $db );
2380 $row = $db->selectRow( 'revision',
2381 [ 'revCount' => 'COUNT(*)' ],
2382 [ 'rev_page' => $id ],
2386 return intval( $row->revCount
);
2392 * Get count of revisions per page...not very efficient
2394 * MCR migration note: this replaces Revision::countByTitle
2396 * @param IDatabase $db
2397 * @param Title $title
2400 public function countRevisionsByTitle( IDatabase
$db, $title ) {
2401 $id = $title->getArticleID();
2403 return $this->countRevisionsByPageId( $db, $id );
2409 * Check if no edits were made by other users since
2410 * the time a user started editing the page. Limit to
2411 * 50 revisions for the sake of performance.
2413 * MCR migration note: this replaces Revision::userWasLastToEdit
2415 * @deprecated since 1.31; Can possibly be removed, since the self-conflict suppression
2416 * logic in EditPage that uses this seems conceptually dubious. Revision::userWasLastToEdit
2417 * has been deprecated since 1.24.
2419 * @param IDatabase $db The Database to perform the check on.
2420 * @param int $pageId The ID of the page in question
2421 * @param int $userId The ID of the user in question
2422 * @param string $since Look at edits since this time
2424 * @return bool True if the given user was the only one to edit since the given timestamp
2426 public function userWasLastToEdit( IDatabase
$db, $pageId, $userId, $since ) {
2427 $this->checkDatabaseWikiId( $db );
2433 $revQuery = $this->getQueryInfo();
2435 $revQuery['tables'],
2437 'rev_user' => $revQuery['fields']['rev_user'],
2440 'rev_page' => $pageId,
2441 'rev_timestamp > ' . $db->addQuotes( $db->timestamp( $since ) )
2444 [ 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ],
2447 foreach ( $res as $row ) {
2448 if ( $row->rev_user
!= $userId ) {
2456 * Load a revision based on a known page ID and current revision ID from the DB
2458 * This method allows for the use of caching, though accessing anything that normally
2459 * requires permission checks (aside from the text) will trigger a small DB lookup.
2461 * MCR migration note: this replaces Revision::newKnownCurrent
2463 * @param Title $title the associated page title
2464 * @param int $revId current revision of this page. Defaults to $title->getLatestRevID().
2466 * @return RevisionRecord|bool Returns false if missing
2468 public function getKnownCurrentRevision( Title
$title, $revId ) {
2469 $db = $this->getDBConnectionRef( DB_REPLICA
);
2471 $pageId = $title->getArticleID();
2478 $revId = $title->getLatestRevID();
2483 'No latest revision known for page ' . $title->getPrefixedDBkey()
2484 . ' even though it exists with page ID ' . $pageId
2489 $row = $this->cache
->getWithSetCallback(
2490 // Page/rev IDs passed in from DB to reflect history merges
2491 $this->getRevisionRowCacheKey( $db, $pageId, $revId ),
2492 WANObjectCache
::TTL_WEEK
,
2493 function ( $curValue, &$ttl, array &$setOpts ) use ( $db, $pageId, $revId ) {
2494 $setOpts +
= Database
::getCacheSetOptions( $db );
2497 'rev_page' => intval( $pageId ),
2498 'page_id' => intval( $pageId ),
2499 'rev_id' => intval( $revId ),
2502 $row = $this->fetchRevisionRowFromConds( $db, $conds );
2503 return $row ?
: false; // don't cache negatives
2507 // Reflect revision deletion and user renames
2509 return $this->newRevisionFromRow( $row, 0, $title );
2516 * Get a cache key for use with a row as selected with getQueryInfo( [ 'page', 'user' ] )
2517 * Caching rows without 'page' or 'user' could lead to issues.
2518 * If the format of the rows returned by the query provided by getQueryInfo changes the
2519 * cache key should be updated to avoid conflicts.
2521 * @param IDatabase $db
2522 * @param int $pageId
2526 private function getRevisionRowCacheKey( IDatabase
$db, $pageId, $revId ) {
2527 return $this->cache
->makeGlobalKey(
2528 self
::ROW_CACHE_KEY
,
2535 // TODO: move relevant methods from Title here, e.g. getFirstRevision, isBigDeletion, etc.