37use InvalidArgumentException;
51use Psr\Log\LoggerAwareInterface;
52use Psr\Log\LoggerInterface;
53use Psr\Log\NullLogger;
61use Wikimedia\Assert\Assert;
170 Assert::parameterType(
'string|boolean',
$wikiId,
'$wikiId' );
174 '$mcrMigrationStage',
175 'Reading from the old and the new schema at the same time is not supported.'
179 '$mcrMigrationStage',
180 'Reading needs to be enabled for the old or the new schema.'
184 '$mcrMigrationStage',
185 'Writing needs to be enabled for the old or the new schema.'
190 '$mcrMigrationStage',
191 'Cannot read the old schema when not also writing it.'
196 '$mcrMigrationStage',
197 'Cannot read the new schema when not also writing it.'
210 $this->logger =
new NullLogger();
219 return ( $this->mcrMigrationStage & $flags ) === $flags;
231 "Cross-wiki content loading is not supported by the pre-MCR schema"
244 return $this->blobStore->isReadOnly();
265 'Content model must be stored in the database for multi content revision migration.'
286 return $lb->getConnection( $mode, [], $this->wikiId );
304 $lb->reuseConnection( $connection );
314 return $lb->getConnectionRef( $mode, [], $this->wikiId );
331 public function getTitle( $pageId, $revId, $queryFlags = self::READ_NORMAL ) {
332 if ( !$pageId && !$revId ) {
333 throw new InvalidArgumentException(
'$pageId and $revId cannot both be 0 or null' );
339 $queryFlags = self::READ_NORMAL;
342 $canUseTitleNewFromId = ( $pageId !==
null && $pageId > 0 && $this->wikiId ===
false );
344 $titleFlags = ( $dbMode ==
DB_MASTER ? Title::GAID_FOR_UPDATE : 0 );
347 if ( $canUseTitleNewFromId ) {
349 $title = Title::newFromID( $pageId, $titleFlags );
356 $canUseRevId = ( $revId !==
null && $revId > 0 );
358 if ( $canUseRevId ) {
361 $row =
$dbr->selectRow(
362 [
'revision',
'page' ],
371 [
'rev_id' => $revId ],
374 [
'page' => [
'JOIN',
'page_id=rev_page' ] ]
378 return Title::newFromRow( $row );
387 __METHOD__ .
' fell back to READ_LATEST and got a Title.',
395 "Could not determine title for page ID $pageId and revision ID $revId"
409 "$name must not be " . var_export(
$value,
true ) .
"!"
426 "$name must not be " . var_export(
$value,
true ) .
"!"
449 $slotRoles =
$rev->getSlotRoles();
453 throw new InvalidArgumentException(
454 'main slot must be provided'
462 throw new InvalidArgumentException(
463 'Only the main slot is supported when not writing to the MCR enabled schema!'
471 throw new InvalidArgumentException(
472 'Only the main slot is supported when not reading from the MCR enabled schema!'
485 if ( !
$rev->isReadyForInsertion() ) {
492 $title = Title::newFromLinkTarget(
$rev->getPageAsLinkTarget() );
495 $parentId =
$rev->getParentId() ===
null
497 :
$rev->getParentId();
523 Assert::postcondition(
$rev->getId() > 0,
'revision must have an ID' );
524 Assert::postcondition(
$rev->getPageId() > 0,
'revision must have a page ID' );
525 Assert::postcondition(
527 'revision must have a comment'
529 Assert::postcondition(
531 'revision must have a user'
540 foreach ( $slotRoles
as $role ) {
542 Assert::postcondition(
543 $slot->getContent() !==
null,
544 $role .
' slot must have content'
546 Assert::postcondition(
547 $slot->hasRevision(),
548 $role .
' slot must have a revision associated'
552 Hooks::run(
'RevisionRecordInserted', [
$rev ] );
556 Hooks::run(
'RevisionInsertComplete', [ &$legacyRevision,
null,
null ] );
570 $slotRoles =
$rev->getSlotRoles();
579 $revisionId = $revisionRow[
'rev_id'];
588 foreach ( $slotRoles
as $role ) {
598 if ( $slot->hasRevision() && $slot->hasContentId() ) {
601 $slot->getRevision() === $revisionId,
602 'slot role ' . $slot->getRole(),
603 'Existing slot should belong to revision '
604 . $revisionId .
', but belongs to revision ' . $slot->getRevision() .
'!'
610 $newSlots[$role] = $slot;
616 $blobAddress = $slot->getAddress();
620 $newSlots[$role] = $this->
insertSlotOn( $dbw, $revisionId, $slot,
$title, $blobHints );
630 (
object)$revisionRow,
646 $textId = $this->blobStore->getTextIdFromAddress( $blobAddress );
648 throw new LogicException(
649 'Blob address not supported in 1.29 database schema: ' . $blobAddress
655 $blobAddress = SqlBlobStore::makeAddressFromTextId( $textId );
659 [
'rev_text_id' => $textId ],
660 [
'rev_id' => $revisionId ],
680 array $blobHints = []
733 if (
$user->getId() === 0 && IP::isValid(
$user->getName() ) ) {
735 'ipc_rev_id' => $revisionId,
736 'ipc_rev_timestamp' => $dbw->
timestamp(
$rev->getTimestamp() ),
737 'ipc_hex' => IP::toHex(
$user->getName() ),
739 $dbw->
insert(
'ip_changes', $ipcRow, __METHOD__ );
762 list( $commentFields, $commentCallback ) =
763 $this->commentStore->insertWithTempTable(
768 $revisionRow += $commentFields;
770 list( $actorFields, $actorCallback ) =
771 $this->actorMigration->getInsertValuesWithTempTable(
776 $revisionRow += $actorFields;
778 $dbw->
insert(
'revision', $revisionRow, __METHOD__ );
780 if ( !isset( $revisionRow[
'rev_id'] ) ) {
782 $revisionRow[
'rev_id'] = intval( $dbw->
insertId() );
784 if ( $dbw->
getType() ===
'mysql' ) {
789 $maxRevId = intval( $dbw->
selectField(
'archive',
'MAX(ar_rev_id)',
'', __METHOD__ ) );
792 $maxRevId2 = intval( $dbw->
selectField(
'slots',
'MAX(slot_revision_id)',
'', __METHOD__ ) );
793 if ( $maxRevId2 >= $maxRevId ) {
794 $maxRevId = $maxRevId2;
799 if ( $maxRevId >= $revisionRow[
'rev_id'] ) {
800 $this->logger->debug(
801 '__METHOD__: Inserted revision {revid} but {table} has revisions up to {maxrevid}.'
802 .
' Trying to fix it.',
804 'revid' => $revisionRow[
'rev_id'],
806 'maxrevid' => $maxRevId,
810 if ( !$dbw->
lock(
'fix-for-T202032', __METHOD__ ) ) {
811 throw new MWException(
'Failed to get database lock for T202032' );
818 $dbw->
delete(
'revision', [
'rev_id' => $revisionRow[
'rev_id'] ], __METHOD__ );
830 $dbw->
selectSQLText(
'archive', [
'v' =>
"MAX(ar_rev_id)" ],
'', __METHOD__ ) .
' FOR UPDATE'
834 $dbw->
selectSQLText(
'slots', [
'v' =>
"MAX(slot_revision_id)" ],
'', __METHOD__ )
842 $row1 ? intval( $row1->v ) : 0,
843 $row2 ? intval( $row2->v ) : 0
849 $revisionRow[
'rev_id'] = $maxRevId + 1;
850 $dbw->
insert(
'revision', $revisionRow, __METHOD__ );
855 $commentCallback( $revisionRow[
'rev_id'] );
856 $actorCallback( $revisionRow[
'rev_id'], $revisionRow );
879 'rev_page' =>
$rev->getPageId(),
880 'rev_parent_id' => $parentId,
881 'rev_minor_edit' =>
$rev->isMinor() ? 1 : 0,
883 'rev_deleted' =>
$rev->getVisibility(),
884 'rev_len' =>
$rev->getSize(),
885 'rev_sha1' =>
$rev->getSha1(),
888 if (
$rev->getId() !==
null ) {
890 $revisionRow[
'rev_id'] =
$rev->getId();
896 $model = $mainSlot->getModel();
897 $format = $mainSlot->getFormat();
900 if ( $this->contentHandlerUseDB ) {
903 $defaultModel = ContentHandler::getDefaultModelFor(
$title );
904 $defaultFormat = ContentHandler::getForModelID( $defaultModel )->getDefaultFormat();
906 $revisionRow[
'rev_content_model'] = ( $model === $defaultModel ) ?
null : $model;
907 $revisionRow[
'rev_content_format'] = ( $format === $defaultFormat ) ?
null : $format;
925 array $blobHints = []
928 $format =
$content->getDefaultFormat();
933 return $this->blobStore->storeBlob(
958 'slot_revision_id' => $revisionId,
959 'slot_role_id' => $this->slotRoleStore->acquireId( $slot->
getRole() ),
960 'slot_content_id' => $contentId,
965 $dbw->
insert(
'slots', $slotRow, __METHOD__ );
976 'content_size' => $slot->
getSize(),
977 'content_sha1' => $slot->
getSha1(),
978 'content_model' => $this->contentModelStore->acquireId( $slot->
getModel() ),
979 'content_address' => $blobAddress,
981 $dbw->
insert(
'content', $contentRow, __METHOD__ );
999 $format =
$content->getDefaultFormat();
1004 if ( !
$handler->isSupportedFormat( $format ) ) {
1005 throw new MWException(
"Can't use format $format with content model $model on $name" );
1008 if ( !$this->contentHandlerUseDB ) {
1014 $roleHandler = $this->slotRoleRegistry->getRoleHandler( $role );
1015 $defaultModel = $roleHandler->getDefaultModel(
$title );
1016 $defaultHandler = ContentHandler::getForModelID( $defaultModel );
1017 $defaultFormat = $defaultHandler->getDefaultFormat();
1019 if ( $model != $defaultModel ) {
1020 throw new MWException(
"Can't save non-default content model with "
1021 .
"\$wgContentHandlerUseDB disabled: model is $model, "
1022 .
"default for $name is $defaultModel"
1026 if ( $format != $defaultFormat ) {
1027 throw new MWException(
"Can't use non-default content format with "
1028 .
"\$wgContentHandlerUseDB disabled: format is $format, "
1029 .
"default for $name is $defaultFormat"
1036 "New content for $name is not valid! Content model is $model"
1075 $pageId =
$title->getArticleID();
1083 [
'page_id' => $pageId ],
1088 if ( !$pageLatest ) {
1095 [
'rev_id' => intval( $pageLatest ) ],
1100 if ( !$oldRevision ) {
1101 $msg =
"Failed to load latest revision ID $pageLatest of page ID $pageId.";
1102 $this->logger->error(
1104 [
'exception' =>
new RuntimeException( $msg ) ]
1113 $newRevision->setComment( $comment );
1114 $newRevision->setUser(
$user );
1115 $newRevision->setTimestamp( $timestamp );
1116 $newRevision->setMinorEdit( $minor );
1118 return $newRevision;
1133 return $rc->getAttribute(
'rc_id' );
1158 if ( !$userIdentity ) {
1165 $actorWhere = $this->actorMigration->getWhere( $db,
'rc_user',
$rev->getUser(),
false );
1168 $actorWhere[
'conds'],
1169 'rc_timestamp' => $db->timestamp(
$rev->getTimestamp() ),
1170 'rc_this_oldid' =>
$rev->getId()
1195 'ar_page_id' =>
'rev_page',
1196 'ar_rev_id' =>
'rev_id',
1199 'ar_text_id' =>
'rev_text_id',
1200 'ar_timestamp' =>
'rev_timestamp',
1201 'ar_user_text' =>
'rev_user_text',
1202 'ar_user' =>
'rev_user',
1203 'ar_actor' =>
'rev_actor',
1204 'ar_minor_edit' =>
'rev_minor_edit',
1205 'ar_deleted' =>
'rev_deleted',
1206 'ar_len' =>
'rev_len',
1207 'ar_parent_id' =>
'rev_parent_id',
1208 'ar_sha1' =>
'rev_sha1',
1209 'ar_comment' =>
'rev_comment',
1210 'ar_comment_cid' =>
'rev_comment_cid',
1211 'ar_comment_id' =>
'rev_comment_id',
1212 'ar_comment_text' =>
'rev_comment_text',
1213 'ar_comment_data' =>
'rev_comment_data',
1214 'ar_comment_old' =>
'rev_comment_old',
1215 'ar_content_format' =>
'rev_content_format',
1216 'ar_content_model' =>
'rev_content_model',
1219 $revRow =
new stdClass();
1220 foreach ( $fieldMap
as $arKey => $revKey ) {
1221 if ( property_exists( $archiveRow, $arKey ) ) {
1222 $revRow->$revKey = $archiveRow->$arKey;
1240 $mainSlotRow =
new stdClass();
1242 $mainSlotRow->model_name =
null;
1243 $mainSlotRow->slot_revision_id =
null;
1244 $mainSlotRow->slot_content_id =
null;
1245 $mainSlotRow->content_address =
null;
1251 if ( is_object( $row ) ) {
1255 throw new LogicException(
'Can\'t emulate the main slot when using MCR schema.' );
1259 if ( !isset( $row->rev_id ) && ( isset( $row->ar_user ) || isset( $row->ar_actor ) ) ) {
1263 if ( isset( $row->rev_text_id ) && $row->rev_text_id > 0 ) {
1264 $mainSlotRow->content_address = SqlBlobStore::makeAddressFromTextId(
1270 $mainSlotRow->slot_origin = isset( $row->slot_origin )
1271 ? intval( $row->slot_origin )
1274 if ( isset( $row->old_text ) ) {
1276 $blobData = isset( $row->old_text ) ? strval( $row->old_text ) :
null;
1278 if ( !property_exists( $row,
'old_flags' ) ) {
1279 throw new InvalidArgumentException(
'old_flags was not set in $row' );
1281 $blobFlags = $row->old_flags ??
'';
1284 $mainSlotRow->slot_revision_id = intval( $row->rev_id );
1286 $mainSlotRow->content_size = isset( $row->rev_len ) ? intval( $row->rev_len ) :
null;
1287 $mainSlotRow->content_sha1 = isset( $row->rev_sha1 ) ? strval( $row->rev_sha1 ) :
null;
1288 $mainSlotRow->model_name = isset( $row->rev_content_model )
1289 ? strval( $row->rev_content_model )
1292 $mainSlotRow->format_name = isset( $row->rev_content_format )
1293 ? strval( $row->rev_content_format )
1296 if ( isset( $row->rev_text_id ) && intval( $row->rev_text_id ) > 0 ) {
1298 $mainSlotRow->slot_content_id
1301 } elseif ( is_array( $row ) ) {
1302 $mainSlotRow->slot_revision_id = isset( $row[
'id'] ) ? intval( $row[
'id'] ) :
null;
1304 $mainSlotRow->slot_origin = isset( $row[
'slot_origin'] )
1305 ? intval( $row[
'slot_origin'] )
1307 $mainSlotRow->content_address = isset( $row[
'text_id'] )
1308 ? SqlBlobStore::makeAddressFromTextId( intval( $row[
'text_id'] ) )
1310 $mainSlotRow->content_size = isset( $row[
'len'] ) ? intval( $row[
'len'] ) :
null;
1311 $mainSlotRow->content_sha1 = isset( $row[
'sha1'] ) ? strval( $row[
'sha1'] ) :
null;
1313 $mainSlotRow->model_name = isset( $row[
'content_model'] )
1314 ? strval( $row[
'content_model'] ) :
null;
1316 $mainSlotRow->format_name = isset( $row[
'content_format'] )
1317 ? strval( $row[
'content_format'] ) :
null;
1318 $blobData = isset( $row[
'text'] ) ? rtrim( strval( $row[
'text'] ) ) :
null;
1321 $blobFlags = isset( $row[
'flags'] ) ? trim( strval( $row[
'flags'] ) ) :
null;
1324 if ( !empty( $row[
'content'] ) ) {
1325 if ( !( $row[
'content'] instanceof
Content ) ) {
1326 throw new MWException(
'content field must contain a Content object.' );
1333 $mainSlotRow->model_name =
$content->getModel();
1336 if ( $mainSlotRow->format_name ===
null ) {
1337 $mainSlotRow->format_name =
$handler->getDefaultFormat();
1341 if ( isset( $row[
'text_id'] ) && intval( $row[
'text_id'] ) > 0 ) {
1343 $mainSlotRow->slot_content_id
1347 throw new MWException(
'Revision constructor passed invalid row format.' );
1352 if ( !isset( $mainSlotRow->slot_origin ) ) {
1353 $mainSlotRow->slot_origin = $mainSlotRow->slot_revision_id;
1356 if ( $mainSlotRow->model_name ===
null ) {
1360 return $this->slotRoleRegistry->getRoleHandler( $slot->getRole() )
1361 ->getDefaultModel(
$title );
1370 use ( $blobData, $blobFlags, $queryFlags, $mainSlotRow )
1376 $mainSlotRow->format_name,
1386 $mainSlotRow->slot_content_id =
1387 function (
SlotRecord $slot )
use ( $queryFlags, $mainSlotRow ) {
1440 if ( $blobData !==
null ) {
1441 Assert::parameterType(
'string', $blobData,
'$blobData' );
1442 Assert::parameterType(
'string|null', $blobFlags,
'$blobFlags' );
1446 if ( $blobFlags ===
null ) {
1450 $data = $this->blobStore->expandBlob( $blobData, $blobFlags, $cacheKey );
1451 if (
$data ===
false ) {
1453 "Failed to expand blob data using flags $blobFlags (key: $cacheKey)"
1461 $data = $this->blobStore->getBlob( $address, $queryFlags );
1464 "Failed to load data blob from $address: " .
$e->getMessage(), 0,
$e
1512 $title = Title::newFromLinkTarget( $linkTarget );
1514 'page_namespace' =>
$title->getNamespace(),
1515 'page_title' =>
$title->getDBkey()
1523 $conds[
'rev_id'] = $revId;
1533 $conds[] =
'rev_id=page_latest';
1557 $conds = [
'page_id' => $pageId ];
1564 $conds[
'rev_id'] = $revId;
1574 $conds[] =
'rev_id=page_latest';
1596 'rev_timestamp' => $db->timestamp( $timestamp ),
1597 'page_namespace' =>
$title->getNamespace(),
1598 'page_title' =>
$title->getDBkey()
1621 'slot_revision_id' => $revId,
1630 foreach (
$res as $row ) {
1632 $row->role_name = $this->slotRoleStore->getName( (
int)$row->slot_role_id );
1633 $row->model_name = $this->contentModelStore->getName( (
int)$row->content_model );
1635 $contentCallback =
function (
SlotRecord $slot )
use ( $queryFlags ) {
1636 return $this->
loadSlotContent( $slot,
null,
null,
null, $queryFlags );
1639 $slots[$row->role_name] =
new SlotRecord( $row, $contentCallback );
1644 'Main slot of revision ' . $revId .
' not found in database!'
1707 Title $title =
null,
1708 array $overrides = []
1710 Assert::parameterType(
'object', $row,
'$row' );
1713 Assert::parameterType(
'integer', $queryFlags,
'$queryFlags' );
1715 if ( !
$title && isset( $overrides[
'title'] ) ) {
1716 if ( !( $overrides[
'title'] instanceof
Title ) ) {
1717 throw new MWException(
'title field override must contain a Title object.' );
1720 $title = $overrides[
'title'];
1723 if ( !isset(
$title ) ) {
1724 if ( isset( $row->ar_namespace ) && isset( $row->ar_title ) ) {
1725 $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
1727 throw new InvalidArgumentException(
1728 'A Title or ar_namespace and ar_title must be given'
1733 foreach ( $overrides
as $key =>
$value ) {
1740 $row->ar_user ??
null,
1741 $row->ar_user_text ??
null,
1742 $row->ar_actor ??
null
1744 }
catch ( InvalidArgumentException $ex ) {
1745 wfWarn( __METHOD__ .
': ' .
$title->getPrefixedDBkey() .
': ' . $ex->getMessage() );
1751 $comment = $this->commentStore->getCommentLegacy( $db,
'ar_comment', $row,
true );
1773 Title $title =
null,
1776 Assert::parameterType(
'object', $row,
'$row' );
1779 $pageId = $row->rev_page ?? 0;
1780 $revId = $row->rev_id ?? 0;
1785 if ( !isset( $row->page_latest ) ) {
1786 $row->page_latest =
$title->getLatestRevID();
1787 if ( $row->page_latest === 0 &&
$title->exists() ) {
1788 wfWarn(
'Encountered title object in limbo: ID ' .
$title->getArticleID() );
1794 $row->rev_user ??
null,
1795 $row->rev_user_text ??
null,
1796 $row->rev_actor ??
null
1798 }
catch ( InvalidArgumentException $ex ) {
1799 wfWarn( __METHOD__ .
': ' .
$title->getPrefixedDBkey() .
': ' . $ex->getMessage() );
1805 $comment = $this->commentStore->getCommentLegacy( $db,
'rev_comment', $row,
true );
1812 function ( $revId )
use ( $queryFlags ) {
1816 [
'rev_id' => intval( $revId ) ]
1823 $title,
$user, $comment, $row, $slots, $this->wikiId );
1847 if ( !
$title && isset( $fields[
'title'] ) ) {
1848 if ( !( $fields[
'title'] instanceof
Title ) ) {
1849 throw new MWException(
'title field must contain a Title object.' );
1852 $title = $fields[
'title'];
1856 $pageId = $fields[
'page'] ?? 0;
1857 $revId = $fields[
'id'] ?? 0;
1862 if ( !isset( $fields[
'page'] ) ) {
1863 $fields[
'page'] =
$title->getArticleID( $queryFlags );
1867 if ( !empty( $fields[
'content'] ) && !( $fields[
'content'] instanceof
Content )
1868 && !is_array( $fields[
'content'] )
1871 'content field must contain a Content object or an array of Content objects.'
1875 if ( !empty( $fields[
'text_id'] ) ) {
1877 throw new MWException(
"The text_id field is only available in the pre-MCR schema" );
1880 if ( !empty( $fields[
'content'] ) ) {
1882 "Text already stored in external store (id {$fields['text_id']}), " .
1883 "can't specify content object"
1889 isset( $fields[
'comment'] )
1892 $commentData = $fields[
'comment_data'] ??
null;
1894 if ( $fields[
'comment'] instanceof
Message ) {
1895 $fields[
'comment'] = CommentStoreComment::newUnsavedComment(
1900 $commentText = trim( strval( $fields[
'comment'] ) );
1901 $fields[
'comment'] = CommentStoreComment::newUnsavedComment(
1911 if ( isset( $fields[
'content'] ) && is_array( $fields[
'content'] ) ) {
1912 foreach ( $fields[
'content']
as $role =>
$content ) {
1913 $revision->setContent( $role,
$content );
1917 $revision->setSlot( $mainSlot );
1934 if ( isset( $fields[
'user'] ) && ( $fields[
'user'] instanceof
UserIdentity ) ) {
1935 $user = $fields[
'user'];
1939 $fields[
'user'] ??
null,
1940 $fields[
'user_text'] ??
null,
1941 $fields[
'actor'] ??
null
1943 }
catch ( InvalidArgumentException $ex ) {
1952 $timestamp = isset( $fields[
'timestamp'] )
1953 ? strval( $fields[
'timestamp'] )
1958 if ( isset( $fields[
'page'] ) ) {
1959 $record->
setPageId( intval( $fields[
'page'] ) );
1962 if ( isset( $fields[
'id'] ) ) {
1963 $record->
setId( intval( $fields[
'id'] ) );
1965 if ( isset( $fields[
'parent_id'] ) ) {
1966 $record->
setParentId( intval( $fields[
'parent_id'] ) );
1969 if ( isset( $fields[
'sha1'] ) ) {
1970 $record->
setSha1( $fields[
'sha1'] );
1972 if ( isset( $fields[
'size'] ) ) {
1973 $record->
setSize( intval( $fields[
'size'] ) );
1976 if ( isset( $fields[
'minor_edit'] ) ) {
1977 $record->
setMinorEdit( intval( $fields[
'minor_edit'] ) !== 0 );
1979 if ( isset( $fields[
'deleted'] ) ) {
1983 if ( isset( $fields[
'comment'] ) ) {
1984 Assert::parameterType(
1985 CommentStoreComment::class,
2027 $conds = [
'rev_page' => intval( $pageid ),
'page_id' => intval( $pageid ) ];
2029 $conds[
'rev_id'] = intval( $id );
2031 $conds[] =
'rev_id=page_latest';
2054 $matchId = intval( $id );
2056 $matchId =
'page_latest';
2063 'page_namespace' =>
$title->getNamespace(),
2064 'page_title' =>
$title->getDBkey()
2089 'rev_timestamp' => $db->
timestamp( $timestamp ),
2090 'page_namespace' =>
$title->getNamespace(),
2091 'page_title' =>
$title->getDBkey()
2122 && !( $flags & self::READ_LATEST )
2123 && $lb->getServerCount() > 1
2124 && $lb->hasOrMadeRecentMasterChanges()
2126 $flags = self::READ_LATEST;
2175 if ( $dbWiki === $storeWiki ) {
2179 $storeWiki = $storeWiki ?: $this->loadBalancer->getLocalDomainID();
2183 if ( $dbWiki === $storeWiki ) {
2188 $storeWiki = str_replace(
'?h',
'-', $storeWiki );
2189 $dbWiki = str_replace(
'?h',
'-', $dbWiki );
2191 if ( $dbWiki === $storeWiki ) {
2195 throw new MWException(
"RevisionStore for $storeWiki "
2196 .
"cannot be used with a DB connection for $dbWiki" );
2216 if ( ( $flags & self::READ_LOCKING ) == self::READ_LOCKING ) {
2249 $roleId = $this->slotRoleStore->getId( $role );
2251 'slot_revision_id' => $revId,
2252 'slot_role_id' => $roleId,
2255 $contentId = $db->
selectField(
'slots',
'slot_content_id', $conditions, __METHOD__ );
2257 return $contentId ?:
null;
2295 $ret[
'tables'][] =
'revision';
2296 $ret[
'fields'] = array_merge(
$ret[
'fields'], [
2307 $commentQuery = $this->commentStore->getJoin(
'rev_comment' );
2308 $ret[
'tables'] = array_merge(
$ret[
'tables'], $commentQuery[
'tables'] );
2309 $ret[
'fields'] = array_merge(
$ret[
'fields'], $commentQuery[
'fields'] );
2310 $ret[
'joins'] = array_merge(
$ret[
'joins'], $commentQuery[
'joins'] );
2312 $actorQuery = $this->actorMigration->getJoin(
'rev_user' );
2313 $ret[
'tables'] = array_merge(
$ret[
'tables'], $actorQuery[
'tables'] );
2314 $ret[
'fields'] = array_merge(
$ret[
'fields'], $actorQuery[
'fields'] );
2315 $ret[
'joins'] = array_merge(
$ret[
'joins'], $actorQuery[
'joins'] );
2318 $ret[
'fields'][] =
'rev_text_id';
2320 if ( $this->contentHandlerUseDB ) {
2321 $ret[
'fields'][] =
'rev_content_format';
2322 $ret[
'fields'][] =
'rev_content_model';
2326 if ( in_array(
'page',
$options,
true ) ) {
2327 $ret[
'tables'][] =
'page';
2328 $ret[
'fields'] = array_merge(
$ret[
'fields'], [
2336 $ret[
'joins'][
'page'] = [
'JOIN', [
'page_id = rev_page' ] ];
2339 if ( in_array(
'user',
$options,
true ) ) {
2340 $ret[
'tables'][] =
'user';
2341 $ret[
'fields'] = array_merge(
$ret[
'fields'], [
2344 $u = $actorQuery[
'fields'][
'rev_user'];
2345 $ret[
'joins'][
'user'] = [
'LEFT JOIN', [
"$u != 0",
"user_id = $u" ] ];
2348 if ( in_array(
'text',
$options,
true ) ) {
2350 throw new InvalidArgumentException(
'text table can no longer be joined directly' );
2360 $ret[
'tables'][] =
'text';
2361 $ret[
'fields'] = array_merge(
$ret[
'fields'], [
2365 $ret[
'joins'][
'text'] = [
'JOIN', [
'rev_text_id=old_id' ] ];
2397 $ret[
'tables'][
'slots'] =
'revision';
2399 $ret[
'fields'][
'slot_revision_id'] =
'slots.rev_id';
2400 $ret[
'fields'][
'slot_content_id'] =
'NULL';
2401 $ret[
'fields'][
'slot_origin'] =
'slots.rev_id';
2404 if ( in_array(
'content',
$options,
true ) ) {
2405 $ret[
'fields'][
'content_size'] =
'slots.rev_len';
2406 $ret[
'fields'][
'content_sha1'] =
'slots.rev_sha1';
2407 $ret[
'fields'][
'content_address']
2408 = $db->buildConcat( [ $db->addQuotes(
'tt:' ),
'slots.rev_text_id' ] );
2410 if ( $this->contentHandlerUseDB ) {
2411 $ret[
'fields'][
'model_name'] =
'slots.rev_content_model';
2413 $ret[
'fields'][
'model_name'] =
'NULL';
2417 $ret[
'tables'][] =
'slots';
2418 $ret[
'fields'] = array_merge(
$ret[
'fields'], [
2425 if ( in_array(
'role',
$options,
true ) ) {
2428 $ret[
'tables'][] =
'slot_roles';
2429 $ret[
'joins'][
'slot_roles'] = [
'LEFT JOIN', [
'slot_role_id = role_id' ] ];
2430 $ret[
'fields'][] =
'role_name';
2433 if ( in_array(
'content',
$options,
true ) ) {
2434 $ret[
'tables'][] =
'content';
2435 $ret[
'fields'] = array_merge(
$ret[
'fields'], [
2441 $ret[
'joins'][
'content'] = [
'JOIN', [
'slot_content_id = content_id' ] ];
2443 if ( in_array(
'model',
$options,
true ) ) {
2446 $ret[
'tables'][] =
'content_models';
2447 $ret[
'joins'][
'content_models'] = [
'LEFT JOIN', [
'content_model = model_id' ] ];
2448 $ret[
'fields'][] =
'model_name';
2471 $commentQuery = $this->commentStore->getJoin(
'ar_comment' );
2472 $actorQuery = $this->actorMigration->getJoin(
'ar_user' );
2474 'tables' => [
'archive' ] + $commentQuery[
'tables'] + $actorQuery[
'tables'],
2487 ] + $commentQuery[
'fields'] + $actorQuery[
'fields'],
2488 'joins' => $commentQuery[
'joins'] + $actorQuery[
'joins'],
2492 $ret[
'fields'][] =
'ar_text_id';
2494 if ( $this->contentHandlerUseDB ) {
2495 $ret[
'fields'][] =
'ar_content_format';
2496 $ret[
'fields'][] =
'ar_content_model';
2538 [
'rev_id',
'rev_len' ],
2539 [
'rev_id' => $revIds ],
2543 foreach (
$res as $row ) {
2544 $revLens[$row->rev_id] = intval( $row->rev_len );
2565 if ( !
$rev->getId() || !
$rev->getPageId() ) {
2580 $prev =
$title->getPreviousRevisionID(
$rev->getId() );
2602 if ( !
$rev->getId() || !
$rev->getPageId() ) {
2617 $next =
$title->getNextRevisionID(
$rev->getId() );
2639 if (
$rev->getPageId() ===
null ) {
2642 # Use page_latest if ID is not given
2643 if ( !
$rev->getId() ) {
2645 'page',
'page_latest',
2646 [
'page_id' =>
$rev->getPageId() ],
2651 'revision',
'rev_id',
2652 [
'rev_page' =>
$rev->getPageId(),
'rev_id < ' .
$rev->getId() ],
2654 [
'ORDER BY' =>
'rev_id DESC' ]
2657 return intval( $prevId );
2673 $conds = [
'rev_id' => $id ];
2674 $conds[
'rev_page'] =
$title->getArticleID();
2675 $timestamp = $db->selectField(
'revision',
'rev_timestamp', $conds, __METHOD__ );
2677 return ( $timestamp !==
false ) ?
wfTimestamp( TS_MW, $timestamp ) :
false;
2693 [
'revCount' =>
'COUNT(*)' ],
2694 [
'rev_page' => $id ],
2698 return intval( $row->revCount );
2713 $id =
$title->getArticleID();
2749 'rev_user' =>
$revQuery[
'fields'][
'rev_user'],
2752 'rev_page' => $pageId,
2756 [
'ORDER BY' =>
'rev_timestamp ASC',
'LIMIT' => 50 ],
2759 foreach (
$res as $row ) {
2760 if ( $row->rev_user != $userId ) {
2783 $pageId =
$title->getArticleID();
2790 $revId =
$title->getLatestRevID();
2795 'No latest revision known for page ' .
$title->getPrefixedDBkey()
2796 .
' even though it exists with page ID ' . $pageId
2805 $row = $this->
cache->getWithSetCallback(
2808 WANObjectCache::TTL_WEEK,
2809 function ( $curValue, &$ttl,
array &$setOpts )
use (
2810 $db, $pageId, $revId, &$fromCache
2812 $setOpts += Database::getCacheSetOptions( $db );
2841 return $this->
cache->makeGlobalKey(
2842 self::ROW_CACHE_KEY,
2857class_alias( RevisionStore::class,
'MediaWiki\Storage\RevisionStore' );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
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
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
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
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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
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
Allows to change the fields on the form that will be generated $name
return true to allow those checks to and false if checking is done & $user
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
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
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))