Aude has submitted this change and it was merged.

Change subject: Handle redirects gracefully on special pages.
......................................................................


Handle redirects gracefully on special pages.

Bug: 70034
Change-Id: Ic84b5268a6b17fa3817d1e797b8e7804daf2a121
---
M repo/i18n/en.json
M repo/i18n/qqq.json
M repo/includes/specials/SpecialWikibaseRepoPage.php
M repo/tests/phpunit/includes/specials/SpecialSetSitelinkTest.php
4 files changed, 42 insertions(+), 4 deletions(-)

Approvals:
  Aude: Looks good to me, approved
  WikidataJenkins: Verified
  jenkins-bot: Checked



diff --git a/repo/i18n/en.json b/repo/i18n/en.json
index 606e834..11563d0 100644
--- a/repo/i18n/en.json
+++ b/repo/i18n/en.json
@@ -104,6 +104,8 @@
        "wikibase-wikibaserepopage-not-itemid": "\"$1\" is not a valid item 
id.",
        "wikibase-wikibaserepopage-invalid-langcode": "The language code \"$1\" 
is unknown. Please use a language code known to the system, such as \"en\".",
        "wikibase-wikibaserepopage-invalid-id": "The id \"$1\" is unknown to 
the system. Please use a valid entity id.",
+       "wikibase-wikibaserepopage-unresolved-redirect": "$1 is a redirect.",
+       "wikibase-wikibaserepopage-storage-exception": "An error occurred while 
trying to load $1: $2.",
        "special-itembytitle": "Item by title",
        "wikibase-itembytitle-lookup-fieldset": "Search for items by site and 
title",
        "wikibase-itembytitle-lookup-site": "Site:",
diff --git a/repo/i18n/qqq.json b/repo/i18n/qqq.json
index fa3e5ff..07822a4 100644
--- a/repo/i18n/qqq.json
+++ b/repo/i18n/qqq.json
@@ -127,6 +127,8 @@
        "wikibase-wikibaserepopage-not-itemid": "Error message when an entity 
id, other than item id, is entered. The message advises users that the id is 
invalid.\n\nParameters:\n* $1 - the invalid id",
        "wikibase-wikibaserepopage-invalid-langcode": "Response informing that 
the language code is not valid. Could give an example of a valid language 
code.\n\nParameters:\n* $1 - the invalid code\n\n\"language identifier\" is the 
same as \"language code\".",
        "wikibase-wikibaserepopage-invalid-id": "Response informing that the 
selected entity ID is not valid.\n\nParameters:\n* $1 - the invalid ID",
+       "wikibase-wikibaserepopage-unresolved-redirect": "Error message shown 
when the user supplied an entity ID that refers to a redirect.\nParameters:\n* 
$1 - the entity ID",
+       "wikibase-wikibaserepopage-storage-exception": "Error message shown 
when an entity could not be loaded due to a storage layer 
exception.\nParameters:\n* $1 - the entity ID\n* $2 - the (unlocalized and 
possibly technical) error message.",
        "special-itembytitle": "{{doc-special|ItemByTitle}}\nThe item is 
