Addshore has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/223272

Change subject: Remove hidden Context in EditStuff
......................................................................

Remove hidden Context in EditStuff

EditEntity
EditFilterHookRunner

Change-Id: Idb0bb818bfe9f7140a161675ca2fc08d720fccab
---
M repo/includes/EditEntity.php
M repo/includes/EditEntityFactory.php
M repo/includes/Hooks/EditFilterHookRunner.php
M repo/includes/UpdateRepo/UpdateRepoJob.php
M repo/includes/UpdateRepo/UpdateRepoOnDeleteJob.php
M repo/includes/UpdateRepo/UpdateRepoOnMoveJob.php
M repo/includes/WikibaseRepo.php
M repo/tests/phpunit/includes/EditEntityTest.php
M repo/tests/phpunit/includes/UpdateRepo/UpdateRepoOnDeleteJobTest.php
M repo/tests/phpunit/includes/UpdateRepo/UpdateRepoOnMoveJobTest.php
M repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php
11 files changed, 41 insertions(+), 46 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/72/223272/4

diff --git a/repo/includes/EditEntity.php b/repo/includes/EditEntity.php
index e1e7c1d..d25c86e 100644
--- a/repo/includes/EditEntity.php
+++ b/repo/includes/EditEntity.php
@@ -4,6 +4,7 @@
 
 use DerivativeContext;
 use Html;
+use IContextSource;
 use InvalidArgumentException;
 use MWException;
 use ReadOnlyError;
@@ -162,16 +163,14 @@
         * @param Entity $newEntity the new entity object
         * @param User $user the user performing the edit
         * @param EditFilterHookRunner $editFilterHookRunner
+        * @param IContextSource $context the context to use while processing 
the edit
+        *
         * @param int|bool $baseRevId the base revision ID for conflict 
checking.
         *        Defaults to false, disabling conflict checks.
         *        `true` can be used to set the base revision to the latest 
revision:
         *        This will detect "late" edit conflicts, i.e. someone 
squeezing in an edit
         *        just before the actual database transaction for saving beings.
         *        The empty string and 0 are both treated as `false`, disabling 
conflict checks.
-        * @param RequestContext|DerivativeContext|null $context the context to 
use while processing
-        *        the edit; defaults to RequestContext::getMain().
-        *
-        * @throws InvalidArgumentException
         */
        public function __construct(
                EntityTitleLookup $titleLookup,
@@ -181,8 +180,8 @@
                Entity $newEntity,
                User $user,
                EditFilterHookRunner $editFilterHookRunner,
-               $baseRevId = false,
-               $context = null
+               IContextSource $context,
+               $baseRevId = false
        ) {
                $this->newEntity = $newEntity;
 
@@ -199,15 +198,6 @@
 
                $this->errorType = 0;
                $this->status = Status::newGood();
-
-               if ( $context !== null && !$context instanceof RequestContext 
&& !$context instanceof DerivativeContext ) {
-                       throw new InvalidArgumentException( '$context must be 
an instance of RequestContext'
-                                . ' or DerivativeContext' );
-               }
-
-               if ( $context === null ) {
-                       $context = RequestContext::getMain();
-               }
 
                $this->context = $context;
 
diff --git a/repo/includes/EditEntityFactory.php 
b/repo/includes/EditEntityFactory.php
index 78eab2f..b8c0c09 100644
--- a/repo/includes/EditEntityFactory.php
+++ b/repo/includes/EditEntityFactory.php
@@ -3,6 +3,7 @@
 namespace Wikibase;
 
 use DerivativeContext;
+use IContextSource;
 use RequestContext;
 use User;
 use Wikibase\DataModel\Entity\Entity;
@@ -46,7 +47,7 @@
        private $editFilterHookRunner;
 
        /**
-        * @var RequestContext|DerivativeContext|null
+        * @var IContextSource
         */
        private $context;
 
@@ -56,7 +57,7 @@
         * @param EntityStore $entityStore
         * @param EntityPermissionChecker $permissionChecker
         * @param EditFilterHookRunner $editFilterHookRunner
-        * @param RequestContext|DerivativeContext|null $context
+        * @param IContextSource $context
         */
        public function __construct(
                EntityTitleLookup $titleLookup,
@@ -64,7 +65,7 @@
                EntityStore $entityStore,
                EntityPermissionChecker $permissionChecker,
                EditFilterHookRunner $editFilterHookRunner,
-               $context = null
+               IContextSource $context
        ) {
                $this->titleLookup = $titleLookup;
                $this->entityRevisionLookup = $entityLookup;
@@ -95,8 +96,8 @@
                        $entity,
                        $user,
                        $this->editFilterHookRunner,
-                       $baseRevId,
-                       $this->context
+                       $this->context,
+                       $baseRevId
                );
        }
 
