Tamslo has uploaded a new change for review.
https://gerrit.wikimedia.org/r/204495
Change subject: Small refactoring
......................................................................
Small refactoring
ViolationStore::insertViolation() is now insertViolations() and can take
a Violation or an array of Violations as argument.
Renamed API module wdq... to wdqa...
Change-Id: Ia479af0e1f3b9afeda7351b7e322c8cd10959bf0
---
M WikidataQuality.php
M constraint-report/specials/SpecialConstraintReport.php
M external-validation/api/CrossCheck.php
M external-validation/tests/phpunit/Api/CrossCheckTest.php
M i18n/en.json
M i18n/qqq.json
M includes/Violations/ViolationStore.php
M tests/phpunit/Violations/ViolationStoreTest.php
8 files changed, 45 insertions(+), 39 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataQuality
refs/changes/95/204495/1
diff --git a/WikidataQuality.php b/WikidataQuality.php
index f32fe35..710141f 100644
--- a/WikidataQuality.php
+++ b/WikidataQuality.php
@@ -48,7 +48,7 @@
// Define API modules
global $wgAPIModules;
-$wgAPIModules[ 'wdqcrosscheck' ] =
'WikidataQuality\ExternalValidation\Api\CrossCheck';
+$wgAPIModules[ 'wdqacrosscheck' ] =
'WikidataQuality\ExternalValidation\Api\CrossCheck';
// Define database table names
define( 'CONSTRAINT_TABLE', 'wdqa_constraints' );
diff --git a/constraint-report/specials/SpecialConstraintReport.php
b/constraint-report/specials/SpecialConstraintReport.php
index a98b32f..998508a 100644
--- a/constraint-report/specials/SpecialConstraintReport.php
+++ b/constraint-report/specials/SpecialConstraintReport.php
@@ -295,6 +295,6 @@
$translator = new CheckResultToViolationTranslator();
$violations = $translator->translateToViolation( $entity,
$results );
$violationStore = new ViolationStore();
- $violationStore->insertViolation( $violations );
+ $violationStore->insertViolations( $violations );
}
}
\ No newline at end of file
diff --git a/external-validation/api/CrossCheck.php
b/external-validation/api/CrossCheck.php
index b46fd95..86cb7e0 100644
--- a/external-validation/api/CrossCheck.php
+++ b/external-validation/api/CrossCheck.php
@@ -225,11 +225,11 @@
*/
public function getExamplesMessages() {
return array (
- 'action=wdqcrosscheck&entities=Q76' =>
'apihelp-wdqcrosscheck-examples-1',
- 'action=wdqcrosscheck&entities=Q76|Q567' =>
'apihelp-wdqcrosscheck-examples-2',
- 'action=wdqcrosscheck&entities=Q76|Q567&properties=P19'
=> 'apihelp-wdqcrosscheck-examples-3',
-
'action=wdqcrosscheck&entities=Q76|Q567&properties=P19|P31' =>
'apihelp-wdqcrosscheck-examples-4',
-
'action=wdqcrosscheck&claims=Q42$D8404CDA-25E4-4334-AF13-A3290BCD9C0F' =>
'apihelp-wdqcrosscheck-examples-5'
+ 'action=wdqacrosscheck&entities=Q76' =>
'apihelp-wdqacrosscheck-examples-1',
+ 'action=wdqacrosscheck&entities=Q76|Q567' =>
'apihelp-wdqacrosscheck-examples-2',
+
'action=wdqacrosscheck&entities=Q76|Q567&properties=P19' =>
'apihelp-wdqacrosscheck-examples-3',
+
'action=wdqacrosscheck&entities=Q76|Q567&properties=P19|P31' =>
'apihelp-wdqacrosscheck-examples-4',
+
'action=wdqacrosscheck&claims=Q42$D8404CDA-25E4-4334-AF13-A3290BCD9C0F' =>
'apihelp-wdqacrosscheck-examples-5'
);
}
}
\ No newline at end of file
diff --git a/external-validation/tests/phpunit/Api/CrossCheckTest.php
b/external-validation/tests/phpunit/Api/CrossCheckTest.php
index b75a093..b7ba9aa 100644
--- a/external-validation/tests/phpunit/Api/CrossCheckTest.php
+++ b/external-validation/tests/phpunit/Api/CrossCheckTest.php
@@ -165,7 +165,7 @@
public function testExecuteInvalidParams()
{
$params = array(
- 'action' => 'wdqcrosscheck',
+ 'action' => 'wdqacrosscheck',
'entities' => 'Q1',
'claims' => 'randomClaimGuid'
);
@@ -176,7 +176,7 @@
public function testExecuteMissingParams()
{
$params = array(
- 'action' => 'wdqcrosscheck'
+ 'action' => 'wdqacrosscheck'
);
$this->setExpectedException( 'UsageException', 'A parameter that is
required was missing (Either provide the ids of entities or ids of claims, that
should be cross-checked.)' );
$this->doApiRequest( $params );
@@ -185,7 +185,7 @@
public function testExecuteWholeItem()
{
$params = array(
- 'action' => 'wdqcrosscheck',
+ 'action' => 'wdqacrosscheck',
'entities' => self::$idMap[ 'Q1' ],
'format' => 'xml'
);
@@ -201,7 +201,7 @@
public function testExecutePropertyFilter()
{
$params = array(
- 'action' => 'wdqcrosscheck',
+ 'action' => 'wdqacrosscheck',
'entities' => self::$idMap[ 'Q1' ],
'properties' => self::$idMap[ 'P1' ]
);
@@ -217,7 +217,7 @@
public function testExecuteNotExistentItem()
{
$params = array(
- 'action' => 'wdqcrosscheck',
+ 'action' => 'wdqacrosscheck',
'entities' => self::NOT_EXISTENT_ITEM_ID
);
$result = $this->doApiRequest( $params );
@@ -228,7 +228,7 @@
public function testExecuteSingleClaim()
{
$params = array(
- 'action' => 'wdqcrosscheck',
+ 'action' => 'wdqacrosscheck',
'claims' => self::$claimGuids[ 'P1' ],
);
$result = $this->doApiRequest( $params );
@@ -245,7 +245,7 @@
public function testExecuteNotExistentClaim()
{
$params = array(
- 'action' => 'wdqcrosscheck',
+ 'action' => 'wdqacrosscheck',
'claims' => self::NOT_EXISTENT_ITEM_ID .
'$7e8ddd02-42e3-478a-adc5-63b1059f6034',
);
$result = $this->doApiRequest( $params );
@@ -256,7 +256,7 @@
public function testExecuteInvalidClaimGuid()
{
$params = array(
- 'action' => 'wdqcrosscheck',
+ 'action' => 'wdqacrosscheck',
'claims' => 'broken-claim-guid',
);
$this->setExpectedException( 'UsageException', 'Invalid claim guid.' );
diff --git a/i18n/en.json b/i18n/en.json
index 76a665f..db9e99d 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -46,13 +46,13 @@
"wikidataquality-externaldbs-license": "License",
"wikidataquality-externaldbs-no-databases": "No external databases available
for cross-check.",
- "apihelp-wdqcrosscheck-description": "API module to cross-check Wikibase
entities against external data.",
- "apihelp-wdqcrosscheck-param-entities": "Ids of the entities that should be
cross-checked. Required unless claims are provided.",
- "apihelp-wdqcrosscheck-param-properties": "Optional filter to cross-check
only statements with specified property ids. This only works, if entities are
given.",
- "apihelp-wdqcrosscheck-param-claims": "Ids of claims that should be
cross-checked. Required unless entities are provided.",
- "apihelp-wdqcrosscheck-examples-1": "Run cross-check for all statements of
item with ID Q76.",
- "apihelp-wdqcrosscheck-examples-2": "Run cross-check for all statements of
item with ID Q76 and item with ID Q567.",
- "apihelp-wdqcrosscheck-examples-3": "Run cross-check for all statements of
item with ID Q76 and item with ID Q567, that uses property with ID P19.",
- "apihelp-wdqcrosscheck-examples-4": "Run cross-check for all statements of
item with ID Q76 and item with ID Q567, that uses property with ID P19 or P31.",
- "apihelp-wdqcrosscheck-examples-5": "Run cross-check for claim with GUID of
Q42$D8404CDA-25E4-4334-AF13-A3290BCD9C0F."
+ "apihelp-wdqacrosscheck-description": "API module to cross-check Wikibase
entities against external data.",
+ "apihelp-wdqacrosscheck-param-entities": "Ids of the entities that should be
cross-checked. Required unless claims are provided.",
+ "apihelp-wdqacrosscheck-param-properties": "Optional filter to cross-check
only statements with specified property ids. This only works, if entities are
given.",
+ "apihelp-wdqacrosscheck-param-claims": "Ids of claims that should be
cross-checked. Required unless entities are provided.",
+ "apihelp-wdqacrosscheck-examples-1": "Run cross-check for all statements of
item with ID Q76.",
+ "apihelp-wdqacrosscheck-examples-2": "Run cross-check for all statements of
item with ID Q76 and item with ID Q567.",
+ "apihelp-wdqacrosscheck-examples-3": "Run cross-check for all statements of
item with ID Q76 and item with ID Q567, that uses property with ID P19.",
+ "apihelp-wdqacrosscheck-examples-4": "Run cross-check for all statements of
item with ID Q76 and item with ID Q567, that uses property with ID P19 or P31.",
+ "apihelp-wdqacrosscheck-examples-5": "Run cross-check for claim with GUID of
Q42$D8404CDA-25E4-4334-AF13-A3290BCD9C0F."
}
\ No newline at end of file
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 37f3cfc..fd2d642 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -45,13 +45,13 @@
"wikidataquality-externaldbs-size": "Name for size from the external
source.\n{{Identical|Size}}",
"wikidataquality-externaldbs-license": "Name for license from the
external source.\n{{Identical|License}}",
"wikidataquality-externaldbs-no-databases": "Message that appears when
no external databases exist.",
- "apihelp-wdqcrosscheck-description":
"{{doc-apihelp-description|wblinktitles}}",
- "apihelp-wdqcrosscheck-param-entities":
"{{doc-apihelp-param|wdqcrosscheck|entities}}",
- "apihelp-wdqcrosscheck-param-properties":
"{{doc-apihelp-param|wdqcrosscheck|properties}}",
- "apihelp-wdqcrosscheck-param-claims":
"{{doc-apihelp-param|wdqcrosscheck|claims}}",
- "apihelp-wdqcrosscheck-examples-1":
"{{doc-apihelp-example|wdqcrosscheck}}",
- "apihelp-wdqcrosscheck-examples-2":
"{{doc-apihelp-example|wdqcrosscheck}}",
- "apihelp-wdqcrosscheck-examples-3":
"{{doc-apihelp-example|wdqcrosscheck}}",
- "apihelp-wdqcrosscheck-examples-4":
"{{doc-apihelp-example|wdqcrosscheck}}",
- "apihelp-wdqcrosscheck-examples-5":
"{{doc-apihelp-example|wdqcrosscheck}}"
+ "apihelp-wdqacrosscheck-description":
"{{doc-apihelp-description|wblinktitles}}",
+ "apihelp-wdqacrosscheck-param-entities":
"{{doc-apihelp-param|wdqacrosscheck|entities}}",
+ "apihelp-wdqacrosscheck-param-properties":
"{{doc-apihelp-param|wdqacrosscheck|properties}}",
+ "apihelp-wdqacrosscheck-param-claims":
"{{doc-apihelp-param|wdqacrosscheck|claims}}",
+ "apihelp-wdqacrosscheck-examples-1":
"{{doc-apihelp-example|wdqacrosscheck}}",
+ "apihelp-wdqacrosscheck-examples-2":
"{{doc-apihelp-example|wdqacrosscheck}}",
+ "apihelp-wdqacrosscheck-examples-3":
"{{doc-apihelp-example|wdqacrosscheck}}",
+ "apihelp-wdqacrosscheck-examples-4":
"{{doc-apihelp-example|wdqacrosscheck}}",
+ "apihelp-wdqacrosscheck-examples-5":
"{{doc-apihelp-example|wdqacrosscheck}}"
}
diff --git a/includes/Violations/ViolationStore.php
b/includes/Violations/ViolationStore.php
index 461a136..83a5cde 100644
--- a/includes/Violations/ViolationStore.php
+++ b/includes/Violations/ViolationStore.php
@@ -20,14 +20,20 @@
private $db;
/**
- * @param array $violations
+ * @param array|Violation $violations
*
* @throws \DBError
*/
- public function insertViolation( array $violations ) {
+ public function insertViolations( $violations ) {
+ if ( $violations instanceof Violation ) {
+ $violations = array( $violations );
+ }
+ if ( !is_array( $violations ) ) {
+ throw new InvalidArgumentException( '$violationa must
be instance of WikidataQuality\Violations\Violation or an array of those.' );
+ }
foreach ( $violations as $violation ) {
if ( !( $violation instanceof Violation ) ) {
- throw new InvalidArgumentException( 'Input of
ValueStore has to be of type WikidataQuality\Violations\Violation' );
+ throw new InvalidArgumentException( 'Objects in
$violations must be instance of WikidataQuality\Violations\Violation' );
}
}
diff --git a/tests/phpunit/Violations/ViolationStoreTest.php
b/tests/phpunit/Violations/ViolationStoreTest.php
index 1a7a275..3a7dbb7 100644
--- a/tests/phpunit/Violations/ViolationStoreTest.php
+++ b/tests/phpunit/Violations/ViolationStoreTest.php
@@ -68,7 +68,7 @@
'claim_guid',
'constraint_claim_guid'
), array ( 'claim_guid="P13$1-2-3-4"' ) )->numRows();
- $violationStore->insertViolation( array ( $violation,
$anotherViolation ) );
+ $violationStore->insertViolations( array ( $violation,
$anotherViolation ) );
$newCount = $this->db->select( VIOLATION_TABLE, array (
'claim_guid',
'constraint_claim_guid'
@@ -87,7 +87,7 @@
$statement->setGuid( $claimGuid );
$violation = new Violation( new ItemId( 'Q42' ), $statement,
'P666$1-2-3-4', new ItemId( 'Q666' ), 1234, 'unverified' );
- $violationStore->insertViolation( array ( $violation ) );
+ $violationStore->insertViolations( $violation );
$updated = $this->db->selectRow( VIOLATION_TABLE, array(
'status', 'updated_at' ), array (
'claim_guid="P13$1-2-3-4"',
@@ -109,7 +109,7 @@
$violation = new Violation( new ItemId( 'Q42' ), $statement,
'P666$1-2-3-4', new ItemId( 'Q666' ), 1234, 'unverified' );
$this->setExpectedException( 'InvalidArgumentException' );
- $violationStore->insertViolation( array ( $violation, 'abcd' )
);
+ $violationStore->insertViolations( array ( $violation, 'abcd' )
);
}
public function addDBData() {
--
To view, visit https://gerrit.wikimedia.org/r/204495
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia479af0e1f3b9afeda7351b7e322c8cd10959bf0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataQuality
Gerrit-Branch: master
Gerrit-Owner: Tamslo <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits