Lucas Werkmeister (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/404710 )

Change subject: Add support for parsing “instance or subclass of” relation
......................................................................

Add support for parsing “instance or subclass of” relation

“instance or subclass of” is a new value for the “relation” parameter,
in addition to the existing “instance of” and “subclass of” values.  A
new config variable is added for the item ID of the “instance or
subclass of” relation item, ConstraintParameterParser learns to parse it
(returning the string “relationOrSubclass” – without spaces, since it
will be used in an i18n message key), and the ConstraintParameters test
trait learns to produce the parameter from that string.

Bug: T169858
Change-Id: I0d2a663e5f2200e71640942dab1d21d92eb9d5f7
---
M extension.json
M src/ConstraintCheck/Helper/ConstraintParameterParser.php
M tests/phpunit/ConstraintParameters.php
3 files changed, 18 insertions(+), 4 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints
 refs/changes/10/404710/1

diff --git a/extension.json b/extension.json
index 212c6e3..bc3d7c8 100644
--- a/extension.json
+++ b/extension.json
@@ -334,6 +334,11 @@
                        "description": "The item ID of the 'subclass of' item, 
which, when used in a 'relation' qualifier of a 'property constraint' statement 
on a property, indicates that the 'type' or 'value type' constraint defined in 
this statement demands a 'subclass' relation.",
                        "public": true
                },
+               "WBQualityConstraintsInstanceOrSubclassOfRelationId": {
+                       "value": "Q30208840",
+                       "description": "The item ID of the 'instance or 
subclass of' item, which, when used in a 'relation' qualifier of a 'property 
constraint' statement on a property, indicates that the 'type' or 'value type' 
constraint defined in this statement demands a 'instance or subclass' 
relation.",
+                       "public": true
+               },
                "WBQualityConstraintsPropertyId": {
                        "value": "P2306",
                        "description": "The property ID of the 'property' 
property (data type: property), which specifies the property parameter of an 
'inverse', 'item requires claim', 'value requires claim', 'difference within 
range', 'mandatory qualifiers', or 'qualifiers' constraint.",
diff --git a/src/ConstraintCheck/Helper/ConstraintParameterParser.php 
b/src/ConstraintCheck/Helper/ConstraintParameterParser.php
index d9750e3..e760668 100644
--- a/src/ConstraintCheck/Helper/ConstraintParameterParser.php
+++ b/src/ConstraintCheck/Helper/ConstraintParameterParser.php
@@ -176,7 +176,7 @@
         * @param array $constraintParameters see {@link 
\WikibaseQuality\Constraint::getConstraintParameters()}
         * @param string $constraintTypeItemId used in error messages
         * @throws ConstraintParameterException if the parameter is invalid or 
missing
-        * @return string 'instance' or 'subclass'
+        * @return string 'instance', 'subclass', or 'instanceOrSubclass'
         */
        public function parseRelationParameter( array $constraintParameters, 
$constraintTypeItemId ) {
                $this->checkError( $constraintParameters );
@@ -194,17 +194,23 @@
                $relationEntityId = $this->parseEntityIdParameter( 
$constraintParameters[$relationId][0], $relationId );
                $instanceId = $this->config->get( 
'WBQualityConstraintsInstanceOfRelationId' );
                $subclassId = $this->config->get( 
'WBQualityConstraintsSubclassOfRelationId' );
+               $instanceOrSubclassId = $this->config->get( 
'WBQualityConstraintsInstanceOrSubclassOfRelationId' );
                switch ( $relationEntityId ) {
                        case $instanceId:
                                return 'instance';
                        case $subclassId:
                                return 'subclass';
+                       case $instanceOrSubclassId:
+                               return 'instanceOrSubclass';
                        default:
                                throw new ConstraintParameterException(
                                        wfMessage( 
'wbqc-violation-message-parameter-oneof' )
                                                ->rawParams( 
$this->constraintParameterRenderer->formatPropertyId( $relationId, 
Role::CONSTRAINT_PARAMETER_PROPERTY ) )
-                                               ->numParams( 2 )
-                                               ->rawParams( 
$this->constraintParameterRenderer->formatItemIdList( [ $instanceId, 
$subclassId ], Role::CONSTRAINT_PARAMETER_VALUE ) )
+                                               ->numParams( 3 )
+                                               ->rawParams( 
$this->constraintParameterRenderer->formatItemIdList(
+                                                       [ $instanceId, 
$subclassId, $instanceOrSubclassId ],
+                                                       
Role::CONSTRAINT_PARAMETER_VALUE
+                                               ) )
                                                ->escaped()
                                );
                }
diff --git a/tests/phpunit/ConstraintParameters.php 
b/tests/phpunit/ConstraintParameters.php
index 3c0b424..5c9895d 100644
--- a/tests/phpunit/ConstraintParameters.php
+++ b/tests/phpunit/ConstraintParameters.php
@@ -109,7 +109,7 @@
        }
 
        /**
-        * @param string $relation 'instance' or 'subclass'
+        * @param string $relation 'instance', 'subclass', or 
'instanceOrSubclass'
         * @return array[]
         */
        public function relationParameter( $relation ) {
@@ -121,6 +121,9 @@
                        case 'subclass':
                                $configKey = 
'WBQualityConstraintsSubclassOfRelationId';
                                break;
+                       case 'instanceOrSubclass':
+                               $configKey = 
'WBQualityConstraintsInstanceOrSubclassOfRelationId';
+                               break;
                        default:
                                throw new InvalidArgumentException( '$relation 
must be instance or subclass' );
                }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0d2a663e5f2200e71640942dab1d21d92eb9d5f7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <lucas.werkmeis...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to