diff --git a/repo/includes/Hooks/EditFilterHookRunner.php 
b/repo/includes/Hooks/EditFilterHookRunner.php
index 9a3e16d..94b65fb 100644
--- a/repo/includes/Hooks/EditFilterHookRunner.php
+++ b/repo/includes/Hooks/EditFilterHookRunner.php
@@ -45,17 +45,8 @@
        public function __construct(
                EntityTitleLookup $titleLookup,
                EntityContentFactory $entityContentFactory,
-               $context = null
+               IContextSource $context
        ) {
-               if ( $context !== null && !$context instanceof RequestContext 
&& !$context instanceof DerivativeContext ) {
-                       throw new InvalidArgumentException( '$context must be 
an instance of RequestContext'
-                               . ' or DerivativeContext' );
-               }
-
-               if ( $context === null ) {
-                       $context = RequestContext::getMain();
-               }
-
                $this->titleLookup = $titleLookup;
                $this->entityContentFactory = $entityContentFactory;
                $this->context = $context;
diff --git a/repo/includes/UpdateRepo/UpdateRepoJob.php 
b/repo/includes/UpdateRepo/UpdateRepoJob.php
index be74678..fc38cbf 100644
--- a/repo/includes/UpdateRepo/UpdateRepoJob.php
+++ b/repo/includes/UpdateRepo/UpdateRepoJob.php
@@ -4,6 +4,7 @@
 
 use InvalidArgumentException;
 use Job;
+use RequestContext;
 use Title;
 use User;
 use Wikibase\DataModel\Entity\Item;
@@ -56,12 +57,13 @@
        public function __construct( $command, Title $title, $params = false ) {
                parent::__construct( $command, $title, $params );
                $wikibaseRepo = WikibaseRepo::getDefaultInstance();
+               $context = RequestContext::getMain();
 
                $this->initRepoJobServices(
                        $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
                        $wikibaseRepo->getEntityStore(),
                        $wikibaseRepo->getSummaryFormatter(),
-                       $wikibaseRepo->newEditEntityFactory()
+                       $wikibaseRepo->newEditEntityFactory( $context )
                );
        }
 
diff --git a/repo/includes/UpdateRepo/UpdateRepoOnDeleteJob.php 
b/repo/includes/UpdateRepo/UpdateRepoOnDeleteJob.php
index a28a5da..7326f81 100644
--- a/repo/includes/UpdateRepo/UpdateRepoOnDeleteJob.php
+++ b/repo/includes/UpdateRepo/UpdateRepoOnDeleteJob.php
@@ -3,6 +3,7 @@
 namespace Wikibase\Repo\UpdateRepo;
 
 use OutOfBoundsException;
+use RequestContext;
 use SiteStore;
 use Title;
 use Wikibase\DataModel\Entity\Item;
@@ -48,13 +49,14 @@
                parent::__construct( 'UpdateRepoOnDelete', $title, $params );
 
                $wikibaseRepo = WikibaseRepo::getDefaultInstance();
+               $context = RequestContext::getMain();
 
                $this->initServices(
                        $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
                        $wikibaseRepo->getEntityStore(),
                        $wikibaseRepo->getSummaryFormatter(),
                        $wikibaseRepo->getSiteStore(),
-                       $wikibaseRepo->newEditEntityFactory()
+                       $wikibaseRepo->newEditEntityFactory( $context )
                );
        }
 
diff --git a/repo/includes/UpdateRepo/UpdateRepoOnMoveJob.php 
b/repo/includes/UpdateRepo/UpdateRepoOnMoveJob.php
index 591b4ee..f786ec4 100644
--- a/repo/includes/UpdateRepo/UpdateRepoOnMoveJob.php
+++ b/repo/includes/UpdateRepo/UpdateRepoOnMoveJob.php
@@ -3,6 +3,7 @@
 namespace Wikibase\Repo\UpdateRepo;
 
 use OutOfBoundsException;
+use RequestContext;
 use SiteStore;
 use Title;
 use Wikibase\DataModel\Entity\Item;
@@ -53,13 +54,14 @@
                parent::__construct( 'UpdateRepoOnMove', $title, $params );
 
                $wikibaseRepo = WikibaseRepo::getDefaultInstance();
+               $context = RequestContext::getMain();
 
                $this->initServices(
                        $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
                        $wikibaseRepo->getEntityStore(),
                        $wikibaseRepo->getSummaryFormatter(),
                        $wikibaseRepo->getSiteStore(),
-                       $wikibaseRepo->newEditEntityFactory()
+                       $wikibaseRepo->newEditEntityFactory( $context )
                );
        }
 
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 0f33a75..6873fd6 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -8,6 +8,7 @@
 use DataValues\Serializers\DataValueSerializer;
 use Deserializers\Deserializer;
 use IContextSource;
+use RequestContext;
 use RuntimeException;
 use Serializers\Serializer;
 use SiteSQLStore;
