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, without locking all extra tables.
900 $oldRevision = $this->loadRevisionFromId( $dbw, $pageLatest );
902 // Construct the new revision
903 $timestamp = wfTimestampNow(); // TODO: use a callback, so we can override it for testing.
904 $newRevision = MutableRevisionRecord
::newFromParentRevision( $oldRevision );
906 $newRevision->setComment( $comment );
907 $newRevision->setUser( $user );
908 $newRevision->setTimestamp( $timestamp );
909 $newRevision->setMinorEdit( $minor );
915 * MCR migration note: this replaces Revision::isUnpatrolled
917 * @todo This is overly specific, so move or kill this method.
919 * @param RevisionRecord $rev
921 * @return int Rcid of the unpatrolled row, zero if there isn't one
923 public function getRcIdIfUnpatrolled( RevisionRecord
$rev ) {
924 $rc = $this->getRecentChange( $rev );
925 if ( $rc && $rc->getAttribute( 'rc_patrolled' ) == RecentChange
::PRC_UNPATROLLED
) {
926 return $rc->getAttribute( 'rc_id' );
933 * Get the RC object belonging to the current revision, if there's one
935 * MCR migration note: this replaces Revision::getRecentChange
937 * @todo move this somewhere else?
939 * @param RevisionRecord $rev
940 * @param int $flags (optional) $flags include:
941 * IDBAccessObject::READ_LATEST: Select the data from the master
943 * @return null|RecentChange
945 public function getRecentChange( RevisionRecord
$rev, $flags = 0 ) {
946 $dbr = $this->getDBConnection( DB_REPLICA
);
948 list( $dbType, ) = DBAccessObjectUtils
::getDBOptions( $flags );
950 $userIdentity = $rev->getUser( RevisionRecord
::RAW
);
952 if ( !$userIdentity ) {
953 // If the revision has no user identity, chances are it never went
954 // into the database, and doesn't have an RC entry.
958 // TODO: Select by rc_this_oldid alone - but as of Nov 2017, there is no index on that!
959 $actorWhere = $this->actorMigration
->getWhere( $dbr, 'rc_user', $rev->getUser(), false );
960 $rc = RecentChange
::newFromConds(
962 $actorWhere['conds'],
963 'rc_timestamp' => $dbr->timestamp( $rev->getTimestamp() ),
964 'rc_this_oldid' => $rev->getId()
970 $this->releaseDBConnection( $dbr );
972 // XXX: cache this locally? Glue it to the RevisionRecord?
977 * Maps fields of the archive row to corresponding revision rows.
979 * @param object $archiveRow
981 * @return object a revision row object, corresponding to $archiveRow.
983 private static function mapArchiveFields( $archiveRow ) {
985 // keep with ar prefix:
988 // not the same suffix:
989 'ar_page_id' => 'rev_page',
990 'ar_rev_id' => 'rev_id',
993 'ar_text_id' => 'rev_text_id',
994 'ar_timestamp' => 'rev_timestamp',
995 'ar_user_text' => 'rev_user_text',
996 'ar_user' => 'rev_user',
997 'ar_actor' => 'rev_actor',
998 'ar_minor_edit' => 'rev_minor_edit',
999 'ar_deleted' => 'rev_deleted',
1000 'ar_len' => 'rev_len',
1001 'ar_parent_id' => 'rev_parent_id',
1002 'ar_sha1' => 'rev_sha1',
1003 'ar_comment' => 'rev_comment',
1004 'ar_comment_cid' => 'rev_comment_cid',
1005 'ar_comment_id' => 'rev_comment_id',
1006 'ar_comment_text' => 'rev_comment_text',
1007 'ar_comment_data' => 'rev_comment_data',
1008 'ar_comment_old' => 'rev_comment_old',
1009 'ar_content_format' => 'rev_content_format',
1010 'ar_content_model' => 'rev_content_model',
1013 $revRow = new stdClass();
1014 foreach ( $fieldMap as $arKey => $revKey ) {
1015 if ( property_exists( $archiveRow, $arKey ) ) {
1016 $revRow->$revKey = $archiveRow->$arKey;
1024 * Constructs a RevisionRecord for the revisions main slot, based on the MW1.29 schema.
1026 * @param object|array $row Either a database row or an array
1027 * @param int $queryFlags for callbacks
1028 * @param Title $title
1030 * @return SlotRecord The main slot, extracted from the MW 1.29 style row.
1031 * @throws MWException
1033 private function emulateMainSlot_1_29( $row, $queryFlags, Title
$title ) {
1034 $mainSlotRow = new stdClass();
1035 $mainSlotRow->role_name
= 'main';
1036 $mainSlotRow->model_name
= null;
1037 $mainSlotRow->slot_revision_id
= null;
1038 $mainSlotRow->content_address
= null;
1044 if ( is_object( $row ) ) {
1045 if ( $this->mcrMigrationStage
>= MIGRATION_NEW
) {
1046 // Don't emulate from a row when using the new schema.
1047 // Emulating from an array is still OK.
1048 throw new LogicException( 'Can\'t emulate the main slot when using MCR schema.' );
1052 if ( !isset( $row->rev_id
) && ( isset( $row->ar_user
) ||
isset( $row->ar_actor
) ) ) {
1053 $row = $this->mapArchiveFields( $row );
1056 if ( isset( $row->rev_text_id
) && $row->rev_text_id
> 0 ) {
1057 $mainSlotRow->content_address
= SqlBlobStore
::makeAddressFromTextId(
1062 // This is used by null-revisions
1063 $mainSlotRow->slot_origin
= isset( $row->slot_origin
)
1064 ?
intval( $row->slot_origin
)
1067 if ( isset( $row->old_text
) ) {
1068 // this happens when the text-table gets joined directly, in the pre-1.30 schema
1069 $blobData = isset( $row->old_text
) ?
strval( $row->old_text
) : null;
1070 // Check against selects that might have not included old_flags
1071 if ( !property_exists( $row, 'old_flags' ) ) {
1072 throw new InvalidArgumentException( 'old_flags was not set in $row' );
1074 $blobFlags = ( $row->old_flags
=== null ) ?
'' : $row->old_flags
;
1077 $mainSlotRow->slot_revision_id
= intval( $row->rev_id
);
1079 $mainSlotRow->content_size
= isset( $row->rev_len
) ?
intval( $row->rev_len
) : null;
1080 $mainSlotRow->content_sha1
= isset( $row->rev_sha1
) ?
strval( $row->rev_sha1
) : null;
1081 $mainSlotRow->model_name
= isset( $row->rev_content_model
)
1082 ?
strval( $row->rev_content_model
)
1084 // XXX: in the future, we'll probably always use the default format, and drop content_format
1085 $mainSlotRow->format_name
= isset( $row->rev_content_format
)
1086 ?
strval( $row->rev_content_format
)
1088 } elseif ( is_array( $row ) ) {
1089 $mainSlotRow->slot_revision_id
= isset( $row['id'] ) ?
intval( $row['id'] ) : null;
1091 $mainSlotRow->slot_origin
= isset( $row['slot_origin'] )
1092 ?
intval( $row['slot_origin'] )
1094 $mainSlotRow->content_address
= isset( $row['text_id'] )
1095 ? SqlBlobStore
::makeAddressFromTextId( intval( $row['text_id'] ) )
1097 $mainSlotRow->content_size
= isset( $row['len'] ) ?
intval( $row['len'] ) : null;
1098 $mainSlotRow->content_sha1
= isset( $row['sha1'] ) ?
strval( $row['sha1'] ) : null;
1100 $mainSlotRow->model_name
= isset( $row['content_model'] )
1101 ?
strval( $row['content_model'] ) : null; // XXX: must be a string!
1102 // XXX: in the future, we'll probably always use the default format, and drop content_format
1103 $mainSlotRow->format_name
= isset( $row['content_format'] )
1104 ?
strval( $row['content_format'] ) : null;
1105 $blobData = isset( $row['text'] ) ?
rtrim( strval( $row['text'] ) ) : null;
1106 // XXX: If the flags field is not set then $blobFlags should be null so that no
1107 // decoding will happen. An empty string will result in default decodings.
1108 $blobFlags = isset( $row['flags'] ) ?
trim( strval( $row['flags'] ) ) : null;
1110 // if we have a Content object, override mText and mContentModel
1111 if ( !empty( $row['content'] ) ) {
1112 if ( !( $row['content'] instanceof Content
) ) {
1113 throw new MWException( 'content field must contain a Content object.' );
1116 /** @var Content $content */
1117 $content = $row['content'];
1118 $handler = $content->getContentHandler();
1120 $mainSlotRow->model_name
= $content->getModel();
1122 // XXX: in the future, we'll probably always use the default format.
1123 if ( $mainSlotRow->format_name
=== null ) {
1124 $mainSlotRow->format_name
= $handler->getDefaultFormat();
1128 throw new MWException( 'Revision constructor passed invalid row format.' );
1131 // With the old schema, the content changes with every revision,
1132 // except for null-revisions.
1133 if ( !isset( $mainSlotRow->slot_origin
) ) {
1134 $mainSlotRow->slot_origin
= $mainSlotRow->slot_revision_id
;
1137 if ( $mainSlotRow->model_name
=== null ) {
1138 $mainSlotRow->model_name
= function ( SlotRecord
$slot ) use ( $title ) {
1139 // TODO: MCR: consider slot role in getDefaultModelFor()! Use LinkTarget!
1140 // TODO: MCR: deprecate $title->getModel().
1141 return ContentHandler
::getDefaultModelFor( $title );
1146 // XXX: We should perhaps fail if $blobData is null and $mainSlotRow->content_address
1147 // is missing, but "empty revisions" with no content are used in some edge cases.
1149 $content = function ( SlotRecord
$slot )
1150 use ( $blobData, $blobFlags, $queryFlags, $mainSlotRow )
1152 return $this->loadSlotContent(
1156 $mainSlotRow->format_name
,
1162 // NOTE: this callback will be looped through RevisionSlot::newInherited(), allowing
1163 // the inherited slot to have the same content_id as the original slot. In that case,
1164 // $slot will be the inherited slot, while $mainSlotRow still refers to the original slot.
1165 $mainSlotRow->slot_content_id
=
1166 function ( SlotRecord
$slot ) use ( $queryFlags, $mainSlotRow ) {
1167 list( $dbMode, ) = DBAccessObjectUtils
::getDBOptions( $queryFlags );
1168 $db = $this->getDBConnectionRef( $dbMode );
1169 return $this->findSlotContentId( $db, $mainSlotRow->slot_revision_id
, 'main' );
1172 return new SlotRecord( $mainSlotRow, $content );
1176 * Loads a Content object based on a slot row.
1178 * This method does not call $slot->getContent(), and may be used as a callback
1179 * called by $slot->getContent().
1181 * MCR migration note: this roughly corresponds to Revision::getContentInternal
1183 * @param SlotRecord $slot The SlotRecord to load content for
1184 * @param string|null $blobData The content blob, in the form indicated by $blobFlags
1185 * @param string|null $blobFlags Flags indicating how $blobData needs to be processed.
1186 * Use null if no processing should happen. That is in constrast to the empty string,
1187 * which causes the blob to be decoded according to the configured legacy encoding.
1188 * @param string|null $blobFormat MIME type indicating how $dataBlob is encoded
1189 * @param int $queryFlags
1191 * @throws RevisionAccessException
1194 private function loadSlotContent(
1201 if ( $blobData !== null ) {
1202 Assert
::parameterType( 'string', $blobData, '$blobData' );
1203 Assert
::parameterType( 'string|null', $blobFlags, '$blobFlags' );
1205 $cacheKey = $slot->hasAddress() ?
$slot->getAddress() : null;
1207 if ( $blobFlags === null ) {
1208 // No blob flags, so use the blob verbatim.
1211 $data = $this->blobStore
->expandBlob( $blobData, $blobFlags, $cacheKey );
1212 if ( $data === false ) {
1213 throw new RevisionAccessException(
1214 "Failed to expand blob data using flags $blobFlags (key: $cacheKey)"
1220 $address = $slot->getAddress();
1222 $data = $this->blobStore
->getBlob( $address, $queryFlags );
1223 } catch ( BlobAccessException
$e ) {
1224 throw new RevisionAccessException(
1225 "Failed to load data blob from $address: " . $e->getMessage(), 0, $e
1230 // Unserialize content
1231 $handler = ContentHandler
::getForModelID( $slot->getModel() );
1233 $content = $handler->unserializeContent( $data, $blobFormat );
1238 * Load a page revision from a given revision ID number.
1239 * Returns null if no such revision can be found.
1241 * MCR migration note: this replaces Revision::newFromId
1244 * IDBAccessObject::READ_LATEST: Select the data from the master
1245 * IDBAccessObject::READ_LOCKING : Select & lock the data from the master
1248 * @param int $flags (optional)
1249 * @return RevisionRecord|null
1251 public function getRevisionById( $id, $flags = 0 ) {
1252 return $this->newRevisionFromConds( [ 'rev_id' => intval( $id ) ], $flags );
1256 * Load either the current, or a specified, revision
1257 * that's attached to a given link target. If not attached
1258 * to that link target, will return null.
1260 * MCR migration note: this replaces Revision::newFromTitle
1263 * IDBAccessObject::READ_LATEST: Select the data from the master
1264 * IDBAccessObject::READ_LOCKING : Select & lock the data from the master
1266 * @param LinkTarget $linkTarget
1267 * @param int $revId (optional)
1268 * @param int $flags Bitfield (optional)
1269 * @return RevisionRecord|null
1271 public function getRevisionByTitle( LinkTarget
$linkTarget, $revId = 0, $flags = 0 ) {
1273 'page_namespace' => $linkTarget->getNamespace(),
1274 'page_title' => $linkTarget->getDBkey()
1277 // Use the specified revision ID.
1278 // Note that we use newRevisionFromConds here because we want to retry
1279 // and fall back to master if the page is not found on a replica.
1280 // Since the caller supplied a revision ID, we are pretty sure the revision is
1281 // supposed to exist, so we should try hard to find it.
1282 $conds['rev_id'] = $revId;
1283 return $this->newRevisionFromConds( $conds, $flags );
1285 // Use a join to get the latest revision.
1286 // Note that we don't use newRevisionFromConds here because we don't want to retry
1287 // and fall back to master. The assumption is that we only want to force the fallback
1288 // if we are quite sure the revision exists because the caller supplied a revision ID.
1289 // If the page isn't found at all on a replica, it probably simply does not exist.
1290 $db = $this->getDBConnection( ( $flags & self
::READ_LATEST
) ? DB_MASTER
: DB_REPLICA
);
1292 $conds[] = 'rev_id=page_latest';
1293 $rev = $this->loadRevisionFromConds( $db, $conds, $flags );
1295 $this->releaseDBConnection( $db );
1301 * Load either the current, or a specified, revision
1302 * that's attached to a given page ID.
1303 * Returns null if no such revision can be found.
1305 * MCR migration note: this replaces Revision::newFromPageId
1308 * IDBAccessObject::READ_LATEST: Select the data from the master (since 1.20)
1309 * IDBAccessObject::READ_LOCKING : Select & lock the data from the master
1311 * @param int $pageId
1312 * @param int $revId (optional)
1313 * @param int $flags Bitfield (optional)
1314 * @return RevisionRecord|null
1316 public function getRevisionByPageId( $pageId, $revId = 0, $flags = 0 ) {
1317 $conds = [ 'page_id' => $pageId ];
1319 // Use the specified revision ID.
1320 // Note that we use newRevisionFromConds here because we want to retry
1321 // and fall back to master if the page is not found on a replica.
1322 // Since the caller supplied a revision ID, we are pretty sure the revision is
1323 // supposed to exist, so we should try hard to find it.
1324 $conds['rev_id'] = $revId;
1325 return $this->newRevisionFromConds( $conds, $flags );
1327 // Use a join to get the latest revision.
1328 // Note that we don't use newRevisionFromConds here because we don't want to retry
1329 // and fall back to master. The assumption is that we only want to force the fallback
1330 // if we are quite sure the revision exists because the caller supplied a revision ID.
1331 // If the page isn't found at all on a replica, it probably simply does not exist.
1332 $db = $this->getDBConnection( ( $flags & self
::READ_LATEST
) ? DB_MASTER
: DB_REPLICA
);
1334 $conds[] = 'rev_id=page_latest';
1335 $rev = $this->loadRevisionFromConds( $db, $conds, $flags );
1337 $this->releaseDBConnection( $db );
1343 * Load the revision for the given title with the given timestamp.
1344 * WARNING: Timestamps may in some circumstances not be unique,
1345 * so this isn't the best key to use.
1347 * MCR migration note: this replaces Revision::loadFromTimestamp
1349 * @param Title $title
1350 * @param string $timestamp
1351 * @return RevisionRecord|null
1353 public function getRevisionByTimestamp( $title, $timestamp ) {
1354 $db = $this->getDBConnection( DB_REPLICA
);
1355 return $this->newRevisionFromConds(
1357 'rev_timestamp' => $db->timestamp( $timestamp ),
1358 'page_namespace' => $title->getNamespace(),
1359 'page_title' => $title->getDBkey()
1367 * @param int $revId The revision to load slots for.
1368 * @param int $queryFlags
1370 * @return SlotRecord[]
1372 private function loadSlotRecords( $revId, $queryFlags ) {
1373 $revQuery = self
::getSlotsQueryInfo( [ 'content' ] );
1375 list( $dbMode, $dbOptions ) = DBAccessObjectUtils
::getDBOptions( $queryFlags );
1376 $db = $this->getDBConnectionRef( $dbMode );
1379 $revQuery['tables'],
1380 $revQuery['fields'],
1382 'slot_revision_id' => $revId,
1391 foreach ( $res as $row ) {
1392 $contentCallback = function ( SlotRecord
$slot ) use ( $queryFlags, $row ) {
1393 return $this->loadSlotContent( $slot, null, null, null, $queryFlags );
1396 $slots[$row->role_name
] = new SlotRecord( $row, $contentCallback );
1399 if ( !isset( $slots['main'] ) ) {
1400 throw new RevisionAccessException(
1401 'Main slot of revision ' . $revId . ' not found in database!'
1409 * Factory method for RevisionSlots.
1411 * @note If other code has a need to construct RevisionSlots objects, this should be made
1412 * public, since RevisionSlots instances should not be constructed directly.
1415 * @param object $revisionRow
1416 * @param int $queryFlags
1417 * @param Title $title
1419 * @return RevisionSlots
1420 * @throws MWException
1422 private function newRevisionSlots(
1428 if ( $this->mcrMigrationStage
< MIGRATION_NEW
) {
1429 // TODO: in MIGRATION_WRITE_BOTH, we could use the old and the new method:
1430 // e.g. call emulateMainSlot_1_29() if loadSlotRecords() fails.
1432 $mainSlot = $this->emulateMainSlot_1_29( $revisionRow, $queryFlags, $title );
1433 $slots = new RevisionSlots( [ 'main' => $mainSlot ] );
1435 // XXX: do we need the same kind of caching here
1436 // that getKnownCurrentRevision uses (if $revId == page_latest?)
1438 $slots = new RevisionSlots( function () use( $revId, $queryFlags ) {
1439 return $this->loadSlotRecords( $revId, $queryFlags );
1447 * Make a fake revision object from an archive table row. This is queried
1448 * for permissions or even inserted (as in Special:Undelete)
1450 * MCR migration note: this replaces Revision::newFromArchiveRow
1452 * @param object $row
1453 * @param int $queryFlags
1454 * @param Title|null $title
1455 * @param array $overrides associative array with fields of $row to override. This may be
1456 * used e.g. to force the parent revision ID or page ID. Keys in the array are fields
1457 * names from the archive table without the 'ar_' prefix, i.e. use 'parent_id' to
1458 * override ar_parent_id.
1460 * @return RevisionRecord
1461 * @throws MWException
1463 public function newRevisionFromArchiveRow(
1466 Title
$title = null,
1467 array $overrides = []
1469 Assert
::parameterType( 'object', $row, '$row' );
1471 // check second argument, since Revision::newFromArchiveRow had $overrides in that spot.
1472 Assert
::parameterType( 'integer', $queryFlags, '$queryFlags' );
1474 if ( !$title && isset( $overrides['title'] ) ) {
1475 if ( !( $overrides['title'] instanceof Title
) ) {
1476 throw new MWException( 'title field override must contain a Title object.' );
1479 $title = $overrides['title'];
1482 if ( !isset( $title ) ) {
1483 if ( isset( $row->ar_namespace
) && isset( $row->ar_title
) ) {
1484 $title = Title
::makeTitle( $row->ar_namespace
, $row->ar_title
);
1486 throw new InvalidArgumentException(
1487 'A Title or ar_namespace and ar_title must be given'
1492 foreach ( $overrides as $key => $value ) {
1494 $row->$field = $value;
1498 $user = User
::newFromAnyId(
1499 $row->ar_user ??
null,
1500 $row->ar_user_text ??
null,
1501 $row->ar_actor ??
null
1503 } catch ( InvalidArgumentException
$ex ) {
1504 wfWarn( __METHOD__
. ': ' . $ex->getMessage() );
1505 $user = new UserIdentityValue( 0, '', 0 );
1508 $comment = $this->commentStore
1509 // Legacy because $row may have come from self::selectFields()
1510 ->getCommentLegacy( $this->getDBConnection( DB_REPLICA
), 'ar_comment', $row, true );
1512 $slots = $this->newRevisionSlots( $row->ar_rev_id
, $row, $queryFlags, $title );
1514 return new RevisionArchiveRecord( $title, $user, $comment, $row, $slots, $this->wikiId
);
1518 * @see RevisionFactory::newRevisionFromRow
1520 * MCR migration note: this replaces Revision::newFromRow
1522 * @param object $row
1523 * @param int $queryFlags
1524 * @param Title|null $title
1526 * @return RevisionRecord
1528 public function newRevisionFromRow( $row, $queryFlags = 0, Title
$title = null ) {
1529 Assert
::parameterType( 'object', $row, '$row' );
1532 $pageId = $row->rev_page ??
0; // XXX: also check page_id?
1533 $revId = $row->rev_id ??
0;
1535 $title = $this->getTitle( $pageId, $revId, $queryFlags );
1538 if ( !isset( $row->page_latest
) ) {
1539 $row->page_latest
= $title->getLatestRevID();
1540 if ( $row->page_latest
=== 0 && $title->exists() ) {
1541 wfWarn( 'Encountered title object in limbo: ID ' . $title->getArticleID() );
1546 $user = User
::newFromAnyId(
1547 $row->rev_user ??
null,
1548 $row->rev_user_text ??
null,
1549 $row->rev_actor ??
null
1551 } catch ( InvalidArgumentException
$ex ) {
1552 wfWarn( __METHOD__
. ': ' . $ex->getMessage() );
1553 $user = new UserIdentityValue( 0, '', 0 );
1556 $comment = $this->commentStore
1557 // Legacy because $row may have come from self::selectFields()
1558 ->getCommentLegacy( $this->getDBConnection( DB_REPLICA
), 'rev_comment', $row, true );
1560 $slots = $this->newRevisionSlots( $row->rev_id
, $row, $queryFlags, $title );
1562 return new RevisionStoreRecord( $title, $user, $comment, $row, $slots, $this->wikiId
);
1566 * Constructs a new MutableRevisionRecord based on the given associative array following
1567 * the MW1.29 convention for the Revision constructor.
1569 * MCR migration note: this replaces Revision::newFromRow
1571 * @param array $fields
1572 * @param int $queryFlags
1573 * @param Title|null $title
1575 * @return MutableRevisionRecord
1576 * @throws MWException
1577 * @throws RevisionAccessException
1579 public function newMutableRevisionFromArray(
1584 if ( !$title && isset( $fields['title'] ) ) {
1585 if ( !( $fields['title'] instanceof Title
) ) {
1586 throw new MWException( 'title field must contain a Title object.' );
1589 $title = $fields['title'];
1593 $pageId = $fields['page'] ??
0;
1594 $revId = $fields['id'] ??
0;
1596 $title = $this->getTitle( $pageId, $revId, $queryFlags );
1599 if ( !isset( $fields['page'] ) ) {
1600 $fields['page'] = $title->getArticleID( $queryFlags );
1603 // if we have a content object, use it to set the model and type
1604 if ( !empty( $fields['content'] ) ) {
1605 if ( !( $fields['content'] instanceof Content
) && !is_array( $fields['content'] ) ) {
1606 throw new MWException(
1607 'content field must contain a Content object or an array of Content objects.'
1612 if ( !empty( $fields['text_id'] ) ) {
1613 if ( $this->mcrMigrationStage
>= MIGRATION_NEW
) {
1614 throw new MWException( "Cannot use text_id field with MCR schema" );
1617 if ( !empty( $fields['content'] ) ) {
1618 throw new MWException(
1619 "Text already stored in external store (id {$fields['text_id']}), " .
1620 "can't specify content object"
1626 isset( $fields['comment'] )
1627 && !( $fields['comment'] instanceof CommentStoreComment
)
1629 $commentData = $fields['comment_data'] ??
null;
1631 if ( $fields['comment'] instanceof Message
) {
1632 $fields['comment'] = CommentStoreComment
::newUnsavedComment(
1637 $commentText = trim( strval( $fields['comment'] ) );
1638 $fields['comment'] = CommentStoreComment
::newUnsavedComment(
1645 $revision = new MutableRevisionRecord( $title, $this->wikiId
);
1646 $this->initializeMutableRevisionFromArray( $revision, $fields );
1648 if ( isset( $fields['content'] ) && is_array( $fields['content'] ) ) {
1649 foreach ( $fields['content'] as $role => $content ) {
1650 $revision->setContent( $role, $content );
1653 $mainSlot = $this->emulateMainSlot_1_29( $fields, $queryFlags, $title );
1654 $revision->setSlot( $mainSlot );
1661 * @param MutableRevisionRecord $record
1662 * @param array $fields
1664 private function initializeMutableRevisionFromArray(
1665 MutableRevisionRecord
$record,
1668 /** @var UserIdentity $user */
1671 if ( isset( $fields['user'] ) && ( $fields['user'] instanceof UserIdentity
) ) {
1672 $user = $fields['user'];
1675 $user = User
::newFromAnyId(
1676 $fields['user'] ??
null,
1677 $fields['user_text'] ??
null,
1678 $fields['actor'] ??
null
1680 } catch ( InvalidArgumentException
$ex ) {
1686 $record->setUser( $user );
1689 $timestamp = isset( $fields['timestamp'] )
1690 ?
strval( $fields['timestamp'] )
1691 : wfTimestampNow(); // TODO: use a callback, so we can override it for testing.
1693 $record->setTimestamp( $timestamp );
1695 if ( isset( $fields['page'] ) ) {
1696 $record->setPageId( intval( $fields['page'] ) );
1699 if ( isset( $fields['id'] ) ) {
1700 $record->setId( intval( $fields['id'] ) );
1702 if ( isset( $fields['parent_id'] ) ) {
1703 $record->setParentId( intval( $fields['parent_id'] ) );
1706 if ( isset( $fields['sha1'] ) ) {
1707 $record->setSha1( $fields['sha1'] );
1709 if ( isset( $fields['size'] ) ) {
1710 $record->setSize( intval( $fields['size'] ) );
1713 if ( isset( $fields['minor_edit'] ) ) {
1714 $record->setMinorEdit( intval( $fields['minor_edit'] ) !== 0 );
1716 if ( isset( $fields['deleted'] ) ) {
1717 $record->setVisibility( intval( $fields['deleted'] ) );
1720 if ( isset( $fields['comment'] ) ) {
1721 Assert
::parameterType(
1722 CommentStoreComment
::class,
1726 $record->setComment( $fields['comment'] );
1731 * Load a page revision from a given revision ID number.
1732 * Returns null if no such revision can be found.
1734 * MCR migration note: this corresponds to Revision::loadFromId
1736 * @note direct use is deprecated!
1737 * @todo remove when unused! there seem to be no callers of Revision::loadFromId
1739 * @param IDatabase $db
1742 * @return RevisionRecord|null
1744 public function loadRevisionFromId( IDatabase
$db, $id ) {
1745 return $this->loadRevisionFromConds( $db, [ 'rev_id' => intval( $id ) ] );
1749 * Load either the current, or a specified, revision
1750 * that's attached to a given page. If not attached
1751 * to that page, will return null.
1753 * MCR migration note: this replaces Revision::loadFromPageId
1755 * @note direct use is deprecated!
1756 * @todo remove when unused!
1758 * @param IDatabase $db
1759 * @param int $pageid
1761 * @return RevisionRecord|null
1763 public function loadRevisionFromPageId( IDatabase
$db, $pageid, $id = 0 ) {
1764 $conds = [ 'rev_page' => intval( $pageid ), 'page_id' => intval( $pageid ) ];
1766 $conds['rev_id'] = intval( $id );
1768 $conds[] = 'rev_id=page_latest';
1770 return $this->loadRevisionFromConds( $db, $conds );
1774 * Load either the current, or a specified, revision
1775 * that's attached to a given page. If not attached
1776 * to that page, will return null.
1778 * MCR migration note: this replaces Revision::loadFromTitle
1780 * @note direct use is deprecated!
1781 * @todo remove when unused!
1783 * @param IDatabase $db
1784 * @param Title $title
1787 * @return RevisionRecord|null
1789 public function loadRevisionFromTitle( IDatabase
$db, $title, $id = 0 ) {
1791 $matchId = intval( $id );
1793 $matchId = 'page_latest';
1796 return $this->loadRevisionFromConds(
1800 'page_namespace' => $title->getNamespace(),
1801 'page_title' => $title->getDBkey()
1809 * Load the revision for the given title with the given timestamp.
1810 * WARNING: Timestamps may in some circumstances not be unique,
1811 * so this isn't the best key to use.
1813 * MCR migration note: this replaces Revision::loadFromTimestamp
1815 * @note direct use is deprecated! Use getRevisionFromTimestamp instead!
1816 * @todo remove when unused!
1818 * @param IDatabase $db
1819 * @param Title $title
1820 * @param string $timestamp
1821 * @return RevisionRecord|null
1823 public function loadRevisionFromTimestamp( IDatabase
$db, $title, $timestamp ) {
1824 return $this->loadRevisionFromConds( $db,
1826 'rev_timestamp' => $db->timestamp( $timestamp ),
1827 'page_namespace' => $title->getNamespace(),
1828 'page_title' => $title->getDBkey()
1836 * Given a set of conditions, fetch a revision
1838 * This method should be used if we are pretty sure the revision exists.
1839 * Unless $flags has READ_LATEST set, this method will first try to find the revision
1840 * on a replica before hitting the master database.
1842 * MCR migration note: this corresponds to Revision::newFromConds
1844 * @param array $conditions
1845 * @param int $flags (optional)
1846 * @param Title $title
1848 * @return RevisionRecord|null
1850 private function newRevisionFromConds( $conditions, $flags = 0, Title
$title = null ) {
1851 $db = $this->getDBConnection( ( $flags & self
::READ_LATEST
) ? DB_MASTER
: DB_REPLICA
);
1852 $rev = $this->loadRevisionFromConds( $db, $conditions, $flags, $title );
1853 $this->releaseDBConnection( $db );
1855 $lb = $this->getDBLoadBalancer();
1857 // Make sure new pending/committed revision are visibile later on
1858 // within web requests to certain avoid bugs like T93866 and T94407.
1860 && !( $flags & self
::READ_LATEST
)
1861 && $lb->getServerCount() > 1
1862 && $lb->hasOrMadeRecentMasterChanges()
1864 $flags = self
::READ_LATEST
;
1865 $db = $this->getDBConnection( DB_MASTER
);
1866 $rev = $this->loadRevisionFromConds( $db, $conditions, $flags, $title );
1867 $this->releaseDBConnection( $db );
1874 * Given a set of conditions, fetch a revision from
1875 * the given database connection.
1877 * MCR migration note: this corresponds to Revision::loadFromConds
1879 * @param IDatabase $db
1880 * @param array $conditions
1881 * @param int $flags (optional)
1882 * @param Title $title
1884 * @return RevisionRecord|null
1886 private function loadRevisionFromConds(
1892 $row = $this->fetchRevisionRowFromConds( $db, $conditions, $flags );
1894 $rev = $this->newRevisionFromRow( $row, $flags, $title );
1903 * Throws an exception if the given database connection does not belong to the wiki this
1904 * RevisionStore is bound to.
1906 * @param IDatabase $db
1907 * @throws MWException
1909 private function checkDatabaseWikiId( IDatabase
$db ) {
1910 $storeWiki = $this->wikiId
;
1911 $dbWiki = $db->getDomainID();
1913 if ( $dbWiki === $storeWiki ) {
1917 // XXX: we really want the default database ID...
1918 $storeWiki = $storeWiki ?
: wfWikiID();
1919 $dbWiki = $dbWiki ?
: wfWikiID();
1921 if ( $dbWiki === $storeWiki ) {
1925 // HACK: counteract encoding imposed by DatabaseDomain
1926 $storeWiki = str_replace( '?h', '-', $storeWiki );
1927 $dbWiki = str_replace( '?h', '-', $dbWiki );
1929 if ( $dbWiki === $storeWiki ) {
1933 throw new MWException( "RevisionStore for $storeWiki "
1934 . "cannot be used with a DB connection for $dbWiki" );
1938 * Given a set of conditions, return a row with the
1939 * fields necessary to build RevisionRecord objects.
1941 * MCR migration note: this corresponds to Revision::fetchFromConds
1943 * @param IDatabase $db
1944 * @param array $conditions
1945 * @param int $flags (optional)
1947 * @return object|false data row as a raw object
1949 private function fetchRevisionRowFromConds( IDatabase
$db, $conditions, $flags = 0 ) {
1950 $this->checkDatabaseWikiId( $db );
1952 $revQuery = $this->getQueryInfo( [ 'page', 'user' ] );
1954 if ( ( $flags & self
::READ_LOCKING
) == self
::READ_LOCKING
) {
1955 $options[] = 'FOR UPDATE';
1957 return $db->selectRow(
1958 $revQuery['tables'],
1959 $revQuery['fields'],
1968 * Finds the ID of a content row for a given revision and slot role.
1969 * This can be used to re-use content rows even while the content ID
1970 * is still missing from SlotRecords, in MIGRATION_WRITE_BOTH mode.
1972 * @todo remove after MCR schema migration is complete.
1974 * @param IDatabase $db
1976 * @param string $role
1980 private function findSlotContentId( IDatabase
$db, $revId, $role ) {
1981 if ( $this->mcrMigrationStage
< MIGRATION_WRITE_BOTH
) {
1986 $roleId = $this->slotRoleStore
->getId( $role );
1988 'slot_revision_id' => $revId,
1989 'slot_role_id' => $roleId,
1992 $contentId = $db->selectField( 'slots', 'slot_content_id', $conditions, __METHOD__
);
1994 return $contentId ?
: null;
1995 } catch ( NameTableAccessException
$ex ) {
1996 // If the role is missing from the slot_roles table,
1997 // the corresponding row in slots cannot exist.
2003 * Return the tables, fields, and join conditions to be selected to create
2004 * a new RevisionStoreRecord object.
2006 * MCR migration note: this replaces Revision::getQueryInfo
2008 * If the format of fields returned changes in any way then the cache key provided by
2009 * self::getRevisionRowCacheKey should be updated.
2013 * @param array $options Any combination of the following strings
2014 * - 'page': Join with the page table, and select fields to identify the page
2015 * - 'user': Join with the user table, and select the user name
2016 * - 'text': Join with the text table, and select fields to load page text. This
2017 * option is deprecated in MW 1.32 with MCR migration stage MIGRATION_WRITE_BOTH,
2018 * and disallowed with MIGRATION_MEW.
2020 * @return array With three keys:
2021 * - tables: (string[]) to include in the `$table` to `IDatabase->select()`
2022 * - fields: (string[]) to include in the `$vars` to `IDatabase->select()`
2023 * - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
2025 public function getQueryInfo( $options = [] ) {
2032 $ret['tables'][] = 'revision';
2033 $ret['fields'] = array_merge( $ret['fields'], [
2044 $commentQuery = $this->commentStore
->getJoin( 'rev_comment' );
2045 $ret['tables'] = array_merge( $ret['tables'], $commentQuery['tables'] );
2046 $ret['fields'] = array_merge( $ret['fields'], $commentQuery['fields'] );
2047 $ret['joins'] = array_merge( $ret['joins'], $commentQuery['joins'] );
2049 $actorQuery = $this->actorMigration
->getJoin( 'rev_user' );
2050 $ret['tables'] = array_merge( $ret['tables'], $actorQuery['tables'] );
2051 $ret['fields'] = array_merge( $ret['fields'], $actorQuery['fields'] );
2052 $ret['joins'] = array_merge( $ret['joins'], $actorQuery['joins'] );
2054 if ( $this->mcrMigrationStage
< MIGRATION_NEW
) {
2055 $ret['fields'][] = 'rev_text_id';
2057 if ( $this->contentHandlerUseDB
) {
2058 $ret['fields'][] = 'rev_content_format';
2059 $ret['fields'][] = 'rev_content_model';
2063 if ( in_array( 'page', $options, true ) ) {
2064 $ret['tables'][] = 'page';
2065 $ret['fields'] = array_merge( $ret['fields'], [
2073 $ret['joins']['page'] = [ 'INNER JOIN', [ 'page_id = rev_page' ] ];
2076 if ( in_array( 'user', $options, true ) ) {
2077 $ret['tables'][] = 'user';
2078 $ret['fields'] = array_merge( $ret['fields'], [
2081 $u = $actorQuery['fields']['rev_user'];
2082 $ret['joins']['user'] = [ 'LEFT JOIN', [ "$u != 0", "user_id = $u" ] ];
2085 if ( in_array( 'text', $options, true ) ) {
2086 if ( $this->mcrMigrationStage
=== MIGRATION_NEW
) {
2087 throw new InvalidArgumentException( 'text table can no longer be joined directly' );
2088 } elseif ( $this->mcrMigrationStage
>= MIGRATION_WRITE_BOTH
) {
2089 wfDeprecated( __METHOD__
. ' with `text` option', '1.32' );
2092 $ret['tables'][] = 'text';
2093 $ret['fields'] = array_merge( $ret['fields'], [
2097 $ret['joins']['text'] = [ 'INNER JOIN', [ 'rev_text_id=old_id' ] ];
2104 * Return the tables, fields, and join conditions to be selected to create
2109 * @param array $options Any combination of the following strings
2110 * - 'content': Join with the content table, and select content meta-data fields
2112 * @return array With three keys:
2113 * - tables: (string[]) to include in the `$table` to `IDatabase->select()`
2114 * - fields: (string[]) to include in the `$vars` to `IDatabase->select()`
2115 * - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
2117 public function getSlotsQueryInfo( $options = [] ) {
2124 if ( $this->mcrMigrationStage
< MIGRATION_NEW
) {
2125 $db = $this->getDBConnectionRef( DB_REPLICA
);
2126 $ret['tables']['slots'] = 'revision';
2128 $ret['fields']['slot_revision_id'] = 'slots.rev_id';
2129 $ret['fields']['slot_content_id'] = 'NULL';
2130 $ret['fields']['slot_origin'] = 'slots.rev_id';
2131 $ret['fields']['role_name'] = $db->addQuotes( 'main' );
2133 if ( in_array( 'content', $options, true ) ) {
2134 $ret['fields']['content_size'] = 'slots.rev_len';
2135 $ret['fields']['content_sha1'] = 'slots.rev_sha1';
2136 $ret['fields']['content_address']
2137 = $db->buildConcat( [ $db->addQuotes( 'tt:' ), 'slots.rev_text_id' ] );
2139 if ( $this->contentHandlerUseDB
) {
2140 $ret['fields']['model_name'] = 'slots.rev_content_model';
2142 $ret['fields']['model_name'] = 'NULL';
2146 // XXX: in MIGRATION_WRITE_BOTH mode, emulate *and* select - using a UNION?
2147 // See Anomie's idea at <https://gerrit.wikimedia.org/r/c/416465/
2148 // 8..10/includes/Storage/RevisionStore.php#2113>
2150 $ret['tables'][] = 'slots';
2151 $ret['tables'][] = 'slot_roles';
2152 $ret['fields'] = array_merge( $ret['fields'], [
2158 $ret['joins']['slot_roles'] = [ 'INNER JOIN', [ 'slot_role_id = role_id' ] ];
2160 if ( in_array( 'content', $options, true ) ) {
2161 $ret['tables'][] = 'content';
2162 $ret['tables'][] = 'content_models';
2163 $ret['fields'] = array_merge( $ret['fields'], [
2169 $ret['joins']['content'] = [ 'INNER JOIN', [ 'slot_content_id = content_id' ] ];
2170 $ret['joins']['content_models'] = [ 'INNER JOIN', [ 'content_model = model_id' ] ];
2178 * Return the tables, fields, and join conditions to be selected to create
2179 * a new RevisionArchiveRecord object.
2181 * MCR migration note: this replaces Revision::getArchiveQueryInfo
2185 * @return array With three keys:
2186 * - tables: (string[]) to include in the `$table` to `IDatabase->select()`
2187 * - fields: (string[]) to include in the `$vars` to `IDatabase->select()`
2188 * - joins: (array) to include in the `$join_conds` to `IDatabase->select()`
2190 public function getArchiveQueryInfo() {
2191 $commentQuery = $this->commentStore
->getJoin( 'ar_comment' );
2192 $actorQuery = $this->actorMigration
->getJoin( 'ar_user' );
2194 'tables' => [ 'archive' ] +
$commentQuery['tables'] +
$actorQuery['tables'],
2207 ] +
$commentQuery['fields'] +
$actorQuery['fields'],
2208 'joins' => $commentQuery['joins'] +
$actorQuery['joins'],
2211 if ( $this->mcrMigrationStage
< MIGRATION_NEW
) {
2212 $ret['fields'][] = 'ar_text_id';
2214 if ( $this->contentHandlerUseDB
) {
2215 $ret['fields'][] = 'ar_content_format';
2216 $ret['fields'][] = 'ar_content_model';
2224 * Do a batched query for the sizes of a set of revisions.
2226 * MCR migration note: this replaces Revision::getParentLengths
2228 * @param int[] $revIds
2229 * @return int[] associative array mapping revision IDs from $revIds to the nominal size
2230 * of the corresponding revision.
2232 public function getRevisionSizes( array $revIds ) {
2233 return $this->listRevisionSizes( $this->getDBConnection( DB_REPLICA
), $revIds );
2237 * Do a batched query for the sizes of a set of revisions.
2239 * MCR migration note: this replaces Revision::getParentLengths
2241 * @deprecated use RevisionStore::getRevisionSizes instead.
2243 * @param IDatabase $db
2244 * @param int[] $revIds
2245 * @return int[] associative array mapping revision IDs from $revIds to the nominal size
2246 * of the corresponding revision.
2248 public function listRevisionSizes( IDatabase
$db, array $revIds ) {
2249 $this->checkDatabaseWikiId( $db );
2253 return $revLens; // empty
2258 [ 'rev_id', 'rev_len' ],
2259 [ 'rev_id' => $revIds ],
2263 foreach ( $res as $row ) {
2264 $revLens[$row->rev_id
] = intval( $row->rev_len
);
2271 * Get previous revision for this title
2273 * MCR migration note: this replaces Revision::getPrevious
2275 * @param RevisionRecord $rev
2276 * @param Title $title if known (optional)
2278 * @return RevisionRecord|null
2280 public function getPreviousRevision( RevisionRecord
$rev, Title
$title = null ) {
2281 if ( $title === null ) {
2282 $title = $this->getTitle( $rev->getPageId(), $rev->getId() );
2284 $prev = $title->getPreviousRevisionID( $rev->getId() );
2286 return $this->getRevisionByTitle( $title, $prev );
2292 * Get next revision for this title
2294 * MCR migration note: this replaces Revision::getNext
2296 * @param RevisionRecord $rev
2297 * @param Title $title if known (optional)
2299 * @return RevisionRecord|null
2301 public function getNextRevision( RevisionRecord
$rev, Title
$title = null ) {
2302 if ( $title === null ) {
2303 $title = $this->getTitle( $rev->getPageId(), $rev->getId() );
2305 $next = $title->getNextRevisionID( $rev->getId() );
2307 return $this->getRevisionByTitle( $title, $next );
2313 * Get previous revision Id for this page_id
2314 * This is used to populate rev_parent_id on save
2316 * MCR migration note: this corresponds to Revision::getPreviousRevisionId
2318 * @param IDatabase $db
2319 * @param RevisionRecord $rev
2323 private function getPreviousRevisionId( IDatabase
$db, RevisionRecord
$rev ) {
2324 $this->checkDatabaseWikiId( $db );
2326 if ( $rev->getPageId() === null ) {
2329 # Use page_latest if ID is not given
2330 if ( !$rev->getId() ) {
2331 $prevId = $db->selectField(
2332 'page', 'page_latest',
2333 [ 'page_id' => $rev->getPageId() ],
2337 $prevId = $db->selectField(
2338 'revision', 'rev_id',
2339 [ 'rev_page' => $rev->getPageId(), 'rev_id < ' . $rev->getId() ],
2341 [ 'ORDER BY' => 'rev_id DESC' ]
2344 return intval( $prevId );
2348 * Get rev_timestamp from rev_id, without loading the rest of the row
2350 * MCR migration note: this replaces Revision::getTimestampFromId
2352 * @param Title $title
2355 * @return string|bool False if not found
2357 public function getTimestampFromId( $title, $id, $flags = 0 ) {
2358 $db = $this->getDBConnection(
2359 ( $flags & IDBAccessObject
::READ_LATEST
) ? DB_MASTER
: DB_REPLICA
2362 $conds = [ 'rev_id' => $id ];
2363 $conds['rev_page'] = $title->getArticleID();
2364 $timestamp = $db->selectField( 'revision', 'rev_timestamp', $conds, __METHOD__
);
2366 $this->releaseDBConnection( $db );
2367 return ( $timestamp !== false ) ?
wfTimestamp( TS_MW
, $timestamp ) : false;
2371 * Get count of revisions per page...not very efficient
2373 * MCR migration note: this replaces Revision::countByPageId
2375 * @param IDatabase $db
2376 * @param int $id Page id
2379 public function countRevisionsByPageId( IDatabase
$db, $id ) {
2380 $this->checkDatabaseWikiId( $db );
2382 $row = $db->selectRow( 'revision',
2383 [ 'revCount' => 'COUNT(*)' ],
2384 [ 'rev_page' => $id ],
2388 return intval( $row->revCount
);
2394 * Get count of revisions per page...not very efficient
2396 * MCR migration note: this replaces Revision::countByTitle
2398 * @param IDatabase $db
2399 * @param Title $title
2402 public function countRevisionsByTitle( IDatabase
$db, $title ) {
2403 $id = $title->getArticleID();
2405 return $this->countRevisionsByPageId( $db, $id );
2411 * Check if no edits were made by other users since
2412 * the time a user started editing the page. Limit to
2413 * 50 revisions for the sake of performance.
2415 * MCR migration note: this replaces Revision::userWasLastToEdit
2417 * @deprecated since 1.31; Can possibly be removed, since the self-conflict suppression
2418 * logic in EditPage that uses this seems conceptually dubious. Revision::userWasLastToEdit
2419 * has been deprecated since 1.24.
2421 * @param IDatabase $db The Database to perform the check on.
2422 * @param int $pageId The ID of the page in question
2423 * @param int $userId The ID of the user in question
2424 * @param string $since Look at edits since this time
2426 * @return bool True if the given user was the only one to edit since the given timestamp
2428 public function userWasLastToEdit( IDatabase
$db, $pageId, $userId, $since ) {
2429 $this->checkDatabaseWikiId( $db );
2435 $revQuery = $this->getQueryInfo();
2437 $revQuery['tables'],
2439 'rev_user' => $revQuery['fields']['rev_user'],
2442 'rev_page' => $pageId,
2443 'rev_timestamp > ' . $db->addQuotes( $db->timestamp( $since ) )
2446 [ 'ORDER BY' => 'rev_timestamp ASC', 'LIMIT' => 50 ],
2449 foreach ( $res as $row ) {
2450 if ( $row->rev_user
!= $userId ) {
2458 * Load a revision based on a known page ID and current revision ID from the DB
2460 * This method allows for the use of caching, though accessing anything that normally
2461 * requires permission checks (aside from the text) will trigger a small DB lookup.
2463 * MCR migration note: this replaces Revision::newKnownCurrent
2465 * @param Title $title the associated page title
2466 * @param int $revId current revision of this page. Defaults to $title->getLatestRevID().
2468 * @return RevisionRecord|bool Returns false if missing
2470 public function getKnownCurrentRevision( Title
$title, $revId ) {
2471 $db = $this->getDBConnectionRef( DB_REPLICA
);
2473 $pageId = $title->getArticleID();
2480 $revId = $title->getLatestRevID();
2485 'No latest revision known for page ' . $title->getPrefixedDBkey()
2486 . ' even though it exists with page ID ' . $pageId
2491 $row = $this->cache
->getWithSetCallback(
2492 // Page/rev IDs passed in from DB to reflect history merges
2493 $this->getRevisionRowCacheKey( $db, $pageId, $revId ),
2494 WANObjectCache
::TTL_WEEK
,
2495 function ( $curValue, &$ttl, array &$setOpts ) use ( $db, $pageId, $revId ) {
2496 $setOpts +
= Database
::getCacheSetOptions( $db );
2499 'rev_page' => intval( $pageId ),
2500 'page_id' => intval( $pageId ),
2501 'rev_id' => intval( $revId ),
2504 $row = $this->fetchRevisionRowFromConds( $db, $conds );
2505 return $row ?
: false; // don't cache negatives
2509 // Reflect revision deletion and user renames
2511 return $this->newRevisionFromRow( $row, 0, $title );
2518 * Get a cache key for use with a row as selected with getQueryInfo( [ 'page', 'user' ] )
2519 * Caching rows without 'page' or 'user' could lead to issues.
2520 * If the format of the rows returned by the query provided by getQueryInfo changes the
2521 * cache key should be updated to avoid conflicts.
2523 * @param IDatabase $db
2524 * @param int $pageId
2528 private function getRevisionRowCacheKey( IDatabase
$db, $pageId, $revId ) {
2529 return $this->cache
->makeGlobalKey(
2530 self
::ROW_CACHE_KEY
,
2537 // TODO: move relevant methods from Title here, e.g. getFirstRevision, isBigDeletion, etc.