Daniel Kinzler has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/377654 )
Change subject: First spike exploring usage of new RevisionStore class ...................................................................... First spike exploring usage of new RevisionStore class Change-Id: Id34772d13b44d3c5be3d9abc891571075bdd7ce6 --- M includes/Revision.php M includes/Title.php M includes/api/ApiQueryAllDeletedRevisions.php M includes/api/ApiQueryAllRevisions.php M includes/api/ApiQueryDeletedRevisions.php M includes/api/ApiQueryRevisions.php M includes/api/ApiQueryRevisionsBase.php M includes/api/ApiQueryUserContributions.php M maintenance/Maintenance.php M maintenance/rebuildtextindex.php 10 files changed, 52 insertions(+), 27 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/54/377654/1 diff --git a/includes/Revision.php b/includes/Revision.php index c282b2f..efc52e0 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -158,6 +158,7 @@ * Returns null if no such revision can be found. * * @deprecated since 1.30, use RevisionStore::getRevisionById() instead. + * @note No callers in core. * * @param IDatabase $db * @param int $id @@ -175,6 +176,7 @@ * to that page, will return null. * * @deprecated since 1.30, use RevisionStore::getRevisionByPageId() instead. + * @note No callers in core. * * @param IDatabase $db * @param int $pageid @@ -434,7 +436,7 @@ * @param Title $title */ public function setTitle( $title ) { - // FIXME! + // FIXME! Quite a few callers! throw new LogicException( 'Not implemented: ' . __METHOD__ ); } diff --git a/includes/Title.php b/includes/Title.php index 0687a15..062545c 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -4144,7 +4144,8 @@ ] ); if ( $row ) { - return new Revision( $row ); + $revStore = MediaWikiServices::getInstance()->getRevisionStore(); + return $revStore->newRevisionFromRow( $row ); } } return null; diff --git a/includes/api/ApiQueryAllDeletedRevisions.php b/includes/api/ApiQueryAllDeletedRevisions.php index b22bb1f..725cd95 100644 --- a/includes/api/ApiQueryAllDeletedRevisions.php +++ b/includes/api/ApiQueryAllDeletedRevisions.php @@ -24,6 +24,7 @@ * * @file */ +use MediaWiki\MediaWikiServices; /** * Query module to enumerate all deleted revisions. @@ -342,7 +343,8 @@ $generated[] = $row->ar_rev_id; } } else { - $revision = Revision::newFromArchiveRow( $row ); + $revisionStore = MediaWikiServices::getInstance()->getRevisionStore(); + $revision = $revisionStore->newRevisionFromArchiveRow( $row ); $rev = $this->extractRevisionInfo( $revision, $row ); if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) { diff --git a/includes/api/ApiQueryAllRevisions.php b/includes/api/ApiQueryAllRevisions.php index 8f7d6eb..d8d4a3b 100644 --- a/includes/api/ApiQueryAllRevisions.php +++ b/includes/api/ApiQueryAllRevisions.php @@ -21,6 +21,7 @@ * * @file */ +use MediaWiki\MediaWikiServices; /** * Query module to enumerate all revisions. @@ -198,7 +199,8 @@ $generated[] = $row->rev_id; } } else { - $revision = Revision::newFromRow( $row ); + $revisionStore = MediaWikiServices::getInstance()->getRevisionStore(); + $revision = $revisionStore->newRevisionFromRow( $row ); $rev = $this->extractRevisionInfo( $revision, $row ); if ( !isset( $pageMap[$row->rev_page] ) ) { diff --git a/includes/api/ApiQueryDeletedRevisions.php b/includes/api/ApiQueryDeletedRevisions.php index 8e4752e..d4f6cb6 100644 --- a/includes/api/ApiQueryDeletedRevisions.php +++ b/includes/api/ApiQueryDeletedRevisions.php @@ -24,6 +24,7 @@ * * @file */ +use MediaWiki\MediaWikiServices; /** * Query module to enumerate deleted revisions for pages. @@ -227,9 +228,11 @@ ); } + $revisionStore = MediaWikiServices::getInstance()->getRevisionStore(); + $revision = $revisionStore->newRevisionFromArchiveRow( $row ); $fit = $this->addPageSubItem( $pageMap[$row->ar_namespace][$row->ar_title], - $this->extractRevisionInfo( Revision::newFromArchiveRow( $row ), $row ), + $this->extractRevisionInfo( $revision, $row ), 'rev' ); if ( !$fit ) { diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 2dfa42a..a854a8b 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -23,6 +23,7 @@ * * @file */ +use MediaWiki\MediaWikiServices; /** * A query action to enumerate revisions of a given page, or show top revisions @@ -392,7 +393,8 @@ if ( $resultPageSet !== null ) { $generated[] = $row->rev_id; } else { - $revision = new Revision( $row ); + $revisionStore = MediaWikiServices::getInstance()->getRevisionStore(); + $revision = $revisionStore->newRevisionFromRow( $row ); $rev = $this->extractRevisionInfo( $revision, $row ); if ( $this->token !== null ) { diff --git a/includes/api/ApiQueryRevisionsBase.php b/includes/api/ApiQueryRevisionsBase.php index 2ffd024..9395c83 100644 --- a/includes/api/ApiQueryRevisionsBase.php +++ b/includes/api/ApiQueryRevisionsBase.php @@ -23,6 +23,7 @@ * * @file */ +use MediaWiki\Storage\RevisionRecord; /** * A base class for functions common to producing a list of revisions. @@ -161,11 +162,11 @@ /** * Extract information from the Revision * - * @param Revision $revision + * @param RevisionRecord $revision * @param object $row Should have a field 'ts_tags' if $this->fld_tags is set * @return array */ - protected function extractRevisionInfo( Revision $revision, $row ) { + protected function extractRevisionInfo( RevisionRecord $revision, $row ) { $title = $revision->getTitle(); $user = $this->getUser(); $vals = []; @@ -219,7 +220,7 @@ $vals['sha1hidden'] = true; $anyHidden = true; } - if ( $revision->userCan( Revision::DELETED_TEXT, $user ) ) { + if ( $revision->userCan( Revision::DELETED_TEXT, $user ) ) { // FIXME if ( $revision->getSha1() != '' ) { $vals['sha1'] = Wikimedia\base_convert( $revision->getSha1(), 36, 16, 40 ); } else { @@ -228,8 +229,10 @@ } } + // TODO: add support for selecting the desired slot(s) + // TODO: remove revision content model if ( $this->fld_contentmodel ) { - $vals['contentmodel'] = $revision->getContentModel(); + $vals['contentmodel'] = $revision->getSlot( 'main' )->getContentModel(); } if ( $this->fld_comment || $this->fld_parsedcomment ) { @@ -241,7 +244,7 @@ $comment = $revision->getComment( Revision::RAW ); if ( $this->fld_comment ) { - $vals['comment'] = $comment; + $vals['comment'] = $comment->text; } if ( $this->fld_parsedcomment ) { @@ -263,7 +266,8 @@ $content = null; global $wgParser; if ( $this->fetchContent ) { - $content = $revision->getContent( Revision::FOR_THIS_USER, $this->getUser() ); + // FIXME: select slot + $content = $revision->getContent( 'main', Revision::FOR_THIS_USER, $this->getUser() ); // Expand templates after getting section content because // template-added sections don't count and Parser::preprocess() // will have less input @@ -380,7 +384,7 @@ $vals['diff'] = []; $context = new DerivativeContext( $this->getContext() ); $context->setTitle( $title ); - $handler = $revision->getContentHandler(); + $handler = $content->getContentHandler(); if ( !is_null( $this->difftotext ) ) { $model = $title->getContentModel(); diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php index bb0f335..06ccf11 100644 --- a/includes/api/ApiQueryUserContributions.php +++ b/includes/api/ApiQueryUserContributions.php @@ -23,6 +23,9 @@ * * @file */ +use MediaWiki\MediaWikiServices; +use MediaWiki\Storage\DefaultRevisionRecord; +use MediaWiki\Storage\RevisionRecord; /** * This query action adds a list of a specified user's contributions to the output. @@ -151,7 +154,8 @@ $revIds[] = $row->rev_parent_id; } } - $this->parentLens = Revision::getParentLengths( $dbSecondary, $revIds ); + $revStore = MediaWikiServices::getInstance()->getRevisionStore(); + $this->parentLens = $revStore->getParentLengths( $dbSecondary, $revIds ); $res->rewind(); // reset } @@ -238,9 +242,9 @@ // Don't include any revisions where we're not supposed to be able to // see the username. if ( !$user->isAllowed( 'deletedhistory' ) ) { - $bitmask = Revision::DELETED_USER; + $bitmask = RevisionRecord::DELETED_USER; } elseif ( !$user->isAllowedAny( 'suppressrevision', 'viewsuppressed' ) ) { - $bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED; + $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED; } else { $bitmask = 0; } @@ -386,7 +390,7 @@ $vals = []; $anyHidden = false; - if ( $row->rev_deleted & Revision::DELETED_TEXT ) { + if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) { $vals['texthidden'] = true; $anyHidden = true; } @@ -394,7 +398,7 @@ // Any rows where we can't view the user were filtered out in the query. $vals['userid'] = (int)$row->rev_user; $vals['user'] = $row->rev_user_text; - if ( $row->rev_deleted & Revision::DELETED_USER ) { + if ( $row->rev_deleted & RevisionRecord::DELETED_USER ) { $vals['userhidden'] = true; $anyHidden = true; } @@ -425,14 +429,15 @@ } if ( $this->fld_comment || $this->fld_parsedcomment ) { - if ( $row->rev_deleted & Revision::DELETED_COMMENT ) { + if ( $row->rev_deleted & RevisionRecord::DELETED_COMMENT ) { $vals['commenthidden'] = true; $anyHidden = true; } - $userCanView = Revision::userCanBitfield( + // XXX: not nice to bind to DefaultRevisionRecord here. + $userCanView = DefaultRevisionRecord::userCanBitfield( $row->rev_deleted, - Revision::DELETED_COMMENT, $this->getUser() + RevisionRecord::DELETED_COMMENT, $this->getUser() ); if ( $userCanView ) { @@ -475,7 +480,7 @@ } } - if ( $anyHidden && $row->rev_deleted & Revision::DELETED_RESTRICTED ) { + if ( $anyHidden && $row->rev_deleted & RevisionRecord::DELETED_RESTRICTED ) { $vals['suppressed'] = true; } diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index 89e8089..2decebb 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -1401,14 +1401,16 @@ */ public function updateSearchIndexForPage( $dbw, $pageId ) { // Get current revision - $rev = Revision::loadFromPageId( $dbw, $pageId ); + $revStore = MediaWikiServices::getInstance()->getRevisionStore(); + $rev = $revStore->loadRevisionFromPageId( $dbw, $pageId ); $title = null; if ( $rev ) { $titleObj = $rev->getTitle(); $title = $titleObj->getPrefixedDBkey(); $this->output( "$title..." ); - # Update searchindex - $u = new SearchUpdate( $pageId, $titleObj->getText(), $rev->getContent() ); + // Update searchindex + // TODO: index all slots! + $u = new SearchUpdate( $pageId, $titleObj->getText(), $rev->getContent( 'main' ) ); $u->doUpdate(); $this->output( "\n" ); } diff --git a/maintenance/rebuildtextindex.php b/maintenance/rebuildtextindex.php index faa4d96..b1bbd6b 100644 --- a/maintenance/rebuildtextindex.php +++ b/maintenance/rebuildtextindex.php @@ -27,6 +27,7 @@ require_once __DIR__ . '/Maintenance.php'; +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\IMaintainableDatabase; use Wikimedia\Rdbms\DatabaseSqlite; @@ -113,8 +114,9 @@ foreach ( $res as $s ) { $title = Title::makeTitle( $s->page_namespace, $s->page_title ); try { - $rev = new Revision( $s ); - $content = $rev->getContent(); + $revStore = MediaWikiServices::getInstance()->getRevisionStore(); + $rev = $revStore->newRevisionFromRow( $s ); + $content = $rev->getContent( 'main' ); // TODO: make this index all slots! $u = new SearchUpdate( $s->page_id, $title, $content ); $u->doUpdate(); -- To view, visit https://gerrit.wikimedia.org/r/377654 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id34772d13b44d3c5be3d9abc891571075bdd7ce6 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits