Lucas Werkmeister (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/352576 )
Change subject: Map item and property IDs from parameters to uppercase ...................................................................... Map item and property IDs from parameters to uppercase In the constraint templates on property talk pages, items and properties are linked using the Q and P templates of Wikidata. Since the first letter of a template name is always mapped to uppercase, it is also possible to specify the templates as e. g. {{p|2676}} instead of {{P|2676}}, and some constraints on Wikidata, e. g. the Qualifiers constraint on P2363, do this. In this case, the ConstraintsFromTemplates script preserves the lowercase p, and the parameters contain a parameter p2676 instead of P2676. In effect, we currently have to assume that item and property IDs in the constraints table may use any capitalization, whereas the serializations returned by the ItemId and PropertyId classes are always uppercase. To compare them correctly, we must therefore first map the parameter IDs to uppercase. Many checkers that operate on entity IDs use a ConnectionCheckerHelper, so we can move the mapping for those checkers into the helper. The other checkers have to be updated to map to uppercase themselves. This commit can hopefully be reverted once constraints are imported exclusively from statements on properties. Bug: T164731 Change-Id: I76d961030d39f452fc06c08e58649952192424aa --- M includes/ConstraintCheck/Checker/DiffWithinRangeChecker.php M includes/ConstraintCheck/Checker/MandatoryQualifiersChecker.php M includes/ConstraintCheck/Checker/OneOfChecker.php M includes/ConstraintCheck/Checker/QualifiersChecker.php M includes/ConstraintCheck/Helper/ConnectionCheckerHelper.php 5 files changed, 14 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseQualityConstraints refs/changes/76/352576/1 diff --git a/includes/ConstraintCheck/Checker/DiffWithinRangeChecker.php b/includes/ConstraintCheck/Checker/DiffWithinRangeChecker.php index 702f0ca..5bd7bd6 100644 --- a/includes/ConstraintCheck/Checker/DiffWithinRangeChecker.php +++ b/includes/ConstraintCheck/Checker/DiffWithinRangeChecker.php @@ -52,7 +52,7 @@ $constraintParameters = $constraint->getConstraintParameters(); $property = false; if ( array_key_exists( 'property', $constraintParameters ) ) { - $property = $constraintParameters['property']; + $property = strtoupper( $constraintParameters['property'] ); $parameters['property'] = $this->constraintParameterParser->parseSingleParameter( $property ); } diff --git a/includes/ConstraintCheck/Checker/MandatoryQualifiersChecker.php b/includes/ConstraintCheck/Checker/MandatoryQualifiersChecker.php index ff20dd4..e247838 100644 --- a/includes/ConstraintCheck/Checker/MandatoryQualifiersChecker.php +++ b/includes/ConstraintCheck/Checker/MandatoryQualifiersChecker.php @@ -60,6 +60,7 @@ $status = CheckResult::STATUS_COMPLIANCE; foreach ( $properties as $property ) { + $property = strtoupper( $property ); if ( !array_key_exists( $property, $qualifiers ) ) { $message = wfMessage( "wbqc-violation-message-mandatory-qualifiers" )->escaped(); $status = CheckResult::STATUS_VIOLATION; diff --git a/includes/ConstraintCheck/Checker/OneOfChecker.php b/includes/ConstraintCheck/Checker/OneOfChecker.php index 8346674..3fa3e62 100644 --- a/includes/ConstraintCheck/Checker/OneOfChecker.php +++ b/includes/ConstraintCheck/Checker/OneOfChecker.php @@ -47,6 +47,7 @@ $items = false; if ( array_key_exists( 'item', $constraintParameters ) ) { $items = explode( ',', $constraintParameters['item'] ); + $items = array_map( 'strtoupper', $items ); $parameters['item'] = $this->helper->parseParameterArray( $items ); } diff --git a/includes/ConstraintCheck/Checker/QualifiersChecker.php b/includes/ConstraintCheck/Checker/QualifiersChecker.php index 0d017bc..fce94c8 100644 --- a/includes/ConstraintCheck/Checker/QualifiersChecker.php +++ b/includes/ConstraintCheck/Checker/QualifiersChecker.php @@ -52,13 +52,19 @@ * $constraintParameters['property'] can be array( '' ), meaning that there are explicitly no qualifiers allowed */ + $properties = []; + if ( array_key_exists( 'property', $constraintParameters ) ) { + $properties = explode( ',', $constraintParameters['property'] ); + $properties = array_map( 'strtoupper', $properties ); + } + $message = ''; $status = CheckResult::STATUS_COMPLIANCE; /** @var Snak $qualifier */ foreach ( $statement->getQualifiers() as $qualifier ) { $pid = $qualifier->getPropertyId()->getSerialization(); - if ( !in_array( $pid, explode( ',', $constraintParameters['property'] ) ) ) { + if ( !in_array( $pid, $properties ) ) { $message = wfMessage( "wbqc-violation-message-qualifiers" )->escaped(); $status = CheckResult::STATUS_VIOLATION; break; diff --git a/includes/ConstraintCheck/Helper/ConnectionCheckerHelper.php b/includes/ConstraintCheck/Helper/ConnectionCheckerHelper.php index cb204df..056e0b7 100644 --- a/includes/ConstraintCheck/Helper/ConnectionCheckerHelper.php +++ b/includes/ConstraintCheck/Helper/ConnectionCheckerHelper.php @@ -25,6 +25,7 @@ * @return boolean */ public function hasProperty( StatementList $statementList, $propertyIdSerialization ) { + $propertyIdSerialization = strtoupper( $propertyIdSerialization ); /** @var Statement $statement */ foreach ( $statementList as $statement ) { if ( $statement->getPropertyId()->getSerialization() === $propertyIdSerialization ) { @@ -48,6 +49,7 @@ $propertyIdSerialization, $itemIdSerializationOrArray ) { + $propertyIdSerialization = strtoupper( $propertyIdSerialization ); /** @var Statement $statement */ foreach ( $statementList as $statement ) { if ( $statement->getPropertyId()->getSerialization() === $propertyIdSerialization ) { @@ -73,6 +75,8 @@ private function arrayHasClaim( Statement $statement, array $itemIdSerializationArray ) { $mainSnak = $statement->getMainSnak(); + $itemIdSerializationArray = array_map( "strtoupper", $itemIdSerializationArray ); + if ( $mainSnak instanceof PropertyValueSnak ) { $dataValue = $mainSnak->getDataValue(); -- To view, visit https://gerrit.wikimedia.org/r/352576 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I76d961030d39f452fc06c08e58649952192424aa 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