Use RevisionLookup and RevisionFactory interfaces in Revision
authoraddshore <addshorewiki@gmail.com>
Tue, 9 Jan 2018 08:53:38 +0000 (08:53 +0000)
committeraddshore <addshorewiki@gmail.com>
Wed, 24 Jan 2018 22:11:31 +0000 (14:11 -0800)
Lets not depend on the big blob that is RevisionStore.
Try to bind to the nice interfaces that we have where possible.

In the future RevisionStore should be split up further into
it's individual interfaces.

It looks like there are some more methods which should be moved
to both RevisionLookup and RevisionFactory.
See draft:
I214c5952d4a0fad55ff4116e90eab9ac3ba54fd3

Change-Id: I8df61374e24abcf4a7e38e53647489b8ecc1fd77

includes/MediaWikiServices.php
includes/Revision.php
includes/ServiceWiring.php
tests/phpunit/includes/MediaWikiServicesTest.php

index 00767c7..c283793 100644 (file)
@@ -15,6 +15,8 @@ use MediaWiki\Preferences\PreferencesFactory;
 use MediaWiki\Shell\CommandFactory;
 use MediaWiki\Storage\BlobStore;
 use MediaWiki\Storage\BlobStoreFactory;
+use MediaWiki\Storage\RevisionFactory;
+use MediaWiki\Storage\RevisionLookup;
 use MediaWiki\Storage\RevisionStore;
 use Wikimedia\Rdbms\LBFactory;
 use LinkCache;
@@ -727,6 +729,22 @@ class MediaWikiServices extends ServiceContainer {
                return $this->getService( 'RevisionStore' );
        }
 
+       /**
+        * @since 1.31
+        * @return RevisionLookup
+        */
+       public function getRevisionLookup() {
+               return $this->getService( 'RevisionLookup' );
+       }
+
+       /**
+        * @since 1.31
+        * @return RevisionFactory
+        */
+       public function getRevisionFactory() {
+               return $this->getService( 'RevisionFactory' );
+       }
+
        /**
         * @since 1.31
         * @return PreferencesFactory
index 510c1ee..d5449b4 100644 (file)
@@ -22,6 +22,8 @@
 
 use MediaWiki\Storage\MutableRevisionRecord;
 use MediaWiki\Storage\RevisionAccessException;
+use MediaWiki\Storage\RevisionFactory;
+use MediaWiki\Storage\RevisionLookup;
 use MediaWiki\Storage\RevisionRecord;
 use MediaWiki\Storage\RevisionStore;
 use MediaWiki\Storage\RevisionStoreRecord;
@@ -64,6 +66,20 @@ class Revision implements IDBAccessObject {
                return MediaWikiServices::getInstance()->getRevisionStore();
        }
 
+       /**
+        * @return RevisionLookup
+        */
+       protected static function getRevisionLookup() {
+               return MediaWikiServices::getInstance()->getRevisionLookup();
+       }
+
+       /**
+        * @return RevisionFactory
+        */
+       protected static function getRevisionFactory() {
+               return MediaWikiServices::getInstance()->getRevisionFactory();
+       }
+
        /**
         * @param bool|string $wiki The ID of the target wiki database. Use false for the local wiki.
         *
@@ -97,7 +113,7 @@ class Revision implements IDBAccessObject {
         * @return Revision|null
         */
        public static function newFromId( $id, $flags = 0 ) {
-               $rec = self::getRevisionStore()->getRevisionById( $id, $flags );
+               $rec = self::getRevisionLookup()->getRevisionById( $id, $flags );
                return $rec === null ? null : new Revision( $rec, $flags );
        }
 
@@ -116,7 +132,7 @@ class Revision implements IDBAccessObject {
         * @return Revision|null
         */
        public static function newFromTitle( LinkTarget $linkTarget, $id = 0, $flags = 0 ) {
-               $rec = self::getRevisionStore()->getRevisionByTitle( $linkTarget, $id, $flags );
+               $rec = self::getRevisionLookup()->getRevisionByTitle( $linkTarget, $id, $flags );
                return $rec === null ? null : new Revision( $rec, $flags );
        }
 
@@ -135,7 +151,7 @@ class Revision implements IDBAccessObject {
         * @return Revision|null
         */
        public static function newFromPageId( $pageId, $revId = 0, $flags = 0 ) {
-               $rec = self::getRevisionStore()->getRevisionByPageId( $pageId, $revId, $flags );
+               $rec = self::getRevisionLookup()->getRevisionByPageId( $pageId, $revId, $flags );
                return $rec === null ? null : new Revision( $rec, $flags );
        }
 
@@ -184,7 +200,7 @@ class Revision implements IDBAccessObject {
                        }
                }
 
-               $rec = self::getRevisionStore()->newRevisionFromArchiveRow( $row, 0, $title, $overrides );
+               $rec = self::getRevisionFactory()->newRevisionFromArchiveRow( $row, 0, $title, $overrides );
                return new Revision( $rec, self::READ_NORMAL, $title );
        }
 
