Merge "Add tests for ApiFormatBase"
[lhc/web/wiklou.git] / includes / Revision.php
index 7d38b4e..54c6de0 100644 (file)
@@ -149,7 +149,7 @@ class Revision implements IDBAccessObject {
         * @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
@@ -161,6 +161,29 @@ class Revision implements IDBAccessObject {
                        unset( $overrides['page'] );
                }
 
+               /**
+                * 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, $title, $overrides );
                return new Revision( $rec, self::READ_NORMAL, $title );
        }
@@ -1156,6 +1179,10 @@ class Revision implements IDBAccessObject {
                        ? $pageIdOrTitle
                        : Title::newFromID( $pageIdOrTitle );
 
+               if ( !$title ) {
+                       return false;
+               }
+
                $record = self::getRevisionStore()->getKnownCurrentRevision( $title, $revId );
                return $record ? new Revision( $record ) : false;
        }