Lucas Werkmeister (WMDE) has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/374788 )
Change subject: Add config setting for API output format
......................................................................
Add config setting for API output format
The variable is a boolean, not an integer (like “API v1”, “v2”), because
we don’t plan to support this switch for very long: soon after we’ve
switched the API format on Wikidata, we’ll remove support for the old
output format from the extension, and then we’ll remove this config
setting as well.
Bug: T174544
Change-Id: I4d9737ff05f15dddb633c21ee96da36e7ce397de
---
M extension.json
M includes/ConstraintCheck/DelegatingConstraintChecker.php
M includes/ConstraintReportFactory.php
M tests/phpunit/Api/CheckConstraintsTest.php
4 files changed, 25 insertions(+), 4 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints
refs/changes/88/374788/1
diff --git a/extension.json b/extension.json
index f5f0a56..f1a125f 100644
--- a/extension.json
+++ b/extension.json
@@ -114,6 +114,11 @@
"description": "Whether to import property constraint
statements into the constraint database or not.",
"public": true
},
+ "WBQualityConstraintsNewApiOutputFormat": {
+ "value": false,
+ "description": "Whether to use the new API output
format, based on the Wikibase entity JSON format, which can accomodate
constraint results on qualifiers and references.",
+ "public": true
+ },
"WBQualityConstraintsSparqlEndpoint": {
"value": "",
"description": "The URL of the SPARQL endpoint. Should
accept the URL parameters 'query', 'format' and 'maxQueryTimeMillis'. Set to ''
(empty string, default) to disable SPARQL functionality.",
diff --git a/includes/ConstraintCheck/DelegatingConstraintChecker.php
b/includes/ConstraintCheck/DelegatingConstraintChecker.php
index 55761de..bab4a64 100644
--- a/includes/ConstraintCheck/DelegatingConstraintChecker.php
+++ b/includes/ConstraintCheck/DelegatingConstraintChecker.php
@@ -12,6 +12,7 @@
use Wikibase\DataModel\Statement\StatementList;
use Wikibase\DataModel\Statement\StatementListProvider;
use WikibaseQuality\ConstraintReport\ConstraintCheck\Context\Context;
+use WikibaseQuality\ConstraintReport\ConstraintCheck\Context\MainSnakContext;
use WikibaseQuality\ConstraintReport\ConstraintCheck\Context\StatementContext;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterException;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterParser;
@@ -66,12 +67,18 @@
private $loggingHelper;
/**
+ * @var string
+ */
+ private $contextClass;
+
+ /**
* @param EntityLookup $lookup
* @param ConstraintChecker[] $checkerMap
* @param ConstraintLookup $constraintRepository
* @param ConstraintParameterParser $constraintParameterParser
* @param StatementGuidParser $statementGuidParser
* @param LoggingHelper $loggingHelper
+ * @param string $contextClass StatementContext::class or
MainSnakContext::class
*/
public function __construct(
EntityLookup $lookup,
@@ -79,7 +86,8 @@
ConstraintLookup $constraintRepository,
ConstraintParameterParser $constraintParameterParser,
StatementGuidParser $statementGuidParser,
- LoggingHelper $loggingHelper
+ LoggingHelper $loggingHelper,
+ $contextClass
) {
$this->entityLookup = $lookup;
$this->checkerMap = $checkerMap;
@@ -87,6 +95,7 @@
$this->constraintParameterParser = $constraintParameterParser;
$this->statementGuidParser = $statementGuidParser;
$this->loggingHelper = $loggingHelper;
+ $this->contextClass = $contextClass;
}
/**
@@ -297,7 +306,7 @@
private function checkConstraintsForStatementOnEntity( array
$constraints, EntityDocument $entity, $statement ) {
$entityId = $entity->getId();
$result = [];
- $context = new StatementContext( $entity, $statement );
+ $context = new $this->contextClass( $entity, $statement );
foreach ( $constraints as $constraint ) {
$parameters = $constraint->getConstraintParameters();
diff --git a/includes/ConstraintReportFactory.php
b/includes/ConstraintReportFactory.php
index 9f0046a..b106d2b 100644
--- a/includes/ConstraintReportFactory.php
+++ b/includes/ConstraintReportFactory.php
@@ -13,6 +13,8 @@
use Wikibase\Lib\SnakFormatter;
use Wikibase\Rdf\RdfVocabulary;
use Wikibase\Repo\WikibaseRepo;
+use WikibaseQuality\ConstraintReport\ConstraintCheck\Context\MainSnakContext;
+use WikibaseQuality\ConstraintReport\ConstraintCheck\Context\StatementContext;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\DelegatingConstraintChecker;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterParser;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\CommonsLinkChecker;
@@ -190,7 +192,10 @@
MediaWikiServices::getInstance()->getStatsdDataFactory(),
LoggerFactory::getInstance(
'WikibaseQualityConstraints' ),
$this->config
- )
+ ),
+ $this->config->get(
'WBQualityConstraintsNewApiOutputFormat' ) ?
+ MainSnakContext::class :
+ StatementContext::class
);
}
diff --git a/tests/phpunit/Api/CheckConstraintsTest.php
b/tests/phpunit/Api/CheckConstraintsTest.php
index aaf1da7..4b5ebab 100644
--- a/tests/phpunit/Api/CheckConstraintsTest.php
+++ b/tests/phpunit/Api/CheckConstraintsTest.php
@@ -22,6 +22,7 @@
use WikibaseQuality\ConstraintReport\Api\CheckConstraints;
use WikibaseQuality\ConstraintReport\Constraint;
use WikibaseQuality\ConstraintReport\ConstraintCheck\ConstraintChecker;
+use WikibaseQuality\ConstraintReport\ConstraintCheck\Context\StatementContext;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\DelegatingConstraintChecker;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterParser;
use WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\LoggingHelper;
@@ -129,7 +130,8 @@
MediaWikiServices::getInstance()->getStatsdDataFactory(),
LoggerFactory::getInstance(
'WikibaseQualityConstraints' ),
$config
- )
+ ),
+ StatementContext::class
);
return new CheckConstraints(
--
To view, visit https://gerrit.wikimedia.org/r/374788
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4d9737ff05f15dddb633c21ee96da36e7ce397de
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits