jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/403117 )
Change subject: Use RevisionLookup and RevisionFactory interfaces in Revision ...................................................................... Use RevisionLookup and RevisionFactory interfaces in Revision 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 --- M includes/MediaWikiServices.php M includes/Revision.php M includes/ServiceWiring.php M tests/phpunit/includes/MediaWikiServicesTest.php 4 files changed, 55 insertions(+), 11 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/MediaWikiServices.php b/includes/MediaWikiServices.php index 00767c7..c283793 100644 --- a/includes/MediaWikiServices.php +++ b/includes/MediaWikiServices.php @@ -15,6 +15,8 @@ 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; @@ -729,6 +731,22 @@ /** * @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 */ public function getPreferencesFactory() { diff --git a/includes/Revision.php b/includes/Revision.php index 510c1ee..d5449b4 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -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; @@ -65,6 +67,20 @@ } /** + * @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. * * @return SqlBlobStore @@ -97,7 +113,7 @@ * @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 @@ * @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 @@ * @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 @@ } } - $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 @@ */ 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 @@ $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 @@ */ 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 @@ */ 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 @@ return false; } - $record = self::getRevisionStore()->getKnownCurrentRevision( $title, $revId ); + $record = self::getRevisionLookup()->getKnownCurrentRevision( $title, $revId ); return $record ? new Revision( $record ) : false; } } diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index dab3b5c..a89619f 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -482,6 +482,14 @@ 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( diff --git a/tests/phpunit/includes/MediaWikiServicesTest.php b/tests/phpunit/includes/MediaWikiServicesTest.php index d19340b..e3d5336 100644 --- a/tests/phpunit/includes/MediaWikiServicesTest.php +++ b/tests/phpunit/includes/MediaWikiServicesTest.php @@ -11,6 +11,7 @@ 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 @@ 'BlobStore' => [ 'BlobStore', BlobStore::class ], '_SqlBlobStore' => [ '_SqlBlobStore', SqlBlobStore::class ], 'RevisionStore' => [ 'RevisionStore', RevisionStore::class ], + 'RevisionLookup' => [ 'RevisionLookup', RevisionLookup::class ], 'HttpRequestFactory' => [ 'HttpRequestFactory', HttpRequestFactory::class ], ]; } -- To view, visit https://gerrit.wikimedia.org/r/403117 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I8df61374e24abcf4a7e38e53647489b8ecc1fd77 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: Reedy <re...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits