Daniel Kinzler has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/368821 )

Change subject: Remove unused EditEntity::showErrorPage.
......................................................................

Remove unused EditEntity::showErrorPage.

This also removes the need to supply an IContextSource to EditEntity
and EditEntityFactory.

Change-Id: I8903b161efb728e81c07e47b2a1f98684749cbec
---
M repo/includes/EditEntity.php
M repo/includes/EditEntityFactory.php
M repo/includes/WikibaseRepo.php
M repo/tests/phpunit/includes/EditEntityTest.php
4 files changed, 5 insertions(+), 120 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/21/368821/1

diff --git a/repo/includes/EditEntity.php b/repo/includes/EditEntity.php
index 6fe10e3..30250e8 100644
--- a/repo/includes/EditEntity.php
+++ b/repo/includes/EditEntity.php
@@ -106,11 +106,6 @@
        private $title = null;
 
        /**
-        * @var IContextSource
-        */
-       private $context;
-
-       /**
         * @var EditFilterHookRunner
         */
        private $editFilterHookRunner;
@@ -178,10 +173,6 @@
         *        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 IContextSource|null $context the context to use while 
processing
-        *        the edit; defaults to RequestContext::getMain().
-        *
-        * @throws InvalidArgumentException
         */
        public function __construct(
                EntityTitleStoreLookup $titleLookup,
@@ -193,8 +184,7 @@
                EntityDocument $newEntity,
                User $user,
                EditFilterHookRunner $editFilterHookRunner,
-               $baseRevId = false,
-               IContextSource $context = null
+               $baseRevId = false
        ) {
                $this->newEntity = $newEntity;
 
@@ -211,12 +201,6 @@
 
                $this->errorType = 0;
                $this->status = Status::newGood();
-
-               if ( $context === null ) {
-                       $context = RequestContext::getMain();
-               }
-
-               $this->context = $context;
 
                $this->titleLookup = $titleLookup;
                $this->entityRevisionLookup = $entityLookup;
@@ -678,56 +662,6 @@
         */
        public function doesCheckForEditConflicts() {
                return $this->getBaseRevisionId() !== false;
-       }
-
-       /**
-        * Shows an error page showing the errors that occurred during 
attemptSave(), if any.
-        *
-        * If $titleMessage is set it is made an assumption that the page is 
still the original
-        * one, and there should be no link back from a special error page.
-        *
-        * @param string|null $titleMessage Message key for the page title.
-        *
-        * @return bool true if an error page was shown, false if there were no 
errors to show.
-        */
-       public function showErrorPage( $titleMessage = null ) {
-               $out = $this->context->getOutput();
-
-               if ( $this->status === null || $this->status->isOK() ) {
-                       return false;
-               }
-
-               if ( $titleMessage === null ) {
-                       $out->prepareErrorPage( wfMessage( 'errorpagetitle' ) );
-               } else {
-                       $out->prepareErrorPage( wfMessage( $titleMessage ), 
wfMessage( 'errorpagetitle' ) );
-               }
-
-               $this->showStatus();
-
-               if ( !isset( $titleMessage ) ) {
-                       $out->returnToMain( '', $this->getTitle() );
-               }
-
-               return true;
-       }
-
-       /**
-        * Shows any errors or warnings from attemptSave().
-        *
-        * @return bool true if any message was shown, false if there were no 
errors to show.
-        */
-       private function showStatus() {
-               if ( $this->status === null || $this->status->isGood() ) {
-                       return false;
-               }
-
-               $out = $this->context->getOutput();
-               $text = $this->status->getHTML();
-
-               $out->addHTML( Html::rawElement( 'div', [ 'class' => 'error' ], 
$text ) );
-
-               return true;
        }
 
        /**
diff --git a/repo/includes/EditEntityFactory.php 
b/repo/includes/EditEntityFactory.php
index d88a6c5..b81e94b 100644
--- a/repo/includes/EditEntityFactory.php
+++ b/repo/includes/EditEntityFactory.php
@@ -55,11 +55,6 @@
        private $editFilterHookRunner;
 
        /**
-        * @var IContextSource|null
-        */
-       private $context;
-
-       /**
         * @param EntityTitleStoreLookup $titleLookup
         * @param EntityRevisionLookup $entityLookup
         * @param EntityStore $entityStore
@@ -67,7 +62,6 @@
         * @param EntityDiffer $entityDiffer
         * @param EntityPatcher $entityPatcher
         * @param EditFilterHookRunner $editFilterHookRunner
-        * @param IContextSource|null $context
         */
        public function __construct(
                EntityTitleStoreLookup $titleLookup,
@@ -76,8 +70,7 @@
                EntityPermissionChecker $permissionChecker,
                EntityDiffer $entityDiffer,
                EntityPatcher $entityPatcher,
-               EditFilterHookRunner $editFilterHookRunner,
-               IContextSource $context = null
+               EditFilterHookRunner $editFilterHookRunner
        ) {
                $this->titleLookup = $titleLookup;
                $this->entityRevisionLookup = $entityLookup;
@@ -86,7 +79,6 @@
                $this->entityDiffer = $entityDiffer;
                $this->entityPatcher = $entityPatcher;
                $this->editFilterHookRunner = $editFilterHookRunner;
-               $this->context = $context;
        }
 
        /**
@@ -112,8 +104,7 @@
                        $entity,
                        $user,
                        $this->editFilterHookRunner,
-                       $baseRevId,
-                       $this->context
+                       $baseRevId
                );
        }
 
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index a2258a3..46a300c 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -1647,10 +1647,6 @@
         * @return EditEntityFactory
         */
        public function newEditEntityFactory( IContextSource $context = null ) {
-               if ( $context === null ) {
-                       $context = RequestContext::getMain();
-               }
-
                return new EditEntityFactory(
                        $this->getEntityTitleLookup(),
                        $this->getEntityRevisionLookup( 'uncached' ),
@@ -1658,8 +1654,7 @@
                        $this->getEntityPermissionChecker(),
                        $this->getEntityDiffer(),
                        $this->getEntityPatcher(),
-                       $this->newEditFilterHookRunner( $context ),
-                       $context
+                       $this->newEditFilterHookRunner( $context )
                );
        }
 
diff --git a/repo/tests/phpunit/includes/EditEntityTest.php 
b/repo/tests/phpunit/includes/EditEntityTest.php
index abf7bcc..803aa45 100644
--- a/repo/tests/phpunit/includes/EditEntityTest.php
+++ b/repo/tests/phpunit/includes/EditEntityTest.php
@@ -142,9 +142,6 @@
                array $permissions = null,
                $editFilterHookRunner = null
        ) {
-               $context = new RequestContext();
-               $context->setRequest( new FauxRequest() );
-
                if ( $user === null ) {
                        $user = User::newFromName( 'EditEntityTestUser' );
                }
@@ -164,8 +161,7 @@
                        $entity,
                        $user,
                        $editFilterHookRunner,
-                       $baseRevId,
-                       $context
+                       $baseRevId
                );
        }
 