identified through use of the site and title, but the lookup failed and further 
qualification must be done. See also Wikidata's glossary for 
[[d:Wikidata:Glossary#languageattribute-label|label]] and 
[[d:Wikidata:Glossary#Items|items]].",
        "wikibase-itembytitle-lookup-fieldset": "This is the title for the 
fieldset on the special page for further refining the search. This is the 
search by site and title.",
        "wikibase-itembytitle-lookup-site": "Label for the textfield holding 
the site id. See also Wikidata's glossary for 
[[d:Wikidata:Glossary#sitelinks|site links]].\n{{Identical|Site}}",
diff --git a/repo/includes/specials/SpecialWikibaseRepoPage.php 
b/repo/includes/specials/SpecialWikibaseRepoPage.php
index 50f8260..bc9940f 100644
--- a/repo/includes/specials/SpecialWikibaseRepoPage.php
+++ b/repo/includes/specials/SpecialWikibaseRepoPage.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Repo\Specials;
 
+use MessageException;
 use MWException;
 use RuntimeException;
 use SiteStore;
@@ -16,6 +17,8 @@
 use Wikibase\Lib\Store\EntityRevisionLookup;
 use Wikibase\Lib\Store\EntityStore;
 use Wikibase\Lib\Store\EntityTitleLookup;
+use Wikibase\Lib\Store\StorageException;
+use Wikibase\Lib\Store\UnresolvedRedirectException;
 use Wikibase\Repo\Store\EntityPermissionChecker;
 use Wikibase\Repo\WikibaseRepo;
 use Wikibase\Summary;
@@ -138,13 +141,27 @@
         * @throws UserInputException
         */
        protected function loadEntity( EntityId $id ) {
-               $entity = $this->entityRevisionLookup->getEntityRevision( $id );
+               try {
+                       $entity = 
$this->entityRevisionLookup->getEntityRevision( $id );
 
-               if ( $entity === null ) {
+                       if ( $entity === null ) {
+                               throw new UserInputException(
+                                       'wikibase-wikibaserepopage-invalid-id',
+                                       array( $id->getSerialization() ),
+                                       'Entity id is unknown'
+                               );
+                       }
+               } catch ( UnresolvedRedirectException $ex ) {
                        throw new UserInputException(
-                               'wikibase-wikibaserepopage-invalid-id',
+                               'wikibase-wikibaserepopage-unresolved-redirect',
                                array( $id->getSerialization() ),
-                               'Entity id is unknown'
+                               'Entity id refers to a redirect'
+                       );
+               } catch ( StorageException $ex ) {
+                       throw new MessageException(
+                               'wikibase-wikibaserepopage-storage-exception',
+                               array( $id->getSerialization(), 
$ex->getMessage() ),
+                               'Entity could not be loaded'
                        );
                }
 
diff --git a/repo/tests/phpunit/includes/specials/SpecialSetSitelinkTest.php 
b/repo/tests/phpunit/includes/specials/SpecialSetSitelinkTest.php
index 1f93c3d..6b69f1a 100644
--- a/repo/tests/phpunit/includes/specials/SpecialSetSitelinkTest.php
+++ b/repo/tests/phpunit/includes/specials/SpecialSetSitelinkTest.php
@@ -3,7 +3,9 @@
 namespace Wikibase\Test;
 
 use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\DataModel\SiteLink;
+use Wikibase\Lib\Store\EntityRedirect;
 use Wikibase\Repo\Specials\SpecialSetSiteLink;
 use Wikibase\Repo\WikibaseRepo;
 
@@ -70,6 +72,11 @@
        private static $badgeId = null;
 
        /**
+        * @var string
+        */
+       private static $redirectId = null;
+
+       /**
         * @var array
         */
        private static $oldBadgeItemsSetting;
@@ -110,8 +117,12 @@
                $item->addSiteLink( new SiteLink( 'dewiki', 'Wikidata', array( 
$badge->getId() ) ) );
                $store->saveEntity( $item, "testing", $GLOBALS['wgUser'], 
EDIT_NEW );
 
+               $redirect = new EntityRedirect( new ItemId('Q12345678'), 
$item->getId() );
+               $store->saveRedirect( $redirect, "testing", $GLOBALS['wgUser'], 
EDIT_NEW );
+
                self::$badgeId = $badge->getId()->getSerialization();
                self::$itemId = $item->getId()->getSerialization();
+               self::$redirectId = 
$redirect->getEntityId()->getSerialization();
        }
 
        private function addBadgeMatcher() {
@@ -196,4 +207,10 @@
                }
        }
 
+       public function testExecuteRedirect() {
+               list( $output, ) = $this->executeSpecialPage( self::$redirectId 
 . '/dewiki', null, 'qqx' );
+
+               $this->assertRegExp( '@<p 
class="error">\(wikibase-wikibaserepopage-unresolved-redirect: .*?\)</p>@', 
$output, "Expected error message" );
+       }
+
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic84b5268a6b17fa3817d1e797b8e7804daf2a121
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: WikidataJenkins <wikidata-servi...@wikimedia.de>
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