Remove usages of Title::get{Previous,Next}RevisionId
authorPetr Pchelko <ppchelko@wikimedia.org>
Tue, 27 Aug 2019 02:45:33 +0000 (19:45 -0700)
committerPetr Pchelko <ppchelko@wikimedia.org>
Fri, 13 Sep 2019 16:49:13 +0000 (09:49 -0700)
The methods were deprecated since 1.34.

Change-Id: Ib95ac1ba36a8ffd6b71ed67642d8abb2e3538bae

includes/actions/HistoryAction.php
includes/actions/RawAction.php
includes/api/ApiEditPage.php
includes/api/ApiSetNotificationTimestamp.php
includes/changes/CategoryMembershipChange.php
includes/diff/DifferenceEngine.php
includes/page/Article.php
includes/user/User.php

index db874f2..6a61045 100644 (file)
@@ -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()
                );
        }
index 8fd4e0a..0586e09 100644 (file)
@@ -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;
index fdf9cf1..06f6f60 100644 (file)
@@ -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();
+                               }
                        }
                }
 
index 7e9f56d..3f6f14c 100644 (file)
@@ -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() );
+                                       }
                                }
                        }
                }
index 2ef9c9f..14e391d 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
 use MediaWiki\Storage\RevisionRecord;
 
 /**
@@ -273,11 +274,15 @@ class CategoryMembershipChange {
         * @return null|string
         */
        private function getPreviousRevisionTimestamp() {
-               $previousRev = Revision::newFromId(
-                               $this->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;
        }
 
 }
index 8a5caa2..7e4e53e 100644 (file)
@@ -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 );
index 4bede96..6aeb038 100644 (file)
@@ -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(),
index d71750b..28de956 100644 (file)
@@ -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 ) );
+                                               }
+                                       }
                                }
                        } );
                }