37use InvalidArgumentException;
51use Psr\Log\LoggerAwareInterface;
52use Psr\Log\LoggerInterface;
53use Psr\Log\NullLogger;
61use Wikimedia\Assert\Assert;
166 Assert::parameterType(
'string|boolean',
$wikiId,
'$wikiId' );
170 '$mcrMigrationStage',
171 'Reading from the old and the new schema at the same time is not supported.'
175 '$mcrMigrationStage',
176 'Reading needs to be enabled for the old or the new schema.'
180 '$mcrMigrationStage',
181 'Writing needs to be enabled for the old or the new schema.'
186 '$mcrMigrationStage',
187 'Cannot read the old schema when not also writing it.'
192 '$mcrMigrationStage',
193 'Cannot read the new schema when not also writing it.'
205 $this->logger =
new NullLogger();
214 return ( $this->mcrMigrationStage & $flags ) === $flags;
226 "Cross-wiki content loading is not supported by the pre-MCR schema"
239 return $this->blobStore->isReadOnly();
259 throw new MWException(
260 'Content model must be stored in the database for multi content revision migration.'
281 return $lb->getConnection( $mode, [], $this->wikiId );
299 $lb->reuseConnection( $connection );
309 return $lb->getConnectionRef( $mode, [], $this->wikiId );
326 public function getTitle( $pageId, $revId, $queryFlags = self::READ_NORMAL ) {
327 if ( !$pageId && !$revId ) {
328 throw new InvalidArgumentException(
'$pageId and $revId cannot both be 0 or null' );
334 $queryFlags = self::READ_NORMAL;
337 $canUseTitleNewFromId = ( $pageId !==
null && $pageId > 0 && $this->wikiId ===
false );
339 $titleFlags = ( $dbMode ==
DB_MASTER ? Title::GAID_FOR_UPDATE : 0 );
342 if ( $canUseTitleNewFromId ) {
344 $title = Title::newFromID( $pageId, $titleFlags );
351 $canUseRevId = ( $revId !==
null && $revId > 0 );
353 if ( $canUseRevId ) {
356 $row =
$dbr->selectRow(
357 [
'revision',
'page' ],
366 [
'rev_id' => $revId ],
369 [
'page' => [
'JOIN',
'page_id=rev_page' ] ]
373 return Title::newFromRow( $row );
379 $title = $this->
getTitle( $pageId, $revId, self::READ_LATEST );
382 __METHOD__ .
' fell back to READ_LATEST and got a Title.',
390 "Could not determine title for page ID $pageId and revision ID $revId"
404 "$name must not be " . var_export(
$value,
true ) .
"!"
421 "$name must not be " . var_export(
$value,
true ) .
"!"
444 $slotRoles =
$rev->getSlotRoles();
448 throw new InvalidArgumentException(
449 'main slot must be provided'
457 throw new InvalidArgumentException(
458 'Only the main slot is supported when not writing to the MCR enabled schema!'
466 throw new InvalidArgumentException(
467 'Only the main slot is supported when not reading from the MCR enabled schema!'
477 $this->
failOnNull( $user->getId(),
'user field' );
478 $this->
failOnEmpty( $user->getName(),
'user_text field' );
480 if ( !
$rev->isReadyForInsertion() ) {
487 $title = Title::newFromLinkTarget(
$rev->getPageAsLinkTarget() );
490 $parentId =
$rev->getParentId() ===
null
492 :
$rev->getParentId();
518 Assert::postcondition(
$rev->getId() > 0,
'revision must have an ID' );
519 Assert::postcondition(
$rev->getPageId() > 0,
'revision must have a page ID' );
520 Assert::postcondition(
522 'revision must have a comment'
524 Assert::postcondition(
526 'revision must have a user'
535 foreach ( $slotRoles as $role ) {
537 Assert::postcondition(
538 $slot->getContent() !==
null,
539 $role .
' slot must have content'
541 Assert::postcondition(
542 $slot->hasRevision(),
543 $role .
' slot must have a revision associated'
547 Hooks::run(
'RevisionRecordInserted', [
$rev ] );
551 Hooks::run(
'RevisionInsertComplete', [ &$legacyRevision,
null,
null ] );
565 $slotRoles =
$rev->getSlotRoles();
574 $revisionId = $revisionRow[
'rev_id'];
583 foreach ( $slotRoles as $role ) {
593 if ( $slot->hasRevision() && $slot->hasContentId() ) {
596 $slot->getRevision() === $revisionId,
597 'slot role ' . $slot->getRole(),
598 'Existing slot should belong to revision '
599 . $revisionId .
', but belongs to revision ' . $slot->getRevision() .
'!'
605 $newSlots[$role] = $slot;
611 $blobAddress = $slot->getAddress();
615 $newSlots[$role] = $this->
insertSlotOn( $dbw, $revisionId, $slot, $title, $blobHints );
625 (
object)$revisionRow,
641 $textId = $this->blobStore->getTextIdFromAddress( $blobAddress );
643 throw new LogicException(
644 'Blob address not supported in 1.29 database schema: ' . $blobAddress
650 $blobAddress = SqlBlobStore::makeAddressFromTextId( $textId );
654 [
'rev_text_id' => $textId ],
655 [
'rev_id' => $revisionId ],
675 array $blobHints = []
677 if ( $protoSlot->hasAddress() ) {
678 $blobAddress = $protoSlot->getAddress();
697 $contentId = $protoSlot->getContentId();
728 if ( $user->getId() === 0 && IP::isValid( $user->getName() ) ) {
730 'ipc_rev_id' => $revisionId,
731 'ipc_rev_timestamp' => $dbw->
timestamp(
$rev->getTimestamp() ),
732 'ipc_hex' => IP::toHex( $user->getName() ),
734 $dbw->
insert(
'ip_changes', $ipcRow, __METHOD__ );
757 list( $commentFields, $commentCallback ) =
758 $this->commentStore->insertWithTempTable(
763 $revisionRow += $commentFields;
765 list( $actorFields, $actorCallback ) =
766 $this->actorMigration->getInsertValuesWithTempTable(
771 $revisionRow += $actorFields;
773 $dbw->
insert(
'revision', $revisionRow, __METHOD__ );
775 if ( !isset( $revisionRow[
'rev_id'] ) ) {
777 $revisionRow[
'rev_id'] = intval( $dbw->
insertId() );
779 if ( $dbw->
getType() ===
'mysql' ) {
784 $maxRevId = intval( $dbw->
selectField(
'archive',
'MAX(ar_rev_id)',
'', __METHOD__ ) );
787 $maxRevId2 = intval( $dbw->
selectField(
'slots',
'MAX(slot_revision_id)',
'', __METHOD__ ) );
788 if ( $maxRevId2 >= $maxRevId ) {
789 $maxRevId = $maxRevId2;
794 if ( $maxRevId >= $revisionRow[
'rev_id'] ) {
795 $this->logger->debug(
796 '__METHOD__: Inserted revision {revid} but {table} has revisions up to {maxrevid}.'
797 .
' Trying to fix it.',
799 'revid' => $revisionRow[
'rev_id'],
801 'maxrevid' => $maxRevId,
805 if ( !$dbw->
lock(
'fix-for-T202032', __METHOD__ ) ) {
806 throw new MWException(
'Failed to get database lock for T202032' );
813 $dbw->
delete(
'revision', [
'rev_id' => $revisionRow[
'rev_id'] ], __METHOD__ );
825 $dbw->selectSqlText(
'archive', [
'v' =>
"MAX(ar_rev_id)" ],
'', __METHOD__ ) .
' FOR UPDATE'
829 $dbw->selectSqlText(
'slots', [
'v' =>
"MAX(slot_revision_id)" ],
'', __METHOD__ )
837 $row1 ? intval( $row1->v ) : 0,
838 $row2 ? intval( $row2->v ) : 0
844 $revisionRow[
'rev_id'] = $maxRevId + 1;
845 $dbw->
insert(
'revision', $revisionRow, __METHOD__ );
850 $commentCallback( $revisionRow[
'rev_id'] );
851 $actorCallback( $revisionRow[
'rev_id'], $revisionRow );
874 'rev_page' =>
$rev->getPageId(),
875 'rev_parent_id' => $parentId,
876 'rev_minor_edit' =>
$rev->isMinor() ? 1 : 0,
878 'rev_deleted' =>
$rev->getVisibility(),
879 'rev_len' =>
$rev->getSize(),
880 'rev_sha1' =>
$rev->getSha1(),
883 if (
$rev->getId() !==
null ) {
885 $revisionRow[
'rev_id'] =
$rev->getId();
891 $model = $mainSlot->getModel();
892 $format = $mainSlot->getFormat();
895 if ( $this->contentHandlerUseDB ) {
898 $defaultModel = ContentHandler::getDefaultModelFor( $title );
899 $defaultFormat = ContentHandler::getForModelID( $defaultModel )->getDefaultFormat();
901 $revisionRow[
'rev_content_model'] = ( $model === $defaultModel ) ?
null : $model;
902 $revisionRow[
'rev_content_format'] = ( $format === $defaultFormat ) ?
null : $format;
920 array $blobHints = []
923 $format =
$content->getDefaultFormat();
928 return $this->blobStore->storeBlob(
953 'slot_revision_id' => $revisionId,
954 'slot_role_id' => $this->slotRoleStore->acquireId( $slot->
getRole() ),
955 'slot_content_id' => $contentId,
960 $dbw->
insert(
'slots', $slotRow, __METHOD__ );
971 'content_size' => $slot->
getSize(),
972 'content_sha1' => $slot->
getSha1(),
973 'content_model' => $this->contentModelStore->acquireId( $slot->
getModel() ),
974 'content_address' => $blobAddress,
976 $dbw->
insert(
'content', $contentRow, __METHOD__ );
993 $format =
$content->getDefaultFormat();
998 if ( !
$handler->isSupportedFormat( $format ) ) {
999 throw new MWException(
"Can't use format $format with content model $model on $name" );
1002 if ( !$this->contentHandlerUseDB ) {
1008 $defaultModel = ContentHandler::getDefaultModelFor( $title );
1009 $defaultHandler = ContentHandler::getForModelID( $defaultModel );
1010 $defaultFormat = $defaultHandler->getDefaultFormat();
1012 if ( $model != $defaultModel ) {
1013 throw new MWException(
"Can't save non-default content model with "
1014 .
"\$wgContentHandlerUseDB disabled: model is $model, "
1015 .
"default for $name is $defaultModel"
1019 if ( $format != $defaultFormat ) {
1020 throw new MWException(
"Can't use non-default content format with "
1021 .
"\$wgContentHandlerUseDB disabled: format is $format, "
1022 .
"default for $name is $defaultFormat"
1029 "New content for $name is not valid! Content model is $model"
1068 $pageId = $title->getArticleID();
1076 [
'page_id' => $pageId ],
1081 if ( !$pageLatest ) {
1088 [
'rev_id' => intval( $pageLatest ) ],
1093 if ( !$oldRevision ) {
1094 $msg =
"Failed to load latest revision ID $pageLatest of page ID $pageId.";
1095 $this->logger->error(
1097 [
'exception' =>
new RuntimeException( $msg ) ]
1106 $newRevision->setComment( $comment );
1107 $newRevision->setUser( $user );
1108 $newRevision->setTimestamp( $timestamp );
1109 $newRevision->setMinorEdit( $minor );
1111 return $newRevision;
1126 return $rc->getAttribute(
'rc_id' );
1151 if ( !$userIdentity ) {
1158 $actorWhere = $this->actorMigration->getWhere( $db,
'rc_user',
$rev->getUser(),
false );
1161 $actorWhere[
'conds'],
1162 'rc_timestamp' => $db->timestamp(
$rev->getTimestamp() ),
1163 'rc_this_oldid' =>
$rev->getId()
1188 'ar_page_id' =>
'rev_page',
1189 'ar_rev_id' =>
'rev_id',
1192 'ar_text_id' =>
'rev_text_id',
1193 'ar_timestamp' =>
'rev_timestamp',
1194 'ar_user_text' =>
'rev_user_text',
1195 'ar_user' =>
'rev_user',
1196 'ar_actor' =>
'rev_actor',
1197 'ar_minor_edit' =>
'rev_minor_edit',
1198 'ar_deleted' =>
'rev_deleted',
1199 'ar_len' =>
'rev_len',
1200 'ar_parent_id' =>
'rev_parent_id',
1201 'ar_sha1' =>
'rev_sha1',
1202 'ar_comment' =>
'rev_comment',
1203 'ar_comment_cid' =>
'rev_comment_cid',
1204 'ar_comment_id' =>
'rev_comment_id',
1205 'ar_comment_text' =>
'rev_comment_text',
1206 'ar_comment_data' =>
'rev_comment_data',
1207 'ar_comment_old' =>
'rev_comment_old',
1208 'ar_content_format' =>
'rev_content_format',
1209 'ar_content_model' =>
'rev_content_model',
1212 $revRow =
new stdClass();
1213 foreach ( $fieldMap as $arKey => $revKey ) {
1214 if ( property_exists( $archiveRow, $arKey ) ) {
1215 $revRow->$revKey = $archiveRow->$arKey;
1233 $mainSlotRow =
new stdClass();
1235 $mainSlotRow->model_name =
null;
1236 $mainSlotRow->slot_revision_id =
null;
1237 $mainSlotRow->slot_content_id =
null;
1238 $mainSlotRow->content_address =
null;
1244 if ( is_object( $row ) ) {
1248 throw new LogicException(
'Can\'t emulate the main slot when using MCR schema.' );
1252 if ( !isset( $row->rev_id ) && ( isset( $row->ar_user ) || isset( $row->ar_actor ) ) ) {
1256 if ( isset( $row->rev_text_id ) && $row->rev_text_id > 0 ) {
1257 $mainSlotRow->content_address = SqlBlobStore::makeAddressFromTextId(
1263 $mainSlotRow->slot_origin = isset( $row->slot_origin )
1264 ? intval( $row->slot_origin )
1267 if ( isset( $row->old_text ) ) {
1269 $blobData = isset( $row->old_text ) ? strval( $row->old_text ) :
null;
1271 if ( !property_exists( $row,
'old_flags' ) ) {
1272 throw new InvalidArgumentException(
'old_flags was not set in $row' );
1274 $blobFlags = $row->old_flags ??
'';
1277 $mainSlotRow->slot_revision_id = intval( $row->rev_id );
1279 $mainSlotRow->content_size = isset( $row->rev_len ) ? intval( $row->rev_len ) :
null;
1280 $mainSlotRow->content_sha1 = isset( $row->rev_sha1 ) ? strval( $row->rev_sha1 ) :
null;
1281 $mainSlotRow->model_name = isset( $row->rev_content_model )
1282 ? strval( $row->rev_content_model )
1285 $mainSlotRow->format_name = isset( $row->rev_content_format )
1286 ? strval( $row->rev_content_format )
1289 if ( isset( $row->rev_text_id ) && intval( $row->rev_text_id ) > 0 ) {
1291 $mainSlotRow->slot_content_id
1294 } elseif ( is_array( $row ) ) {
1295 $mainSlotRow->slot_revision_id = isset( $row[
'id'] ) ? intval( $row[
'id'] ) :
null;
1297 $mainSlotRow->slot_origin = isset( $row[
'slot_origin'] )
1298 ? intval( $row[
'slot_origin'] )
1300 $mainSlotRow->content_address = isset( $row[
'text_id'] )
1301 ? SqlBlobStore::makeAddressFromTextId( intval( $row[
'text_id'] ) )
1303 $mainSlotRow->content_size = isset( $row[
'len'] ) ? intval( $row[
'len'] ) :
null;
1304 $mainSlotRow->content_sha1 = isset( $row[
'sha1'] ) ? strval( $row[
'sha1'] ) :
null;
1306 $mainSlotRow->model_name = isset( $row[
'content_model'] )
1307 ? strval( $row[
'content_model'] ) :
null;
1309 $mainSlotRow->format_name = isset( $row[
'content_format'] )
1310 ? strval( $row[
'content_format'] ) :
null;
1311 $blobData = isset( $row[
'text'] ) ? rtrim( strval( $row[
'text'] ) ) :
null;
1314 $blobFlags = isset( $row[
'flags'] ) ? trim( strval( $row[
'flags'] ) ) :
null;
1317 if ( !empty( $row[
'content'] ) ) {
1318 if ( !( $row[
'content'] instanceof
Content ) ) {
1319 throw new MWException(
'content field must contain a Content object.' );
1326 $mainSlotRow->model_name =
$content->getModel();
1329 if ( $mainSlotRow->format_name ===
null ) {
1330 $mainSlotRow->format_name =
$handler->getDefaultFormat();
1334 if ( isset( $row[
'text_id'] ) && intval( $row[
'text_id'] ) > 0 ) {
1336 $mainSlotRow->slot_content_id
1340 throw new MWException(
'Revision constructor passed invalid row format.' );
1345 if ( !isset( $mainSlotRow->slot_origin ) ) {
1346 $mainSlotRow->slot_origin = $mainSlotRow->slot_revision_id;
1349 if ( $mainSlotRow->model_name ===
null ) {
1350 $mainSlotRow->model_name =
function (
SlotRecord $slot ) use ( $title ) {
1355 return ContentHandler::getDefaultModelFor( $title );
1364 use ( $blobData, $blobFlags, $queryFlags, $mainSlotRow )
1370 $mainSlotRow->format_name,
1380 $mainSlotRow->slot_content_id =
1381 function (
SlotRecord $slot ) use ( $queryFlags, $mainSlotRow ) {
1434 if ( $blobData !==
null ) {
1435 Assert::parameterType(
'string', $blobData,
'$blobData' );
1436 Assert::parameterType(
'string|null', $blobFlags,
'$blobFlags' );
1440 if ( $blobFlags ===
null ) {
1444 $data = $this->blobStore->expandBlob( $blobData, $blobFlags, $cacheKey );
1445 if ( $data ===
false ) {
1447 "Failed to expand blob data using flags $blobFlags (key: $cacheKey)"
1455 $data = $this->blobStore->getBlob( $address, $queryFlags );
1458 "Failed to load data blob from $address: " .
$e->getMessage(), 0,
$e
1507 'page_title' => $linkTarget->
getDBkey()
1515 $conds[
'rev_id'] = $revId;
1525 $conds[] =
'rev_id=page_latest';
1549 $conds = [
'page_id' => $pageId ];
1556 $conds[
'rev_id'] = $revId;
1566 $conds[] =
'rev_id=page_latest';
1588 'rev_timestamp' => $db->timestamp( $timestamp ),
1589 'page_namespace' => $title->getNamespace(),
1590 'page_title' => $title->getDBkey()
1613 'slot_revision_id' => $revId,
1622 foreach (
$res as $row ) {
1624 $row->role_name = $this->slotRoleStore->getName( (
int)$row->slot_role_id );
1625 $row->model_name = $this->contentModelStore->getName( (
int)$row->content_model );
1627 $contentCallback =
function (
SlotRecord $slot ) use ( $queryFlags, $row ) {
1628 return $this->
loadSlotContent( $slot,
null,
null,
null, $queryFlags );
1631 $slots[$row->role_name] =
new SlotRecord( $row, $contentCallback );
1636 'Main slot of revision ' . $revId .
' not found in database!'
1698 Title $title =
null,
1699 array $overrides = []
1701 Assert::parameterType(
'object', $row,
'$row' );
1704 Assert::parameterType(
'integer', $queryFlags,
'$queryFlags' );
1706 if ( !$title && isset( $overrides[
'title'] ) ) {
1707 if ( !( $overrides[
'title'] instanceof
Title ) ) {
1708 throw new MWException(
'title field override must contain a Title object.' );
1711 $title = $overrides[
'title'];
1714 if ( !isset( $title ) ) {
1715 if ( isset( $row->ar_namespace ) && isset( $row->ar_title ) ) {
1716 $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
1718 throw new InvalidArgumentException(
1719 'A Title or ar_namespace and ar_title must be given'
1724 foreach ( $overrides as $key =>
$value ) {
1731 $row->ar_user ??
null,
1732 $row->ar_user_text ??
null,
1733 $row->ar_actor ??
null
1735 }
catch ( InvalidArgumentException $ex ) {
1736 wfWarn( __METHOD__ .
': ' . $title->getPrefixedDBkey() .
': ' . $ex->getMessage() );
1742 $comment = $this->commentStore->getCommentLegacy( $db,
'ar_comment', $row,
true );
1744 $slots = $this->
newRevisionSlots( $row->ar_rev_id, $row, $queryFlags, $title );
1761 Assert::parameterType(
'object', $row,
'$row' );
1764 $pageId = $row->rev_page ?? 0;
1765 $revId = $row->rev_id ?? 0;
1767 $title = $this->
getTitle( $pageId, $revId, $queryFlags );
1770 if ( !isset( $row->page_latest ) ) {
1771 $row->page_latest = $title->getLatestRevID();
1772 if ( $row->page_latest === 0 && $title->exists() ) {
1773 wfWarn(
'Encountered title object in limbo: ID ' . $title->getArticleID() );
1779 $row->rev_user ??
null,
1780 $row->rev_user_text ??
null,
1781 $row->rev_actor ??
null
1783 }
catch ( InvalidArgumentException $ex ) {
1784 wfWarn( __METHOD__ .
': ' . $title->getPrefixedDBkey() .
': ' . $ex->getMessage() );
1790 $comment = $this->commentStore->getCommentLegacy( $db,
'rev_comment', $row,
true );
1792 $slots = $this->
newRevisionSlots( $row->rev_id, $row, $queryFlags, $title );
1816 if ( !$title && isset( $fields[
'title'] ) ) {
1817 if ( !( $fields[
'title'] instanceof
Title ) ) {
1818 throw new MWException(
'title field must contain a Title object.' );
1821 $title = $fields[
'title'];
1825 $pageId = $fields[
'page'] ?? 0;
1826 $revId = $fields[
'id'] ?? 0;
1828 $title = $this->
getTitle( $pageId, $revId, $queryFlags );
1831 if ( !isset( $fields[
'page'] ) ) {
1832 $fields[
'page'] = $title->getArticleID( $queryFlags );
1836 if ( !empty( $fields[
'content'] ) ) {
1837 if ( !( $fields[
'content'] instanceof
Content ) && !is_array( $fields[
'content'] ) ) {
1839 'content field must contain a Content object or an array of Content objects.'
1844 if ( !empty( $fields[
'text_id'] ) ) {
1846 throw new MWException(
"The text_id field is only available in the pre-MCR schema" );
1849 if ( !empty( $fields[
'content'] ) ) {
1851 "Text already stored in external store (id {$fields['text_id']}), " .
1852 "can't specify content object"
1858 isset( $fields[
'comment'] )
1861 $commentData = $fields[
'comment_data'] ??
null;
1863 if ( $fields[
'comment'] instanceof
Message ) {
1864 $fields[
'comment'] = CommentStoreComment::newUnsavedComment(
1869 $commentText = trim( strval( $fields[
'comment'] ) );
1870 $fields[
'comment'] = CommentStoreComment::newUnsavedComment(
1880 if ( isset( $fields[
'content'] ) && is_array( $fields[
'content'] ) ) {
1881 foreach ( $fields[
'content'] as $role =>
$content ) {
1882 $revision->setContent( $role,
$content );
1886 $revision->setSlot( $mainSlot );
1903 if ( isset( $fields[
'user'] ) && ( $fields[
'user'] instanceof
UserIdentity ) ) {
1904 $user = $fields[
'user'];
1908 $fields[
'user'] ??
null,
1909 $fields[
'user_text'] ??
null,
1910 $fields[
'actor'] ??
null
1912 }
catch ( InvalidArgumentException $ex ) {
1918 $record->setUser( $user );
1921 $timestamp = isset( $fields[
'timestamp'] )
1922 ? strval( $fields[
'timestamp'] )
1925 $record->setTimestamp( $timestamp );
1927 if ( isset( $fields[
'page'] ) ) {
1928 $record->setPageId( intval( $fields[
'page'] ) );
1931 if ( isset( $fields[
'id'] ) ) {
1932 $record->setId( intval( $fields[
'id'] ) );
1934 if ( isset( $fields[
'parent_id'] ) ) {
1935 $record->setParentId( intval( $fields[
'parent_id'] ) );
1938 if ( isset( $fields[
'sha1'] ) ) {
1939 $record->setSha1( $fields[
'sha1'] );
1941 if ( isset( $fields[
'size'] ) ) {
1942 $record->setSize( intval( $fields[
'size'] ) );
1945 if ( isset( $fields[
'minor_edit'] ) ) {
1946 $record->setMinorEdit( intval( $fields[
'minor_edit'] ) !== 0 );
1948 if ( isset( $fields[
'deleted'] ) ) {
1949 $record->setVisibility( intval( $fields[
'deleted'] ) );
1952 if ( isset( $fields[
'comment'] ) ) {
1953 Assert::parameterType(
1954 CommentStoreComment::class,
1958 $record->setComment( $fields[
'comment'] );
1996 $conds = [
'rev_page' => intval( $pageid ),
'page_id' => intval( $pageid ) ];
1998 $conds[
'rev_id'] = intval( $id );
2000 $conds[] =
'rev_id=page_latest';
2023 $matchId = intval( $id );
2025 $matchId =
'page_latest';
2032 'page_namespace' => $title->getNamespace(),
2033 'page_title' => $title->getDBkey()
2058 'rev_timestamp' => $db->
timestamp( $timestamp ),
2059 'page_namespace' => $title->getNamespace(),
2060 'page_title' => $title->getDBkey()
2091 && !( $flags & self::READ_LATEST )
2092 && $lb->getServerCount() > 1
2093 && $lb->hasOrMadeRecentMasterChanges()
2095 $flags = self::READ_LATEST;
2144 if ( $dbWiki === $storeWiki ) {
2148 $storeWiki = $storeWiki ?: $this->loadBalancer->getLocalDomainID();
2152 if ( $dbWiki === $storeWiki ) {
2157 $storeWiki = str_replace(
'?h',
'-', $storeWiki );
2158 $dbWiki = str_replace(
'?h',
'-', $dbWiki );
2160 if ( $dbWiki === $storeWiki ) {
2164 throw new MWException(
"RevisionStore for $storeWiki "
2165 .
"cannot be used with a DB connection for $dbWiki" );
2185 if ( ( $flags & self::READ_LOCKING ) == self::READ_LOCKING ) {
2218 $roleId = $this->slotRoleStore->getId( $role );
2220 'slot_revision_id' => $revId,
2221 'slot_role_id' => $roleId,
2224 $contentId = $db->
selectField(
'slots',
'slot_content_id', $conditions, __METHOD__ );
2226 return $contentId ?:
null;
2264 $ret[
'tables'][] =
'revision';
2265 $ret[
'fields'] = array_merge(
$ret[
'fields'], [
2276 $commentQuery = $this->commentStore->getJoin(
'rev_comment' );
2277 $ret[
'tables'] = array_merge(
$ret[
'tables'], $commentQuery[
'tables'] );
2278 $ret[
'fields'] = array_merge(
$ret[
'fields'], $commentQuery[
'fields'] );
2279 $ret[
'joins'] = array_merge(
$ret[
'joins'], $commentQuery[
'joins'] );
2281 $actorQuery = $this->actorMigration->getJoin(
'rev_user' );
2282 $ret[
'tables'] = array_merge(
$ret[
'tables'], $actorQuery[
'tables'] );
2283 $ret[
'fields'] = array_merge(
$ret[
'fields'], $actorQuery[
'fields'] );
2284 $ret[
'joins'] = array_merge(
$ret[
'joins'], $actorQuery[
'joins'] );
2287 $ret[
'fields'][] =
'rev_text_id';
2289 if ( $this->contentHandlerUseDB ) {
2290 $ret[
'fields'][] =
'rev_content_format';
2291 $ret[
'fields'][] =
'rev_content_model';
2295 if ( in_array(
'page',
$options,
true ) ) {
2296 $ret[
'tables'][] =
'page';
2297 $ret[
'fields'] = array_merge(
$ret[
'fields'], [
2305 $ret[
'joins'][
'page'] = [
'INNER JOIN', [
'page_id = rev_page' ] ];
2308 if ( in_array(
'user',
$options,
true ) ) {
2309 $ret[
'tables'][] =
'user';
2310 $ret[
'fields'] = array_merge(
$ret[
'fields'], [
2313 $u = $actorQuery[
'fields'][
'rev_user'];
2314 $ret[
'joins'][
'user'] = [
'LEFT JOIN', [
"$u != 0",
"user_id = $u" ] ];
2317 if ( in_array(
'text',
$options,
true ) ) {
2319 throw new InvalidArgumentException(
'text table can no longer be joined directly' );
2329 $ret[
'tables'][] =
'text';
2330 $ret[
'fields'] = array_merge(
$ret[
'fields'], [
2334 $ret[
'joins'][
'text'] = [
'INNER JOIN', [
'rev_text_id=old_id' ] ];
2366 $ret[
'tables'][
'slots'] =
'revision';
2368 $ret[
'fields'][
'slot_revision_id'] =
'slots.rev_id';
2369 $ret[
'fields'][
'slot_content_id'] =
'NULL';
2370 $ret[
'fields'][
'slot_origin'] =
'slots.rev_id';
2373 if ( in_array(
'content',
$options,
true ) ) {
2374 $ret[
'fields'][
'content_size'] =
'slots.rev_len';
2375 $ret[
'fields'][
'content_sha1'] =
'slots.rev_sha1';
2376 $ret[
'fields'][
'content_address']
2377 = $db->buildConcat( [ $db->addQuotes(
'tt:' ),
'slots.rev_text_id' ] );
2379 if ( $this->contentHandlerUseDB ) {
2380 $ret[
'fields'][
'model_name'] =
'slots.rev_content_model';
2382 $ret[
'fields'][
'model_name'] =
'NULL';
2386 $ret[
'tables'][] =
'slots';
2387 $ret[
'fields'] = array_merge(
$ret[
'fields'], [
2394 if ( in_array(
'role',
$options,
true ) ) {
2397 $ret[
'tables'][] =
'slot_roles';
2398 $ret[
'joins'][
'slot_roles'] = [
'LEFT JOIN', [
'slot_role_id = role_id' ] ];
2399 $ret[
'fields'][] =
'role_name';
2402 if ( in_array(
'content',
$options,
true ) ) {
2403 $ret[
'tables'][] =
'content';
2404 $ret[
'fields'] = array_merge(
$ret[
'fields'], [
2410 $ret[
'joins'][
'content'] = [
'INNER JOIN', [
'slot_content_id = content_id' ] ];
2412 if ( in_array(
'model',
$options,
true ) ) {
2415 $ret[
'tables'][] =
'content_models';
2416 $ret[
'joins'][
'content_models'] = [
'LEFT JOIN', [
'content_model = model_id' ] ];
2417 $ret[
'fields'][] =
'model_name';
2440 $commentQuery = $this->commentStore->getJoin(
'ar_comment' );
2441 $actorQuery = $this->actorMigration->getJoin(
'ar_user' );
2443 'tables' => [
'archive' ] + $commentQuery[
'tables'] + $actorQuery[
'tables'],
2456 ] + $commentQuery[
'fields'] + $actorQuery[
'fields'],
2457 'joins' => $commentQuery[
'joins'] + $actorQuery[
'joins'],
2461 $ret[
'fields'][] =
'ar_text_id';
2463 if ( $this->contentHandlerUseDB ) {
2464 $ret[
'fields'][] =
'ar_content_format';
2465 $ret[
'fields'][] =
'ar_content_model';
2507 [
'rev_id',
'rev_len' ],
2508 [
'rev_id' => $revIds ],
2512 foreach (
$res as $row ) {
2513 $revLens[$row->rev_id] = intval( $row->rev_len );
2530 if ( $title ===
null ) {
2533 $prev = $title->getPreviousRevisionID(
$rev->getId() );
2551 if ( $title ===
null ) {
2554 $next = $title->getNextRevisionID(
$rev->getId() );
2575 if (
$rev->getPageId() ===
null ) {
2578 # Use page_latest if ID is not given
2579 if ( !
$rev->getId() ) {
2581 'page',
'page_latest',
2582 [
'page_id' =>
$rev->getPageId() ],
2587 'revision',
'rev_id',
2588 [
'rev_page' =>
$rev->getPageId(),
'rev_id < ' .
$rev->getId() ],
2590 [
'ORDER BY' =>
'rev_id DESC' ]
2593 return intval( $prevId );
2609 $conds = [
'rev_id' => $id ];
2610 $conds[
'rev_page'] = $title->getArticleID();
2611 $timestamp = $db->selectField(
'revision',
'rev_timestamp', $conds, __METHOD__ );
2613 return ( $timestamp !==
false ) ?
wfTimestamp( TS_MW, $timestamp ) :
false;
2629 [
'revCount' =>
'COUNT(*)' ],
2630 [
'rev_page' => $id ],
2634 return intval( $row->revCount );
2649 $id = $title->getArticleID();
2685 'rev_user' =>
$revQuery[
'fields'][
'rev_user'],
2688 'rev_page' => $pageId,
2692 [
'ORDER BY' =>
'rev_timestamp ASC',
'LIMIT' => 50 ],
2695 foreach (
$res as $row ) {
2696 if ( $row->rev_user != $userId ) {
2719 $pageId = $title->getArticleID();
2726 $revId = $title->getLatestRevID();
2731 'No latest revision known for page ' . $title->getPrefixedDBkey()
2732 .
' even though it exists with page ID ' . $pageId
2737 $row = $this->
cache->getWithSetCallback(
2740 WANObjectCache::TTL_WEEK,
2741 function ( $curValue, &$ttl,
array &$setOpts ) use ( $db, $pageId, $revId ) {
2742 $setOpts += Database::getCacheSetOptions( $db );
2745 'rev_page' => intval( $pageId ),
2746 'page_id' => intval( $pageId ),
2747 'rev_id' => intval( $revId ),
2751 return $row ?:
false;
2775 return $this->
cache->makeGlobalKey(
2776 self::ROW_CACHE_KEY,
2791class_alias( RevisionStore::class,
'MediaWiki\Storage\RevisionStore' );
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfBacktrace( $raw=null)
Get a debug backtrace as a string.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
This class handles the logic for the actor table migration.
A content handler knows how do deal with a specific type of content on a wiki page.
Helper class for DAO classes.
static getDBOptions( $bitfield)
Get an appropriate DB index, options, and fallback DB index for a query.
static hasFlags( $bitfield, $flags)
A collection of public static functions to play with IP address and IP ranges.
Exception thrown when an unregistered content model is requested.
The Message class provides methods which fulfil two basic services:
Utility class for creating new RC entries.
static newFromConds( $conds, $fname=__METHOD__, $dbType=DB_REPLICA)
Find the first recent change matching some specific conditions.
Represents a title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static newFromAnyId( $userId, $userName, $actorId)
Static factory method for creation from an ID, name, and/or actor ID.
Multi-datacenter aware caching interface.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped & $options
namespace and then decline to actually register it file or subcat img or subcat $title
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
processing should stop and the error should be shown to the user * false
returning false will NOT prevent logging $e
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
const SCHEMA_COMPAT_WRITE_BOTH
const SCHEMA_COMPAT_READ_NEW
const SCHEMA_COMPAT_READ_BOTH
const SCHEMA_COMPAT_WRITE_OLD
const SCHEMA_COMPAT_READ_OLD
const SCHEMA_COMPAT_WRITE_NEW
Base interface for content objects.
Interface for database access objects.
you have access to all of the normal MediaWiki so you can get a DB use the cache
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))