@@ -202,9 +218,9 @@ class Revision implements IDBAccessObject {
         */
        public static function newFromRow( $row ) {
                if ( is_array( $row ) ) {
-                       $rec = self::getRevisionStore()->newMutableRevisionFromArray( $row );
+                       $rec = self::getRevisionFactory()->newMutableRevisionFromArray( $row );
                } else {
-                       $rec = self::getRevisionStore()->newRevisionFromRow( $row );
+                       $rec = self::getRevisionFactory()->newRevisionFromRow( $row );
                }
 
                return new Revision( $rec );
@@ -492,13 +508,13 @@ class Revision implements IDBAccessObject {
                                $row['user'] = $wgUser;
                        }
 
-                       $this->mRecord = self::getRevisionStore()->newMutableRevisionFromArray(
+                       $this->mRecord = self::getRevisionFactory()->newMutableRevisionFromArray(
                                $row,
                                $queryFlags,
                                $this->ensureTitle( $row, $queryFlags, $title )
                        );
                } elseif ( is_object( $row ) ) {
-                       $this->mRecord = self::getRevisionStore()->newRevisionFromRow(
+                       $this->mRecord = self::getRevisionFactory()->newRevisionFromRow(
                                $row,
                                $queryFlags,
                                $this->ensureTitle( $row, $queryFlags, $title )
@@ -976,7 +992,7 @@ class Revision implements IDBAccessObject {
         */
        public function getPrevious() {
                $title = $this->getTitle();
-               $rec = self::getRevisionStore()->getPreviousRevision( $this->mRecord, $title );
+               $rec = self::getRevisionLookup()->getPreviousRevision( $this->mRecord, $title );
                return $rec === null ? null : new Revision( $rec, self::READ_NORMAL, $title );
        }
 
@@ -987,7 +1003,7 @@ class Revision implements IDBAccessObject {
         */
        public function getNext() {
                $title = $this->getTitle();
-               $rec = self::getRevisionStore()->getNextRevision( $this->mRecord, $title );
+               $rec = self::getRevisionLookup()->getNextRevision( $this->mRecord, $title );
                return $rec === null ? null : new Revision( $rec, self::READ_NORMAL, $title );
        }
 
@@ -1247,7 +1263,7 @@ class Revision implements IDBAccessObject {
                        return false;
                }
 
-               $record = self::getRevisionStore()->getKnownCurrentRevision( $title, $revId );
+               $record = self::getRevisionLookup()->getKnownCurrentRevision( $title, $revId );
                return $record ? new Revision( $record ) : false;
        }
 }
index dab3b5c..a89619f 100644 (file)
@@ -482,6 +482,14 @@ return [
                return $store;
        },
 
+       'RevisionLookup' => function ( MediaWikiServices $services ) {
+               return $services->getRevisionStore();
+       },
+
+       'RevisionFactory' => function ( MediaWikiServices $services ) {
+               return $services->getRevisionStore();
+       },
+
        'BlobStoreFactory' => function ( MediaWikiServices $services ) {
                global $wgContLang;
                return new BlobStoreFactory(
index d19340b..e3d5336 100644 (file)
@@ -11,6 +11,7 @@ use MediaWiki\Services\ServiceDisabledException;
 use MediaWiki\Shell\CommandFactory;
 use MediaWiki\Storage\BlobStore;
 use MediaWiki\Storage\BlobStoreFactory;
+use MediaWiki\Storage\RevisionLookup;
 use MediaWiki\Storage\RevisionStore;
 use MediaWiki\Storage\SqlBlobStore;
 
@@ -341,6 +342,7 @@ class MediaWikiServicesTest extends MediaWikiTestCase {
                        'BlobStore' => [ 'BlobStore', BlobStore::class ],
                        '_SqlBlobStore' => [ '_SqlBlobStore', SqlBlobStore::class ],
                        'RevisionStore' => [ 'RevisionStore', RevisionStore::class ],
+                       'RevisionLookup' => [ 'RevisionLookup', RevisionLookup::class ],
                        'HttpRequestFactory' => [ 'HttpRequestFactory', HttpRequestFactory::class ],
                ];
        }