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

Change subject: Add flag to disable format constraint
......................................................................

Add flag to disable format constraint

This allows administrators to quickly disable this constraint type if it
turns out to cause performance problems.

Bug: T169966
Change-Id: I168fdb110a211dc0c7f355c85f0b8c8d8cb52eda
---
M extension.json
M includes/ConstraintCheck/Checker/FormatChecker.php
M includes/ConstraintReportFactory.php
M tests/phpunit/Checker/FormatChecker/FormatCheckerTest.php
4 files changed, 43 insertions(+), 2 deletions(-)


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

diff --git a/extension.json b/extension.json
index e51627d..5f72bc5 100644
--- a/extension.json
+++ b/extension.json
@@ -89,6 +89,11 @@
                        "description": "The maximum runtime for queries on the 
configured SPARQL endpoint, in milliseconds.",
                        "public": true
                },
+               "WBQualityConstraintsCheckFormatConstraint": {
+                       "value": true,
+                       "description": "Whether or not to check the 'format' 
constraint. If this flag is set to false, any check of the 'format' constraint 
will return a 'todo' status with the 'wbqc-violation-message-security-reason' 
message.",
+                       "public": true
+               },
                "WBQualityConstraintsInstanceOfId": {
                        "value": "P31",
                        "description": "The property ID of the 'instance of' 
property (data type: item), which specifies the class(es) of an item.",
diff --git a/includes/ConstraintCheck/Checker/FormatChecker.php 
b/includes/ConstraintCheck/Checker/FormatChecker.php
index cabeaa1..7299c24 100644
--- a/includes/ConstraintCheck/Checker/FormatChecker.php
+++ b/includes/ConstraintCheck/Checker/FormatChecker.php
@@ -2,6 +2,7 @@
 
 namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Checker;
 
+use Config;
 use DataValues\StringValue;
 use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\DataModel\Snak\PropertyValueSnak;
@@ -37,17 +38,25 @@
        private $sparqlHelper;
 
        /**
+        * @var Config
+        */
+       private $config;
+
+       /**
         * @param ConstraintParameterParser $constraintParameterParser
         * @param ConstraintParameterRenderer $constraintParameterRenderer
+        * @param Config $config
         * @param SparqlHelper|null $sparqlHelper
         */
        public function __construct(
                ConstraintParameterParser $constraintParameterParser,
                ConstraintParameterRenderer $constraintParameterRenderer,
+               Config $config,
                SparqlHelper $sparqlHelper = null
        ) {
                $this->constraintParameterParser = $constraintParameterParser;
                $this->constraintParameterRenderer = 
$constraintParameterRenderer;
+               $this->config = $config;
                $this->sparqlHelper = $sparqlHelper;
        }
 
@@ -104,7 +113,7 @@
                                return new CheckResult( $entity->getId(), 
$statement, $constraint, $parameters, CheckResult::STATUS_VIOLATION, $message );
                }
 
-               if ( $this->sparqlHelper !== null ) {
+               if ( $this->sparqlHelper !== null && $this->config->get( 
'WBQualityConstraintsCheckFormatConstraint' ) ) {
                        if ( $this->sparqlHelper->matchesRegularExpression( 
$text, $format ) ) {
                                $message = '';
                                $status = CheckResult::STATUS_COMPLIANCE;
diff --git a/includes/ConstraintReportFactory.php 
b/includes/ConstraintReportFactory.php
index e6f101a..e3b923a 100644
--- a/includes/ConstraintReportFactory.php
+++ b/includes/ConstraintReportFactory.php
@@ -222,7 +222,7 @@
                                'Single value' => new SingleValueChecker(),
                                'Multi value' => new MultiValueChecker(),
                                'Unique value' => new UniqueValueChecker( 
$this->constraintParameterRenderer, $sparqlHelper ),
-                               'Format' => new FormatChecker( 
$this->constraintParameterParser, $this->constraintParameterRenderer, 
$sparqlHelper ),
+                               'Format' => new FormatChecker( 
$this->constraintParameterParser, $this->constraintParameterRenderer, 
$this->config, $sparqlHelper ),
                                'Commons link' => new CommonsLinkChecker( 
$this->constraintParameterParser, $this->constraintParameterRenderer, 
$this->titleParser ),
                                'One of' => new OneOfChecker( 
$this->constraintParameterParser, $this->constraintParameterRenderer ),
                        ];
diff --git a/tests/phpunit/Checker/FormatChecker/FormatCheckerTest.php 
b/tests/phpunit/Checker/FormatChecker/FormatCheckerTest.php
index cf817d6..02802ae 100644
--- a/tests/phpunit/Checker/FormatChecker/FormatCheckerTest.php
+++ b/tests/phpunit/Checker/FormatChecker/FormatCheckerTest.php
@@ -2,6 +2,7 @@
 
 namespace WikibaseQuality\ConstraintReport\Test\FormatChecker;
 
+use HashConfig;
 use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\DataModel\Snak\PropertyNoValueSnak;
 use Wikibase\DataModel\Statement\Statement;
@@ -52,6 +53,7 @@
                $this->formatChecker = new FormatChecker(
                        $this->getConstraintParameterParser(),
                        $this->getConstraintParameterRenderer(),
+                       $this->getDefaultConfig(),
                        $sparqlHelper
                );
        }
@@ -294,6 +296,7 @@
                $checker = new FormatChecker(
                        $this->getConstraintParameterParser(),
                        $this->getConstraintParameterRenderer(),
+                       $this->getDefaultConfig(),
                        null
                );
 
@@ -306,6 +309,30 @@
                $this->assertTodoViolation( $result );
        }
 
+       public function testFormatConstraintDisabled() {
+               $statement = new Statement( new PropertyValueSnak( new 
PropertyId( 'P1' ), new StringValue( '' ) ) );
+               $constraint = $this->getConstraintMock( $this->formatParameter( 
'.' ) );
+               $sparqlHelper = $this->getMockBuilder( SparqlHelper::class )
+                                         ->disableOriginalConstructor()
+                                         ->setMethods( [ 
'matchesRegularExpression' ] )
+                                         ->getMock();
+               $sparqlHelper->expects( $this->never() )->method( 
'matchesRegularExpression' );
+               $checker = new FormatChecker(
+                       $this->getConstraintParameterParser(),
+                       $this->getConstraintParameterRenderer(),
+                       new HashConfig( [ 
'WBQualityConstraintsCheckFormatConstraint' => false ] ),
+                       $sparqlHelper
+               );
+
+               $result = $checker->checkConstraint(
+                       $statement,
+                       $constraint,
+                       $this->getEntity()
+               );
+
+               $this->assertTodo( $result );
+       }
+
        /**
         * @param string[] $parameters
         *

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I168fdb110a211dc0c7f355c85f0b8c8d8cb52eda
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