Soeren.oldag has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/217259

Change subject: Implemented hints from review from Daniel.
......................................................................

Implemented hints from review from Daniel.

Change-Id: I3cafc18c668f54bc7e761b534d777b05e951453f
---
M WikibaseQualityConstraints.php
M i18n/en.json
M i18n/qqq.json
M includes/ConstraintReportFactory.php
M includes/Violations/CheckResultToViolationTranslator.php
R includes/Violations/ConstraintViolationFormatter.php
M specials/SpecialConstraintReport.php
M tests/phpunit/Specials/SpecialConstraintReportTest.php
R tests/phpunit/Violations/ConstraintViolationFormatterTest.php
9 files changed, 72 insertions(+), 108 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataQualityConstraints
 refs/changes/59/217259/1

diff --git a/WikibaseQualityConstraints.php b/WikibaseQualityConstraints.php
index 586f017..0fb8282 100644
--- a/WikibaseQualityConstraints.php
+++ b/WikibaseQualityConstraints.php
@@ -47,5 +47,9 @@
        $GLOBALS['wgDebugLogGroups']['wbq_evaluation'] = 
'/var/log/mediawiki/wbq_evaluation.log';
 
     // Register violation context
-    $GLOBALS['wbqViolationContexts'][] = function() { return 
WikibaseQuality\ConstraintReport\ConstraintReportFactory::getDefaultInstance()->getViolationContext();
 };
+       define( 'WBQ_CONSTRAINTS_ID', 'wbqc' );
+       $GLOBALS['wbqSubExtensions'][WBQ_CONSTRAINTS_ID] = array(
+               'violationTypes' => function() { return array_keys( 
WikibaseQuality\ConstraintReport\ConstraintReportFactory::getDefaultInstance()->getConstraintCheckerMap()
 ); },
+               'violationFormatter' => function() { return 
WikibaseQuality\ConstraintReport\ConstraintReportFactory::getDefaultInstance()->getViolationFormatter();
 }
+       );
 } );
\ No newline at end of file
diff --git a/i18n/en.json b/i18n/en.json
index bbd6322..c093766 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -22,7 +22,7 @@
   "wbqc-constraintreport-result-link-to-claim": "go to claim",
   "wbqc-constraintreport-result-link-to-constraint": "go to constraint",
 
-  "wbqc-violations-group": "Constraints",
+  "wbq-subextension-name-wbqc": "Constraints",
   "wbqc-violation-header-parameters": "Parameters:",
   "wbqc-violation-message": "Constraint check has pointed out a violation. 
Please click on icon for further information."
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 743dbb3..abbbda3 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -16,5 +16,9 @@
        "wbqc-constraintreport-result-table-header-claim": "Header of the 
column that displays a link to the claim, the used property and its 
value.\n{{Identical|Claim}}",
        "wbqc-constraintreport-result-table-header-constraint": "Header of the 
column that gives information about which constraint was 
checked.\n{{Identical|Constraint}}",
        "wbqc-constraintreport-result-link-to-claim": "Text for the link to a 
claim group on the entity page.",
-       "wbqc-constraintreport-result-link-to-constraint": "Text for the link 
to a constraint on the property page."
+       "wbqc-constraintreport-result-link-to-constraint": "Text for the link 
to a constraint on the property page.",
+
+  "wbq-subextension-name-wbqc": "Name of this subextension. Is shown in 
special page that lists all the violations.",
+  "wbqc-violation-header-parameters": "Header for section in violations 
special page that displays the parameters of the constraint.",
+  "wbqc-violation-message": "message that is shown for violated claims in 
pop-up on item page. First parameter is name of the data source."
 }
diff --git a/includes/ConstraintReportFactory.php 
b/includes/ConstraintReportFactory.php
index aad8cde..42dead5 100644
--- a/includes/ConstraintReportFactory.php
+++ b/includes/ConstraintReportFactory.php
@@ -29,7 +29,8 @@
 use WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\RangeCheckerHelper;
 use WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\TypeCheckerHelper;
 use 