@@ -410,36 +406,6 @@
 
                $this->assertEquals( $expectedConflict, $status->hasMessage( 
'edit-conflict' ),
                        "Saving should have failed late if and only if a base 
rev was provided.\n$statusMessage" );
-
-               $this->assertEquals( $expectedConflict, 
$editEntity->showErrorPage(),
-                       "If and only if there was an error, an error page 
should be shown.\n$statusMessage" );
-       }
-
-       public function testErrorPage_DoesNotDoubleEscapeHtmlCharacters() {
-               $repo = $this->getMockRepository();
-               $permissions = [];
-               $context = new RequestContext();
-               // Cannot reuse makeEditEntity because we need the access the 
context
-               $editEntity = new EditEntity(
-                       $this->getEntityTitleLookup(),
-                       $repo,
-                       $repo,
-                       $this->getEntityPermissionChecker( $permissions ),
-                       new EntityDiffer(),
-                       new EntityPatcher(),
-                       new Item(),
-                       $this->getUser( 'EditEntityTestUser' ),
-                       $this->getMockEditFitlerHookRunner(),
-                       false,
-                       $context
-               );
-
-               $editEntity->checkEditPermissions();
-               $editEntity->showErrorPage();
-               $html = $context->getOutput()->getHTML();
-
-               $this->assertContains( '<li>', $html, 'Unescaped HTML' );
-               $this->assertNotContains( '&amp;lt;', $html, 'No double 
escaping' );
        }
 
        public function dataCheckEditPermissions() {
@@ -724,7 +690,6 @@
 
                $this->assertEquals( $shouldWork, $edit->getStatus()->isOK() );
                $this->assertNotEquals( $shouldWork, $edit->hasError( 
EditEntity::TOKEN_ERROR ) );
-               $this->assertNotEquals( $shouldWork, $edit->showErrorPage() );
        }
 
        public function provideAttemptSaveWatch() {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8903b161efb728e81c07e47b2a1f98684749cbec
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>

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

Reply via email to