Dominic.sauer has uploaded a new change for review.

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

Change subject: Add changes for showing icon and messages in UI on items page.
......................................................................

Add changes for showing icon and messages in UI on items page.

Change-Id: I789b0d393699beeb22ea4b7d504eb457478a1c66
---
M i18n/en.json
M i18n/qqq.json
M includes/DumpMetaInformation/DumpMetaInformationRepo.php
M includes/Violations/CrossCheckResultToViolationTranslator.php
M includes/Violations/CrossCheckViolationContext.php
5 files changed, 132 insertions(+), 18 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataQualityExternalValidation
 refs/changes/29/214329/1

diff --git a/i18n/en.json b/i18n/en.json
index e3399c0..aa6c153 100755
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -49,5 +49,10 @@
   "wbqev-violation-header-external-source": "External source:",
   "wbqev-violation-header-local-value": "Wikidata value:",
   "wbqev-violation-header-external-values": "External values:",
-  "wbqev-violation-message": "Cross-Check with $1 has pointed out a violation. 
Please click on icon for further information."
+  "wbqev-violation-short-message": "Cross-Check with $1 has pointed out a 
violation. Please click on icon for further information.",
+  "wbqev-violation-long-message-headline": "$1",
+  "wbqev-violation-long-message-plural": "The values stated in the $1 are $2.",
+  "wbqev-violation-long-message-singular": "The value stated in the $1 is $2.",
+  "wbqev-violation-long-message-external-source": "external source",
+  "wbqev-violation-long-message-solve-issue": "In order to solve this issue, 
please check carefully which value is right and add a reference."
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index c48eb84..979ee50 100755
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -53,5 +53,10 @@
     "wbqev-violation-header-external-source": "Header for section in 
violations special page that displays the name of the external source.",
     "wbqev-violation-header-local-value": "Header for section in violations 
special page that displays the data values stored in external databases.",
     "wbqev-violation-header-external-values": "Header for section in 
violations special page that displays the name of the external source.",
-    "wbqev-violation-message": "Message that is shown for violated claims on 
item page. First parameter is name of the data source."
+    "wbqev-violation-short-message": "Short message that is shown for violated 
claims in pop-up on item page. First parameter is name of the data source.",
+    "wbqev-violation-long-message-headline": "Header for long message that is 
shown for violated claims on item page.",
+    "wbqev-violation-long-message-plural": "Long message that is shown for 
violated claims on item page. Plural values version. First parameter is link to 
source, second parameter name of the data source.",
+    "wbqev-violation-long-message-singular": "Long message that is shown for 
violated claims on item page. Singular value version. First parameter is link 
to source, second parameter name of the data source.",
+    "wbqev-violation-long-message-external-source": "Name for external source 
used in link to source on items page.",
+    "wbqev-violation-long-message-solve-issue": "Message that is shown for 
violated claims in order to advise the user how to solve the issue."
 }
diff --git a/includes/DumpMetaInformation/DumpMetaInformationRepo.php 
b/includes/DumpMetaInformation/DumpMetaInformationRepo.php
index af0c1a9..6000335 100755
--- a/includes/DumpMetaInformation/DumpMetaInformationRepo.php
+++ b/includes/DumpMetaInformation/DumpMetaInformationRepo.php
@@ -158,7 +158,7 @@
      *
      * @return DumpMetaInformation[]
      */
