Revert "[MCR] Add optional $title param to Revision byId methods"
[lhc/web/wiklou.git] / includes / Revision.php
index ea73a61..9a29386 100644 (file)
@@ -65,10 +65,14 @@ class Revision implements IDBAccessObject {
        }
 
        /**
+        * @param bool|string $wikiId The ID of the target wiki database. Use false for the local wiki.
+        *
         * @return SqlBlobStore
         */
-       protected static function getBlobStore() {
-               $store = MediaWikiServices::getInstance()->getBlobStore();
+       protected static function getBlobStore( $wiki = false ) {
+               $store = MediaWikiServices::getInstance()
+                       ->getBlobStoreFactory()
+                       ->newSqlBlobStore( $wiki );
 
                if ( !$store instanceof SqlBlobStore ) {
                        throw new RuntimeException(
@@ -141,13 +145,25 @@ class Revision implements IDBAccessObject {
         *
         * @param object $row
         * @param array $overrides
+        * @param Title $title (optional)
         *
         * @throws MWException
         * @return Revision
         */
-       public static function newFromArchiveRow( $row, $overrides = [] ) {
-               $rec = self::getRevisionStore()->newRevisionFromArchiveRow( $row, 0, null, $overrides );
-               return new Revision( $rec );
+       public static function newFromArchiveRow( $row, $overrides = [], Title $title = null ) {
+               /**
+                * MCR Migration: https://phabricator.wikimedia.org/T183564
+                * This method used to overwrite attributes, then passed to Revision::__construct
+                * RevisionStore::newRevisionFromArchiveRow instead overrides row field names
+                * So do a conversion here.
+                */
+               if ( array_key_exists( 'page', $overrides ) ) {
+                       $overrides['page_id'] = $overrides['page'];
+                       unset( $overrides['page'] );
+               }
+
+               $rec = self::getRevisionStore()->newRevisionFromArchiveRow( $row, 0, $title, $overrides );
+               return new Revision( $rec, self::READ_NORMAL, $title );
        }
 
        /**
@@ -879,8 +895,10 @@ class Revision implements IDBAccessObject {
         * @return Revision|null
         */
        public function getPrevious() {
-               $rec = self::getRevisionStore()->getPreviousRevision( $this->mRecord );
-               return $rec === null ? null : new Revision( $rec );
+               $rec = self::getRevisionStore()->getPreviousRevision( $this->mRecord, $this->getTitle() );
+               return $rec === null
+                       ? null
+                       : new Revision( $rec, self::READ_NORMAL, $this->getTitle() );
        }
 
        /**
@@ -889,8 +907,10 @@ class Revision implements IDBAccessObject {
         * @return Revision|null
         */
        public function getNext() {
-               $rec = self::getRevisionStore()->getNextRevision( $this->mRecord );
-               return $rec === null ? null : new Revision( $rec );
+               $rec = self::getRevisionStore()->getNextRevision( $this->mRecord, $this->getTitle() );
+               return $rec === null
+                       ? null
+                       : new Revision( $rec, self::READ_NORMAL, $this->getTitle() );
        }
 
        /**
@@ -925,7 +945,7 @@ class Revision implements IDBAccessObject {
 
                $cacheKey = isset( $row->old_id ) ? ( 'tt:' . $row->old_id ) : null;
 
-               return self::getBlobStore()->expandBlob( $text, $flags, $cacheKey );
+               return self::getBlobStore( $wiki )->expandBlob( $text, $flags, $cacheKey );
        }
 
        /**
@@ -979,8 +999,10 @@ class Revision implements IDBAccessObject {
 
                $this->mRecord = $rec;
 
+               // Avoid PHP 7.1 warning of passing $this by reference
+               $revision = $this;
                // TODO: hard-deprecate in 1.32 (or even 1.31?)
-               Hooks::run( 'RevisionInsertComplete', [ $this, null, null ] );
+               Hooks::run( 'RevisionInsertComplete', [ &$revision, null, null ] );
 
                return $rec->getId();
        }