@@ -337,11 +338,11 @@
        }
 
        /**
-        * @param IContextSource|null $context
+        * @param IContextSource $context
         *
         * @return EditFilterHookRunner
         */
-       private function newEditFilterHookRunner( IContextSource $context = 
null ) {
+       private function newEditFilterHookRunner( IContextSource $context ) {
                return new EditFilterHookRunner(
                        $this->getEntityTitleLookup(),
                        $this->getEntityContentFactory(),
@@ -1070,11 +1071,11 @@
        }
 
        /**
-        * @param IContextSource|null $context
+        * @param IContextSource $context
         *
         * @return ApiHelperFactory
         */
-       public function getApiHelperFactory( IContextSource $context = null ) {
+       public function getApiHelperFactory( IContextSource $context ) {
                return new ApiHelperFactory(
                        $this->getEntityTitleLookup(),
                        $this->getExceptionLocalizer(),
@@ -1087,11 +1088,11 @@
        }
 
        /**
-        * @param IContextSource|null $context
+        * @param IContextSource $context
         *
         * @return EditEntityFactory
         */
-       public function newEditEntityFactory( IContextSource $context = null ) {
+       public function newEditEntityFactory( IContextSource $context ) {
                return new EditEntityFactory(
                        $this->getEntityTitleLookup(),
                        $this->getEntityRevisionLookup( 'uncached' ),
diff --git a/repo/tests/phpunit/includes/EditEntityTest.php 
b/repo/tests/phpunit/includes/EditEntityTest.php
index 1835c1a..e106d7a 100644
--- a/repo/tests/phpunit/includes/EditEntityTest.php
+++ b/repo/tests/phpunit/includes/EditEntityTest.php
@@ -164,8 +164,8 @@
                        $entity,
                        $user,
                        $editFilterHookRunner,
-                       $baseRevId,
-                       $context
+                       $context,
+                       $baseRevId
                );
        }
 
@@ -424,8 +424,8 @@
                        new Item(),
                        $this->getUser( 'EditEntityTestUser' ),
                        $this->getMockEditFitlerHookRunner(),
-                       false,
-                       $context
+                       $context,
+                       false
                );
 
                $editEntity->checkEditPermissions();
diff --git 
a/repo/tests/phpunit/includes/UpdateRepo/UpdateRepoOnDeleteJobTest.php 
b/repo/tests/phpunit/includes/UpdateRepo/UpdateRepoOnDeleteJobTest.php
index e99a293..c8be485 100644
--- a/repo/tests/phpunit/includes/UpdateRepo/UpdateRepoOnDeleteJobTest.php
+++ b/repo/tests/phpunit/includes/UpdateRepo/UpdateRepoOnDeleteJobTest.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Repo\Tests\UpdateRepo;
 
+use RequestContext;
 use Title;
 use User;
 use Status;
@@ -148,7 +149,8 @@
                                $mockRepository,
                                $mockRepository,
                                $this->getEntityPermissionChecker(),
-                               $this->getMockEditFitlerHookRunner()
+                               $this->getMockEditFitlerHookRunner(),
+                               RequestContext::getMain()
                        )
                );
 
diff --git a/repo/tests/phpunit/includes/UpdateRepo/UpdateRepoOnMoveJobTest.php 
b/repo/tests/phpunit/includes/UpdateRepo/UpdateRepoOnMoveJobTest.php
index c03a035..e9e9647 100644
--- a/repo/tests/phpunit/includes/UpdateRepo/UpdateRepoOnMoveJobTest.php
+++ b/repo/tests/phpunit/includes/UpdateRepo/UpdateRepoOnMoveJobTest.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Repo\Tests\UpdateRepo;
 
+use RequestContext;
 use Status;
 use Title;
 use User;
@@ -144,7 +145,8 @@
                                $mockRepository,
                                $mockRepository,
                                $this->getEntityPermissionChecker(),
-                               $this->getMockEditFitlerHookRunner()
+                               $this->getMockEditFitlerHookRunner(),
+                               RequestContext::getMain()
                        )
                );
 
diff --git 
a/repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php
 
b/repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php
index 63e773f..7c8294e 100644
--- 
a/repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php
+++ 
b/repo/tests/phpunit/includes/specials/SpecialSetLabelDescriptionAliasesTest.php
@@ -4,6 +4,7 @@
 
 use FauxRequest;
 use FauxResponse;
+use RequestContext;
 use Status;
 use ValueValidators\Result;
 use WebRequest;
@@ -59,7 +60,8 @@
                                $this->getEntityRevisionLookup(),
                                $this->getEntityStore(),
                                $this->getEntityPermissionChecker(),
-                               $this->getMockEditFitlerHookRunner()
+                               $this->getMockEditFitlerHookRunner(),
+                               RequestContext::getMain()
                        )
                );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/223272
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idb0bb818bfe9f7140a161675ca2fc08d720fccab
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to