-    public function getALl() {
+    public function getAll() {
         $db = wfGetDB( DB_SLAVE );
         $dumpMetaInformation = $this->getFromDb( $db );
 
diff --git a/includes/Violations/CrossCheckResultToViolationTranslator.php 
b/includes/Violations/CrossCheckResultToViolationTranslator.php
index d427b13..454e5e2 100755
--- a/includes/Violations/CrossCheckResultToViolationTranslator.php
+++ b/includes/Violations/CrossCheckResultToViolationTranslator.php
@@ -49,7 +49,7 @@
             $status = Violation::STATUS_VIOLATION;
             $additionalInformation = $this->buildAdditionalInformation( 
$crossCheckResult );
 
-            $violationArray[] = new Violation( $entityId, $propertyId, 
$claimGuid, $constraintId, $constraintTypeEntityId, $revisionId, $status, 
$additionalInformation);
+            $violationArray[] = new Violation( $entityId, $propertyId, 
$claimGuid, $constraintId, $constraintTypeEntityId, $revisionId, $status, 
$additionalInformation );
         }
 
         return $violationArray;
diff --git a/includes/Violations/CrossCheckViolationContext.php 
b/includes/Violations/CrossCheckViolationContext.php
old mode 100644
new mode 100755
index 783f8df..f1b42c5
--- a/includes/Violations/CrossCheckViolationContext.php
+++ b/includes/Violations/CrossCheckViolationContext.php
@@ -79,7 +79,7 @@
      */
     public function getTypes() {
         $types = array();
-        $dumpMetaInformation = $this->dumpMetaInformationRepo->getALl();
+        $dumpMetaInformation = $this->dumpMetaInformationRepo->getAll();
         foreach ( $dumpMetaInformation as $dump ) {
             $type = $dump->getSourceItemId()->getSerialization(); //TODO: 
return EntityId instead of serialization
             if( !in_array( $type, $types ) ) {
@@ -91,9 +91,24 @@
     }
 
     /**
+     * @param array $additionalInformation
+     *
+     * @return array
+     */
+    public function getDataSourceUrl( array $additionalInformation ) {
+        if ( array_key_exists( 'dump_id', $additionalInformation ) ) {
+            $dumpId = $additionalInformation['dump_id'];
+            $dumpMetaInformation = $this->dumpMetaInformationRepo->getWithId( 
$dumpId );
+
+            return $dumpMetaInformation->getSourceUrl();
+        }
+    }
+
+    /**
      * @see ViolationContext::isContextFor
      *
      * @param Violation $violation
+     *
      * @return bool
      */
     public function isContextFor( Violation $violation ) {
@@ -106,6 +121,9 @@
      * @see ViolationContext::formatAdditionalInformation
      *
      * @param Violation $violation
+     *
+     * @throws InvalidArgumentException
+     *
      * @return string
      */
     public function formatAdditionalInformation( Violation $violation ) {
@@ -114,8 +132,8 @@
         }
 
         $additionalInfo = $violation->getAdditionalInfo();
-        $output = $this->formatDataSource( $additionalInfo );
-        $output .= $this->formatExternalValues( $additionalInfo );
+        $output = $this->buildDataSourceSection( $additionalInfo );
+        $output .= $this->buildExternalValuesSection( $additionalInfo );
 
         return $output;
     }
@@ -124,7 +142,7 @@
      * @param array $additionalInformation
      * @return string
      */
-    private function formatDataSource( array $additionalInformation ) {
+    private function buildDataSourceSection( array $additionalInformation ) {
         if ( array_key_exists( 'dump_id', $additionalInformation ) ) {
             $dumpId = $additionalInformation['dump_id'];
             $dumpMetaInformation = $this->dumpMetaInformationRepo->getWithId( 
$dumpId );
@@ -142,19 +160,29 @@
      * @param array $additionalInformation
      * @return string
      */
+    private function buildExternalValuesSection( array $additionalInformation 
) {
+        if ( array_key_exists( 'external_values', $additionalInformation ) ) {
+            $externalValues = $this->formatExternalValues( 
$additionalInformation );
+
+            return $this->buildSection(
+                'wbqev-violation-header-external-values',
+                implode( Html::element( 'br' ), $externalValues )
+            );
+        }
+    }
+
+    /**
+     * @param array $additionalInformation
+     * @return string
+     */
     private function formatExternalValues( array $additionalInformation ) {
         if ( array_key_exists( 'external_values', $additionalInformation ) ) {
-            $externalValues = array_map(
+            return array_map(
                 function ( $serializedDataValue ) {
                     $dataValue = $this->dataValueDeserializer->deserialize( 
$serializedDataValue );
                     return $this->valueFormatter->format( $dataValue );
                 },
                 $additionalInformation['external_values']
-            );
-
-            return $this->buildSection(
-                'wbqev-violation-header-external-values',
-                implode( Html::element( 'br' ), $externalValues )
             );
         }
     }
@@ -183,18 +211,94 @@
 
     /**
      * @param Violation $violation
+     * @throws InvalidArgumentException
      * @return string
      */
-    public function getMessage( Violation $violation ) {
+    public function getIconPath( Violation $violation ) {
         if ( !$this->isContextFor( $violation ) ) {
-            throw new InvalidArgumentException( 'Formatting of given violation 
is not supported by current formatter.' );
+            throw new InvalidArgumentException( 'The given violation is not 
supported by any context.' );
+        }
+
+        return '/wikidata/extensions/Quality/images/severe_arrows.png';
+    }
+
+    /**
+     * @param Violation $violation
+     * @throws InvalidArgumentException
+     * @return string
+     */
+    public function getShortMessage( Violation $violation ) {
+        if ( !$this->isContextFor( $violation ) ) {
+            throw new InvalidArgumentException( 'The given violation is not 
supported by any context.' );
         }
 
         $dataSourceEntityId = new ItemId( 
$violation->getConstraintTypeEntityId() );
         $dataSource = $this->entityIdFormatter->formatEntityId( 
$dataSourceEntityId );
 
-        return wfMessage( 'wbqev-violation-message' )
+        return wfMessage( 'wbqev-violation-short-message' )
             ->params( $dataSource )
             ->text();
     }
-}
\ No newline at end of file
+
+    /**
+     * @param Violation $violation
+     * @throws InvalidArgumentException
+     * @return string
+     */
+    public function getLongMessage( Violation $violation ) {
+        if ( !$this->isContextFor( $violation ) ) {
+            throw new InvalidArgumentException( 'The given violation is not 
supported by any context.' );
+        }
+
+        $dataSourceEntityId = new ItemId( 
$violation->getConstraintTypeEntityId() );
+        $dataSource = $this->entityIdFormatter->formatEntityId( 
$dataSourceEntityId );
+        $additionalInfo = $violation->getAdditionalInfo();
+        $externalValues = $this->formatExternalValues( $additionalInfo );
+        $dataSourceUrl = $this->getDataSourceUrl( $additionalInfo );
+
+        return $this->buildLongMessage( $additionalInfo, $dataSource, 
$dataSourceUrl, $externalValues );
+    }
+
+    /**
+     * Build long message for item page.
+     *
+     * @param array $additionalInfo
+     * @param string $dataSource
+     * @param string $dataSourceUrl
+     * @param string $externalValues
+     * @return string
+     */
+    private function buildLongMessage( array $additionalInfo, $dataSource, 
$dataSourceUrl, $externalValues ) {
+
+        $messagePathExternalValues = 'wbqev-violation-long-message-plural';
+        if ( sizeof( $additionalInfo['external_values'] ) === 1 ) {
+            $messagePathExternalValues = 
'wbqev-violation-long-message-singular';
+        }
+
+        $messageHeadline =
+            '<span class="wbq-long-message-headline">'
+            . wfMessage( 'wbqev-violation-long-message-headline' )
+                ->params( $dataSource )
+                ->text()
+            . '</span>';
+        $linkToExternalSource =
+            '<a href="'
+            . $dataSourceUrl
+            . '">'
+            . wfMessage( 'wbqev-violation-long-message-external-source' )
+                ->text()
+            . '</a>';
+        $messageExternalValues = wfMessage( $messagePathExternalValues )
+            ->params( $linkToExternalSource , implode(', ' , $externalValues) )
+            ->text();
+        $messageSolveIssue = wfMessage( 
'wbqev-violation-long-message-solve-issue' )
+            ->text();
+
+        return
+            $messageHeadline
+            . Html::element( 'br' )
+            . $messageExternalValues
+            . Html::element( 'br' )
+            . $messageSolveIssue;
+    }
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I789b0d393699beeb22ea4b7d504eb457478a1c66
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataQualityExternalValidation
Gerrit-Branch: master
Gerrit-Owner: Dominic.sauer <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to