Daniel Kinzler has uploaded a new change for review. ( 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. 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 15 files changed, 197 insertions(+), 93 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/06/366606/1 diff --git a/repo/Wikibase.php b/repo/Wikibase.php index 76a74c9..a7e1675 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() ); @@ -807,7 +806,6 @@ return new Wikibase\Repo\Specials\SpecialSetDescription( $copyrightView, $wikibaseRepo->getSummaryFormatter(), - $wikibaseRepo->getEntityRevisionLookup( 'uncached' ), $wikibaseRepo->getEntityTitleLookup(), $wikibaseRepo->newEditEntityFactory() ); @@ -825,7 +823,6 @@ return new Wikibase\Repo\Specials\SpecialSetAliases( $copyrightView, $wikibaseRepo->getSummaryFormatter(), - $wikibaseRepo->getEntityRevisionLookup( 'uncached' ), $wikibaseRepo->getEntityTitleLookup(), $wikibaseRepo->newEditEntityFactory() ); @@ -843,7 +840,6 @@ return new Wikibase\Repo\Specials\SpecialSetLabelDescriptionAliases( $copyrightView, $wikibaseRepo->getSummaryFormatter(), - $wikibaseRepo->getEntityRevisionLookup( 'uncached' ), $wikibaseRepo->getEntityTitleLookup(), $wikibaseRepo->newEditEntityFactory(), $wikibaseRepo->getChangeOpFactoryProvider()->getFingerprintChangeOpFactory(), @@ -871,7 +867,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 b51c76e..e44aa10 100644 --- a/repo/includes/EditEntity.php +++ b/repo/includes/EditEntity.php @@ -344,7 +344,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..a28601c 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,14 @@ abstract class SpecialModifyEntity extends SpecialWikibaseRepoPage { /** - * @var EntityRevisionLookup + * @var EntityDocument|null */ - private $entityRevisionLookup; - - /** - * @var EntityRevision|null - */ - protected $entityRevision = null; + private $entity = null; /** * @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 +45,6 @@ $title, SpecialPageCopyrightView $copyrightView, SummaryFormatter $summaryFormatter, - EntityRevisionLookup $entityRevisionLookup, EntityTitleLookup $entityTitleLookup, EditEntityFactory $editEntityFactory ) { @@ -63,11 +56,114 @@ $entityTitleLookup, $editEntityFactory ); - $this->entityRevisionLookup = $entityRevisionLookup; } public function doesWrites() { return true; + } + + /** + * Returns the ID of the Entity being modified. + * + * @return null|EntityId + * @throws \MWException + */ + protected function getEntityId() { + return $this->getEditEntity()->getEntityId(); + } + + /** + * Returns the base revision. If no base revision ID was passed to prepareEditEntity(), + * this returns the latest revision. + * + * @throws UserInputException + * + * @return null|EntityRevision + */ + protected function getBaseRevision() { + $id = $this->getEntityId(); + try { + $baseRev = $this->getEditEntity()->getBaseRevision(); + + if ( $baseRev === null ) { + $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 current revision. + * + * @throws UserInputException + * + * @return null|EntityRevision + */ + protected function getLatestRevision() { + $id = $this->getEntityId(); + try { + return $this->getEditEntity()->getLatestRevision(); + } 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' + ); + } + } + + /** + * Convenience function for getting the ID of the revision the edit is based on. + * + * @return int + */ + protected function getBaseRevisionId() { + $baseRev = $this->getBaseRevision(); + return $baseRev === null ? 0 : $baseRev->getRevisionId(); + } + + /** + * Returns the EntityDocument that is to be modified by code in this class (or subclasses). + * The first call to this method calls loadEntity(). + * + * @throws MessageException + * @throws UserInputException + * + * @return EntityDocument + */ + protected function getEntityForModification() { + if ( !$this->entity ) { + $this->entity = $this->loadEntity(); + } + + return $this->entity; } /** @@ -85,28 +181,26 @@ $this->setHeaders(); $this->outputHeader(); + $summary = false; + $entity = null; + try { $this->prepareArguments( $subPage ); + + $valid = $this->validateInput(); + $entity = $this->getEntityForModification(); + + if ( $valid ) { + $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,28 +223,31 @@ $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 ); + $entityId = $idString === null ? null : $this->parseEntityId( $idString ); + + $this->prepareEditEntity( $entityId, $baseRevId ); } /** - * Loads the entity for this entity id. - * - * @param EntityId $id + * Loads the entity for modification. + * This will be a copy of the base revision. * * @throws MessageException * @throws UserInputException - * @return EntityRevision + * @return EntityDocument */ - protected function loadEntity( EntityId $id ) { + private function loadEntity() { + $id = $this->getEntityId(); + try { - $entity = $this->entityRevisionLookup - ->getEntityRevision( $id, 0, EntityRevisionLookup::LATEST_FROM_MASTER ); + $revision = $this->getBaseRevision(); + $entity = $revision === null ? null : $revision->getEntity()->copy(); if ( $entity === null ) { throw new UserInputException( @@ -249,7 +346,7 @@ * continue by calling modifyEntity(). */ protected function validateInput() { - return $this->entityRevision !== null && $this->getRequest()->wasPosted(); + return $this->getBaseRevision() !== null && $this->getRequest()->wasPosted(); } /** @@ -274,11 +371,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 48ffdff..2b66784 100644 --- a/repo/includes/Specials/SpecialModifyTerm.php +++ b/repo/includes/Specials/SpecialModifyTerm.php @@ -7,12 +7,12 @@ use InvalidArgumentException; use Language; use PermissionsError; +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\WikibaseRepo; use Wikibase\Summary; @@ -55,7 +55,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 */ @@ -63,7 +62,6 @@ $title, SpecialPageCopyrightView $copyrightView, SummaryFormatter $summaryFormatter, - EntityRevisionLookup $entityRevisionLookup, EntityTitleLookup $entityTitleLookup, EditEntityFactory $editEntityFactory ) { @@ -71,7 +69,6 @@ $title, $copyrightView, $summaryFormatter, - $entityRevisionLookup, $entityTitleLookup, $editEntityFactory ); @@ -140,7 +137,7 @@ } try { - $this->checkTermChangePermissions( $this->entityRevision->getEntity() ); + $this->checkTermChangePermissions( $this->getEntityId() ); } catch ( PermissionsError $e ) { $this->showErrorHTML( $this->msg( 'permissionserrors' ) . ': ' . $e->permission ); return false; @@ -176,13 +173,13 @@ } /** - * @param EntityDocument $entity + * @param EntityId $entityId * * @throws PermissionsError * @throws InvalidArgumentException */ - private function checkTermChangePermissions( EntityDocument $entity ) { - $restriction = $entity->getType() . '-term'; + private function checkTermChangePermissions( EntityId $entityId ) { + $restriction = $entityId->getEntityType() . '-term'; if ( !$this->getUser()->isAllowed( $restriction ) ) { throw new PermissionsError( $restriction ); diff --git a/repo/includes/Specials/SpecialNewEntity.php b/repo/includes/Specials/SpecialNewEntity.php index 86a193d..0898c9a 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 cc5ccdc..6c477ed 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\Summary; use Wikibase\SummaryFormatter; @@ -22,7 +21,6 @@ public function __construct( SpecialPageCopyrightView $copyrightView, SummaryFormatter $summaryFormatter, - EntityRevisionLookup $entityRevisionLookup, EntityTitleLookup $entityTitleLookup, EditEntityFactory $editEntityFactory ) { @@ -30,7 +28,6 @@ 'SetAliases', $copyrightView, $summaryFormatter, - $entityRevisionLookup, $entityTitleLookup, $editEntityFactory ); @@ -50,7 +47,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 41046ea..bd80121 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\Summary; use Wikibase\SummaryFormatter; @@ -22,7 +21,6 @@ public function __construct( SpecialPageCopyrightView $copyrightView, SummaryFormatter $summaryFormatter, - EntityRevisionLookup $entityRevisionLookup, EntityTitleLookup $entityTitleLookup, EditEntityFactory $editEntityFactory ) { @@ -30,7 +28,6 @@ 'SetDescription', $copyrightView, $summaryFormatter, - $entityRevisionLookup, $entityTitleLookup, $editEntityFactory ); @@ -50,7 +47,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 f1b6f67..ba2dc33 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\Summary; use Wikibase\SummaryFormatter; @@ -22,7 +21,6 @@ public function __construct( SpecialPageCopyrightView $copyrightView, SummaryFormatter $summaryFormatter, - EntityRevisionLookup $entityRevisionLookup, EntityTitleLookup $entityTitleLookup, EditEntityFactory $editEntityFactory ) { @@ -30,7 +28,6 @@ 'SetLabel', $copyrightView, $summaryFormatter, - $entityRevisionLookup, $entityTitleLookup, $editEntityFactory ); @@ -50,7 +47,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 c9e36be..dd82fa3 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\Summary; use Wikibase\SummaryFormatter; @@ -62,7 +61,6 @@ public function __construct( SpecialPageCopyrightView $copyrightView, SummaryFormatter $summaryFormatter, - EntityRevisionLookup $entityRevisionLookup, EntityTitleLookup $entityTitleLookup, EditEntityFactory $editEntityFactory, FingerprintChangeOpFactory $changeOpFactory, @@ -72,7 +70,6 @@ 'SetLabelDescriptionAliases', $copyrightView, $summaryFormatter, - $entityRevisionLookup, $entityTitleLookup, $editEntityFactory ); @@ -92,10 +89,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() ); } /** @@ -232,9 +229,8 @@ $this->languageCode = null; } - if ( $this->languageCode !== null && $this->entityRevision !== null ) { - $entity = $this->entityRevision->getEntity(); - + $entity = $this->getEntityForModification(); + if ( $this->languageCode !== null && $entity !== null ) { if ( $entity instanceof FingerprintProvider ) { $this->setFingerprintFields( $entity->getFingerprint() ); } diff --git a/repo/includes/Specials/SpecialSetSiteLink.php b/repo/includes/Specials/SpecialSetSiteLink.php index 25ebd7c..5f1811f 100644 --- a/repo/includes/Specials/SpecialSetSiteLink.php +++ b/repo/includes/Specials/SpecialSetSiteLink.php @@ -96,7 +96,6 @@ public function __construct( SpecialPageCopyrightView $copyrightView, SummaryFormatter $summaryFormatter, - EntityRevisionLookup $entityRevisionLookup, EntityTitleLookup $entityTitleLookup, EditEntityFactory $editEntityFactory, SiteLookup $siteLookup, @@ -110,7 +109,6 @@ 'SetSiteLink', $copyrightView, $summaryFormatter, - $entityRevisionLookup, $entityTitleLookup, $editEntityFactory ); @@ -139,11 +137,13 @@ // explode the sub page from the format Special:SetSitelink/q123/enwiki $parts = ( $subPage === '' ) ? [] : explode( '/', $subPage, 2 ); + $baseRevision = $this->getBaseRevision(); + // check if id belongs to an item - if ( $this->entityRevision !== null - && !( $this->entityRevision->getEntity() instanceof Item ) + if ( $baseRevision !== null + && !( $baseRevision->getEntity() instanceof Item ) ) { - $itemId = $this->entityRevision->getEntity()->getId(); + $itemId = $baseRevision->getEntity()->getId(); $msg = $this->msg( 'wikibase-setsitelink-not-item', $itemId->getSerialization() ); $this->showErrorHTML( $msg->parse() ); $this->entityRevision = null; @@ -280,7 +280,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 6383a19..651fd4e 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,6 +162,8 @@ /** * Saves the entity using the given summary. * + * @note Call prepareEditEntity() first. + * * @param EntityDocument $entity * @param Summary $summary * @param string $token @@ -138,16 +176,9 @@ EntityDocument $entity, Summary $summary, $token, - $flags = EDIT_UPDATE, - $baseRev = false + $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 667c80b..1f2a1b3 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() ); diff --git a/repo/tests/phpunit/includes/Specials/SpecialSetDescriptionTest.php b/repo/tests/phpunit/includes/Specials/SpecialSetDescriptionTest.php index 890ee74..e3187a8 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() ); diff --git a/repo/tests/phpunit/includes/Specials/SpecialSetLabelDescriptionAliasesTest.php b/repo/tests/phpunit/includes/Specials/SpecialSetLabelDescriptionAliasesTest.php index 8bafef8..6f59600f 100644 --- a/repo/tests/phpunit/includes/Specials/SpecialSetLabelDescriptionAliasesTest.php +++ b/repo/tests/phpunit/includes/Specials/SpecialSetLabelDescriptionAliasesTest.php @@ -62,7 +62,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 4473c22..c855152 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() ); -- To view, visit https://gerrit.wikimedia.org/r/366606 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I35a32c186db5c4a7ae2553124988b5ccca43e429 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits