Addshore has uploaded a new change for review.
https://gerrit.wikimedia.org/r/72528
Change subject: Standardising many errors throught the api
......................................................................
Standardising many errors throught the api
Bug: 45276
Change-Id: Ibc91a10bf098055e4a8c35f6a512911bb7fbe82f
---
M repo/Wikibase.i18n.php
M repo/includes/api/CreateClaim.php
M repo/includes/api/EditEntity.php
M repo/includes/api/GetClaims.php
M repo/includes/api/GetEntities.php
M repo/includes/api/RemoveClaims.php
M repo/includes/api/RemoveQualifiers.php
M repo/includes/api/RemoveReferences.php
M repo/includes/api/SetClaim.php
M repo/includes/api/SetClaimValue.php
M repo/includes/api/SetQualifier.php
M repo/includes/api/SetReference.php
M repo/includes/api/SetStatementRank.php
M repo/tests/phpunit/includes/api/CreateClaimTest.php
M repo/tests/phpunit/includes/api/EditEntityTest.php
M repo/tests/phpunit/includes/api/GetClaimsTest.php
M repo/tests/phpunit/includes/api/RemoveClaimsTest.php
M repo/tests/phpunit/includes/api/RemoveQualifiersTest.php
M repo/tests/phpunit/includes/api/RemoveReferencesTest.php
M repo/tests/phpunit/includes/api/SetClaimValueTest.php
M repo/tests/phpunit/includes/api/SetQualifierTest.php
M repo/tests/phpunit/includes/api/SetReferenceTest.php
M repo/tests/phpunit/includes/api/SetStatementRankTest.php
23 files changed, 79 insertions(+), 72 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/28/72528/1
diff --git a/repo/Wikibase.i18n.php b/repo/Wikibase.i18n.php
index 1345986..1ed8778 100644
--- a/repo/Wikibase.i18n.php
+++ b/repo/Wikibase.i18n.php
@@ -243,9 +243,7 @@
'wikibase-api-no-external-page' => 'The external client site did not
provide page information.', # Do not translate
'wikibase-api-add-sitelink-failed' => 'The site link could not be
saved.', # Do not translate
'wikibase-api-remove-sitelink-failed' => 'The site link could not be
removed.', # Do not translate
- 'wikibase-api-cant-edit' => 'Edit not allowed:
-$1', # Do not translate
- 'wikibase-api-json-invalid' => 'The supplied JSON structure could not
be parsed or recreated as a valid structure.', # Do not translate
+ 'wikibase-api-cant-edit' => 'Edit not allowed: $1', # Do not translate
'wikibase-api-not-recognized' => 'An invalid property was requested:
$1.', # Do not translate
'wikibase-api-not-recognized-string' => 'A string was expected, but not
found.', # Do not translate
'wikibase-api-not-recognized-array' => 'An array was expected, but not
found.', # Do not translate
@@ -258,17 +256,14 @@
'wikibase-api-data-or-id-xor-wikititle' => 'Either provide the item
"id" or pairs of "site" and "title" for a corresponding page, or "data" for a
new item.', # Do not translate
'wikibase-api-id-xor-wikititle' => 'Either provide the item "id" or
pairs of "site" and "title" for a corresponding page.', # Do not translate
'wikibase-api-ids-xor-wikititles' => 'Either provide the item "ids" or
pairs of "sites" and "titles" for corresponding pages.', # Do not translate
- 'wikibase-api-no-such-entity' => 'Could not find an existing entity.',
# Do not translate
'wikibase-api-link-exists' => 'An article on the specified wiki is
already linked.', # Do not translate
'wikibase-api-add-with-id' => 'Cannot add with the id of an existing
item.', # Do not translate
'wikibase-api-add-exists' => 'Cannot add to an existing item.', # Do
not translate
'wikibase-api-update-without-id' => 'Update without a previous id is
not possible.', # Do not translate
- 'wikibase-api-no-such-item-link' => 'Could not find an existing item
for this link.', # Do not translate
'wikibase-api-create-failed' => 'Attempted creation of a new item
failed: $1', # Do not translate
'wikibase-api-modify-failed' => 'Attempted modification of the item
failed.', # Do not translate
'wikibase-api-delete-failed' => 'Attempted deletion of the item
failed.', # Do not translate
'wikibase-api-save-failed' => 'Attempted save of the item failed: $1',
# Do not translate
- 'wikibase-api-invalid-contentmodel' => 'The content model for the page
is invalid.', # Do not translate
'wikibase-api-alias-incomplete' => 'Cannot find a definition of the
alias for the item.', # Do not translate
'wikibase-api-alias-not-found' => 'Cannot find any previous alias in
the item.', # Do not translate
'wikibase-api-alias-found' => 'Found a previous alias in the item.', #
Do not translate
@@ -279,6 +274,18 @@
'wikibase-api-session-failure' => 'The current session has failed. You
have to log in again.', # Do not translate
'wikibase-api-illegal-field' => 'Illegal field used in call: $1', # Do
not translate
'wikibase-api-edit-conflict' => 'Edit conflict, could not patch the
current revision', # Do not translate
+ 'wikibase-api-invalid-contentmodel' => 'The content model for the page
is invalid.', # Do not translate
+ 'wikibase-api-invalid-claim' => 'Invalid claim', # Do not translate
+ 'wikibase-api-invalid-guid' => 'Invalid claim guid', # Do not translate
+ 'wikibase-api-invalid-snak' => 'Invalid snak', # Do not translate
+ 'wikibase-api-invalid-json' => 'Invalid json: The supplied JSON
structure could not be parsed or recreated as a valid structure.', # Do not
translate
+ 'wikibase-api-no-such-entity' => 'Could not find an existing entity.',
# Do not translate
+ 'wikibase-api-no-such-entity-revision' => 'Count not find entity
revision.', # Do not translate
+ 'wikibase-api-no-such-item-link' => 'Could not find an existing item
for this link.', # Do not translate
+ 'wikibase-api-no-such-site' => 'Could not find the site.', # Do not
translate
+ 'wikibase-api-no-such-statement' => 'Could not find the statement.', #
Do not translate
+ 'wikibase-api-no-such-claim' => 'Could not find the claim.', # Do not
translate
+ 'wikibase-api-no-such-qualifier' => 'Could not find the qualifier.', #
Do not translate
'wikibase-self-conflict-patched' => 'Your edit was patched into the
latest version, overriding some of your own intermediate changes.',
'wikibase-conflict-patched' => 'Your edit was patched into the latest
version.',
diff --git a/repo/includes/api/CreateClaim.php
b/repo/includes/api/CreateClaim.php
index 9267bda..224269b 100644
--- a/repo/includes/api/CreateClaim.php
+++ b/repo/includes/api/CreateClaim.php
@@ -94,16 +94,16 @@
}
catch ( IllegalValueException $ex ) {
wfProfileOut( __METHOD__ );
- $this->dieUsage( $ex->getMessage(),
'claim-invalid-snak' );
+ $this->dieUsage( $ex->getMessage(), 'invalid-snak' );
}
catch ( InvalidArgumentException $ex ) {
// shouldn't happen, but might.
wfProfileOut( __METHOD__ );
- $this->dieUsage( $ex->getMessage(),
'claim-invalid-snak' );
+ $this->dieUsage( $ex->getMessage(), 'invalid-snak' );
}
catch ( ParseException $parseException ) {
wfProfileOut( __METHOD__ );
- $this->dieUsage( $parseException->getMessage(),
'claim-invalid-guid' );
+ $this->dieUsage( $parseException->getMessage(),
'invalid-guid' );
}
$this->snakValidation->validateSnak( $snak );
@@ -221,7 +221,7 @@
$entityId = $entityIdParser->parse( $params['property'] );
if ( $entityId->getEntityType() !== Property::ENTITY_TYPE ) {
- $this->dieUsage( "Property expected, got " .
$entityId->getEntityType(), 'claim-invalid-snak' );
+ $this->dieUsage( "Property expected, got " .
$entityId->getEntityType(), 'invalid-snak' );
}
return $factory->newSnak(
diff --git a/repo/includes/api/EditEntity.php b/repo/includes/api/EditEntity.php
index 543b042..debe25e 100644
--- a/repo/includes/api/EditEntity.php
+++ b/repo/includes/api/EditEntity.php
@@ -327,7 +327,7 @@
$linkSite = $sites->getSite( $globalSiteId );
} else {
wfProfileOut( __METHOD__ );
- $this->dieUsage( "There is no site for global
site id '$globalSiteId'", 'site-not-found' );
+ $this->dieUsage( "There is no site for global
site id '$globalSiteId'", 'no-such-site' );
}
if ( array_key_exists( 'remove', $arg ) ||
$arg['title'] === "" ) {
@@ -381,7 +381,7 @@
if ( is_null( $data ) ) {
wfProfileOut( __METHOD__ );
- $this->dieUsage( $this->msg(
'wikibase-api-json-invalid' )->text(), 'json-invalid' );
+ $this->dieUsage( $this->msg(
'wikibase-api-invalid-json' )->text(), 'invalid-json' );
}
if ( !is_array( $data ) ) { // NOTE: json_decode will decode
any JS literal or structure, not just objects!
diff --git a/repo/includes/api/GetClaims.php b/repo/includes/api/GetClaims.php
index 1c71a93..5a3f787 100644
--- a/repo/includes/api/GetClaims.php
+++ b/repo/includes/api/GetClaims.php
@@ -62,7 +62,7 @@
$entity = $entityId ? $this->getEntity( $entityId ) : null;
if ( !$entity ) {
- $this->dieUsage( "No entity found matching ID $id",
'no-such-entity-id' );
+ $this->dieUsage( "No entity found matching ID $id",
'no-such-entity' );
}
$this->outputClaims( $this->getClaims( $entity, $claimGuid ) );
@@ -104,7 +104,7 @@
$content = EntityContentFactory::singleton()->getFromId( $id );
if ( $content === null ) {
- $this->dieUsage( "The specified entity does not exist,
so it's claims cannot be obtained", 'getclaims-entity-not-found' );
+ $this->dieUsage( "The specified entity does not exist,
so it's claims cannot be obtained", 'no-such-entity' );
}
return $content->getEntity();
@@ -163,7 +163,7 @@
$params = $this->extractRequestParams();
if ( !isset( $params['entity'] ) && !isset( $params['claim'] )
) {
- $this->dieUsage( 'Either the entity parameter or the
key parameter need to be set', 'getclaims-entity-or-key' );
+ $this->dieUsage( 'Either the entity parameter or the
key parameter need to be set', 'entity-or-key' );
}
$claimGuid = null;
@@ -174,14 +174,14 @@
$claimGuidValidator = new ClaimGuidValidator( $entityPrefixes );
if ( isset( $params['claim'] ) &&
$claimGuidValidator->validateFormat( $params['claim'] ) === false ) {
- $this->dieUsage( 'Claim guid is invalid',
'getclaims-invalid-guid' );
+ $this->dieUsage( $this->msg(
'wikibase-api-invalid-guid' )->text(), 'invalid-guid' );
}
if ( isset( $params['entity'] ) && isset( $params['claim'] ) ) {
$entityId = Entity::getIdFromClaimGuid(
$params['claim'] );
if ( $entityId !== $params['entity'] ) {
- $this->dieUsage( 'If both entity id and claim
key are provided they need to point to the same entity',
'getclaims-id-mismatch' );
+ $this->dieUsage( 'If both entity id and claim
key are provided they need to point to the same entity', 'id-mismatch' );
}
}
else if ( isset( $params['entity'] ) ) {
diff --git a/repo/includes/api/GetEntities.php
b/repo/includes/api/GetEntities.php
index 9969088..84fff53 100644
--- a/repo/includes/api/GetEntities.php
+++ b/repo/includes/api/GetEntities.php
@@ -129,7 +129,7 @@
if ( !$entityId ) {
//TODO: report as missing instead?
wfProfileOut( __METHOD__ );
- $this->dieUsage( "Invalid id: $id", 'no-such-entity-id'
);
+ $this->dieUsage( "Invalid id: $id", 'no-such-entity' );
}
// key should be numeric to get the correct behavior
diff --git a/repo/includes/api/RemoveClaims.php
b/repo/includes/api/RemoveClaims.php
index 4883629..a44ca66 100644
--- a/repo/includes/api/RemoveClaims.php
+++ b/repo/includes/api/RemoveClaims.php
@@ -167,7 +167,7 @@
$guids[$entityId][] = $guid;
} else {
- $this->dieUsage( 'Invalid claim guid',
'removeclaims-invalid-guid' );
+ $this->dieUsage( $this->msg(
'wikibase-api-invalid-guid' )->text(), 'invalid-guid' );
}
}
@@ -226,7 +226,7 @@
$entityId = EntityId::newFromPrefixedId( $id );
if ( $entityId === null ) {
- $this->dieUsage( 'Invalid entity id provided',
'removeclaims-invalid-entity-id' );
+ $this->dieUsage( 'Invalid entity id provided',
'no-such-entity' );
}
$entityTitle =
EntityContentFactory::singleton()->getTitleForId( $entityId );
@@ -234,7 +234,7 @@
$content = $this->loadEntityContent( $entityTitle,
$baseRevisionId );
if ( $content === null ) {
- $this->dieUsage( "The specified entity does not
exist, so it's claims cannot be obtained", 'removeclaims-entity-not-found' );
+ $this->dieUsage( "The specified entity does not
exist, so it's claims cannot be obtained", 'no-such-entity' );
}
$contents[] = $content;
diff --git a/repo/includes/api/RemoveQualifiers.php
b/repo/includes/api/RemoveQualifiers.php
index 9dbb802..ea96598 100644
--- a/repo/includes/api/RemoveQualifiers.php
+++ b/repo/includes/api/RemoveQualifiers.php
@@ -80,14 +80,14 @@
$claimGuidValidator = new ClaimGuidValidator( $entityPrefixes );
if ( !( $claimGuidValidator->validateFormat( $params['claim'] )
) ) {
- $this->dieUsage( 'Invalid claim guid',
'removequalifiers-invalid-guid' );
+ $this->dieUsage( $this->msg(
'wikibase-api-invalid-guid' )->text(), 'invalid-guid' );
}
$entityId = EntityId::newFromPrefixedId(
Entity::getIdFromClaimGuid( $params['claim'] ) );
$entityTitle =
EntityContentFactory::singleton()->getTitleForId( $entityId );
if ( $entityTitle === null ) {
- $this->dieUsage( 'No such entity',
'removequalifiers-entity-not-found' );
+ $this->dieUsage( $this->msg(
'wikibase-api-no-such-entity' )->text(), 'no-such-entity' );
}
$baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
@@ -110,7 +110,7 @@
foreach ( array_unique( $params['qualifiers'] ) as
$qualifierHash ) {
if ( !$qualifiers->hasSnakHash( $qualifierHash ) ) {
// TODO: does $qualifierHash need to be escaped?
- $this->dieUsage( 'There is no qualifier with
hash ' . $qualifierHash, 'removequalifiers-qualifier-not-found' );
+ $this->dieUsage( 'There is no qualifier with
hash ' . $qualifierHash, 'no-such-qualifier' );
}
$qualifiers->removeSnakHash( $qualifierHash );
@@ -129,7 +129,7 @@
$claims = new Claims( $entity->getClaims() );
if ( !$claims->hasClaimWithGuid( $claimGuid ) ) {
- $this->dieUsage( 'No such claim',
'removequalifiers-claim-not-found' );
+ $this->dieUsage( $this->msg(
'wikibase-api-no-such-claim' )->text(), 'no-such-claim' );
}
$claim = $claims->getClaimWithGuid( $claimGuid );
diff --git a/repo/includes/api/RemoveReferences.php
b/repo/includes/api/RemoveReferences.php
index fd680ef..7f6696a 100644
--- a/repo/includes/api/RemoveReferences.php
+++ b/repo/includes/api/RemoveReferences.php
@@ -90,14 +90,14 @@
$claimGuidValidator = new ClaimGuidValidator( $entityPrefixes );
if ( !( $claimGuidValidator->validateFormat(
$params['statement'] ) ) ) {
- $this->dieUsage( 'Invalid claim guid',
'removereferences-invalid-guid' );
+ $this->dieUsage( $this->msg(
'wikibase-api-invalid-guid' )->text(), 'invalid-guid' );
}
$entityId = EntityId::newFromPrefixedId(
Entity::getIdFromClaimGuid( $params['statement'] ) );
$entityTitle =
EntityContentFactory::singleton()->getTitleForId( $entityId );
if ( $entityTitle === null ) {
- $this->dieUsage( 'No such entity',
'removereferences-entity-not-found' );
+ $this->dieUsage( $this->msg(
'wikibase-api-no-such-entity' )->text(), 'no-such-entity' );
}
$baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
@@ -116,7 +116,7 @@
$claims = new Claims( $entity->getClaims() );
if ( !$claims->hasClaimWithGuid( $statementGuid ) ) {
- $this->dieUsage( 'No such statement',
'removereferences-statement-not-found' );
+ $this->dieUsage( $this->msg(
'wikibase-api-no-such-claim' )->text(), 'no-such-claim' );
}
$statement = $claims->getClaimWithGuid( $statementGuid );
@@ -124,7 +124,7 @@
if ( ! ( $statement instanceof Statement ) ) {
$this->dieUsage(
'The referenced claim is not a statement and
thus cannot have references',
- 'removereferences-not-a-statement'
+ 'not-a-statement'
);
}
@@ -142,7 +142,7 @@
$this->dieUsage(
// TODO: does $refHash need to be
escaped somehow?
'The statement does not have any
associated reference with the provided reference hash "' . $refHash . '"',
- 'removereferences-no-such-reference'
+ 'no-such-reference'
);
}
}
diff --git a/repo/includes/api/SetClaim.php b/repo/includes/api/SetClaim.php
index 050be43..5ce5c68 100644
--- a/repo/includes/api/SetClaim.php
+++ b/repo/includes/api/SetClaim.php
@@ -147,7 +147,7 @@
assert( $claim instanceof Claim );
return $claim;
} catch ( IllegalValueException $ex ) {
- $this->dieUsage( $ex->getMessage(),
'setclaim-invalid-claim' );
+ $this->dieUsage( $ex->getMessage(), 'invalid-claim' );
}
}
diff --git a/repo/includes/api/SetClaimValue.php
b/repo/includes/api/SetClaimValue.php
index 4204ccc..32594ad 100644
--- a/repo/includes/api/SetClaimValue.php
+++ b/repo/includes/api/SetClaimValue.php
@@ -118,14 +118,14 @@
$claimGuidValidator = new ClaimGuidValidator( $entityPrefixes );
if ( !( $claimGuidValidator->validate( $params['claim'] ) ) ) {
- $this->dieUsage( 'Invalid claim guid',
'setclaimvalue-invalid-guid' );
+ $this->dieUsage( $this->msg(
'wikibase-api-invalid-guid' )->text(), 'invalid-guid' );
}
$entityId = EntityId::newFromPrefixedId(
Entity::getIdFromClaimGuid( $params['claim'] ) );
$entityTitle =
EntityContentFactory::singleton()->getTitleForId( $entityId );
if ( $entityTitle === null ) {
- $this->dieUsage( 'No such entity',
'setclaimvalue-entity-not-found' );
+ $this->dieUsage( $this->msg(
'wikibase-api-no-such-entity' )->text(), 'no-such-entity' );
}
$baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
@@ -150,7 +150,7 @@
$claims = new Claims( $entity->getClaims() );
if ( !$claims->hasClaimWithGuid( $guid ) ) {
- $this->dieUsage( 'No such claim',
'setclaimvalue-claim-not-found' );
+ $this->dieUsage( $this->msg(
'wikibase-api-no-such-claim' )->text(), 'no-such-claim' );
}
$claim = $claims->getClaimWithGuid( $guid );
@@ -185,7 +185,7 @@
return $claim;
} catch ( IllegalValueException $ex ) {
- $this->dieUsage( $ex->getMessage(),
'setclaim-invalid-snak' );
+ $this->dieUsage( $ex->getMessage(), 'invalid-snak' );
}
}
diff --git a/repo/includes/api/SetQualifier.php
b/repo/includes/api/SetQualifier.php
index 4ee94e3..29aea69 100644
--- a/repo/includes/api/SetQualifier.php
+++ b/repo/includes/api/SetQualifier.php
@@ -154,14 +154,14 @@
$claimGuidValidator = new ClaimGuidValidator( $entityPrefixes );
if ( !( $claimGuidValidator->validate( $params['claim'] ) ) ) {
- $this->dieUsage( 'Invalid claim guid',
'setqualifier-invalid-guid' );
+ $this->dieUsage( $this->msg(
'wikibase-api-invalid-guid' )->text(), 'invalid-guid' );
}
$entityId = EntityId::newFromPrefixedId(
Entity::getIdFromClaimGuid( $params['claim'] ) );
$entityTitle =
EntityContentFactory::singleton()->getTitleForId( $entityId );
if ( $entityTitle === null ) {
- $this->dieUsage( 'No such entity',
'setqualifier-entity-not-found' );
+ $this->dieUsage( $this->msg(
'wikibase-api-no-such-entity' )->text(), 'no-such-entity' );
}
$baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
@@ -184,7 +184,7 @@
$claims = new \Wikibase\Claims( $entity->getClaims() );
if ( !$claims->hasClaimWithGuid( $claimGuid ) ) {
- $this->dieUsage( 'No such claim',
'setqualifier-claim-not-found' );
+ $this->dieUsage( $this->msg(
'wikibase-api-no-such-claim' )->text(), 'no-such-claim' );
}
$claim = $claims->getClaimWithGuid( $claimGuid );
@@ -224,7 +224,7 @@
*/
protected function updateQualifier( Snaks $qualifiers, $snakHash ) {
if ( !$qualifiers->hasSnakHash( $snakHash ) ) {
- $this->dieUsage( 'No such qualifier',
'setqualifier-qualifier-not-found' );
+ $this->dieUsage( $this->msg(
'wikibase-api-no-such-qualifier' )->text(), 'no-such-qualifier' );
}
$params = $this->extractRequestParams();
@@ -258,7 +258,7 @@
} catch ( IllegalValueException $ex ) {
//Note: This handles failures during snak
instantiation, not validation.
// Validation errors are handled by the validation
helper.
- $this->dieUsage( $ex->getMessage(),
'setclaim-invalid-snak' );
+ $this->dieUsage( $ex->getMessage(), 'invalid-snak' );
}
return false; // we should never get here.
@@ -290,7 +290,7 @@
*/
protected function newSnak( EntityId $propertyId, $snakType, $valueData
) {
if ( $propertyId->getEntityType() !== Property::ENTITY_TYPE ) {
- $this->dieUsage( "Property expected, got " .
$propertyId->getEntityType(), 'claim-invalid-snak' );
+ $this->dieUsage( "Property expected, got " .
$propertyId->getEntityType(), 'invalid-snak' );
}
//TODO: Inject this, or at least initialize it in a central
location.
@@ -327,7 +327,7 @@
return $qualifiers->addSnak( $newQualifier );
} catch ( IllegalValueException $ex ) {
- $this->dieUsage( $ex->getMessage(),
'setclaim-invalid-snak' );
+ $this->dieUsage( $ex->getMessage(), 'invalid-snak' );
}
return false; // we should never get here.
diff --git a/repo/includes/api/SetReference.php
b/repo/includes/api/SetReference.php
index 3dfe76f..02750af 100644
--- a/repo/includes/api/SetReference.php
+++ b/repo/includes/api/SetReference.php
@@ -114,19 +114,19 @@
$claimGuidValidator = new ClaimGuidValidator( $entityPrefixes );
if ( !( $claimGuidValidator->validate( $params['statement'] ) )
) {
- $this->dieUsage( 'Invalid guid',
'setreference-invalid-guid' );
+ $this->dieUsage( $this->msg(
'wikibase-api-invalid-guid' )->text(), 'invalid-guid' );
}
$entityId = EntityId::newFromPrefixedId(
Entity::getIdFromClaimGuid( $params['statement'] ) );
if ( $entityId === null ) {
- $this->dieUsage( 'No such entity',
'setreference-entity-not-found' );
+ $this->dieUsage( $this->msg(
'wikibase-api-no-such-entity' )->text(), 'no-such-entity' );
}
$entityTitle =
EntityContentFactory::singleton()->getTitleForId( $entityId );
if ( $entityTitle === null ) {
- $this->dieUsage( 'No such entity',
'setreference-entity-not-found' );
+ $this->dieUsage( $this->msg(
'wikibase-api-no-such-entity' )->text(), 'no-such-entity' );
}
$baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
@@ -145,7 +145,7 @@
$rawSnaks = \FormatJson::decode( $rawSnaks, true );
if ( !is_array( $rawSnaks ) || !count( $rawSnaks ) ) {
- $this->dieUsage( 'No snaks or invalid JSON given',
'setreference-no-snaks' );
+ $this->dieUsage( 'No snaks or invalid JSON given',
'invalid-json' );
}
$snaks = new SnakList();
@@ -156,7 +156,7 @@
try {
foreach ( $rawSnaks as $byPropertySnaks ) {
if ( !is_array( $byPropertySnaks ) ) {
- $this->dieUsage( 'Invalid snak JSON
given', 'setreference-invalid-snaks' );
+ $this->dieUsage( 'Invalid snak JSON
given', 'invalid-json' );
}
foreach ( $byPropertySnaks as $rawSnak ) {
$snak =
$snakUnserializer->newFromSerialization( $rawSnak );
@@ -166,7 +166,7 @@
}
} catch ( IllegalValueException $ex ) {
// Handle Snak instantiation failures
- $this->dieUsage( $ex->getMessage(),
'setreference-invalid-snaks' );
+ $this->dieUsage( $ex->getMessage(), 'invalid-json' );
}
return $snaks;
@@ -186,7 +186,7 @@
$claims = new Claims( $entity->getClaims() );
if ( !$claims->hasClaimWithGuid( $statementGuid ) ) {
- $this->dieUsage( 'No such statement',
'setreference-statement-not-found' );
+ $this->dieUsage( $this->msg(
'wikibase-api-no-such-statement' )->text(), 'no-such-statement' );
}
$statement = $claims->getClaimWithGuid( $statementGuid );
@@ -194,7 +194,7 @@
if ( ! ( $statement instanceof Statement ) ) {
$this->dieUsage(
'The referenced claim is not a statement and
thus cannot have references',
- 'setreference-not-a-statement'
+ 'not-a-statement'
);
}
@@ -212,7 +212,7 @@
else {
$this->dieUsage(
'The statement does not have any
associated reference with the provided reference hash',
- 'setreference-no-such-reference'
+ 'no-such-reference'
);
}
}
diff --git a/repo/includes/api/SetStatementRank.php
b/repo/includes/api/SetStatementRank.php
index 75e330e..a3fb7e9 100644
--- a/repo/includes/api/SetStatementRank.php
+++ b/repo/includes/api/SetStatementRank.php
@@ -92,14 +92,14 @@
$claimGuidValidator = new ClaimGuidValidator( $entityPrefixes );
if ( !( $claimGuidValidator->validate( $params['statement'] ) )
) {
- $this->dieUsage( 'Invalid claim guid',
'setstatementrank-invalid-guid' );
+ $this->dieUsage( $this->msg(
'wikibase-api-invalid-guid' )->text(), 'invalid-guid' );
}
$entityId = EntityId::newFromPrefixedId(
Entity::getIdFromClaimGuid( $params['statement'] ) );
$entityTitle =
EntityContentFactory::singleton()->getTitleForId( $entityId );
if ( $entityTitle === null ) {
- $this->dieUsage( 'No such entity',
'setstatementrank-entity-not-found' );
+ $this->dieUsage( $this->msg(
'wikibase-api-no-such-entity' )->text(), 'no-such-entity' );
}
$baseRevisionId = isset( $params['baserevid'] ) ? intval(
$params['baserevid'] ) : null;
@@ -120,7 +120,7 @@
$claims = new \Wikibase\Claims( $entity->getClaims() );
if ( !$claims->hasClaimWithGuid( $statementGuid ) ) {
- $this->dieUsage( 'No such statement',
'setstatementrank-statement-not-found' );
+ $this->dieUsage( $this->msg(
'wikibase-api-no-such-statement' )->text(), 'no-such-statement' );
}
$statement = $claims->getClaimWithGuid( $statementGuid );
@@ -128,7 +128,7 @@
if ( ! ( $statement instanceof Statement ) ) {
$this->dieUsage(
'The referenced claim is not a statement and
thus does not have a rank',
- 'setstatementrank-not-a-statement'
+ 'not-a-statement'
);
}
diff --git a/repo/tests/phpunit/includes/api/CreateClaimTest.php
b/repo/tests/phpunit/includes/api/CreateClaimTest.php
index ba4efcc..ba68048 100644
--- a/repo/tests/phpunit/includes/api/CreateClaimTest.php
+++ b/repo/tests/phpunit/includes/api/CreateClaimTest.php
@@ -124,7 +124,7 @@
'value' => '"Foo.png"',
);
- $argLists[] = array( 'claim-invalid-snak', $params );
+ $argLists[] = array( 'invalid-snak', $params );
$params = array(
'action' => 'wbcreateclaim',
@@ -176,7 +176,7 @@
'value' => '{"x":"foo", "y":"bar"}',
);
- $argLists[] = array( 'claim-invalid-snak', $params );
+ $argLists[] = array( 'invalid-snak', $params );
return $argLists;
}
diff --git a/repo/tests/phpunit/includes/api/EditEntityTest.php
b/repo/tests/phpunit/includes/api/EditEntityTest.php
index 6580e93..3eea4a5 100644
--- a/repo/tests/phpunit/includes/api/EditEntityTest.php
+++ b/repo/tests/phpunit/includes/api/EditEntityTest.php
@@ -433,7 +433,7 @@
// json must be valid
array(
'',
- "json-invalid"
+ "invalid-json"
),
// json must be an object
diff --git a/repo/tests/phpunit/includes/api/GetClaimsTest.php
b/repo/tests/phpunit/includes/api/GetClaimsTest.php
index 4bb36e2..4cd34f3 100644
--- a/repo/tests/phpunit/includes/api/GetClaimsTest.php
+++ b/repo/tests/phpunit/includes/api/GetClaimsTest.php
@@ -185,7 +185,7 @@
try {
$this->doApiRequest( $params );
} catch ( \UsageException $e ) {
- $this->assertEquals( $e->getCodeString(),
'getclaims-invalid-guid', 'Invalid claim guid raised correct error' );
+ $this->assertEquals( $e->getCodeString(),
'invalid-guid', 'Invalid claim guid raised correct error' );
$caughtException = true;
}
diff --git a/repo/tests/phpunit/includes/api/RemoveClaimsTest.php
b/repo/tests/phpunit/includes/api/RemoveClaimsTest.php
index 77c9f56..9a09c65 100644
--- a/repo/tests/phpunit/includes/api/RemoveClaimsTest.php
+++ b/repo/tests/phpunit/includes/api/RemoveClaimsTest.php
@@ -160,7 +160,7 @@
try {
$this->doApiRequest( $params );
} catch ( \UsageException $e ) {
- $this->assertEquals( $e->getCodeString(),
'removeclaims-invalid-guid', 'Invalid claim guid raised correct error' );
+ $this->assertEquals( $e->getCodeString(),
'invalid-guid', 'Invalid claim guid raised correct error' );
$caughtException = true;
}
diff --git a/repo/tests/phpunit/includes/api/RemoveQualifiersTest.php
b/repo/tests/phpunit/includes/api/RemoveQualifiersTest.php
index 1d8ec6a..839c293 100644
--- a/repo/tests/phpunit/includes/api/RemoveQualifiersTest.php
+++ b/repo/tests/phpunit/includes/api/RemoveQualifiersTest.php
@@ -100,7 +100,7 @@
$this->makeInvalidRequest(
$statement->getGuid(),
array( '~=[,,_,,]:3' ),
- 'removequalifiers-qualifier-not-found'
+ 'no-such-qualifier'
);
}
else {
@@ -132,7 +132,7 @@
$this->assertInternalType( 'array', $resultArray, 'top level
element is an array' );
$this->assertArrayHasKey( 'pageinfo', $resultArray, 'top level
element has a pageinfo key' );
- $this->makeInvalidRequest( $statementGuid, $hashes,
'removequalifiers-qualifier-not-found' );
+ $this->makeInvalidRequest( $statementGuid, $hashes,
'no-such-qualifier' );
}
protected function makeInvalidRequest( $statementGuid, array $hashes,
$expectedError = null ) {
@@ -173,7 +173,7 @@
try {
$this->doApiRequest( $params );
} catch ( \UsageException $e ) {
- $this->assertEquals( $e->getCodeString(),
'removequalifiers-invalid-guid', 'Invalid claim guid raised correct error' );
+ $this->assertEquals( $e->getCodeString(),
'invalid-guid', 'Invalid claim guid raised correct error' );
$caughtException = true;
}
diff --git a/repo/tests/phpunit/includes/api/RemoveReferencesTest.php
b/repo/tests/phpunit/includes/api/RemoveReferencesTest.php
index 60bafb8..3ed5964 100644
--- a/repo/tests/phpunit/includes/api/RemoveReferencesTest.php
+++ b/repo/tests/phpunit/includes/api/RemoveReferencesTest.php
@@ -108,7 +108,7 @@
$this->makeInvalidRequest(
$statement->getGuid(),
array( '~=[,,_,,]:3' ),
- 'removereferences-no-such-reference'
+ 'no-such-reference'
);
}
else {
@@ -133,7 +133,7 @@
$this->assertInternalType( 'array', $resultArray, 'top level
element is an array' );
$this->assertArrayHasKey( 'pageinfo', $resultArray, 'top level
element has a pageinfo key' );
- $this->makeInvalidRequest( $statementGuid, $hashes,
'removereferences-no-such-reference' );
+ $this->makeInvalidRequest( $statementGuid, $hashes,
'no-such-reference' );
}
protected function makeInvalidRequest( $statementGuid, array $hashes,
$expectedError = null ) {
@@ -174,7 +174,7 @@
try {
$this->doApiRequest( $params );
} catch ( \UsageException $e ) {
- $this->assertEquals( $e->getCodeString(),
'removereferences-invalid-guid', 'Invalid statement guid raised correct error'
);
+ $this->assertEquals( $e->getCodeString(),
'invalid-guid', 'Invalid statement guid raised correct error' );
$caughtException = true;
}
diff --git a/repo/tests/phpunit/includes/api/SetClaimValueTest.php
b/repo/tests/phpunit/includes/api/SetClaimValueTest.php
index 761c331..1f59c3c 100644
--- a/repo/tests/phpunit/includes/api/SetClaimValueTest.php
+++ b/repo/tests/phpunit/includes/api/SetClaimValueTest.php
@@ -149,7 +149,7 @@
try {
$this->doApiRequest( $params );
} catch ( \UsageException $e ) {
- $this->assertEquals( $e->getCodeString(),
'setclaimvalue-invalid-guid', 'Invalid claim guid raised correct error' );
+ $this->assertEquals( $e->getCodeString(),
'invalid-guid', 'Invalid claim guid raised correct error' );
$caughtException = true;
}
diff --git a/repo/tests/phpunit/includes/api/SetQualifierTest.php
b/repo/tests/phpunit/includes/api/SetQualifierTest.php
index 45e7fc5..0048865 100644
--- a/repo/tests/phpunit/includes/api/SetQualifierTest.php
+++ b/repo/tests/phpunit/includes/api/SetQualifierTest.php
@@ -236,7 +236,7 @@
try {
$this->doApiRequest( $params );
} catch ( \UsageException $e ) {
- $this->assertEquals( $e->getCodeString(),
'setqualifier-invalid-guid', 'Invalid claim guid raised correct error' );
+ $this->assertEquals( $e->getCodeString(),
'invalid-guid', 'Invalid claim guid raised correct error' );
$caughtException = true;
}
diff --git a/repo/tests/phpunit/includes/api/SetReferenceTest.php
b/repo/tests/phpunit/includes/api/SetReferenceTest.php
index c627bb2..5c35526 100644
--- a/repo/tests/phpunit/includes/api/SetReferenceTest.php
+++ b/repo/tests/phpunit/includes/api/SetReferenceTest.php
@@ -142,7 +142,7 @@
$this->assertFalse( true, 'Invalid request should raise
an exception' );
}
catch ( \UsageException $e ) {
- $this->assertEquals( 'setreference-no-such-reference',
$e->getCodeString(), 'Invalid request raised correct error' );
+ $this->assertEquals( 'no-such-reference',
$e->getCodeString(), 'Invalid request raised correct error' );
}
}
@@ -176,8 +176,8 @@
$refHash = $reference->getHash();
return array(
- array( 'xyz', $snakHash, $refHash,
'setreference-invalid-guid' ),
- array( 'x$y$z', $snakHash, $refHash,
'setreference-invalid-guid' )
+ array( 'xyz', $snakHash, $refHash, 'invalid-guid' ),
+ array( 'x$y$z', $snakHash, $refHash, 'invalid-guid' )
);
}
diff --git a/repo/tests/phpunit/includes/api/SetStatementRankTest.php
b/repo/tests/phpunit/includes/api/SetStatementRankTest.php
index eff1cfe..0be099d 100644
--- a/repo/tests/phpunit/includes/api/SetStatementRankTest.php
+++ b/repo/tests/phpunit/includes/api/SetStatementRankTest.php
@@ -226,7 +226,7 @@
try {
$this->doApiRequest( $params );
} catch ( \UsageException $e ) {
- $this->assertEquals( $e->getCodeString(),
'setstatementrank-invalid-guid', 'Invalid claim guid raised correct error' );
+ $this->assertEquals( $e->getCodeString(),
'invalid-guid', 'Invalid claim guid raised correct error' );
$caughtException = true;
}
--
To view, visit https://gerrit.wikimedia.org/r/72528
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibc91a10bf098055e4a8c35f6a512911bb7fbe82f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits