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';
86 * @see $wgContentHandlerUseDB
88 private $contentHandlerUseDB = true;
93 private $loadBalancer;
103 private $commentStore;
106 * @var ActorMigration
108 private $actorMigration;
111 * @var LoggerInterface
116 * @var NameTableStore
118 private $contentModelStore;
121 * @var NameTableStore
123 private $slotRoleStore;
125 /** @var int One of the MIGRATION_* constants */
126 private $mcrMigrationStage;
129 * @todo $blobStore should be allowed to be any BlobStore!
131 * @param LoadBalancer $loadBalancer
132 * @param SqlBlobStore $blobStore
133 * @param WANObjectCache $cache
134 * @param CommentStore $commentStore
135 * @param NameTableStore $contentModelStore
136 * @param NameTableStore $slotRoleStore
137 * @param int $migrationStage
138 * @param ActorMigration $actorMigration
139 * @param bool|string $wikiId
141 public function __construct(
142 LoadBalancer
$loadBalancer,
143 SqlBlobStore
$blobStore,
144 WANObjectCache
$cache,
145 CommentStore
$commentStore,
146 NameTableStore
$contentModelStore,
147 NameTableStore
$slotRoleStore,
149 ActorMigration
$actorMigration,
152 Assert
::parameterType( 'string|boolean', $wikiId, '$wikiId' );
153 Assert
::parameterType( 'integer', $migrationStage, '$migrationStage' );
155 $this->loadBalancer
= $loadBalancer;
156 $this->blobStore
= $blobStore;
157 $this->cache
= $cache;
158 $this->commentStore
= $commentStore;
159 $this->contentModelStore
= $contentModelStore;
160 $this->slotRoleStore
= $slotRoleStore;
161 $this->mcrMigrationStage
= $migrationStage;
162 $this->actorMigration
= $actorMigration;
163 $this->wikiId
= $wikiId;
164 $this->logger
= new NullLogger();
167 public function setLogger( LoggerInterface
$logger ) {
168 $this->logger
= $logger;
172 * @return bool Whether the store is read-only
174 public function isReadOnly() {
175 return $this->blobStore
->isReadOnly();
181 public function getContentHandlerUseDB() {
182 return $this->contentHandlerUseDB
;
186 * @see $wgContentHandlerUseDB
187 * @param bool $contentHandlerUseDB
188 * @throws MWException
190 public function setContentHandlerUseDB( $contentHandlerUseDB ) {
191 if ( !$contentHandlerUseDB && $this->mcrMigrationStage
> MIGRATION_OLD
) {
192 throw new MWException(
193 'Content model must be stored in the database for multi content revision migration.'
196 $this->contentHandlerUseDB
= $contentHandlerUseDB;
200 * @return LoadBalancer
202 private function getDBLoadBalancer() {
203 return $this->loadBalancer
;
207 * @param int $mode DB_MASTER or DB_REPLICA
211 private function getDBConnection( $mode ) {
212 $lb = $this->getDBLoadBalancer();
213 return $lb->getConnection( $mode, [], $this->wikiId
);
217 * @param IDatabase $connection
219 private function releaseDBConnection( IDatabase
$connection ) {
220 $lb = $this->getDBLoadBalancer();
221 $lb->reuseConnection( $connection );
225 * @param int $mode DB_MASTER or DB_REPLICA
229 private function getDBConnectionRef( $mode ) {
230 $lb = $this->getDBLoadBalancer();
231 return $lb->getConnectionRef( $mode, [], $this->wikiId
);
235 * Determines the page Title based on the available information.
237 * MCR migration note: this corresponds to Revision::getTitle
239 * @note this method should be private, external use should be avoided!
241 * @param int|null $pageId
242 * @param int|null $revId
243 * @param int $queryFlags
246 * @throws RevisionAccessException
248 public function getTitle( $pageId, $revId, $queryFlags = self
::READ_NORMAL
) {
249 if ( !$pageId && !$revId ) {
250 throw new InvalidArgumentException( '$pageId and $revId cannot both be 0 or null' );
253 // This method recalls itself with READ_LATEST if READ_NORMAL doesn't get us a Title
254 // So ignore READ_LATEST_IMMUTABLE flags and handle the fallback logic in this method
255 if ( DBAccessObjectUtils
::hasFlags( $queryFlags, self
::READ_LATEST_IMMUTABLE
) ) {
256 $queryFlags = self
::READ_NORMAL
;
259 $canUseTitleNewFromId = ( $pageId !== null && $pageId > 0 && $this->wikiId
=== false );
260 list( $dbMode, $dbOptions ) = DBAccessObjectUtils
::getDBOptions( $queryFlags );
261 $titleFlags = ( $dbMode == DB_MASTER ? Title
::GAID_FOR_UPDATE
: 0 );
263 // Loading by ID is best, but Title::newFromID does not support that for foreign IDs.
264 if ( $canUseTitleNewFromId ) {
265 // TODO: better foreign title handling (introduce TitleFactory)
266 $title = Title
::newFromID( $pageId, $titleFlags );
272 // rev_id is defined as NOT NULL, but this revision may not yet have been inserted.
273 $canUseRevId = ( $revId !== null && $revId > 0 );
275 if ( $canUseRevId ) {
276 $dbr = $this->getDBConnectionRef( $dbMode );
277 // @todo: Title::getSelectFields(), or Title::getQueryInfo(), or something like that
278 $row = $dbr->selectRow(
279 [ 'revision', 'page' ],
288 [ 'rev_id' => $revId ],
291 [ 'page' => [ 'JOIN', 'page_id=rev_page' ] ]
294 // TODO: better foreign title handling (introduce TitleFactory)
295 return Title
::newFromRow( $row );
299 // If we still don't have a title, fallback to master if that wasn't already happening.
300 if ( $dbMode !== DB_MASTER
) {
301 $title = $this->getTitle( $pageId, $revId, self
::READ_LATEST
);
304 __METHOD__
. ' fell back to READ_LATEST and got a Title.',
305 [ 'trace' => wfBacktrace() ]
311 throw new RevisionAccessException(
312 "Could not determine title for page ID $pageId and revision ID $revId"
317 * @param mixed $value
318 * @param string $name
320 * @throws IncompleteRevisionException if $value is null
321 * @return mixed $value, if $value is not null
323 private function failOnNull( $value, $name ) {
324 if ( $value === null ) {
325 throw new IncompleteRevisionException(
326 "$name must not be " . var_export( $value, true ) . "!"
334 * @param mixed $value
335 * @param string $name
337 * @throws IncompleteRevisionException if $value is empty
338 * @return mixed $value, if $value is not null
340 private function failOnEmpty( $value, $name ) {
341 if ( $value === null ||
$value === 0 ||
$value === '' ) {
342 throw new IncompleteRevisionException(
343 "$name must not be " . var_export( $value, true ) . "!"
351 * Insert a new revision into the database, returning the new revision record
352 * on success and dies horribly on failure.
354 * MCR migration note: this replaces Revision::insertOn
356 * @param RevisionRecord $rev
357 * @param IDatabase $dbw (master connection)
359 * @throws InvalidArgumentException
360 * @return RevisionRecord the new revision record.
362 public function insertRevisionOn( RevisionRecord
$rev, IDatabase
$dbw ) {
363 // TODO: pass in a DBTransactionContext instead of a database connection.
364 $this->checkDatabaseWikiId( $dbw );
366 $slotRoles = $rev->getSlotRoles();
368 // Make sure the main slot is always provided throughout migration
369 if ( !in_array( 'main', $slotRoles ) ) {
370 throw new InvalidArgumentException(
371 'main slot must be provided'
375 // While inserting into the old schema make sure only the main slot is allowed.
376 // TODO: support extra slots in MIGRATION_WRITE_BOTH mode!
377 if ( $this->mcrMigrationStage
<= MIGRATION_WRITE_BOTH
&& $slotRoles !== [ 'main' ] ) {
378 throw new InvalidArgumentException(
379 'Only the main slot is supported with MCR migration mode <= MIGRATION_WRITE_BOTH!'
384 $this->failOnNull( $rev->getSize(), 'size field' );
385 $this->failOnEmpty( $rev->getSha1(), 'sha1 field' );
386 $this->failOnEmpty( $rev->getTimestamp(), 'timestamp field' );
387 $comment = $this->failOnNull( $rev->getComment( RevisionRecord
::RAW
), 'comment' );
388 $user = $this->failOnNull( $rev->getUser( RevisionRecord
::RAW
), 'user' );
389 $this->failOnNull( $user->getId(), 'user field' );
390 $this->failOnEmpty( $user->getName(), 'user_text field' );
392 // TODO: we shouldn't need an actual Title here.
393 $title = Title
::newFromLinkTarget( $rev->getPageAsLinkTarget() );
394 $pageId = $this->failOnEmpty( $rev->getPageId(), 'rev_page field' ); // check this early
396 $parentId = $rev->getParentId() === null
397 ?
$this->getPreviousRevisionId( $dbw, $rev )
398 : $rev->getParentId();
400 /** @var RevisionRecord $rev */
401 $rev = $dbw->doAtomicSection(
403 function ( IDatabase
$dbw, $fname ) use (
411 return $this->insertRevisionInternal(
424 Assert
::postcondition( $rev->getId() > 0, 'revision must have an ID' );
425 Assert
::postcondition( $rev->getPageId() > 0, 'revision must have a page ID' );
426 Assert
::postcondition(
427 $rev->getComment( RevisionRecord
::RAW
) !== null,
428 'revision must have a comment'
430 Assert
::postcondition(
431 $rev->getUser( RevisionRecord
::RAW
) !== null,
432 'revision must have a user'
435 // Trigger exception if the main slot is missing.
436 // Technically, this could go away with MIGRATION_NEW: while
437 // calling code may require a main slot to exist, RevisionStore
438 // really should not know or care about that requirement.
439 $rev->getSlot( 'main', RevisionRecord
::RAW
);
441 foreach ( $slotRoles as $role ) {
442 $slot = $rev->getSlot( $role, RevisionRecord
::RAW
);
443 Assert
::postcondition(
444 $slot->getContent() !== null,
445 $role . ' slot must have content'
447 Assert
::postcondition(
448 $slot->hasRevision(),
449 $role . ' slot must have a revision associated'
453 Hooks
::run( 'RevisionRecordInserted', [ $rev ] );
455 // TODO: deprecate in 1.32!
456 $legacyRevision = new Revision( $rev );
457 Hooks
::run( 'RevisionInsertComplete', [ &$legacyRevision, null, null ] );
462 private function insertRevisionInternal(
466 CommentStoreComment
$comment,
471 $slotRoles = $rev->getSlotRoles();
473 $revisionRow = $this->insertRevisionRowOn(
480 $revisionId = $revisionRow['rev_id'];
483 BlobStore
::PAGE_HINT
=> $pageId,
484 BlobStore
::REVISION_HINT
=> $revisionId,
485 BlobStore
::PARENT_HINT
=> $parentId,
489 foreach ( $slotRoles as $role ) {
490 $slot = $rev->getSlot( $role, RevisionRecord
::RAW
);
492 if ( $slot->hasRevision() ) {
493 // If the SlotRecord already has a revision ID set, this means it already exists
494 // in the database, and should already belong to the current revision.
495 // TODO: properly abort transaction if the assertion fails!
497 $slot->getRevision() === $revisionId,
498 'slot role ' . $slot->getRole(),
499 'Existing slot should belong to revision '
500 . $revisionId . ', but belongs to revision ' . $slot->getRevision() . '!'
503 // Slot exists, nothing to do, move along.
504 // This happens when restoring archived revisions.
506 $newSlots[$role] = $slot;
508 // Write the main slot's text ID to the revision table for backwards compatibility
509 if ( $slot->getRole() === 'main' && $this->mcrMigrationStage
<= MIGRATION_WRITE_BOTH
) {
510 $blobAddress = $slot->getAddress();
511 $this->updateRevisionTextId( $dbw, $revisionId, $blobAddress );
514 $newSlots[$role] = $this->insertSlotOn( $dbw, $revisionId, $slot, $title, $blobHints );
518 $this->insertIpChangesRow( $dbw, $user, $rev, $revisionId );
520 $rev = new RevisionStoreRecord(
524 (object)$revisionRow,
525 new RevisionSlots( $newSlots ),
533 * @param IDatabase $dbw
534 * @param int $revisionId
535 * @param string &$blobAddress (may change!)
537 private function updateRevisionTextId( IDatabase
$dbw, $revisionId, &$blobAddress ) {
538 $textId = $this->blobStore
->getTextIdFromAddress( $blobAddress );
540 throw new LogicException(
541 'Blob address not supported in 1.29 database schema: ' . $blobAddress
545 // getTextIdFromAddress() is free to insert something into the text table, so $textId
546 // may be a new value, not anything already contained in $blobAddress.
547 $blobAddress = SqlBlobStore
::makeAddressFromTextId( $textId );
551 [ 'rev_text_id' => $textId ],
552 [ 'rev_id' => $revisionId ],
558 * @param IDatabase $dbw
559 * @param int $revisionId
560 * @param SlotRecord $protoSlot
561 * @param Title $title
562 * @param array $blobHints See the BlobStore::XXX_HINT constants
565 private function insertSlotOn(
568 SlotRecord
$protoSlot,
570 array $blobHints = []
572 if ( $protoSlot->hasAddress() ) {
573 $blobAddress = $protoSlot->getAddress();
575 $blobAddress = $this->storeContentBlob( $protoSlot, $title, $blobHints );
578 // Write the main slot's text ID to the revision table for backwards compatibility
579 if ( $protoSlot->getRole() === 'main' && $this->mcrMigrationStage
<= MIGRATION_WRITE_BOTH
) {
580 $this->updateRevisionTextId( $dbw, $revisionId, $blobAddress );
583 if ( $this->mcrMigrationStage
>= MIGRATION_WRITE_BOTH
) {
584 if ( $protoSlot->hasContentId() ) {
585 $contentId = $protoSlot->getContentId();
587 $contentId = $this->insertContentRowOn( $protoSlot, $dbw, $blobAddress );
590 $this->insertSlotRowOn( $protoSlot, $dbw, $revisionId, $contentId );
595 $savedSlot = SlotRecord
::newSaved(
606 * Insert IP revision into ip_changes for use when querying for a range.
607 * @param IDatabase $dbw
609 * @param RevisionRecord $rev
610 * @param int $revisionId
612 private function insertIpChangesRow(
618 if ( $user->getId() === 0 && IP
::isValid( $user->getName() ) ) {
620 'ipc_rev_id' => $revisionId,
621 'ipc_rev_timestamp' => $dbw->timestamp( $rev->getTimestamp() ),
622 'ipc_hex' => IP
::toHex( $user->getName() ),
624 $dbw->insert( 'ip_changes', $ipcRow, __METHOD__
);
629 * @param IDatabase $dbw
630 * @param RevisionRecord $rev
631 * @param Title $title
632 * @param int $parentId
634 * @return array a revision table row
636 * @throws MWException
637 * @throws MWUnknownContentModelException
639 private function insertRevisionRowOn(
645 $revisionRow = $this->getBaseRevisionRow( $dbw, $rev, $title, $parentId );
647 list( $commentFields, $commentCallback ) =
648 $this->commentStore
->insertWithTempTable(
651 $rev->getComment( RevisionRecord
::RAW
)
653 $revisionRow +
= $commentFields;
655 list( $actorFields, $actorCallback ) =
656 $this->actorMigration
->getInsertValuesWithTempTable(
659 $rev->getUser( RevisionRecord
::RAW
)
661 $revisionRow +
= $actorFields;
663 $dbw->insert( 'revision', $revisionRow, __METHOD__
);
665 if ( !isset( $revisionRow['rev_id'] ) ) {
666 // only if auto-increment was used
667 $revisionRow['rev_id'] = intval( $dbw->insertId() );
670 $commentCallback( $revisionRow['rev_id'] );
671 $actorCallback( $revisionRow['rev_id'], $revisionRow );
677 * @param IDatabase $dbw
678 * @param RevisionRecord $rev
679 * @param Title $title
680 * @param int $parentId
682 * @return array [ 0 => array $revisionRow, 1 => callable ]
683 * @throws MWException
684 * @throws MWUnknownContentModelException
686 private function getBaseRevisionRow(
692 // Record the edit in revisions
694 'rev_page' => $rev->getPageId(),
695 'rev_parent_id' => $parentId,
696 'rev_minor_edit' => $rev->isMinor() ?
1 : 0,
697 'rev_timestamp' => $dbw->timestamp( $rev->getTimestamp() ),
698 'rev_deleted' => $rev->getVisibility(),
699 'rev_len' => $rev->getSize(),
700 'rev_sha1' => $rev->getSha1(),
703 if ( $rev->getId() !== null ) {
704 // Needed to restore revisions with their original ID
705 $revisionRow['rev_id'] = $rev->getId();
708 if ( $this->mcrMigrationStage
<= MIGRATION_WRITE_BOTH
) {
709 // In non MCR more this IF section will relate to the main slot
710 $mainSlot = $rev->getSlot( 'main' );
711 $model = $mainSlot->getModel();
712 $format = $mainSlot->getFormat();
714 // MCR migration note: rev_content_model and rev_content_format will go away
715 if ( $this->contentHandlerUseDB
) {
716 $defaultModel = ContentHandler
::getDefaultModelFor( $title );
717 $defaultFormat = ContentHandler
::getForModelID( $defaultModel )->getDefaultFormat();
719 $revisionRow['rev_content_model'] = ( $model === $defaultModel ) ?
null : $model;
720 $revisionRow['rev_content_format'] = ( $format === $defaultFormat ) ?
null : $format;
728 * @param SlotRecord $slot
729 * @param Title $title
730 * @param array $blobHints See the BlobStore::XXX_HINT constants
732 * @throws MWException
733 * @return string the blob address
735 private function storeContentBlob(
738 array $blobHints = []
740 $content = $slot->getContent();
741 $format = $content->getDefaultFormat();
742 $model = $content->getModel();
744 $this->checkContent( $content, $title );
746 return $this->blobStore
->storeBlob(
747 $content->serialize( $format ),
748 // These hints "leak" some information from the higher abstraction layer to
749 // low level storage to allow for optimization.
753 BlobStore
::DESIGNATION_HINT
=> 'page-content',
754 BlobStore
::ROLE_HINT
=> $slot->getRole(),
755 BlobStore
::SHA1_HINT
=> $slot->getSha1(),
756 BlobStore
::MODEL_HINT
=> $model,
757 BlobStore
::FORMAT_HINT
=> $format,
764 * @param SlotRecord $slot
765 * @param IDatabase $dbw
766 * @param int $revisionId
767 * @param int $contentId
769 private function insertSlotRowOn( SlotRecord
$slot, IDatabase
$dbw, $revisionId, $contentId ) {
771 'slot_revision_id' => $revisionId,
772 'slot_role_id' => $this->slotRoleStore
->acquireId( $slot->getRole() ),
773 'slot_content_id' => $contentId,
774 // If the slot has a specific origin use that ID, otherwise use the ID of the revision
775 // that we just inserted.
776 'slot_origin' => $slot->hasOrigin() ?
$slot->getOrigin() : $revisionId,
778 $dbw->insert( 'slots', $slotRow, __METHOD__
);
782 * @param SlotRecord $slot
783 * @param IDatabase $dbw
784 * @param string $blobAddress
785 * @return int content row ID
787 private function insertContentRowOn( SlotRecord
$slot, IDatabase
$dbw, $blobAddress ) {
789 'content_size' => $slot->getSize(),
790 'content_sha1' => $slot->getSha1(),
791 'content_model' => $this->contentModelStore
->acquireId( $slot->getModel() ),
792 'content_address' => $blobAddress,
794 $dbw->insert( 'content', $contentRow, __METHOD__
);
795 return intval( $dbw->insertId() );
799 * MCR migration note: this corresponds to Revision::checkContentModel
801 * @param Content $content
802 * @param Title $title
804 * @throws MWException
805 * @throws MWUnknownContentModelException
807 private function checkContent( Content
$content, Title
$title ) {
808 // Note: may return null for revisions that have not yet been inserted
810 $model = $content->getModel();
811 $format = $content->getDefaultFormat();
812 $handler = $content->getContentHandler();
816 if ( !$handler->isSupportedFormat( $format ) ) {
817 throw new MWException( "Can't use format $format with content model $model on $name" );
820 if ( !$this->contentHandlerUseDB
) {
821 // if $wgContentHandlerUseDB is not set,
822 // all revisions must use the default content model and format.
824 $defaultModel = ContentHandler
::getDefaultModelFor( $title );
825 $defaultHandler = ContentHandler
::getForModelID( $defaultModel );
826 $defaultFormat = $defaultHandler->getDefaultFormat();
828 if ( $model != $defaultModel ) {
829 throw new MWException( "Can't save non-default content model with "
830 . "\$wgContentHandlerUseDB disabled: model is $model, "
831 . "default for $name is $defaultModel"
835 if ( $format != $defaultFormat ) {
836 throw new MWException( "Can't use non-default content format with "
837 . "\$wgContentHandlerUseDB disabled: format is $format, "
838 . "default for $name is $defaultFormat"
843 if ( !$content->isValid() ) {
844 throw new MWException(
845 "New content for $name is not valid! Content model is $model"
851 * Create a new null-revision for insertion into a page's
852 * history. This will not re-save the text, but simply refer
853 * to the text from the previous version.
855 * Such revisions can for instance identify page rename
856 * operations and other such meta-modifications.
858 * @note: This method grabs a FOR UPDATE lock on the relevant row of the page table,
859 * to prevent a new revision from being inserted before the null revision has been written
862 * MCR migration note: this replaces Revision::newNullRevision
864 * @todo Introduce newFromParentRevision(). newNullRevision can then be based on that
867 * @param IDatabase $dbw used for obtaining the lock on the page table row
868 * @param Title $title Title of the page to read from
869 * @param CommentStoreComment $comment RevisionRecord's summary
870 * @param bool $minor Whether the revision should be considered as minor
871 * @param User $user The user to attribute the revision to
873 * @return RevisionRecord|null RevisionRecord or null on error
875 public function newNullRevision(
878 CommentStoreComment
$comment,
882 $this->checkDatabaseWikiId( $dbw );
884 // T51581: Lock the page table row to ensure no other process
885 // is adding a revision to the page at the same time.
886 // Avoid locking extra tables, compare T191892.
887 $pageLatest = $dbw->selectField(
890 [ 'page_id' => $title->getArticleID() ],
895 if ( !$pageLatest ) {
899 // Fetch the actual revision row from master, without locking all extra tables.
900 $oldRevision = $this->loadRevisionFromConds(
902 [ 'rev_id' => intval( $pageLatest ) ],
907 // Construct the new revision
908 $timestamp = wfTimestampNow(); // TODO: use a callback, so we can override it for testing.
909 $newRevision = MutableRevisionRecord
::newFromParentRevision( $oldRevision );
911 $newRevision->setComment( $comment );
912 $newRevision->setUser( $user );
913 $newRevision->setTimestamp( $timestamp );
914 $newRevision->setMinorEdit( $minor );
920 * MCR migration note: this replaces Revision::isUnpatrolled
922 * @todo This is overly specific, so move or kill this method.
924 * @param RevisionRecord $rev
926 * @return int Rcid of the unpatrolled row, zero if there isn't one
928 public function getRcIdIfUnpatrolled( RevisionRecord
$rev ) {
929 $rc = $this->getRecentChange( $rev );
930 if ( $rc && $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_UNPATROLLED
) {
931 return $rc->getAttribute( 'rc_id' );
938 * Get the RC object belonging to the current revision, if there's one
940 * MCR migration note: this replaces Revision::getRecentChange
942 * @todo move this somewhere else?
944 * @param RevisionRecord $rev
945 * @param int $flags (optional) $flags include:
946 * IDBAccessObject::READ_LATEST: Select the data from the master
948 * @return null|RecentChange
950 public function getRecentChange( RevisionRecord
$rev, $flags = 0 ) {
951 $dbr = $this->getDBConnection( DB_REPLICA
);
953 list( $dbType, ) = DBAccessObjectUtils
::getDBOptions( $flags );
955 $userIdentity = $rev->getUser( RevisionRecord
::RAW
);
957 if ( !$userIdentity ) {
958 // If the revision has no user identity, chances are it never went
959 // into the database, and doesn't have an RC entry.
963 // TODO: Select by rc_this_oldid alone - but as of Nov 2017, there is no index on that!
964 $actorWhere = $this->actorMigration
->getWhere( $dbr, 'rc_user', $rev->getUser(), false );
965 $rc = RecentChange
::newFromConds(
967 $actorWhere['conds'],
968 'rc_timestamp' => $dbr->timestamp( $rev->getTimestamp() ),
969 'rc_this_oldid' => $rev->getId()
975 $this->releaseDBConnection( $dbr );
977 // XXX: cache this locally? Glue it to the RevisionRecord?
982 * Maps fields of the archive row to corresponding revision rows.
984 * @param object $archiveRow
986 * @return object a revision row object, corresponding to $archiveRow.
988 private static function mapArchiveFields( $archiveRow ) {
990 // keep with ar prefix:
993 // not the same suffix:
994 'ar_page_id' => 'rev_page',
995 'ar_rev_id' => 'rev_id',
998 'ar_text_id' => 'rev_text_id',
999 'ar_timestamp' => 'rev_timestamp',
1000 'ar_user_text' => 'rev_user_text',
1001 'ar_user' => 'rev_user',
1002 'ar_actor' => 'rev_actor',
1003 'ar_minor_edit' => 'rev_minor_edit',
1004 'ar_deleted' => 'rev_deleted',
1005 'ar_len' => 'rev_len',
1006 'ar_parent_id' => 'rev_parent_id',
1007 'ar_sha1' => 'rev_sha1',
1008 'ar_comment' => 'rev_comment',
1009 'ar_comment_cid' => 'rev_comment_cid',
1010 'ar_comment_id' => 'rev_comment_id',
1011 'ar_comment_text' => 'rev_comment_text',
1012 'ar_comment_data' => 'rev_comment_data',
1013 'ar_comment_old' => 'rev_comment_old',
1014 'ar_content_format' => 'rev_content_format',
1015 'ar_content_model' => 'rev_content_model',
1018 $revRow = new stdClass();
1019 foreach ( $fieldMap as $arKey => $revKey ) {
1020 if ( property_exists( $archiveRow, $arKey ) ) {
1021 $revRow->$revKey = $archiveRow->$arKey;
1029 * Constructs a RevisionRecord for the revisions main slot, based on the MW1.29 schema.
1031 * @param object|array $row Either a database row or an array
1032 * @param int $queryFlags for callbacks
1033 * @param Title $title
1035 * @return SlotRecord The main slot, extracted from the MW 1.29 style row.
1036 * @throws MWException
1038 private function emulateMainSlot_1_29( $row, $queryFlags, Title
$title ) {
1039 $mainSlotRow = new stdClass();
1040 $mainSlotRow->role_name
= 'main';
1041 $mainSlotRow->model_name
= null;
1042 $mainSlotRow->slot_revision_id
= null;
1043 $mainSlotRow->content_address
= null;
1049 if ( is_object( $row ) ) {
1050 if ( $this->mcrMigrationStage
>= MIGRATION_NEW
) {
1051 // Don't emulate from a row when using the new schema.
1052 // Emulating from an array is still OK.
1053 throw new LogicException( 'Can\'t emulate the main slot when using MCR schema.' );
1057 if ( !isset( $row->rev_id
) && ( isset( $row->ar_user
) ||
isset( $row->ar_actor
) ) ) {
1058 $row = $this->mapArchiveFields( $row );
1061 if ( isset( $row->rev_text_id
) && $row->rev_text_id
> 0 ) {
1062 $mainSlotRow->content_address
= SqlBlobStore
::makeAddressFromTextId(
1067 // This is used by null-revisions
1068 $mainSlotRow->slot_origin
= isset( $row->slot_origin
)
1069 ?
intval( $row->slot_origin
)
1072 if ( isset( $row->old_text
) ) {
1073 // this happens when the text-table gets joined directly, in the pre-1.30 schema
1074 $blobData = isset( $row->old_text
) ?
strval( $row->old_text
) : null;
1075 // Check against selects that might have not included old_flags
1076 if ( !property_exists( $row, 'old_flags' ) ) {
1077 throw new InvalidArgumentException( 'old_flags was not set in $row' );
1079 $blobFlags = ( $row->old_flags
=== null ) ?
'' : $row->old_flags
;
1082 $mainSlotRow->slot_revision_id
= intval( $row->rev_id
);
1084 $mainSlotRow->content_size
= isset( $row->rev_len
) ?
intval( $row->rev_len
) : null;
1085 $mainSlotRow->content_sha1
= isset( $row->rev_sha1
) ?
strval( $row->rev_sha1
) : null;
1086 $mainSlotRow->model_name
= isset( $row->rev_content_model
)
1087 ?
strval( $row->rev_content_model
)
1089 // XXX: in the future, we'll probably always use the default format, and drop content_format
1090 $mainSlotRow->format_name
= isset( $row->rev_content_format
)
1091 ?
strval( $row->rev_content_format
)
1093 } elseif ( is_array( $row ) ) {
1094 $mainSlotRow->slot_revision_id
= isset( $row['id'] ) ?
intval( $row['id'] ) : null;
1096 $mainSlotRow->slot_origin
= isset( $row['slot_origin'] )
1097 ?
intval( $row['slot_origin'] )
1099 $mainSlotRow->content_address
= isset( $row['text_id'] )
1100 ? SqlBlobStore
::makeAddressFromTextId( intval( $row['text_id'] ) )
1102 $mainSlotRow->content_size
= isset( $row['len'] ) ?
intval( $row['len'] ) : null;
1103 $mainSlotRow->content_sha1
= isset( $row['sha1'] ) ?
strval( $row['sha1'] ) : null;
1105 $mainSlotRow->model_name
= isset( $row['content_model'] )
1106 ?
strval( $row['content_model'] ) : null; // XXX: must be a string!
1107 // XXX: in the future, we'll probably always use the default format, and drop content_format
1108 $mainSlotRow->format_name
= isset( $row['content_format'] )
1109 ?
strval( $row['content_format'] ) : null;
1110 $blobData = isset( $row['text'] ) ?
rtrim( strval( $row['text'] ) ) : null;
1111 // XXX: If the flags field is not set then $blobFlags should be null so that no
1112 // decoding will happen. An empty string will result in default decodings.
1113 $blobFlags = isset( $row['flags'] ) ?
trim( strval( $row['flags'] ) ) : null;
1115 // if we have a Content object, override mText and mContentModel
1116 if ( !empty( $row['content'] ) ) {
1117 if ( !( $row['content'] instanceof Content
) ) {
1118 throw new MWException( 'content field must contain a Content object.' );
1121 /** @var Content $content */
1122 $content = $row['content'];
1123 $handler = $content->getContentHandler();
1125 $mainSlotRow->model_name
= $content->getModel();
1127 // XXX: in the future, we'll probably always use the default format.
1128 if ( $mainSlotRow->format_name
=== null ) {
1129 $mainSlotRow->format_name
= $handler->getDefaultFormat();
1133 throw new MWException( 'Revision constructor passed invalid row format.' );
1136 // With the old schema, the content changes with every revision,
1137 // except for null-revisions.
1138 if ( !isset( $mainSlotRow->slot_origin
) ) {
1139 $mainSlotRow->slot_origin
= $mainSlotRow->slot_revision_id
;
1142 if ( $mainSlotRow->model_name
=== null ) {
1143 $mainSlotRow->model_name
= function ( SlotRecord
$slot ) use ( $title ) {
1144 // TODO: MCR: consider slot role in getDefaultModelFor()! Use LinkTarget!
1145 // TODO: MCR: deprecate $title->getModel().
1146 return ContentHandler
::getDefaultModelFor( $title );
1151 // XXX: We should perhaps fail if $blobData is null and $mainSlotRow->content_address
1152 // is missing, but "empty revisions" with no content are used in some edge cases.
1154 $content = function ( SlotRecord
$slot )
1155 use ( $blobData, $blobFlags, $queryFlags, $mainSlotRow )
1157 return $this->loadSlotContent(
1161 $mainSlotRow->format_name
,
1167 // NOTE: this callback will be looped through RevisionSlot::newInherited(), allowing
1168 // the inherited slot to have the same content_id as the original slot. In that case,
1169 // $slot will be the inherited slot, while $mainSlotRow still refers to the original slot.
1170 $mainSlotRow->slot_content_id
=
1171 function ( SlotRecord
$slot ) use ( $queryFlags, $mainSlotRow ) {
1172 list( $dbMode, ) = DBAccessObjectUtils
::getDBOptions( $queryFlags );
1173 $db = $this->getDBConnectionRef( $dbMode );
1174 return $this->findSlotContentId( $db, $mainSlotRow->slot_revision_id
, 'main' );
1177 return new SlotRecord( $mainSlotRow, $content );
1181 * Loads a Content object based on a slot row.
1183 * This method does not call $slot->getContent(), and may be used as a callback
1184 * called by $slot->getContent().
1186 * MCR migration note: this roughly corresponds to Revision::getContentInternal
1188 * @param SlotRecord $slot The SlotRecord to load content for
1189 * @param string|null $blobData The content blob, in the form indicated by $blobFlags
1190 * @param string|null $blobFlags Flags indicating how $blobData needs to be processed.
1191 * Use null if no processing should happen. That is in constrast to the empty string,
1192 * which causes the blob to be decoded according to the configured legacy encoding.
1193 * @param string|null $blobFormat MIME type indicating how $dataBlob is encoded
1194 * @param int $queryFlags
1196 * @throws RevisionAccessException
1199 private function loadSlotContent(
1206 if ( $blobData !== null ) {
1207 Assert
::parameterType( 'string', $blobData, '$blobData' );
1208 Assert
::parameterType( 'string|null', $blobFlags, '$blobFlags' );
1210 $cacheKey = $slot->hasAddress() ?
$slot->getAddress() : null;
1212 if ( $blobFlags === null ) {
1213 // No blob flags, so use the blob verbatim.
1216 $data = $this->blobStore
->expandBlob( $blobData, $blobFlags, $cacheKey );
1217 if ( $data === false ) {
1218 throw new RevisionAccessException(
1219 "Failed to expand blob data using flags $blobFlags (key: $cacheKey)"
1225 $address = $slot->getAddress();
1227 $data = $this->blobStore
->getBlob( $address, $queryFlags );
1228 } catch ( BlobAccessException
$e ) {
1229 throw new RevisionAccessException(
1230 "Failed to load data blob from $address: " . $e->getMessage(), 0, $e
1235 // Unserialize content
1236 $handler = ContentHandler
::getForModelID( $slot->getModel() );
1238 $content = $handler->unserializeContent( $data, $blobFormat );
1243 * Load a page revision from a given revision ID number.
1244 * Returns null if no such revision can be found.
1246 * MCR migration note: this replaces Revision::newFromId
1249 * IDBAccessObject::READ_LATEST: Select the data from the master
1250 * IDBAccessObject::READ_LOCKING : Select & lock the data from the master
1253 * @param int $flags (optional)
1254 * @return RevisionRecord|null
1256 public function getRevisionById( $id, $flags = 0 ) {
1257 return $this->newRevisionFromConds( [ 'rev_id' => intval( $id ) ], $flags );
1261 * Load either the current, or a specified, revision
1262 * that's attached to a given link target. If not attached
1263 * to that link target, will return null.
1265 * MCR migration note: this replaces Revision::newFromTitle
1268 * IDBAccessObject::READ_LATEST: Select the data from the master
1269 * IDBAccessObject::READ_LOCKING : Select & lock the data from the master
1271 * @param LinkTarget $linkTarget
1272 * @param int $revId (optional)
1273 * @param int $flags Bitfield (optional)
1274 * @return RevisionRecord|null
1276 public function getRevisionByTitle( LinkTarget
$linkTarget, $revId = 0, $flags = 0 ) {
1278 'page_namespace' => $linkTarget->getNamespace(),
1279 'page_title' => $linkTarget->getDBkey()
1282 // Use the specified revision ID.
1283 // Note that we use newRevisionFromConds here because we want to retry
1284 // and fall back to master if the page is not found on a replica.
1285 // Since the caller supplied a revision ID, we are pretty sure the revision is
1286 // supposed to exist, so we should try hard to find it.
1287 $conds['rev_id'] = $revId;
1288 return $this->newRevisionFromConds( $conds, $flags );
1290 // Use a join to get the latest revision.
1291 // Note that we don't use newRevisionFromConds here because we don't want to retry
1292 // and fall back to master. The assumption is that we only want to force the fallback
1293 // if we are quite sure the revision exists because the caller supplied a revision ID.
1294 // If the page isn't found at all on a replica, it probably simply does not exist.
1295 $db = $this->getDBConnection( ( $flags & self
::READ_LATEST
) ? DB_MASTER
: DB_REPLICA
);
1297 $conds[] = 'rev_id=page_latest';
1298 $rev = $this->loadRevisionFromConds( $db, $conds, $flags );
1300 $this->releaseDBConnection( $db );
1306 * Load either the current, or a specified, revision
1307 * that's attached to a given page ID.
1308 * Returns null if no such revision can be found.
1310 * MCR migration note: this replaces Revision::newFromPageId
1313 * IDBAccessObject::READ_LATEST: Select the data from the master (since 1.20)
1314 * IDBAccessObject::READ_LOCKING : Select & lock the data from the master
1316 * @param int $pageId
1317 * @param int $revId (optional)
1318 * @param int $flags Bitfield (optional)
1319 * @return RevisionRecord|null
1321 public function getRevisionByPageId( $pageId, $revId = 0, $flags = 0 ) {
1322 $conds = [ 'page_id' => $pageId ];
1324 // Use the specified revision ID.
1325 // Note that we use newRevisionFromConds here because we want to retry
1326 // and fall back to master if the page is not found on a replica.
1327 // Since the caller supplied a revision ID, we are pretty sure the revision is
1328 // supposed to exist, so we should try hard to find it.
1329 $conds['rev_id'] = $revId;
1330 return $this->newRevisionFromConds( $conds, $flags );
1332 // Use a join to get the latest revision.
1333 // Note that we don't use newRevisionFromConds here because we don't want to retry
1334 // and fall back to master. The assumption is that we only want to force the fallback
1335 // if we are quite sure the revision exists because the caller supplied a revision ID.
1336 // If the page isn't found at all on a replica, it probably simply does not exist.
1337 $db = $this->getDBConnection( ( $flags & self
::READ_LATEST
) ? DB_MASTER
: DB_REPLICA
);
1339 $conds[] = 'rev_id=page_latest';
1340 $rev = $this->loadRevisionFromConds( $db, $conds, $flags );
1342 $this->releaseDBConnection( $db );
1348 * Load the revision for the given title with the given timestamp.
1349 * WARNING: Timestamps may in some circumstances not be unique,
1350 * so this isn't the best key to use.
1352 * MCR migration note: this replaces Revision::loadFromTimestamp
1354 * @param Title $title
1355 * @param string $timestamp
1356 * @return RevisionRecord|null
1358 public function getRevisionByTimestamp( $title, $timestamp ) {
1359 $db = $this->getDBConnection( DB_REPLICA
);
1360 return $this->newRevisionFromConds(
1362 'rev_timestamp' => $db->timestamp( $timestamp ),
1363 'page_namespace' => $title->getNamespace(),
1364 'page_title' => $title->getDBkey()
1372 * @param int $revId The revision to load slots for.
1373 * @param int $queryFlags
1375 * @return SlotRecord[]
1377 private function loadSlotRecords( $revId, $queryFlags ) {
1378 $revQuery = self
::getSlotsQueryInfo( [ 'content' ] );
1380 list( $dbMode, $dbOptions ) = DBAccessObjectUtils
::getDBOptions( $queryFlags );
1381 $db = $this->getDBConnectionRef( $dbMode );
1384 $revQuery['tables'],
1385 $revQuery['fields'],
1387 'slot_revision_id' => $revId,
1396 foreach ( $res as $row ) {
1397 $contentCallback = function ( SlotRecord
$slot ) use ( $queryFlags, $row ) {
1398 return $this->loadSlotContent( $slot, null, null, null, $queryFlags );
1401 $slots[$row->role_name
] = new SlotRecord( $row, $contentCallback );
1404 if ( !isset( $slots['main'] ) ) {
1405 throw new RevisionAccessException(
1406 'Main slot of revision ' . $revId . ' not found in database!'
1414 * Factory method for RevisionSlots.
1416 * @note If other code has a need to construct RevisionSlots objects, this should be made
1417 * public, since RevisionSlots instances should not be constructed directly.
1420 * @param object $revisionRow
1421 * @param int $queryFlags
1422 * @param Title $title
1424 * @return RevisionSlots
1425 * @throws MWException
1427 private function newRevisionSlots(
1433 if ( $this->mcrMigrationStage
< MIGRATION_NEW
) {
1434 // TODO: in MIGRATION_WRITE_BOTH, we could use the old and the new method:
1435 // e.g. call emulateMainSlot_1_29() if loadSlotRecords() fails.
1437 $mainSlot = $this->emulateMainSlot_1_29( $revisionRow, $queryFlags, $title );
1438 $slots = new RevisionSlots( [ 'main' => $mainSlot ] );
1440 // XXX: do we need the same kind of caching here
1441 // that getKnownCurrentRevision uses (if $revId == page_latest?)
1443 $slots = new RevisionSlots( function () use( $revId, $queryFlags ) {
1444 return $this->loadSlotRecords( $revId, $queryFlags );
1452 * Make a fake revision object from an archive table row. This is queried
1453 * for permissions or even inserted (as in Special:Undelete)
1455 * MCR migration note: this replaces Revision::newFromArchiveRow
1457 * @param object $row
1458 * @param int $queryFlags
1459 * @param Title|null $title
1460 * @param array $overrides associative array with fields of $row to override. This may be
1461 * used e.g. to force the parent revision ID or page ID. Keys in the array are fields
1462 * names from the archive table without the 'ar_' prefix, i.e. use 'parent_id' to
1463 * override ar_parent_id.
1465 * @return RevisionRecord
1466 * @throws MWException
1468 public function newRevisionFromArchiveRow(
1471 Title
$title = null,
1472 array $overrides = []
1474 Assert
::parameterType( 'object', $row, '$row' );
1476 // check second argument, since Revision::newFromArchiveRow had $overrides in that spot.
1477 Assert
::parameterType( 'integer', $queryFlags, '$queryFlags' );
1479 if ( !$title && isset( $overrides['title'] ) ) {
1480 if ( !( $overrides['title'] instanceof Title
) ) {
1481 throw new MWException( 'title field override must contain a Title object.' );
1484 $title = $overrides['title'];
1487 if ( !isset( $title ) ) {
1488 if ( isset( $row->ar_namespace
) && isset( $row->ar_title
) ) {
1489 $title = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
1491 throw new InvalidArgumentException(
1492 'A Title or ar_namespace and ar_title must be given'
1497 foreach ( $overrides as $key => $value ) {
1499 $row->$field = $value;
1503 $user = User
::newFromAnyId(
1504 $row->ar_user ??
null,
1505 $row->ar_user_text ??
null,
1506 $row->ar_actor ??
null
1508 } catch ( InvalidArgumentException
$ex ) {
1509 wfWarn( __METHOD__
. ': ' . $ex->getMessage() );
1510 $user = new UserIdentityValue( 0, '', 0 );
1513 $comment = $this->commentStore
1514 // Legacy because $row may have come from self::selectFields()
1515 ->getCommentLegacy( $this->getDBConnection( DB_REPLICA
), 'ar_comment', $row, true );
1517 $slots = $this->newRevisionSlots( $row->ar_rev_id
, $row, $queryFlags, $title );
1519 return new RevisionArchiveRecord( $title, $user, $comment, $row, $slots, $this->wikiId
);
1523 * @see RevisionFactory::newRevisionFromRow
1525 * MCR migration note: this replaces Revision::newFromRow
1527 * @param object $row
1528 * @param int $queryFlags
1529 * @param Title|null $title
1531 * @return RevisionRecord
1533 public function newRevisionFromRow( $row, $queryFlags = 0, Title
$title = null ) {
1534 Assert
::parameterType( 'object', $row, '$row' );
1537 $pageId = $row->rev_page ??
0; // XXX: also check page_id?
1538 $revId = $row->rev_id ??
0;
1540 $title = $this->getTitle( $pageId, $revId, $queryFlags );
1543 if ( !isset( $row->page_latest
) ) {
1544 $row->page_latest
= $title->getLatestRevID();
1545 if ( $row->page_latest
=== 0 && $title->exists() ) {
1546 wfWarn( 'Encountered title object in limbo: ID ' . $title->getArticleID() );
1551 $user = User
::newFromAnyId(
1552 $row->rev_user ??
null,
1553 $row->rev_user_text ??
null,
1554 $row->rev_actor ??
null
1556 } catch ( InvalidArgumentException
$ex ) {
1557 wfWarn( __METHOD__
. ': ' . $ex->getMessage() );
1558 $user = new UserIdentityValue( 0, '', 0 );
1561 $comment = $this->commentStore
1562 // Legacy because $row may have come from self::selectFields()
1563 ->getCommentLegacy( $this->getDBConnection( DB_REPLICA
), 'rev_comment', $row, true );
1565 $slots = $this->newRevisionSlots( $row->rev_id
, $row, $queryFlags, $title );
1567 return new RevisionStoreRecord( $title, $user, $comment, $row, $slots, $this->wikiId
);
1571 * Constructs a new MutableRevisionRecord based on the given associative array following
1572 * the MW1.29 convention for the Revision constructor.
1574 * MCR migration note: this replaces Revision::newFromRow
1576 * @param array $fields
1577 * @param int $queryFlags
1578 * @param Title|null $title
1580 * @return MutableRevisionRecord
1581 * @throws MWException
1582 * @throws RevisionAccessException
1584 public function newMutableRevisionFromArray(
1589 if ( !$title && isset( $fields['title'] ) ) {
1590 if ( !( $fields['title'] instanceof Title
) ) {
1591 throw new MWException( 'title field must contain a Title object.' );
1594 $title = $fields['title'];
1598 $pageId = $fields['page'] ??
0;
1599 $revId = $fields['id'] ??
0;
1601 $title = $this->getTitle( $pageId, $revId, $queryFlags );
1604 if ( !isset( $fields['page'] ) ) {
1605 $fields['page'] = $title->getArticleID( $queryFlags );
1608 // if we have a content object, use it to set the model and type
1609 if ( !empty( $fields['content'] ) ) {
1610 if ( !( $fields['content'] instanceof Content
) && !is_array( $fields['content'] ) ) {
1611 throw new MWException(
1612 'content field must contain a Content object or an array of Content objects.'
1617 if ( !empty( $fields['text_id'] ) ) {
1618 if ( $this->mcrMigrationStage
>= MIGRATION_NEW
) {
1619 throw new MWException( "Cannot use text_id field with MCR schema" );
1622 if ( !empty( $fields['content'] ) ) {
1623 throw new MWException(
1624 "Text already stored in external store (id {$fields['text_id']}), " .
1625 "can't specify content object"
1631 isset( $fields['comment'] )
1632 && !( $fields['comment'] instanceof CommentStoreComment
)
1634 $commentData = $fields['comment_data'] ??
null;
1636 if ( $fields['comment'] instanceof Message
) {
1637 $fields['comment'] = CommentStoreComment
::newUnsavedComment(
1642 $commentText = trim( strval( $fields['comment'] ) );
1643 $fields['comment'] = CommentStoreComment
::newUnsavedComment(
1650 $revision = new MutableRevisionRecord( $title, $this->wikiId
);
1651 $this->initializeMutableRevisionFromArray( $revision, $fields );
1653 if ( isset( $fields['content'] ) && is_array( $fields['content'] ) ) {
1654 foreach ( $fields['content'] as $role => $content ) {
1655 $revision->setContent( $role, $content );
1658 $mainSlot = $this->emulateMainSlot_1_29( $fields, $queryFlags, $title );
1659 $revision->setSlot( $mainSlot );
1666 * @param MutableRevisionRecord $record
1667 * @param array $fields
1669 private function initializeMutableRevisionFromArray(
1670 MutableRevisionRecord
$record,
1673 /** @var UserIdentity $user */
1676 if ( isset( $fields['user'] ) && ( $fields['user'] instanceof UserIdentity
) ) {
1677 $user = $fields['user'];
1680 $user = User
::newFromAnyId(
1681 $fields['user'] ??
null,
1682 $fields['user_text'] ??
null,
1683 $fields['actor'] ??
null
1685 } catch ( InvalidArgumentException
$ex ) {
1691 $record->setUser( $user );
1694 $timestamp = isset( $fields['timestamp'] )
1695 ?
strval( $fields['timestamp'] )
1696 : wfTimestampNow(); // TODO: use a callback, so we can override it for testing.
1698 $record->setTimestamp( $timestamp );
1700 if ( isset( $fields['page'] ) ) {
1701 $record->setPageId( intval( $fields['page'] ) );
1704 if ( isset( $fields['id'] ) ) {
1705 $record->setId( intval( $fields['id'] ) );
1707 if ( isset( $fields['parent_id'] ) ) {
1708 $record->setParentId( intval( $fields['parent_id'] ) );
1711 if ( isset( $fields['sha1'] ) ) {
1712 $record->setSha1( $fields['sha1'] );
1714 if ( isset( $fields['size'] ) ) {
1715 $record->setSize( intval( $fields['size'] ) );
1718 if ( isset( $fields['minor_edit'] ) ) {
1719 $record->setMinorEdit( intval( $fields['minor_edit'] ) !== 0 );
1721 if ( isset( $fields['deleted'] ) ) {
1722 $record->setVisibility( intval( $fields['deleted'] ) );
1725 if ( isset( $fields['comment'] ) ) {
1726 Assert
::parameterType(
1727 CommentStoreComment
::class,
1731 $record->setComment( $fields['comment'] );
1736 * Load a page revision from a given revision ID number.
1737 * Returns null if no such revision can be found.
1739 * MCR migration note: this corresponds to Revision::loadFromId
1741 * @note direct use is deprecated!
1742 * @todo remove when unused! there seem to be no callers of Revision::loadFromId
1744 * @param IDatabase $db
1747 * @return RevisionRecord|null
1749 public function loadRevisionFromId( IDatabase
$db, $id ) {
1750 return $this->loadRevisionFromConds( $db, [ 'rev_id' => intval( $id ) ] );
1754 * Load either the current, or a specified, revision
1755 * that's attached to a given page. If not attached
1756 * to that page, will return null.
1758 * MCR migration note: this replaces Revision::loadFromPageId
1760 * @note direct use is deprecated!
1761 * @todo remove when unused!
1763 * @param IDatabase $db
1764 * @param int $pageid
1766 * @return RevisionRecord|null
1768 public function loadRevisionFromPageId( IDatabase
$db, $pageid, $id = 0 ) {
1769 $conds = [ 'rev_page' => intval( $pageid ), 'page_id' => intval( $pageid ) ];
1771 $conds['rev_id'] = intval( $id );
1773 $conds[] = 'rev_id=page_latest';
1775 return $this->loadRevisionFromConds( $db, $conds );
1779 * Load either the current, or a specified, revision
1780 * that's attached to a given page. If not attached
1781 * to that page, will return null.
1783 * MCR migration note: this replaces Revision::loadFromTitle
1785 * @note direct use is deprecated!
1786 * @todo remove when unused!
1788 * @param IDatabase $db
1789 * @param Title $title
1792 * @return RevisionRecord|null
1794 public function loadRevisionFromTitle( IDatabase
$db, $title, $id = 0 ) {
1796 $matchId = intval( $id );
1798 $matchId = 'page_latest';
1801 return $this->loadRevisionFromConds(
1805 'page_namespace' => $title->getNamespace(),
1806 'page_title' => $title->getDBkey()
1814 * Load the revision for the given title with the given timestamp.
1815 * WARNING: Timestamps may in some circumstances not be unique,
1816 * so this isn't the best key to use.
1818 * MCR migration note: this replaces Revision::loadFromTimestamp
1820 * @note direct use is deprecated! Use getRevisionFromTimestamp instead!
1821 * @todo remove when unused!
1823 * @param IDatabase $db
1824 * @param Title $title
1825 * @param string $timestamp
1826 * @return RevisionRecord|null
1828 public function loadRevisionFromTimestamp( IDatabase
$db, $title, $timestamp ) {
1829 return $this->loadRevisionFromConds( $db,
1831 'rev_timestamp' => $db->timestamp( $timestamp ),
1832 'page_namespace' => $title->getNamespace(),
1833 'page_title' => $title->getDBkey()
1841 * Given a set of conditions, fetch a revision
1843 * This method should be used if we are pretty sure the revision exists.
1844 * Unless $flags has READ_LATEST set, this method will first try to find the revision
1845 * on a replica before hitting the master database.
1847 * MCR migration note: this corresponds to Revision::newFromConds
1849 * @param array $conditions
1850 * @param int $flags (optional)
1851 * @param Title $title
1853 * @return RevisionRecord|null
1855 private function newRevisionFromConds( $conditions, $flags = 0, Title
$title = null ) {
1856 $db = $this->getDBConnection( ( $flags & self
::READ_LATEST
) ? DB_MASTER
: DB_REPLICA
);
1857 $rev = $this->loadRevisionFromConds( $db, $conditions, $flags, $title );
1858 $this->releaseDBConnection( $db );
1860 $lb = $this->getDBLoadBalancer();
1862 // Make sure new pending/committed revision are visibile later on
1863 // within web requests to certain avoid bugs like T93866 and T94407.
1865 && !( $flags & self
::READ_LATEST
)
1866 && $lb->getServerCount() > 1
1867 && $lb->hasOrMadeRecentMasterChanges()
1869 $flags = self
::READ_LATEST
;
1870 $db = $this->getDBConnection( DB_MASTER
);
1871 $rev = $this->loadRevisionFromConds( $db, $conditions, $flags, $title );
1872 $this->releaseDBConnection( $db );
1879 * Given a set of conditions, fetch a revision from
1880 * the given database connection.
1882 * MCR migration note: this corresponds to Revision::loadFromConds
1884 * @param IDatabase $db
1885 * @param array $conditions
1886 * @param int $flags (optional)
1887 * @param Title $title
1889 * @return RevisionRecord|null
1891 private function loadRevisionFromConds(
1897 $row = $this->fetchRevisionRowFromConds( $db, $conditions, $flags );
1899 $rev = $this->newRevisionFromRow( $row, $flags, $title );
1908 * Throws an exception if the given database connection does not belong to the wiki this
1909 * RevisionStore is bound to.
1911 * @param IDatabase $db
1912 * @throws MWException
1914 private function checkDatabaseWikiId( IDatabase
$db ) {
1915 $storeWiki = $this->wikiId
;
1916 $dbWiki = $db->getDomainID();
1918 if ( $dbWiki === $storeWiki ) {
1922 // XXX: we really want the default database ID...
1923 $storeWiki = $storeWiki ?
: wfWikiID();
1924 $dbWiki = $dbWiki ?
: wfWikiID();
1926 if ( $dbWiki === $storeWiki ) {
1930 // HACK: counteract encoding imposed by DatabaseDomain
1931 $storeWiki = str_replace( '?h', '-', $storeWiki );
1932 $dbWiki = str_replace( '?h', '-', $dbWiki );
1934 if ( $dbWiki === $storeWiki ) {
1938 throw new MWException( "RevisionStore for $storeWiki "
1939 . "cannot be used with a DB connection for $dbWiki" );
1943 * Given a set of conditions, return a row with the
1944 * fields necessary to build RevisionRecord objects.
1946 * MCR migration note: this corresponds to Revision::fetchFromConds
1948 * @param IDatabase $db
1949 * @param array $conditions
1950 * @param int $flags (optional)
1952 * @return object|false data row as a raw object
1954 private function fetchRevisionRowFromConds( IDatabase
$db, $conditions, $flags = 0 ) {
1955 $this->checkDatabaseWikiId( $db );
1957 $revQuery = $this->getQueryInfo( [ 'page', 'user' ] );
1959 if ( ( $flags & self
::READ_LOCKING
) == self
::READ_LOCKING
) {
1960 $options[] = 'FOR UPDATE';
1962 return $db->selectRow(
1963 $revQuery['tables'],
1964 $revQuery['fields'],
1973 * Finds the ID of a content row for a given revision and slot role.
1974 * This can be used to re-use content rows even while the content ID
1975 * is still missing from SlotRecords, in MIGRATION_WRITE_BOTH mode.
1977 * @todo remove after MCR schema migration is complete.
1979 * @param IDatabase $db
1981 * @param string $role
1985 private function findSlotContentId( IDatabase
$db, $revId, $role ) {
1986 if ( $this->mcrMigrationStage
< MIGRATION_WRITE_BOTH
) {
1991 $roleId = $this->slotRoleStore
->getId( $role );
1993 'slot_revision_id' => $revId,
1994 'slot_role_id' => $roleId,
1997 $contentId = $db->selectField( 'slots', 'slot_content_id', $conditions, __METHOD__
);
1999 return $contentId ?
: null;
2000 } catch ( NameTableAccessException
$ex ) {
2001 // If the role is missing from the slot_roles table,
2002 // the corresponding row in slots cannot exist.
2008 * Return the tables, fields, and join conditions to be selected to create
2009 * a new RevisionStoreRecord object.
2011 * MCR migration note: this replaces Revision::getQueryInfo
2013 * If the format of fields returned changes in any way then the cache key provided by
2014 * self::getRevisionRowCacheKey should be updated.
2018 * @param array $options Any combination of the following strings
2019 * - 'page': Join with the page table, and select fields to identify the page
2020 * - 'user': Join with the user table, and select the user name
2021 * - 'text': Join with the text table, and select fields to load page text. This
2022 * option is deprecated in MW 1.32 with MCR migration stage MIGRATION_WRITE_BOTH,
2023 * and disallowed with MIGRATION_MEW.
2025 * @return array With three keys:
2026 * - tables: (string[]) to include in the `$table` to `IDatabase->select()`
2027 * - fields: (string[]) to include in the `$vars` to `IDatabase->select()`
2028 * - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
2030 public function getQueryInfo( $options = [] ) {
2037 $ret['tables'][] = 'revision';
2038 $ret['fields'] = array_merge( $ret['fields'], [
2049 $commentQuery = $this->commentStore
->getJoin( 'rev_comment' );
2050 $ret['tables'] = array_merge( $ret['tables'], $commentQuery['tables'] );
2051 $ret['fields'] = array_merge( $ret['fields'], $commentQuery['fields'] );
2052 $ret['joins'] = array_merge( $ret['joins'], $commentQuery['joins'] );
2054 $actorQuery = $this->actorMigration
->getJoin( 'rev_user' );
2055 $ret['tables'] = array_merge( $ret['tables'], $actorQuery['tables'] );
2056 $ret['fields'] = array_merge( $ret['fields'], $actorQuery['fields'] );
2057 $ret['joins'] = array_merge( $ret['joins'], $actorQuery['joins'] );
2059 if ( $this->mcrMigrationStage
< MIGRATION_NEW
) {
2060 $ret['fields'][] = 'rev_text_id';
2062 if ( $this->contentHandlerUseDB
) {
2063 $ret['fields'][] = 'rev_content_format';
2064 $ret['fields'][] = 'rev_content_model';
2068 if ( in_array( 'page', $options, true ) ) {
2069 $ret['tables'][] = 'page';
2070 $ret['fields'] = array_merge( $ret['fields'], [
2078 $ret['joins']['page'] = [ 'INNER JOIN', [ 'page_id = rev_page' ] ];
2081 if ( in_array( 'user', $options, true ) ) {
2082 $ret['tables'][] = 'user';
2083 $ret['fields'] = array_merge( $ret['fields'], [
2086 $u = $actorQuery['fields']['rev_user'];
2087 $ret['joins']['user'] = [ 'LEFT JOIN', [ "$u != 0", "user_id = $u" ] ];
2090 if ( in_array( 'text', $options, true ) ) {
2091 if ( $this->mcrMigrationStage
=== MIGRATION_NEW
) {
2092 throw new InvalidArgumentException( 'text table can no longer be joined directly' );
2093 } elseif ( $this->mcrMigrationStage
>= MIGRATION_WRITE_BOTH
) {
2094 wfDeprecated( __METHOD__
. ' with `text` option', '1.32' );
2097 $ret['tables'][] = 'text';
2098 $ret['fields'] = array_merge( $ret['fields'], [
2102 $ret['joins']['text'] = [ 'INNER JOIN', [ 'rev_text_id=old_id' ] ];
2109 * Return the tables, fields, and join conditions to be selected to create
2114 * @param array $options Any combination of the following strings
2115 * - 'content': Join with the content table, and select content meta-data fields
2117 * @return array With three keys:
2118 * - tables: (string[]) to include in the `$table` to `IDatabase->select()`
2119 * - fields: (string[]) to include in the `$vars` to `IDatabase->select()`
2120 * - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
2122 public function getSlotsQueryInfo( $options = [] ) {
2129 if ( $this->mcrMigrationStage
< MIGRATION_NEW
) {
2130 $db = $this->getDBConnectionRef( DB_REPLICA
);
2131 $ret['tables']['slots'] = 'revision';
2133 $ret['fields']['slot_revision_id'] = 'slots.rev_id';
2134 $ret['fields']['slot_content_id'] = 'NULL';
2135 $ret['fields']['slot_origin'] = 'slots.rev_id';
2136 $ret['fields']['role_name'] = $db->addQuotes( 'main' );
2138 if ( in_array( 'content', $options, true ) ) {
2139 $ret['fields']['content_size'] = 'slots.rev_len';
2140 $ret['fields']['content_sha1'] = 'slots.rev_sha1';
2141 $ret['fields']['content_address']
2142 = $db->buildConcat( [ $db->addQuotes( 'tt:' ), 'slots.rev_text_id' ] );
2144 if ( $this->contentHandlerUseDB
) {
2145 $ret['fields']['model_name'] = 'slots.rev_content_model';
2147 $ret['fields']['model_name'] = 'NULL';
2151 // XXX: in MIGRATION_WRITE_BOTH mode, emulate *and* select - using a UNION?
2152 // See Anomie's idea at <https://gerrit.wikimedia.org/r/c/416465/
2153 // 8..10/includes/Storage/RevisionStore.php#2113>
2155 $ret['tables'][] = 'slots';
2156 $ret['tables'][] = 'slot_roles';
2157 $ret['fields'] = array_merge( $ret['fields'], [
2163 $ret['joins']['slot_roles'] = [ 'INNER JOIN', [ 'slot_role_id = role_id' ] ];
2165 if ( in_array( 'content', $options, true ) ) {
2166 $ret['tables'][] = 'content';
2167 $ret['tables'][] = 'content_models';
2168 $ret['fields'] = array_merge( $ret['fields'], [
2174 $ret['joins']['content'] = [ 'INNER JOIN', [ 'slot_content_id = content_id' ] ];
2175 $ret['joins']['content_models'] = [ 'INNER JOIN', [ 'content_model = model_id' ] ];
2183 * Return the tables, fields, and join conditions to be selected to create
2184 * a new RevisionArchiveRecord object.
2186 * MCR migration note: this replaces Revision::getArchiveQueryInfo
2190 * @return array With three keys:
2191 * - tables: (string[]) to include in the `$table` to `IDatabase->select()`
2192 * - fields: (string[]) to include in the `$vars` to `IDatabase->select()`
2193 * - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
2195 public function getArchiveQueryInfo() {
2196 $commentQuery = $this->commentStore
->getJoin( 'ar_comment' );
2197 $actorQuery = $this->actorMigration
->getJoin( 'ar_user' );
2199 'tables' => [ 'archive' ] +
$commentQuery['tables'] +
$actorQuery['tables'],
2212 ] +
$commentQuery['fields'] +
$actorQuery['fields'],
2213 'joins' => $commentQuery['joins'] +
$actorQuery['joins'],
2216 if ( $this->mcrMigrationStage
< MIGRATION_NEW
) {
2217 $ret['fields'][] = 'ar_text_id';
2219 if ( $this->contentHandlerUseDB
) {
2220 $ret['fields'][] = 'ar_content_format';
2221 $ret['fields'][] = 'ar_content_model';
2229 * Do a batched query for the sizes of a set of revisions.
2231 * MCR migration note: this replaces Revision::getParentLengths
2233 * @param int[] $revIds
2234 * @return int[] associative array mapping revision IDs from $revIds to the nominal size
2235 * of the corresponding revision.
2237 public function getRevisionSizes( array $revIds ) {
2238 return $this->listRevisionSizes( $this->getDBConnection( DB_REPLICA
), $revIds );
2242 * Do a batched query for the sizes of a set of revisions.
2244 * MCR migration note: this replaces Revision::getParentLengths
2246 * @deprecated use RevisionStore::getRevisionSizes instead.
2248 * @param IDatabase $db
2249 * @param int[] $revIds
2250 * @return int[] associative array mapping revision IDs from $revIds to the nominal size
2251 * of the corresponding revision.
2253 public function listRevisionSizes( IDatabase
$db, array $revIds ) {
2254 $this->checkDatabaseWikiId( $db );
2258 return $revLens; // empty
2263 [ 'rev_id', 'rev_len' ],
2264 [ 'rev_id' => $revIds ],
2268 foreach ( $res as $row ) {
2269 $revLens[$row->rev_id
] = intval( $row->rev_len
);
2276 * Get previous revision for this title
2278 * MCR migration note: this replaces Revision::getPrevious
2280 * @param RevisionRecord $rev
2281 * @param Title $title if known (optional)
2283 * @return RevisionRecord|null
2285 public function getPreviousRevision( RevisionRecord
$rev, Title
$title = null ) {
2286 if ( $title === null ) {
2287 $title = $this->getTitle( $rev->getPageId(), $rev->getId() );
2289 $prev = $title->getPreviousRevisionID( $rev->getId() );
2291 return $this->getRevisionByTitle( $title, $prev );
2297 * Get next revision for this title
2299 * MCR migration note: this replaces Revision::getNext
2301 * @param RevisionRecord $rev
2302 * @param Title $title if known (optional)
2304 * @return RevisionRecord|null
2306 public function getNextRevision( RevisionRecord
$rev, Title
$title = null ) {
2307 if ( $title === null ) {
2308 $title = $this->getTitle( $rev->getPageId(), $rev->getId() );
2310 $next = $title->getNextRevisionID( $rev->getId() );
2312 return $this->getRevisionByTitle( $title, $next );
2318 * Get previous revision Id for this page_id
2319 * This is used to populate rev_parent_id on save
2321 * MCR migration note: this corresponds to Revision::getPreviousRevisionId
2323 * @param IDatabase $db
2324 * @param RevisionRecord $rev
2328 private function getPreviousRevisionId( IDatabase
$db, RevisionRecord
$rev ) {
2329 $this->checkDatabaseWikiId( $db );
2331 if ( $rev->getPageId() === null ) {
2334 # Use page_latest if ID is not given
2335 if ( !$rev->getId() ) {
2336 $prevId = $db->selectField(
2337 'page', 'page_latest',
2338 [ 'page_id' => $rev->getPageId() ],
2342 $prevId = $db->selectField(
2343 'revision', 'rev_id',
2344 [ 'rev_page' => $rev->getPageId(), 'rev_id < ' . $rev->getId() ],
2346 [ 'ORDER BY' => 'rev_id DESC' ]
2349 return intval( $prevId );
2353 * Get rev_timestamp from rev_id, without loading the rest of the row
2355 * MCR migration note: this replaces Revision::getTimestampFromId
2357 * @param Title $title
2360 * @return string|bool False if not found
2362 public function getTimestampFromId( $title, $id, $flags = 0 ) {
2363 $db = $this->getDBConnection(
2364 ( $flags & IDBAccessObject
::READ_LATEST
) ? DB_MASTER
: DB_REPLICA
2367 $conds = [ 'rev_id' => $id ];
2368 $conds['rev_page'] = $title->getArticleID();
2369 $timestamp = $db->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
2371 $this->releaseDBConnection( $db );
2372 return ( $timestamp !== false ) ?
wfTimestamp( TS_MW
, $timestamp ) : false;
2376 * Get count of revisions per page...not very efficient
2378 * MCR migration note: this replaces Revision::countByPageId
2380 * @param IDatabase $db
2381 * @param int $id Page id
2384 public function countRevisionsByPageId( IDatabase
$db, $id ) {
2385 $this->checkDatabaseWikiId( $db );
2387 $row = $db->selectRow( 'revision',
2388 [ 'revCount' => 'COUNT(*)' ],
2389 [ 'rev_page' => $id ],
2393 return intval( $row->revCount
);
2399 * Get count of revisions per page...not very efficient
2401 * MCR migration note: this replaces Revision::countByTitle
2403 * @param IDatabase $db
2404 * @param Title $title
2407 public function countRevisionsByTitle( IDatabase
$db, $title ) {
2408 $id = $title->getArticleID();
2410 return $this->countRevisionsByPageId( $db, $id );
2416 * Check if no edits were made by other users since
2417 * the time a user started editing the page. Limit to
2418 * 50 revisions for the sake of performance.
2420 * MCR migration note: this replaces Revision::userWasLastToEdit
2422 * @deprecated since 1.31; Can possibly be removed, since the self-conflict suppression
2423 * logic in EditPage that uses this seems conceptually dubious. Revision::userWasLastToEdit
2424 * has been deprecated since 1.24.
2426 * @param IDatabase $db The Database to perform the check on.
2427 * @param int $pageId The ID of the page in question
2428 * @param int $userId The ID of the user in question
2429 * @param string $since Look at edits since this time
2431 * @return bool True if the given user was the only one to edit since the given timestamp
2433 public function userWasLastToEdit( IDatabase
$db, $pageId, $userId, $since ) {
2434 $this->checkDatabaseWikiId( $db );
2440 $revQuery = $this->getQueryInfo();
2442 $revQuery['tables'],
2444 'rev_user' => $revQuery['fields']['rev_user'],
2447 'rev_page' => $pageId,
2448 'rev_timestamp > ' . $db->addQuotes( $db->timestamp( $since ) )
2451 [ 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ],
2454 foreach ( $res as $row ) {
2455 if ( $row->rev_user
!= $userId ) {
2463 * Load a revision based on a known page ID and current revision ID from the DB
2465 * This method allows for the use of caching, though accessing anything that normally
2466 * requires permission checks (aside from the text) will trigger a small DB lookup.
2468 * MCR migration note: this replaces Revision::newKnownCurrent
2470 * @param Title $title the associated page title
2471 * @param int $revId current revision of this page. Defaults to $title->getLatestRevID().
2473 * @return RevisionRecord|bool Returns false if missing
2475 public function getKnownCurrentRevision( Title
$title, $revId ) {
2476 $db = $this->getDBConnectionRef( DB_REPLICA
);
2478 $pageId = $title->getArticleID();
2485 $revId = $title->getLatestRevID();
2490 'No latest revision known for page ' . $title->getPrefixedDBkey()
2491 . ' even though it exists with page ID ' . $pageId
2496 $row = $this->cache
->getWithSetCallback(
2497 // Page/rev IDs passed in from DB to reflect history merges
2498 $this->getRevisionRowCacheKey( $db, $pageId, $revId ),
2499 WANObjectCache
::TTL_WEEK
,
2500 function ( $curValue, &$ttl, array &$setOpts ) use ( $db, $pageId, $revId ) {
2501 $setOpts +
= Database
::getCacheSetOptions( $db );
2504 'rev_page' => intval( $pageId ),
2505 'page_id' => intval( $pageId ),
2506 'rev_id' => intval( $revId ),
2509 $row = $this->fetchRevisionRowFromConds( $db, $conds );
2510 return $row ?
: false; // don't cache negatives
2514 // Reflect revision deletion and user renames
2516 return $this->newRevisionFromRow( $row, 0, $title );
2523 * Get a cache key for use with a row as selected with getQueryInfo( [ 'page', 'user' ] )
2524 * Caching rows without 'page' or 'user' could lead to issues.
2525 * If the format of the rows returned by the query provided by getQueryInfo changes the
2526 * cache key should be updated to avoid conflicts.
2528 * @param IDatabase $db
2529 * @param int $pageId
2533 private function getRevisionRowCacheKey( IDatabase
$db, $pageId, $revId ) {
2534 return $this->cache
->makeGlobalKey(
2535 self
::ROW_CACHE_KEY
,
2542 // TODO: move relevant methods from Title here, e.g. getFirstRevision, isBigDeletion, etc.