WikibaseQuality\ConstraintReport\Violations\CheckResultToViolationTranslator;
-use WikibaseQuality\ConstraintReport\Violations\ConstraintViolationContext;
+use WikibaseQuality\ConstraintReport\Violations\ConstraintViolationFormatter;
+use WikibaseQuality\Violations\ViolationFormatter;
 
 
 class ConstraintReportFactory {
@@ -63,6 +64,11 @@
         * @var array
         */
        private $constraintParameterMap;
+
+       /**
+        * @var ViolationFormatter
+        */
+       private $violationFormatter;
 
     /**
      * @var CheckResultToViolationTranslator
@@ -111,7 +117,7 @@
        /**
         * @return array
         */
-       private function getConstraintCheckerMap(){
+       public function getConstraintCheckerMap(){
                if ( $this->constraintCheckerMap === null ) {
                        $constraintReportHelper = new ConstraintReportHelper();
                        $connectionCheckerHelper = new 
ConnectionCheckerHelper();
@@ -185,12 +191,14 @@
        }
 
     /**
-     * @return ConstraintViolationContext
+     * @return ViolationFormatter
      */
-    public function getViolationContext() {
-        return new ConstraintViolationContext(
-            array_keys( $this->getConstraintCheckerMap() )
-        );
+    public function getViolationFormatter() {
+               if ( $this->violationFormatter === null ) {
+                       $this->violationFormatter = new 
ConstraintViolationFormatter();
+               }
+
+               return $this->violationFormatter;
     }
 
     /**
diff --git a/includes/Violations/CheckResultToViolationTranslator.php 
b/includes/Violations/CheckResultToViolationTranslator.php
index 8d1fe0f..5bee29e 100644
--- a/includes/Violations/CheckResultToViolationTranslator.php
+++ b/includes/Violations/CheckResultToViolationTranslator.php
@@ -74,6 +74,6 @@
             }
         }
 
-        return ConstraintViolationContext::CONTEXT_ID . 
Violation::CONSTRAINT_ID_DELIMITER . $constraintId;
+        return WBQ_CONSTRAINTS_ID. Violation::CONSTRAINT_ID_DELIMITER . 
$constraintId;
     }
 }
\ No newline at end of file
diff --git a/includes/Violations/ConstraintViolationContext.php 
b/includes/Violations/ConstraintViolationFormatter.php
similarity index 62%
rename from includes/Violations/ConstraintViolationContext.php
rename to includes/Violations/ConstraintViolationFormatter.php
index fd6b453..4878577 100755
--- a/includes/Violations/ConstraintViolationContext.php
+++ b/includes/Violations/ConstraintViolationFormatter.php
@@ -5,74 +5,30 @@
 
 use Html;
 use Doctrine\Instantiator\Exception\InvalidArgumentException;
-use WikibaseQuality\ConstraintReport\ConstraintReportFactory;
 use WikibaseQuality\Violations\Violation;
-use WikibaseQuality\Violations\ViolationContext;
+use WikibaseQuality\Violations\ViolationFormatter;
 
-class ConstraintViolationContext implements ViolationContext {
+class ConstraintViolationFormatter implements ViolationFormatter {
 
-    const CONTEXT_ID = 'wbqc';
-
-    /**
-     * @var array
-     */
-    private $types;
-
-    /**
-     * @param array $types
-     */
-    public function __construct( array $types ) {
-        $this->types = $types;
-    }
-
-    /**
-     * @see ViolationContext::getId
-     * @codeCoverageIgnore
-     *
-     * @return string
-     */
-    public function getId() {
-        return self::CONTEXT_ID;
-    }
-
-    /**
-     * @see ViolationContext::getName
-     * @codeCoverageIgnore
-     *
-     * @return string
-     */
-    public function getName() {
-        return 'wbqc-violations-group';
-    }
-
-    /**
-     * @see ViolationContext::getTypes
-     *
-     * @return array
-     */
-    public function getTypes() {
-        return $this->types;
-    }
-
-    /**
-     * @see ViolationContext::isContextFor
+       /**
+     * @see ViolationFormatter::isFormatterFor
      *
      * @param Violation $violation
      * @return bool
      */
-    public function isContextFor( Violation $violation ) {
+    public function isFormatterFor( Violation $violation ) {
         $splitConstraintId = explode( Violation::CONSTRAINT_ID_DELIMITER, 
$violation->getConstraintId() );
         $prefix = $splitConstraintId[0];
 
-        return $prefix === $this->getId();
+        return $prefix === WBQ_CONSTRAINTS_ID;
     }
 
     /**
      * @param Violation $violation
-     * @return string
+     * @return string HTML
      */
     public function formatAdditionalInformation( Violation $violation ) {
-        if ( !$this->isContextFor( $violation ) ) {
+        if ( !$this->isFormatterFor( $violation ) ) {
             throw new InvalidArgumentException( 'Given violation is not part 
of current context.' );
         }
 
@@ -107,10 +63,10 @@
     /**
      * @param Violation $violation
      * @throws InvalidArgumentException
-     * @return string
+     * @return string HTML
      */
     public function getIconClass( Violation $violation ) {
-        if ( !$this->isContextFor( $violation ) ) {
+        if ( !$this->isFormatterFor( $violation ) ) {
             throw new InvalidArgumentException( 'Given violation is not part 
of current context.' );
         }
         //TODO: Choose depending on type
@@ -119,20 +75,20 @@
 
     /**
      * @param Violation $violation
-     * @return string
+     * @return string HTML
      */
     public function getShortMessage( Violation $violation ) {
         //TODO: Implement message system depending on constraint type
-        return wfMessage( 'wbqc-violation-message' )->text();
+        return wfMessage( 'wbqc-violation-message' )->escaped();
     }
 
     /**
      * @param Violation $violation
      * @param bool $permissionStatus
-     * @return string
+     * @return string HTML
      */
     public function getLongMessage( Violation $violation, $permissionStatus ) {
         //TODO: Implement message system depending on constraint type
-        return wfMessage( 'wbqc-violation-message' )->text();
+        return wfMessage( 'wbqc-violation-message' )->escaped();
     }
 }
\ No newline at end of file
diff --git a/specials/SpecialConstraintReport.php 
b/specials/SpecialConstraintReport.php
index c8f8fd7..ec48e1d 100644
--- a/specials/SpecialConstraintReport.php
+++ b/specials/SpecialConstraintReport.php
@@ -34,9 +34,9 @@
 use WikibaseQuality\ConstraintReport\EvaluateConstraintReportJob;
 use WikibaseQuality\ConstraintReport\EvaluateConstraintReportJobService;
 use 
WikibaseQuality\ConstraintReport\Violations\CheckResultToViolationTranslator;
-use WikibaseQuality\Html\HtmlTable;
-use WikibaseQuality\Html\HtmlTableHeader;
-use WikibaseQuality\Violations\ViolationRepo;
+use WikibaseQuality\Html\HtmlTableBuilder;
+use WikibaseQuality\Html\HtmlTableHeaderBuilder;
+use WikibaseQuality\Violations\ViolationStore;
 use WikibaseQuality\WikibaseQualityFactory;
 
 
@@ -102,9 +102,9 @@
     private $checkResultToViolationTranslator;
 
     /**
-     * @var ViolationRepo
+     * @var ViolationStore
      */
-    private $violationRepo;
+    private $violationStore;
 
        /**
         * @param string $name
@@ -137,7 +137,7 @@
         );
 
         $this->checkResultToViolationTranslator = 
ConstraintReportFactory::getDefaultInstance()->getCheckResultToViolationTranslator();
-        $this->violationRepo = 
WikibaseQualityFactory::getDefaultInstance()->getViolationRepo();
+        $this->violationStore = 
WikibaseQualityFactory::getDefaultInstance()->getViolationStore();
        }
 
     /**
@@ -323,17 +323,17 @@
         */
        private function buildResultTable( EntityId $entityId, $results ) {
                // Set table headers
-               $table = new HtmlTable(
+               $table = new HtmlTableBuilder(
                        array (
-                               new HtmlTableHeader(
+                               new HtmlTableHeaderBuilder(
                                        $this->msg( 
'wbqc-constraintreport-result-table-header-status' )->escaped(),
                                        true
                                ),
-                               new HtmlTableHeader(
+                               new HtmlTableHeaderBuilder(
                                        $this->msg( 
'wbqc-constraintreport-result-table-header-claim' )->escaped(),
                                        true
                                ),
-                               new HtmlTableHeader(
+                               new HtmlTableHeaderBuilder(
                                        $this->msg( 
'wbqc-constraintreport-result-table-header-constraint' )->escaped(),
                                        true
                                )
@@ -693,7 +693,7 @@
     private function saveResultsInViolationsTable( $entity, $results ) {
         $violations = 
$this->checkResultToViolationTranslator->translateToViolation( $entity, 
$results );
         foreach( $violations as $violation ) {
-            $this->violationRepo->save( $violation );
+            $this->violationStore->save( $violation );
         }
     }
 
@@ -705,6 +705,6 @@
                $jobs[] = EvaluateConstraintReportJob::newInsertNow( 
$entity->getId()->getSerialization(), $checkTimeStamp, $results );
                $jobs[] = EvaluateConstraintReportJob::newInsertDeferred( 
$entity->getId()->getSerialization(), $checkTimeStamp, 10*60 );
                $jobs[] = EvaluateConstraintReportJob::newInsertDeferred( 
$entity->getId()->getSerialization(), $checkTimeStamp, 60*60 );
-               JobQueueGroup::singleton()->push( $jobs );
+               //JobQueueGroup::singleton()->push( $jobs );
        }
 }
diff --git a/tests/phpunit/Specials/SpecialConstraintReportTest.php 
b/tests/phpunit/Specials/SpecialConstraintReportTest.php
index 0e8db03..bf5b275 100644
--- a/tests/phpunit/Specials/SpecialConstraintReportTest.php
+++ b/tests/phpunit/Specials/SpecialConstraintReportTest.php
@@ -27,9 +27,9 @@
  * @uses   
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintReportHelper
  * @uses   
WikibaseQuality\ConstraintReport\ConstraintCheck\DelegatingConstraintChecker
  * @uses   WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult
- * @uses   WikibaseQuality\Html\HtmlTable
- * @uses   WikibaseQuality\Html\HtmlTableCell
- * @uses   WikibaseQuality\Html\HtmlTableHeader
+ * @uses   WikibaseQuality\Html\HtmlTableBuilder
+ * @uses   WikibaseQuality\Html\HtmlTableCellBuilder
+ * @uses   WikibaseQuality\Html\HtmlTableHeaderBuilder
  *
  * @author BP2014N1
  * @license GNU GPL v2+
diff --git a/tests/phpunit/Violations/ConstraintViolationContextTest.php 
b/tests/phpunit/Violations/ConstraintViolationFormatterTest.php
similarity index 77%
rename from tests/phpunit/Violations/ConstraintViolationContextTest.php
rename to tests/phpunit/Violations/ConstraintViolationFormatterTest.php
index 8219e1f..db1c8f8 100755
--- a/tests/phpunit/Violations/ConstraintViolationContextTest.php
+++ b/tests/phpunit/Violations/ConstraintViolationFormatterTest.php
@@ -3,18 +3,18 @@
 namespace WikibaseQuality\ConstraintReport\Test\Violations;
 
 use Language;
-use WikibaseQuality\ConstraintReport\Violations\ConstraintViolationContext;
+use WikibaseQuality\ConstraintReport\Violations\ConstraintViolationFormatter;
 
 
 /**
- * @covers 
WikibaseQuality\ConstraintReport\Violations\ConstraintViolationContext
+ * @covers 
WikibaseQuality\ConstraintReport\Violations\ConstraintViolationFormatter
  *
  * @group WikibaseQualityConstraints
  *
  * @author BP2014N1
  * @license GNU GPL v2+
  */
-class ConstraintViolationContextTest extends \MediaWikiTestCase {
+class ConstraintViolationFormatterTest extends \MediaWikiTestCase {
 
     /**
      * @var array
@@ -22,9 +22,9 @@
     private $types;
 
     /**
-     * @var ConstraintViolationContext
+     * @var ConstraintViolationFormatter
      */
-    private $violationContext;
+    private $violationFormatter;
 
     public function setUp(){
         parent::setUp();
@@ -34,37 +34,29 @@
             'bar',
             'foobar'
         );
-        $this->violationContext = new ConstraintViolationContext( $this->types 
);
+        $this->violationFormatter = new ConstraintViolationFormatter( 
$this->types );
     }
 
     public function tearDown() {
-        unset( $this->violationContext );
+        unset( $this->violationFormatter );
 
         parent::tearDown();
     }
 
-
-    public function testGetTypes() {
-        $actualResult = $this->violationContext->getTypes();
-
-        $this->assertArrayEquals( $this->types, $actualResult );
-    }
-
-
     /**
-     * @dataProvider isContextForDataProvider
+     * @dataProvider isFormatterForDataProvider
      */
-    public function testIsContextFor( $expectedResult, $violation ){
-        $actualResult = $this->violationContext->isContextFor( $violation );
+    public function testIsFormatterFor( $expectedResult, $violation ){
+        $actualResult = $this->violationFormatter->isFormatterFor( $violation 
);
 
         $this->assertEquals( $expectedResult, $actualResult );
     }
 
     /**
-     * Test cases for testIsContextFor
+     * Test cases for testIsFormatterFor
      * @return array
      */
-    public function isContextForDataProvider() {
+    public function isFormatterForDataProvider() {
         return array(
             array(
                 true,
@@ -86,7 +78,7 @@
 
         global $wgLang;
         $wgLang = Language::factory( 'qqx' );
-        $actualResult = $this->violationContext->formatAdditionalInformation( 
$violation );
+        $actualResult = 
$this->violationFormatter->formatAdditionalInformation( $violation );
 
         $this->assertEquals( $expectedResult, $actualResult );
     }
@@ -139,20 +131,20 @@
     }
 
     public function testGetIconClass() {
-        $actualResult = $this->violationContext->getIconClass( 
$this->getViolationMock( 'wbqc|foobar', array() ) );
+        $actualResult = $this->violationFormatter->getIconClass( 
$this->getViolationMock( 'wbqc|foobar', array() ) );
 
                $this->assertTrue( is_string( $actualResult ) );
     }
 
     public function testGetShortMessage() {
-        $actualResult = $this->violationContext->getShortMessage( 
$this->getViolationMock() );
+        $actualResult = $this->violationFormatter->getShortMessage( 
$this->getViolationMock() );
         $expectedResult = '(wbqc-violation-message)';
 
         $this->assertEquals( $expectedResult, $actualResult );
     }
 
     public function testGetLongMessage() {
-        $actualResult = $this->violationContext->getLongMessage( 
$this->getViolationMock(), true );
+        $actualResult = $this->violationFormatter->getLongMessage( 
$this->getViolationMock(), true );
         $expectedResult = '(wbqc-violation-message)';
 
         $this->assertEquals( $expectedResult, $actualResult );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3cafc18c668f54bc7e761b534d777b05e951453f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Soeren.oldag <soeren_ol...@freenet.de>

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

Reply via email to