jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/366606 )

Change subject: Refactor SpecialModifyEntity to use EditPage.
......................................................................


Refactor SpecialModifyEntity to use EditPage.

SpecialModifyEntity and friends can now make proper use of the
state managed inside the EditEntity interactor object.

Bug: T170805
Change-Id: I35a32c186db5c4a7ae2553124988b5ccca43e429
---
M repo/Wikibase.php
M repo/includes/EditEntity.php
M repo/includes/Specials/SpecialModifyEntity.php
M repo/includes/Specials/SpecialModifyTerm.php
M repo/includes/Specials/SpecialNewEntity.php
M repo/includes/Specials/SpecialSetAliases.php
M repo/includes/Specials/SpecialSetDescription.php
M repo/includes/Specials/SpecialSetLabel.php
M repo/includes/Specials/SpecialSetLabelDescriptionAliases.php
M repo/includes/Specials/SpecialSetSiteLink.php
M repo/includes/Specials/SpecialWikibaseRepoPage.php
M repo/tests/phpunit/includes/Specials/SpecialSetAliasesTest.php
M repo/tests/phpunit/includes/Specials/SpecialSetDescriptionTest.php
M repo/tests/phpunit/includes/Specials/SpecialSetLabelDescriptionAliasesTest.php
M repo/tests/phpunit/includes/Specials/SpecialSetLabelTest.php
M repo/tests/phpunit/includes/Specials/SpecialSetSiteLinkTest.php
16 files changed, 199 insertions(+), 130 deletions(-)

Approvals:
  WMDE-leszek: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/Wikibase.php b/repo/Wikibase.php
