Merge "API: Fix doc comment for ApiFormatNone"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 29 Dec 2017 13:48:06 +0000 (13:48 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 29 Dec 2017 13:48:06 +0000 (13:48 +0000)
includes/Revision.php
includes/Storage/RevisionStore.php
includes/page/PageArchive.php

index 8f36e88..4058c63 100644 (file)
@@ -94,54 +94,11 @@ class Revision implements IDBAccessObject {
         *
         * @param int $id
         * @param int $flags (optional)
-        * @param Title $title (optional) If known you can pass the Title in here.
-        *  Passing no Title may result in another DB query if there are recent writes.
         * @return Revision|null
         */
-       public static function newFromId( $id, $flags = 0, Title $title = null ) {
-               /**
-                * MCR RevisionStore Compat
-                *
-                * If the title is not passed in as a param (already known) then select it here.
-                *
-                * Do the selection with MASTER if $flags includes READ_LATEST or recent changes
-                * have happened on our load balancer.
-                *
-                * If we select the title here and pass it down it will results in fewer queries
-                * further down the stack.
-                */
-               if ( !$title ) {
-                       if (
-                               $flags & self::READ_LATEST ||
-                               wfGetLB()->hasOrMadeRecentMasterChanges()
-                       ) {
-                               $dbr = wfGetDB( DB_MASTER );
-                       } else {
-                               $dbr = wfGetDB( DB_REPLICA );
-                       }
-                       $row = $dbr->selectRow(
-                               [ 'revision', 'page' ],
-                               [
-                                       'page_namespace',
-                                       'page_title',
-                                       'page_id',
-                                       'page_latest',
-                                       'page_is_redirect',
-                                       'page_len',
-                               ],
-                               [ 'rev_id' => $id ],
-                               __METHOD__,
-                               [],
-                               [ 'page' => [ 'JOIN', 'page_id=rev_page' ] ]
-                       );
-                       if ( $row ) {
-                               $title = Title::newFromRow( $row );
-                       }
-                       wfGetLB()->reuseConnection( $dbr );
-               }
-
-               $rec = self::getRevisionStore()->getRevisionById( $id, $flags, $title );
-               return $rec === null ? null : new Revision( $rec, $flags, $title );
+       public static function newFromId( $id, $flags = 0 ) {
+               $rec = self::getRevisionStore()->getRevisionById( $id, $flags );
+               return $rec === null ? null : new Revision( $rec, $flags );
        }
 
        /**
@@ -188,12 +145,11 @@ class Revision implements IDBAccessObject {
         *
         * @param object $row
         * @param array $overrides
-        * @param Title $title (optional)
         *
         * @throws MWException
         * @return Revision
         */
-       public static function newFromArchiveRow( $row, $overrides = [], Title $title = null ) {
+       public static function newFromArchiveRow( $row, $overrides = [] ) {
                /**
                 * MCR Migration: https://phabricator.wikimedia.org/T183564
                 * This method used to overwrite attributes, then passed to Revision::__construct
@@ -205,7 +161,30 @@ class Revision implements IDBAccessObject {
                        unset( $overrides['page'] );
                }
 
-               $rec = self::getRevisionStore()->newRevisionFromArchiveRow( $row, 0, $title, $overrides );
+               /**
+                * We require a Title for both the Revision object and the RevisionRecord.
+                * Below is duplicated logic from RevisionStore::newRevisionFromArchiveRow
+                * to fetch a title in order pass it into the Revision object.
+                */
+               $title = null;
+               if ( isset( $overrides['title'] ) ) {
+                       if ( !( $overrides['title'] instanceof Title ) ) {
+                               throw new MWException( 'title field override must contain a Title object.' );
+                       }
+
+                       $title = $overrides['title'];
+               }
+               if ( $title !== null ) {
+                       if ( isset( $row->ar_namespace ) && isset( $row->ar_title ) ) {
+                               $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
+                       } else {
+                               throw new InvalidArgumentException(
+                                       'A Title or ar_namespace and ar_title must be given'
+                               );
+                       }
+               }
+
+               $rec = self::getRevisionStore()->newRevisionFromArchiveRow( $row, 0, null, $overrides );
                return new Revision( $rec, self::READ_NORMAL, $title );
        }
 
@@ -938,10 +917,8 @@ class Revision implements IDBAccessObject {
         * @return Revision|null
         */
        public function getPrevious() {
-               $rec = self::getRevisionStore()->getPreviousRevision( $this->mRecord, $this->getTitle() );
-               return $rec === null
-                       ? null
-                       : new Revision( $rec, self::READ_NORMAL, $this->getTitle() );
+               $rec = self::getRevisionStore()->getPreviousRevision( $this->mRecord );
+               return $rec === null ? null : new Revision( $rec );
        }
 
        /**
@@ -950,10 +927,8 @@ class Revision implements IDBAccessObject {
         * @return Revision|null
         */
        public function getNext() {
-               $rec = self::getRevisionStore()->getNextRevision( $this->mRecord, $this->getTitle() );
-               return $rec === null
-                       ? null
-                       : new Revision( $rec, self::READ_NORMAL, $this->getTitle() );
+               $rec = self::getRevisionStore()->getNextRevision( $this->mRecord );
+               return $rec === null ? null : new Revision( $rec );
        }
 
        /**
index 0209621..ce56efc 100644 (file)
@@ -848,11 +848,10 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
         *
         * @param int $id
         * @param int $flags (optional)
-        * @param Title $title (optional)
         * @return RevisionRecord|null
         */
-       public function getRevisionById( $id, $flags = 0, Title $title = null ) {
-               return $this->newRevisionFromConds( [ 'rev_id' => intval( $id ) ], $flags, $title );
+       public function getRevisionById( $id, $flags = 0 ) {
+               return $this->newRevisionFromConds( [ 'rev_id' => intval( $id ) ], $flags );
        }
 
        /**
@@ -1679,14 +1678,11 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
         * MCR migration note: this replaces Revision::getPrevious
         *
         * @param RevisionRecord $rev
-        * @param Title $title if known (optional)
         *
         * @return RevisionRecord|null
         */
-       public function getPreviousRevision( RevisionRecord $rev, Title $title = null ) {
-               if ( $title === null ) {
-                       $title = $this->getTitle( $rev->getPageId(), $rev->getId() );
-               }
+       public function getPreviousRevision( RevisionRecord $rev ) {
+               $title = $this->getTitle( $rev->getPageId(), $rev->getId() );
                $prev = $title->getPreviousRevisionID( $rev->getId() );
                if ( $prev ) {
                        return $this->getRevisionByTitle( $title, $prev );
@@ -1700,14 +1696,11 @@ class RevisionStore implements IDBAccessObject, RevisionFactory, RevisionLookup
         * MCR migration note: this replaces Revision::getNext
         *
         * @param RevisionRecord $rev
-        * @param Title $title if known (optional)
         *
         * @return RevisionRecord|null
         */
-       public function getNextRevision( RevisionRecord $rev, Title $title = null ) {
-               if ( $title === null ) {
-                       $title = $this->getTitle( $rev->getPageId(), $rev->getId() );
-               }
+       public function getNextRevision( RevisionRecord $rev ) {
+               $title = $this->getTitle( $rev->getPageId(), $rev->getId() );
                $next = $title->getNextRevisionID( $rev->getId() );
                if ( $next ) {
                        return $this->getRevisionByTitle( $title, $next );
index 0ef038f..05247ca 100644 (file)
@@ -255,11 +255,7 @@ class PageArchive {
                );
 
                if ( $row ) {
-                       return Revision::newFromArchiveRow(
-                               $row,
-                               [ 'title' => $this->title ],
-                               $this->title
-                       );
+                       return Revision::newFromArchiveRow( $row, [ 'title' => $this->title ] );
                }
 
                return null;
@@ -608,12 +604,10 @@ class PageArchive {
                        $oldPageId = (int)$latestRestorableRow->ar_page_id; // pass this to ArticleUndelete hook
 
                        // grab the content to check consistency with global state before restoring the page.
-                       $revision = Revision::newFromArchiveRow(
-                               $latestRestorableRow,
+                       $revision = Revision::newFromArchiveRow( $latestRestorableRow,
                                [
                                        'title' => $article->getTitle(), // used to derive default content model
-                               ],
-                               $article->getTitle()
+                               ]
                        );
                        $user = User::newFromName( $revision->getUserText( Revision::RAW ), false );
                        $content = $revision->getContent( Revision::RAW );
@@ -676,15 +670,12 @@ class PageArchive {
                                }
                                // Insert one revision at a time...maintaining deletion status
                                // unless we are specifically removing all restrictions...
-                               $revision = Revision::newFromArchiveRow(
-                                       $row,
+                               $revision = Revision::newFromArchiveRow( $row,
                                        [
                                                'page' => $pageId,
                                                'title' => $this->title,
                                                'deleted' => $unsuppress ? 0 : $row->ar_deleted
-                                       ],
-                                       $this->title
-                               );
+                                       ] );
 
                                // This will also copy the revision to ip_changes if it was an IP edit.
                                $revision->insertOn( $dbw );