jenkins-bot has submitted this change and it was merged.

Change subject: Don't use EntityIdParser if only ItemIds are supported
......................................................................


Don't use EntityIdParser if only ItemIds are supported

Also improved some error messages.

Change-Id: Ie6cc3dd47fca2423d33acc258f5eadeb117dcfea
---
M repo/includes/api/ModifyEntity.php
M repo/includes/specials/SpecialSetSiteLink.php
M repo/tests/phpunit/includes/api/EditEntityTest.php
3 files changed, 12 insertions(+), 24 deletions(-)

Approvals:
  Thiemo Mättig (WMDE): Looks good to me, approved
  jenkins-bot: Verified



diff --git a/repo/includes/api/ModifyEntity.php 
b/repo/includes/api/ModifyEntity.php
index 22b7e2d..7008013 100644
--- a/repo/includes/api/ModifyEntity.php
+++ b/repo/includes/api/ModifyEntity.php
@@ -4,6 +4,7 @@
 
 use ApiBase;
 use ApiMain;
+use InvalidArgumentException;
 use LogicException;
 use Status;
 use UsageException;
@@ -20,6 +21,7 @@
 use Wikibase\Repo\WikibaseRepo;
 use Wikibase\StringNormalizer;
 use Wikibase\Summary;
+use WikiPage;
 
 /**
  * Base class for API modules modifying a single entity identified based on id 
xor a combination of site and page title.
@@ -194,16 +196,11 @@
 
                foreach ( $badgesParams as $badgeSerialization ) {
                        try {
-                               $badgeId = $this->getIdParser()->parse( 
$badgeSerialization );
-                       } catch( EntityIdParsingException $e ) {
+                               $badgeId = new ItemId( $badgeSerialization );
+                       } catch( InvalidArgumentException $e ) {
                                $this->dieError( 'Badges: could not parse "' . 
$badgeSerialization
-                                       . '", the id is invalid', 
'no-such-entity-id' );
-                               $badgeId = null;
-                       }
-
-                       if ( !( $badgeId instanceof ItemId ) ) {
-                               $this->dieError( 'Badges: entity with id "' . 
$badgeSerialization
-                                       . '" is not an item', 'not-item' );
+                                       . '", the id is invalid', 
'invalid-entity-id' );
+                               continue;
                        }
 
                        if ( !array_key_exists( $badgeId->getPrefixedId(), 
$this->badgeItems ) ) {
diff --git a/repo/includes/specials/SpecialSetSiteLink.php 
b/repo/includes/specials/SpecialSetSiteLink.php
index 83deb8f..d2eadb3 100644
--- a/repo/includes/specials/SpecialSetSiteLink.php
+++ b/repo/includes/specials/SpecialSetSiteLink.php
@@ -413,22 +413,13 @@
         * @return ItemId[]|boolean
         */
        protected function parseBadges( array $badges, Status $status ) {
-               $repo = WikibaseRepo::getDefaultInstance();
-
-               $entityIdParser = $repo->getEntityIdParser();
-
                $badgesObjects = array();
 
                foreach ( $badges as $badge ) {
                        try {
-                               $badgeId = $entityIdParser->parse( $badge );
-                       } catch ( EntityIdParsingException $ex ) {
-                               $status->fatal( 
'wikibase-setsitelink-not-badge', $badge );
-                               return false;
-                       }
-
-                       if ( !( $badgeId instanceof ItemId ) ) {
-                               $status->fatal( 
'wikibase-setsitelink-not-item', $badgeId->getPrefixedId() );
+                               $badgeId = new ItemId( $badge );
+                       } catch ( InvalidArgumentException $ex ) {
+                               $status->fatal( 
'wikibase-wikibaserepopage-not-itemid', $badge );
                                return false;
                        }
 
@@ -440,7 +431,7 @@
                        $itemTitle = $this->getEntityTitle( $badgeId );
 
                        if ( is_null( $itemTitle ) || !$itemTitle->exists() ) {
-                               $status->fatal( 
'wikibase-setsitelink-not-badge', $badgeId );
+                               $status->fatal( 
'wikibase-wikibaserepopage-invalid-id', $badgeId );
                                return false;
                        }
 
diff --git a/repo/tests/phpunit/includes/api/EditEntityTest.php 
b/repo/tests/phpunit/includes/api/EditEntityTest.php
index 9a58b4f..5ae6c0e 100644
--- a/repo/tests/phpunit/includes/api/EditEntityTest.php
+++ b/repo/tests/phpunit/includes/api/EditEntityTest.php
@@ -459,10 +459,10 @@
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'not-recognized', 'message' => 'Unknown key in 
json: remove' ) ) ),
                        'bad badge id' => array( // bad badge id
                                'p' => array( 'site' => 'enwiki', 'title' => 
'Berlin', 'data' => 
'{"sitelinks":{"dewiki":{"site":"dewiki","title":"TestPage!","badges":["abc","%Q149%"]}}}'
 ),
-                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'no-such-entity-id' ) ) ),
+                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'invalid-entity-id' ) ) ),
                        'badge id is not an item id' => array( // badge id is 
not an item id
                                'p' => array( 'site' => 'enwiki', 'title' => 
'Berlin', 'data' => 
'{"sitelinks":{"dewiki":{"site":"dewiki","title":"TestPage!","badges":["P2","%Q149%"]}}}'
 ),
-                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'not-item' ) ) ),
+                               'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'invalid-entity-id' ) ) ),
                        'badge id is not specified' => array( // badge id is 
not specified
                                'p' => array( 'site' => 'enwiki', 'title' => 
'Berlin', 'data' => 
'{"sitelinks":{"dewiki":{"site":"dewiki","title":"TestPage!","badges":["%Q149%","%Q32%"]}}}'
 ),
                                'e' => array( 'exception' => array( 'type' => 
'UsageException', 'code' => 'not-badge' ) ) ),

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie6cc3dd47fca2423d33acc258f5eadeb117dcfea
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Bene <benestar.wikime...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Bene <benestar.wikime...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@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