From 56c21d059c5fab51aac1fa4b0eb8df0a98a72ca1 Mon Sep 17 00:00:00 2001 From: Petr Pchelko Date: Mon, 26 Aug 2019 19:45:33 -0700 Subject: [PATCH] Remove usages of Title::get{Previous,Next}RevisionId The methods were deprecated since 1.34. Change-Id: Ib95ac1ba36a8ffd6b71ed67642d8abb2e3538bae --- includes/actions/HistoryAction.php | 21 +++++++++------- includes/actions/RawAction.php | 18 +++++++++---- includes/api/ApiEditPage.php | 15 +++++++---- includes/api/ApiSetNotificationTimestamp.php | 15 +++++------ includes/changes/CategoryMembershipChange.php | 15 +++++++---- includes/diff/DifferenceEngine.php | 19 ++++++++++++-- includes/page/Article.php | 25 +++++++++++++++---- includes/user/User.php | 16 ++++++++---- 8 files changed, 101 insertions(+), 43 deletions(-) diff --git a/includes/actions/HistoryAction.php b/includes/actions/HistoryAction.php index db874f2de5..6a6104570c 100644 --- a/includes/actions/HistoryAction.php +++ b/includes/actions/HistoryAction.php @@ -433,27 +433,30 @@ class HistoryAction extends FormlessAction { * @return FeedItem */ function feedItem( $row ) { - $rev = new Revision( $row, 0, $this->getTitle() ); - + $revisionStore = MediaWikiServices::getInstance()->getRevisionStore(); + $rev = $revisionStore->newRevisionFromRow( $row, 0, $this->getTitle() ); + $prevRev = $revisionStore->getPreviousRevision( $rev ); + $revComment = $rev->getComment() === null ? null : $rev->getComment()->text; $text = FeedUtils::formatDiffRow( $this->getTitle(), - $this->getTitle()->getPreviousRevisionID( $rev->getId() ), + $prevRev ? $prevRev->getId() : false, $rev->getId(), $rev->getTimestamp(), - $rev->getComment() + $revComment ); - if ( $rev->getComment() == '' ) { + $revUserText = $rev->getUser() ? $rev->getUser()->getName() : ''; + if ( $revComment == '' ) { $contLang = MediaWikiServices::getInstance()->getContentLanguage(); $title = $this->msg( 'history-feed-item-nocomment', - $rev->getUserText(), + $revUserText, $contLang->timeanddate( $rev->getTimestamp() ), $contLang->date( $rev->getTimestamp() ), $contLang->time( $rev->getTimestamp() ) )->inContentLanguage()->text(); } else { - $title = $rev->getUserText() . + $title = $revUserText . $this->msg( 'colon-separator' )->inContentLanguage()->text() . - FeedItem::stripComment( $rev->getComment() ); + FeedItem::stripComment( $revComment ); } return new FeedItem( @@ -461,7 +464,7 @@ class HistoryAction extends FormlessAction { $text, $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ), $rev->getTimestamp(), - $rev->getUserText(), + $revUserText, $this->getTitle()->getTalkPage()->getFullURL() ); } diff --git a/includes/actions/RawAction.php b/includes/actions/RawAction.php index 8fd4e0ad55..0586e093c5 100644 --- a/includes/actions/RawAction.php +++ b/includes/actions/RawAction.php @@ -238,23 +238,31 @@ class RawAction extends FormlessAction { */ public function getOldId() { $oldid = $this->getRequest()->getInt( 'oldid' ); + $rl = MediaWikiServices::getInstance()->getRevisionLookup(); switch ( $this->getRequest()->getText( 'direction' ) ) { case 'next': # output next revision, or nothing if there isn't one - $nextid = 0; + $nextRev = null; if ( $oldid ) { - $nextid = $this->getTitle()->getNextRevisionID( $oldid ); + $oldRev = $rl->getRevisionById( $oldid ); + if ( $oldRev ) { + $nextRev = $rl->getNextRevision( $oldRev ); + } } - $oldid = $nextid ?: -1; + $oldid = $nextRev ? $nextRev->getId() : -1; break; case 'prev': # output previous revision, or nothing if there isn't one + $prevRev = null; if ( !$oldid ) { # get the current revision so we can get the penultimate one $oldid = $this->page->getLatest(); } - $previd = $this->getTitle()->getPreviousRevisionID( $oldid ); - $oldid = $previd ?: -1; + $oldRev = $rl->getRevisionById( $oldid ); + if ( $oldRev ) { + $prevRev = $rl->getPreviousRevision( $oldRev ); + } + $oldid = $prevRev ? $prevRev->getId() : -1; break; case 'cur': $oldid = 0; diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index fdf9cf1bf9..06f6f6097d 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -20,6 +20,7 @@ * @file */ +use MediaWiki\MediaWikiServices; use MediaWiki\Storage\RevisionRecord; /** @@ -239,11 +240,15 @@ class ApiEditPage extends ApiBase { $params['text'] = $newContent->serialize( $contentFormat ); // If no summary was given and we only undid one rev, // use an autosummary - if ( is_null( $params['summary'] ) && - $titleObj->getNextRevisionID( $undoafterRev->getId() ) == $params['undo'] - ) { - $params['summary'] = wfMessage( 'undo-summary' ) - ->params( $params['undo'], $undoRev->getUserText() )->inContentLanguage()->text(); + + if ( is_null( $params['summary'] ) ) { + $nextRev = MediaWikiServices::getInstance()->getRevisionLookup() + ->getNextRevision( $undoafterRev->getRevisionRecord() ); + if ( $nextRev && $nextRev->getId() == $params['undo'] ) { + $params['summary'] = wfMessage( 'undo-summary' ) + ->params( $params['undo'], $undoRev->getUserText() ) + ->inContentLanguage()->text(); + } } } diff --git a/includes/api/ApiSetNotificationTimestamp.php b/includes/api/ApiSetNotificationTimestamp.php index 7e9f56d09c..3f6f14c1b3 100644 --- a/includes/api/ApiSetNotificationTimestamp.php +++ b/includes/api/ApiSetNotificationTimestamp.php @@ -93,13 +93,14 @@ class ApiSetNotificationTimestamp extends ApiBase { $titles = $pageSet->getGoodTitles(); $title = reset( $titles ); if ( $title ) { - $revid = $title->getNextRevisionID( $params['newerthanrevid'], Title::READ_LATEST ); - if ( $revid ) { - $timestamp = $dbw->timestamp( - MediaWikiServices::getInstance()->getRevisionStore()->getTimestampFromId( $title, $revid ) - ); - } else { - $timestamp = null; + $timestamp = null; + $rl = MediaWikiServices::getInstance()->getRevisionLookup(); + $currRev = $rl->getRevisionById( $params['newerthanrevid'], Title::READ_LATEST ); + if ( $currRev ) { + $nextRev = $rl->getNextRevision( $currRev, Title::READ_LATEST ); + if ( $nextRev ) { + $timestamp = $dbw->timestamp( $nextRev->getTimestamp() ); + } } } } diff --git a/includes/changes/CategoryMembershipChange.php b/includes/changes/CategoryMembershipChange.php index 2ef9c9f95f..14e391d7a0 100644 --- a/includes/changes/CategoryMembershipChange.php +++ b/includes/changes/CategoryMembershipChange.php @@ -1,5 +1,6 @@ pageTitle->getPreviousRevisionID( $this->pageTitle->getLatestRevID() ) - ); - - return $previousRev ? $previousRev->getTimestamp() : null; + $rl = MediaWikiServices::getInstance()->getRevisionLookup(); + $latestRev = $rl->getRevisionByTitle( $this->pageTitle ); + if ( $latestRev ) { + $previousRev = $rl->getPreviousRevision( $latestRev ); + if ( $previousRev ) { + return $previousRev->getTimestamp(); + } + } + return null; } } diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index 8a5caa2dce..7e4e53e2b6 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -1713,14 +1713,29 @@ class DifferenceEngine extends ContextSource { * false signifies that there is no previous/next revision ($old is the oldest/newest one). */ public function mapDiffPrevNext( $old, $new ) { + $rl = MediaWikiServices::getInstance()->getRevisionLookup(); if ( $new === 'prev' ) { // Show diff between revision $old and the previous one. Get previous one from DB. $newid = intval( $old ); - $oldid = $this->getTitle()->getPreviousRevisionID( $newid ); + $oldid = false; + $newRev = $rl->getRevisionById( $newid ); + if ( $newRev ) { + $oldRev = $rl->getPreviousRevision( $newRev ); + if ( $oldRev ) { + $oldid = $oldRev->getId(); + } + } } elseif ( $new === 'next' ) { // Show diff between revision $old and the next one. Get next one from DB. $oldid = intval( $old ); - $newid = $this->getTitle()->getNextRevisionID( $oldid ); + $newid = false; + $oldRev = $rl->getRevisionById( $oldid ); + if ( $oldRev ) { + $newRev = $rl->getNextRevision( $oldRev ); + if ( $newRev ) { + $newid = $newRev->getId(); + } + } } else { $oldid = intval( $old ); $newid = intval( $new ); diff --git a/includes/page/Article.php b/includes/page/Article.php index 4bede965ab..6aeb038251 100644 --- a/includes/page/Article.php +++ b/includes/page/Article.php @@ -363,8 +363,16 @@ class Article implements Page { } } + $rl = MediaWikiServices::getInstance()->getRevisionLookup(); + $oldRev = $this->mRevision ? $this->mRevision->getRevisionRecord() : null; if ( $request->getVal( 'direction' ) == 'next' ) { - $nextid = $this->getTitle()->getNextRevisionID( $oldid ); + $nextid = 0; + if ( $oldRev ) { + $nextRev = $rl->getNextRevision( $oldRev ); + if ( $nextRev ) { + $nextid = $nextRev->getId(); + } + } if ( $nextid ) { $oldid = $nextid; $this->mRevision = null; @@ -372,7 +380,13 @@ class Article implements Page { $this->mRedirectUrl = $this->getTitle()->getFullURL( 'redirect=no' ); } } elseif ( $request->getVal( 'direction' ) == 'prev' ) { - $previd = $this->getTitle()->getPreviousRevisionID( $oldid ); + $previd = 0; + if ( $oldRev ) { + $prevRev = $rl->getPreviousRevision( $oldRev ); + if ( $prevRev ) { + $previd = $prevRev->getId(); + } + } if ( $previd ) { $oldid = $previd; $this->mRevision = null; @@ -1599,8 +1613,9 @@ class Article implements Page { 'oldid' => $oldid ] + $extraParams ); - $prev = $this->getTitle()->getPreviousRevisionID( $oldid ); - $prevlink = $prev + $rl = MediaWikiServices::getInstance()->getRevisionLookup(); + $prevExist = (bool)$rl->getPreviousRevision( $revision->getRevisionRecord() ); + $prevlink = $prevExist ? Linker::linkKnown( $this->getTitle(), $context->msg( 'previousrevision' )->escaped(), @@ -1611,7 +1626,7 @@ class Article implements Page { ] + $extraParams ) : $context->msg( 'previousrevision' )->escaped(); - $prevdiff = $prev + $prevdiff = $prevExist ? Linker::linkKnown( $this->getTitle(), $context->msg( 'diff' )->escaped(), diff --git a/includes/user/User.php b/includes/user/User.php index d71750bcfd..28de956826 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -3738,11 +3738,17 @@ class User implements IDBAccessObject, UserIdentity { $this->setNewtalk( false ); // If there is a new, unseen, revision, use its timestamp - $nextid = $oldid - ? $title->getNextRevisionID( $oldid, Title::READ_LATEST ) - : null; - if ( $nextid ) { - $this->setNewtalk( true, Revision::newFromId( $nextid ) ); + if ( $oldid ) { + $rl = MediaWikiServices::getInstance()->getRevisionLookup(); + $oldRev = $rl->getRevisionById( $oldid, Title::READ_LATEST ); + if ( $oldRev ) { + $newRev = $rl->getNextRevision( $oldRev ); + if ( $newRev ) { + // TODO: actually no need to wrap in a revision, + // setNewtalk really only needs a RevRecord + $this->setNewtalk( true, new Revision( $newRev ) ); + } + } } } ); } -- 2.20.1