index 8cd2f3e..680c660 100644
--- a/repo/Wikibase.php
+++ b/repo/Wikibase.php
@@ -789,7 +789,6 @@
                return new Wikibase\Repo\Specials\SpecialSetLabel(
                        $copyrightView,
                        $wikibaseRepo->getSummaryFormatter(),
-                       $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
                        $wikibaseRepo->getEntityTitleLookup(),
                        $wikibaseRepo->newEditEntityFactory(),
                        $wikibaseRepo->getEntityPermissionChecker()
@@ -808,7 +807,6 @@
                return new Wikibase\Repo\Specials\SpecialSetDescription(
                        $copyrightView,
                        $wikibaseRepo->getSummaryFormatter(),
-                       $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
                        $wikibaseRepo->getEntityTitleLookup(),
                        $wikibaseRepo->newEditEntityFactory(),
                        $wikibaseRepo->getEntityPermissionChecker()
@@ -827,7 +825,6 @@
                return new Wikibase\Repo\Specials\SpecialSetAliases(
                        $copyrightView,
                        $wikibaseRepo->getSummaryFormatter(),
-                       $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
                        $wikibaseRepo->getEntityTitleLookup(),
                        $wikibaseRepo->newEditEntityFactory(),
                        $wikibaseRepo->getEntityPermissionChecker()
@@ -846,7 +843,6 @@
                return new 
Wikibase\Repo\Specials\SpecialSetLabelDescriptionAliases(
                        $copyrightView,
                        $wikibaseRepo->getSummaryFormatter(),
-                       $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
                        $wikibaseRepo->getEntityTitleLookup(),
                        $wikibaseRepo->newEditEntityFactory(),
                        
$wikibaseRepo->getChangeOpFactoryProvider()->getFingerprintChangeOpFactory(),
@@ -875,7 +871,6 @@
                return new Wikibase\Repo\Specials\SpecialSetSiteLink(
                        $copyrightView,
                        $wikibaseRepo->getSummaryFormatter(),
-                       $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
                        $wikibaseRepo->getEntityTitleLookup(),
                        $wikibaseRepo->newEditEntityFactory(),
                        $siteLookup,
diff --git a/repo/includes/EditEntity.php b/repo/includes/EditEntity.php
index e4cc811..2566dc7 100644
--- a/repo/includes/EditEntity.php
+++ b/repo/includes/EditEntity.php
@@ -325,7 +325,11 @@
                                $this->baseRev = $this->getLatestRevision();
                        } else {
                                $id = $this->getEntityId();
-                               $this->baseRev = 
$this->entityRevisionLookup->getEntityRevision( $id, $baseRevId );
+                               $this->baseRev = 
$this->entityRevisionLookup->getEntityRevision(
+                                       $id,
+                                       $baseRevId,
+                                       
EntityRevisionLookup::LATEST_FROM_SLAVE_WITH_FALLBACK
+                               );
 
                                if ( $this->baseRev === null ) {
                                        throw new MWException( 'Base revision 
ID not found: rev ' . $baseRevId
diff --git a/repo/includes/Specials/SpecialModifyEntity.php 
b/repo/includes/Specials/SpecialModifyEntity.php
index 34c455b..00a30f6 100644
--- a/repo/includes/Specials/SpecialModifyEntity.php
+++ b/repo/includes/Specials/SpecialModifyEntity.php
@@ -4,15 +4,15 @@
 
 use HTMLForm;
 use Html;
+use MWException;
+use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\Repo\ChangeOp\ChangeOp;
 use Wikibase\Repo\ChangeOp\ChangeOpException;
 use Wikibase\Repo\ChangeOp\ChangeOpValidationException;
 use Wikibase\DataModel\Entity\EntityDocument;
-use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\EditEntityFactory;
 use Wikibase\EntityRevision;
 use Wikibase\Lib\MessageException;
-use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Lib\Store\EntityTitleLookup;
 use Wikibase\Lib\Store\RevisionedUnresolvedRedirectException;
 use Wikibase\Lib\Store\StorageException;
@@ -30,20 +30,19 @@
 abstract class SpecialModifyEntity extends SpecialWikibaseRepoPage {
 
        /**
-        * @var EntityRevisionLookup
+        * @var EntityDocument|null
         */
-       private $entityRevisionLookup;
+       private $entity = null;
 
        /**
-        * @var EntityRevision|null
+        * @var EntityId|null
         */
-       protected $entityRevision = null;
+       private $entityId;
 
        /**
         * @param string $title The title of the special page
         * @param SpecialPageCopyrightView $copyrightView
         * @param SummaryFormatter $summaryFormatter
-        * @param EntityRevisionLookup $entityRevisionLookup
         * @param EntityTitleLookup $entityTitleLookup
         * @param EditEntityFactory $editEntityFactory
         */
@@ -51,7 +50,6 @@
                $title,
                SpecialPageCopyrightView $copyrightView,
                SummaryFormatter $summaryFormatter,
-               EntityRevisionLookup $entityRevisionLookup,
                EntityTitleLookup $entityTitleLookup,
                EditEntityFactory $editEntityFactory
        ) {
@@ -63,11 +61,114 @@
                        $entityTitleLookup,
                        $editEntityFactory
                );
-               $this->entityRevisionLookup = $entityRevisionLookup;
        }
 
        public function doesWrites() {
                return true;
+       }
+
+       /**
+        * Returns the ID of the Entity being modified.
+        * Returns null if no entity ID was specified in the request.
+        *
+        * @note The return value is undefined before prepareArguments() has 
been called.
+        *
+        * @return null|EntityId
+        * @throws \MWException
+        */
+       protected function getEntityId() {
+               return $this->entityId;
+       }
+
+       /**
+        * Returns the base revision. If no base revision ID was passed to 
prepareEditEntity(),
+        * this returns the latest revision.
+        *
+        * @throws UserInputException
+        *
+        * @return EntityRevision
+        */
+       protected function getBaseRevision() {
+               $id = $this->getEntityId();
+               try {
+                       $baseRev = $this->getEditEntity()->getBaseRevision();
+
+                       if ( $baseRev === null ) {
+                               throw new UserInputException(
+                                       'wikibase-wikibaserepopage-invalid-id',
+                                       [ $id->getSerialization() ],
+                                       'Entity ID "' . $id->getSerialization() 
. '" is unknown'
+                               );
+                       }
+               } catch ( RevisionedUnresolvedRedirectException $ex ) {
+                       throw new UserInputException(
+                               'wikibase-wikibaserepopage-unresolved-redirect',
+                               [ $id->getSerialization() ],
+                               'Entity ID "' . $id->getSerialization() . '"" 
refers to a redirect'
+                       );
+               } catch ( StorageException $ex ) {
+                       throw new UserInputException(
+                               'wikibase-wikibaserepopage-storage-exception',
+                               [ $id->getSerialization(), $ex->getMessage() ],
+                               'Entity "' . $id->getSerialization() . '" could 
not be loaded'
+                       );
+               }
+
+               return $baseRev;
+       }
+
+       /**
+        * Returns the current revision.
+        *
+        * @throws UserInputException
+        *
+        * @return null|EntityRevision
+        */
+       protected function getLatestRevision() {
+               $id = $this->getEntityId();
+               try {
+                       $baseRev = $this->getEditEntity()->getLatestRevision();
+
+                       if ( $baseRev === null ) {
+                               throw new UserInputException(
+                                       'wikibase-wikibaserepopage-invalid-id',
+                                       [ $id->getSerialization() ],
+                                       'Entity ID "' . $id->getSerialization() 
. '" is unknown'
+                               );
+                       }
+               } catch ( RevisionedUnresolvedRedirectException $ex ) {
+                       throw new UserInputException(
+                               'wikibase-wikibaserepopage-unresolved-redirect',
+                               [ $id->getSerialization() ],
+                               'Entity ID "' . $id->getSerialization() . '"" 
refers to a redirect'
+                       );
+               } catch ( StorageException $ex ) {
+                       throw new UserInputException(
+                               'wikibase-wikibaserepopage-storage-exception',
+                               [ $id->getSerialization(), $ex->getMessage() ],
+                               'Entity "' . $id->getSerialization() . '" could 
not be loaded'
+                       );
+               }
+
+               return $baseRev;
+       }
+
+       /**
+        * Returns the EntityDocument that is to be modified by code in this 
class (or subclasses).
+        * The first call to this method calls getBaseRevision().
+        *
+        * @throws MessageException
+        * @throws UserInputException
+        *
+        * @return EntityDocument
+        */
+       protected function getEntityForModification() {
+               if ( !$this->entity ) {
+                       $revision = $this->getBaseRevision();
+                       $this->entity = $revision->getEntity()->copy();
+               }
+
+               return $this->entity;
        }
 
        /**
@@ -85,28 +186,26 @@
                $this->setHeaders();
                $this->outputHeader();
 
+               $summary = false;
+               $entity = null;
+
                try {
                        $this->prepareArguments( $subPage );
+
+                       $valid = $this->validateInput();
+                       $entity = $this->getEntityId() ? 
$this->getEntityForModification() : null;
+
+                       if ( $valid && $entity ) {
+                               $summary = $this->modifyEntity( $entity );
+                       }
                } catch ( UserInputException $ex ) {
                        $error = $this->msg( $ex->getKey(), $ex->getParams() 
)->parse();
                        $this->showErrorHTML( $error );
                }
 
-               $summary = false;
-               $valid = $this->validateInput();
-               $entity = $this->entityRevision === null ? null : 
$this->entityRevision->getEntity();
-
-               if ( $valid ) {
-                       $summary = $this->modifyEntity( $entity );
-               }
-
-               if ( !$summary ) {
+               if ( !$entity || !$summary ) {
                        $this->setForm( $entity );
                } else {
-                       //TODO: Add conflict detection. All we need to do is to 
provide the base rev from
-                       // $this->entityRevision to the saveEntity() call. But 
we need to make sure
-                       // conflicts are reported in a nice way first. In 
particular, we'd want to
-                       // show the form again.
                        $status = $this->saveEntity( $entity, $summary, 
$this->getRequest()->getVal( 'wpEditToken' ) );
 
                        if ( !$status->isOK() && $status->getErrorsArray() ) {
@@ -129,51 +228,15 @@
                $parts = $subPage === '' ? [] : explode( '/', $subPage, 2 );
 
                $idString = $this->getRequest()->getVal( 'id', isset( $parts[0] 
) ? $parts[0] : null );
+               $baseRevId = $this->getRequest()->getInt( 'revid', 0 );
 
                if ( !$idString ) {
                        return;
                }
 
-               $entityId = $this->parseEntityId( $idString );
-               $this->entityRevision = $this->loadEntity( $entityId );
-       }
+               $this->entityId = $this->parseEntityId( $idString );
 
-       /**
-        * Loads the entity for this entity id.
-        *
-        * @param EntityId $id
-        *
-        * @throws MessageException
-        * @throws UserInputException
-        * @return EntityRevision
-        */
-       protected function loadEntity( EntityId $id ) {
-               try {
-                       $entity = $this->entityRevisionLookup
-                               ->getEntityRevision( $id, 0, 
EntityRevisionLookup::LATEST_FROM_MASTER );
-
-                       if ( $entity === null ) {
-                               throw new UserInputException(
-                                       'wikibase-wikibaserepopage-invalid-id',
-                                       [ $id->getSerialization() ],
-                                       'Entity ID "' . $id->getSerialization() 
. '" is unknown'
-                               );
-                       }
-               } catch ( RevisionedUnresolvedRedirectException $ex ) {
-                       throw new UserInputException(
-                               'wikibase-wikibaserepopage-unresolved-redirect',
-                               [ $id->getSerialization() ],
-                               'Entity ID "' . $id->getSerialization() . '"" 
refers to a redirect'
-                       );
-               } catch ( StorageException $ex ) {
-                       throw new UserInputException(
-                               'wikibase-wikibaserepopage-storage-exception',
-                               [ $id->getSerialization(), $ex->getMessage() ],
-                               'Entity "' . $id->getSerialization() . '" could 
not be loaded'
-                       );
-               }
-
-               return $entity;
+               $this->prepareEditEntity( $this->entityId, $baseRevId );
        }
 
        /**
@@ -249,7 +312,7 @@
         * continue by calling modifyEntity().
         */
        protected function validateInput() {
-               return $this->entityRevision !== null && 
$this->getRequest()->wasPosted();
+               return $this->getEntityId() !== null && 
$this->getRequest()->wasPosted();
        }
 
        /**
@@ -274,11 +337,7 @@
        protected function applyChangeOp( ChangeOp $changeOp, EntityDocument 
$entity, Summary $summary = null ) {
                // NOTE: always validate modification against the current 
revision!
                // TODO: this should be re-engineered, see T126231
-               $currentEntityRevision = 
$this->entityRevisionLookup->getEntityRevision(
-                       $entity->getId(),
-                       0,
-                       EntityRevisionLookup::LATEST_FROM_SLAVE_WITH_FALLBACK
-               );
+               $currentEntityRevision = $this->getLatestRevision();
                $result = $changeOp->validate( 
$currentEntityRevision->getEntity() );
 
                if ( !$result->isValid() ) {
diff --git a/repo/includes/Specials/SpecialModifyTerm.php 
b/repo/includes/Specials/SpecialModifyTerm.php
index 989cd33..7229b44 100644
--- a/repo/includes/Specials/SpecialModifyTerm.php
+++ b/repo/includes/Specials/SpecialModifyTerm.php
@@ -6,12 +6,12 @@
 use Html;
 use Language;
 use Status;
+use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\Repo\ChangeOp\ChangeOpException;
 use Wikibase\Repo\ChangeOp\FingerprintChangeOpFactory;
 use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\EditEntityFactory;
 use Wikibase\Lib\ContentLanguages;
-use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Lib\Store\EntityTitleLookup;
 use Wikibase\Repo\Store\EntityPermissionChecker;
 use Wikibase\Repo\WikibaseRepo;
@@ -60,7 +60,6 @@
         * @param string $title The title of the special page
         * @param SpecialPageCopyrightView $copyrightView
         * @param SummaryFormatter $summaryFormatter
-        * @param EntityRevisionLookup $entityRevisionLookup
         * @param EntityTitleLookup $entityTitleLookup
         * @param EditEntityFactory $editEntityFactory
         * @param EntityPermissionChecker $permissionChecker
@@ -69,7 +68,6 @@
                $title,
                SpecialPageCopyrightView $copyrightView,
                SummaryFormatter $summaryFormatter,
-               EntityRevisionLookup $entityRevisionLookup,
                EntityTitleLookup $entityTitleLookup,
                EditEntityFactory $editEntityFactory,
                EntityPermissionChecker $permissionChecker
@@ -78,7 +76,6 @@
                        $title,
                        $copyrightView,
                        $summaryFormatter,
-                       $entityRevisionLookup,
                        $entityTitleLookup,
                        $editEntityFactory
                );
@@ -147,10 +144,15 @@
                        return false;
                }
 
-               $status = $this->checkTermChangePermissions( 
$this->entityRevision->getEntity() );
-               if ( !$status->isOK() ) {
-                       $this->showErrorHTML( $this->msg( 'permissionserrors' ) 
);
-                       return false;
+               $entityId = $this->getEntityId();
+
+               if ( $entityId ) {
+                       $status = $this->checkTermChangePermissions( $entityId 
);
+
+                       if ( !$status->isOK() ) {
+                               $this->showErrorHTML( $this->msg( 
'permissionserrors' ) );
+                               return false;
+                       }
                }
 
                // If the user just enters an item id and a language, dont 
remove the term.
@@ -183,15 +185,15 @@
        }
 
        /**
-        * @param EntityDocument $entity
+        * @param EntityId $entityId
         *
         * @return Status
         */
-       private function checkTermChangePermissions( EntityDocument $entity ) {
-               return $this->permissionChecker->getPermissionStatusForEntity(
+       private function checkTermChangePermissions( EntityId $entityId ) {
+               return $this->permissionChecker->getPermissionStatusForEntityId(
                        $this->getUser(),
                        EntityPermissionChecker::ACTION_EDIT_TERMS,
-                       $entity
+                       $entityId
                );
        }
 
diff --git a/repo/includes/Specials/SpecialNewEntity.php 
b/repo/includes/Specials/SpecialNewEntity.php
index ed93d41..019f74a 100644
--- a/repo/includes/Specials/SpecialNewEntity.php
+++ b/repo/includes/Specials/SpecialNewEntity.php
@@ -153,6 +153,7 @@
 
                                        $summary = $this->createSummary( 
$entity );
 
+                                       $this->prepareEditEntity();
                                        $saveStatus = $this->saveEntity(
                                                $entity,
                                                $summary,
diff --git a/repo/includes/Specials/SpecialSetAliases.php 
b/repo/includes/Specials/SpecialSetAliases.php
index 66c3322..8ab7309 100644
--- a/repo/includes/Specials/SpecialSetAliases.php
+++ b/repo/includes/Specials/SpecialSetAliases.php
@@ -6,7 +6,6 @@
 use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\DataModel\Term\AliasesProvider;
 use Wikibase\EditEntityFactory;
-use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Lib\Store\EntityTitleLookup;
 use Wikibase\Repo\Store\EntityPermissionChecker;
 use Wikibase\Summary;
@@ -23,7 +22,6 @@
        public function __construct(
                SpecialPageCopyrightView $copyrightView,
                SummaryFormatter $summaryFormatter,
-               EntityRevisionLookup $entityRevisionLookup,
                EntityTitleLookup $entityTitleLookup,
                EditEntityFactory $editEntityFactory,
                EntityPermissionChecker $entityPermissionChecker
@@ -32,7 +30,6 @@
                        'SetAliases',
                        $copyrightView,
                        $summaryFormatter,
-                       $entityRevisionLookup,
                        $entityTitleLookup,
                        $editEntityFactory,
                        $entityPermissionChecker
@@ -53,7 +50,7 @@
                        return false;
                }
 
-               return $this->entityRevision->getEntity() instanceof 
AliasesProvider;
+               return $this->getBaseRevision()->getEntity() instanceof 
AliasesProvider;
        }
 
        /**
diff --git a/repo/includes/Specials/SpecialSetDescription.php 
b/repo/includes/Specials/SpecialSetDescription.php
index 08103b9..0e1eed9 100644
--- a/repo/includes/Specials/SpecialSetDescription.php
+++ b/repo/includes/Specials/SpecialSetDescription.php
@@ -6,7 +6,6 @@
 use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\DataModel\Term\DescriptionsProvider;
 use Wikibase\EditEntityFactory;
-use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Lib\Store\EntityTitleLookup;
 use Wikibase\Repo\Store\EntityPermissionChecker;
 use Wikibase\Summary;
@@ -23,7 +22,6 @@
        public function __construct(
                SpecialPageCopyrightView $copyrightView,
                SummaryFormatter $summaryFormatter,
-               EntityRevisionLookup $entityRevisionLookup,
                EntityTitleLookup $entityTitleLookup,
                EditEntityFactory $editEntityFactory,
                EntityPermissionChecker $entityPermissionChecker
@@ -32,7 +30,6 @@
                        'SetDescription',
                        $copyrightView,
                        $summaryFormatter,
-                       $entityRevisionLookup,
                        $entityTitleLookup,
                        $editEntityFactory,
                        $entityPermissionChecker
@@ -53,7 +50,7 @@
                        return false;
                }
 
-               return $this->entityRevision->getEntity() instanceof 
DescriptionsProvider;
+               return $this->getBaseRevision()->getEntity() instanceof 
DescriptionsProvider;
        }
 
        /**
diff --git a/repo/includes/Specials/SpecialSetLabel.php 
b/repo/includes/Specials/SpecialSetLabel.php
index 98929ee..b0b7d7c 100644
--- a/repo/includes/Specials/SpecialSetLabel.php
+++ b/repo/includes/Specials/SpecialSetLabel.php
@@ -6,7 +6,6 @@
 use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\DataModel\Term\LabelsProvider;
 use Wikibase\EditEntityFactory;
-use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Lib\Store\EntityTitleLookup;
 use Wikibase\Repo\Store\EntityPermissionChecker;
 use Wikibase\Summary;
@@ -23,7 +22,6 @@
        public function __construct(
                SpecialPageCopyrightView $copyrightView,
                SummaryFormatter $summaryFormatter,
-               EntityRevisionLookup $entityRevisionLookup,
                EntityTitleLookup $entityTitleLookup,
                EditEntityFactory $editEntityFactory,
                EntityPermissionChecker $entityPermissionChecker
@@ -32,7 +30,6 @@
                        'SetLabel',
                        $copyrightView,
                        $summaryFormatter,
-                       $entityRevisionLookup,
                        $entityTitleLookup,
                        $editEntityFactory,
                        $entityPermissionChecker
@@ -53,7 +50,7 @@
                        return false;
                }
 
-               return $this->entityRevision->getEntity() instanceof 
LabelsProvider;
+               return $this->getBaseRevision()->getEntity() instanceof 
LabelsProvider;
        }
 
        /**
diff --git a/repo/includes/Specials/SpecialSetLabelDescriptionAliases.php 
b/repo/includes/Specials/SpecialSetLabelDescriptionAliases.php
index 81352f9..12d4c67 100644
--- a/repo/includes/Specials/SpecialSetLabelDescriptionAliases.php
+++ b/repo/includes/Specials/SpecialSetLabelDescriptionAliases.php
@@ -15,7 +15,6 @@
 use Wikibase\DataModel\Term\FingerprintProvider;
 use Wikibase\EditEntityFactory;
 use Wikibase\Lib\ContentLanguages;
-use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Lib\Store\EntityTitleLookup;
 use Wikibase\Repo\Store\EntityPermissionChecker;
 use Wikibase\Summary;
@@ -68,7 +67,6 @@
        public function __construct(
                SpecialPageCopyrightView $copyrightView,
                SummaryFormatter $summaryFormatter,
-               EntityRevisionLookup $entityRevisionLookup,
                EntityTitleLookup $entityTitleLookup,
                EditEntityFactory $editEntityFactory,
                FingerprintChangeOpFactory $changeOpFactory,
@@ -79,7 +77,6 @@
                        'SetLabelDescriptionAliases',
                        $copyrightView,
                        $summaryFormatter,
-                       $entityRevisionLookup,
                        $entityTitleLookup,
                        $editEntityFactory
                );
@@ -100,10 +97,10 @@
         */
        protected function validateInput() {
                return parent::validateInput()
-                       && $this->entityRevision->getEntity() instanceof 
FingerprintProvider
+                       && $this->getBaseRevision()->getEntity() instanceof 
FingerprintProvider
                        && $this->isValidLanguageCode( $this->languageCode )
                        && $this->wasPostedWithLabelDescriptionOrAliases()
-                       && $this->isAllowedToChangeTerms( 
$this->entityRevision->getEntity() );
+                       && $this->isAllowedToChangeTerms( 
$this->getBaseRevision()->getEntity() );
        }
 
        /**
@@ -244,9 +241,8 @@
                        $this->languageCode = null;
                }
 
-               if ( $this->languageCode !== null && $this->entityRevision !== 
null ) {
-                       $entity = $this->entityRevision->getEntity();
-
+               if ( $this->languageCode !== null && $this->getEntityId() ) {
+                       $entity = $this->getEntityForModification();
                        if ( $entity instanceof FingerprintProvider ) {
                                $this->setFingerprintFields( 
$entity->getFingerprint() );
                        }
diff --git a/repo/includes/Specials/SpecialSetSiteLink.php 
b/repo/includes/Specials/SpecialSetSiteLink.php
index 25ebd7c..facb2a6 100644
--- a/repo/includes/Specials/SpecialSetSiteLink.php
+++ b/repo/includes/Specials/SpecialSetSiteLink.php
@@ -83,7 +83,6 @@
        /**
         * @param SpecialPageCopyrightView $copyrightView
         * @param SummaryFormatter $summaryFormatter
-        * @param EntityRevisionLookup $entityRevisionLookup
         * @param EntityTitleLookup $entityTitleLookup
         * @param EditEntityFactory $editEntityFactory
         * @param SiteLookup $siteLookup
@@ -96,7 +95,6 @@
        public function __construct(
                SpecialPageCopyrightView $copyrightView,
                SummaryFormatter $summaryFormatter,
-               EntityRevisionLookup $entityRevisionLookup,
                EntityTitleLookup $entityTitleLookup,
                EditEntityFactory $editEntityFactory,
                SiteLookup $siteLookup,
@@ -110,7 +108,6 @@
                        'SetSiteLink',
                        $copyrightView,
                        $summaryFormatter,
-                       $entityRevisionLookup,
                        $entityTitleLookup,
                        $editEntityFactory
                );
@@ -139,14 +136,14 @@
                // explode the sub page from the format 
Special:SetSitelink/q123/enwiki
                $parts = ( $subPage === '' ) ? [] : explode( '/', $subPage, 2 );
 
+               $entityId = $this->getEntityId();
+
                // check if id belongs to an item
-               if ( $this->entityRevision !== null
-                       && !( $this->entityRevision->getEntity() instanceof 
Item )
+               if ( $entityId !== null
+                       && $entityId->getEntityType() !== Item::ENTITY_TYPE
                ) {
-                       $itemId = $this->entityRevision->getEntity()->getId();
-                       $msg = $this->msg( 'wikibase-setsitelink-not-item', 
$itemId->getSerialization() );
+                       $msg = $this->msg( 'wikibase-setsitelink-not-item', 
$entityId->getSerialization() );
                        $this->showErrorHTML( $msg->parse() );
-                       $this->entityRevision = null;
                }
 
                $this->site = trim( $request->getVal( 'site', isset( $parts[1] 
) ? $parts[1] : '' ) );
@@ -280,7 +277,7 @@
                                'id' => [
                                        'name' => 'id',
                                        'type' => 'hidden',
-                                       'default' => 
$this->entityRevision->getEntity()->getId()->getSerialization()
+                                       'default' => 
$this->getEntityId()->getSerialization()
                                ],
                                'remove' => [
                                        'name' => 'remove',
diff --git a/repo/includes/Specials/SpecialWikibaseRepoPage.php 
b/repo/includes/Specials/SpecialWikibaseRepoPage.php
index 6ad3a13..7f02447 100644
--- a/repo/includes/Specials/SpecialWikibaseRepoPage.php
+++ b/repo/includes/Specials/SpecialWikibaseRepoPage.php
@@ -9,6 +9,7 @@
 use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\ItemId;
+use Wikibase\EditEntity;
 use Wikibase\EditEntityFactory;
 use Wikibase\Lib\Store\EntityTitleLookup;
 use Wikibase\Lib\UserInputException;
@@ -45,6 +46,11 @@
        private $editEntityFactory;
 
        /**
+        * @var EditEntity
+        */
+       private $editEntity = null;
+
+       /**
         * @param string $title The title of the special page
         * @param string $restriction The required user right
         * @param SpecialPageCopyrightView $copyrightView
@@ -65,6 +71,36 @@
                $this->summaryFormatter = $summaryFormatter;
                $this->entityTitleLookup = $entityTitleLookup;
                $this->editEntityFactory = $editEntityFactory;
+       }
+
+       /**
+        * @param EntityId|null $id
+        * @param int $baseRev
+        * @return EditEntity
+        */
+       protected function prepareEditEntity( EntityId $id = null, $baseRev = 0 
) {
+               $this->editEntity = $this->editEntityFactory->newEditEntity(
+                       $this->getUser(),
+                       $id,
+                       $baseRev
+               );
+
+               return $this->editEntity;
+       }
+
+       /**
+        * Returns the EditEntity interactor.
+        *
+        * @note Call only after calling prepareEditEntity() first.
+        *
+        * @return EditEntity
+        */
+       protected function getEditEntity() {
+               if ( !$this->editEntity ) {
+                       throw new RuntimeException( 'Call prepareEditEntity() 
before calling getEditEntity()' );
+               }
+
+               return $this->editEntity;
        }
 
        /**
@@ -126,11 +162,12 @@
        /**
         * Saves the entity using the given summary.
         *
+        * @note Call prepareEditEntity() first.
+        *
         * @param EntityDocument $entity
         * @param Summary $summary
         * @param string $token
         * @param int $flags The edit flags (see WikiPage::doEditContent)
-        * @param int $baseRev the base revision, for conflict detection
         *
         * @return Status
         */
@@ -138,16 +175,9 @@
                EntityDocument $entity,
                Summary $summary,
                $token,
-               $flags = EDIT_UPDATE,
-               $baseRev = 0
+               $flags = EDIT_UPDATE
        ) {
-               $editEntity = $this->editEntityFactory->newEditEntity(
-                       $this->getUser(),
-                       $entity->getId(),
-                       $baseRev
-               );
-
-               $status = $editEntity->attemptSave(
+               $status = $this->getEditEntity()->attemptSave(
                        $entity,
                        $this->summaryFormatter->formatSummary( $summary ),
                        $flags,
diff --git a/repo/tests/phpunit/includes/Specials/SpecialSetAliasesTest.php 
b/repo/tests/phpunit/includes/Specials/SpecialSetAliasesTest.php
index 755e7b6..a652ad7 100644
--- a/repo/tests/phpunit/includes/Specials/SpecialSetAliasesTest.php
+++ b/repo/tests/phpunit/includes/Specials/SpecialSetAliasesTest.php
@@ -35,7 +35,6 @@
                return new SpecialSetAliases(
                        $copyrightView,
                        $wikibaseRepo->getSummaryFormatter(),
-                       $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
                        $wikibaseRepo->getEntityTitleLookup(),
                        $wikibaseRepo->newEditEntityFactory(),
                        $wikibaseRepo->getEntityPermissionChecker()
diff --git a/repo/tests/phpunit/includes/Specials/SpecialSetDescriptionTest.php 
b/repo/tests/phpunit/includes/Specials/SpecialSetDescriptionTest.php
index 2303585..ec0b620 100644
--- a/repo/tests/phpunit/includes/Specials/SpecialSetDescriptionTest.php
+++ b/repo/tests/phpunit/includes/Specials/SpecialSetDescriptionTest.php
@@ -35,7 +35,6 @@
                return new SpecialSetDescription(
                        $copyrightView,
                        $wikibaseRepo->getSummaryFormatter(),
-                       $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
                        $wikibaseRepo->getEntityTitleLookup(),
                        $wikibaseRepo->newEditEntityFactory(),
                        $wikibaseRepo->getEntityPermissionChecker()
diff --git 
a/repo/tests/phpunit/includes/Specials/SpecialSetLabelDescriptionAliasesTest.php
 
b/repo/tests/phpunit/includes/Specials/SpecialSetLabelDescriptionAliasesTest.php
index 258a4a6..cc5898b 100644
--- 
a/repo/tests/phpunit/includes/Specials/SpecialSetLabelDescriptionAliasesTest.php
+++ 
b/repo/tests/phpunit/includes/Specials/SpecialSetLabelDescriptionAliasesTest.php
@@ -66,7 +66,6 @@
                return new SpecialSetLabelDescriptionAliases(
                        $copyrightView,
                        $this->getSummaryFormatter(),
-                       $this->getEntityRevisionLookup(),
                        $this->getEntityTitleLookup(),
                        new EditEntityFactory(
                                $this->getEntityTitleLookup(),
@@ -390,7 +389,6 @@
                return new SpecialSetLabelDescriptionAliases(
                        $copyrightView,
                        $this->getSummaryFormatter(),
-                       $this->getEntityRevisionLookup(),
                        $this->getEntityTitleLookup(),
                        new EditEntityFactory(
                                $this->getEntityTitleLookup(),
diff --git a/repo/tests/phpunit/includes/Specials/SpecialSetLabelTest.php 
b/repo/tests/phpunit/includes/Specials/SpecialSetLabelTest.php
index 6a3226a..83fc005 100644
--- a/repo/tests/phpunit/includes/Specials/SpecialSetLabelTest.php
+++ b/repo/tests/phpunit/includes/Specials/SpecialSetLabelTest.php
@@ -35,7 +35,6 @@
                return new SpecialSetLabel(
                        $copyrightView,
                        $wikibaseRepo->getSummaryFormatter(),
-                       $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
                        $wikibaseRepo->getEntityTitleLookup(),
                        $wikibaseRepo->newEditEntityFactory(),
                        $wikibaseRepo->getEntityPermissionChecker()
diff --git a/repo/tests/phpunit/includes/Specials/SpecialSetSiteLinkTest.php 
b/repo/tests/phpunit/includes/Specials/SpecialSetSiteLinkTest.php
index 8268cbb..6233365 100644
--- a/repo/tests/phpunit/includes/Specials/SpecialSetSiteLinkTest.php
+++ b/repo/tests/phpunit/includes/Specials/SpecialSetSiteLinkTest.php
@@ -78,7 +78,6 @@
                return new SpecialSetSiteLink(
                        $copyrightView,
                        $wikibaseRepo->getSummaryFormatter(),
-                       $wikibaseRepo->getEntityRevisionLookup( 'uncached' ),
                        $wikibaseRepo->getEntityTitleLookup(),
                        $wikibaseRepo->newEditEntityFactory(),
                        $siteLookup,

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I35a32c186db5c4a7ae2553124988b5ccca43e429
Gerrit-PatchSet: 15
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to