Soeren.oldag has submitted this change and it was merged.
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
M tests/phpunit/Violations/CrossCheckViolationContextTest.php
6 files changed, 210 insertions(+), 32 deletions(-)
Approvals:
Soeren.oldag: Verified; Looks good to me, approved
diff --git a/i18n/en.json b/i18n/en.json
index e3399c0..6f429fe 100755
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -49,5 +49,8 @@
"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": "This value does not match with a value in
$1. Please click on icon for further information.",
+ "wbqev-violation-long-message-headline": "$1",
+ "wbqev-violation-long-message-external-values": "The
{{PLURAL:$2|value|values}} stated in the external source {{PLURAL:$2|is|are}}
$1.",
+ "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 e14631d..352cef6 100755
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -46,9 +46,12 @@
"apihelp-wbqevcrosscheck-examples-3":
"{{doc-apihelp-example|wbqevcrosscheck}}",
"apihelp-wbqevcrosscheck-examples-4":
"{{doc-apihelp-example|wbqevcrosscheck}}",
"apihelp-wbqevcrosscheck-examples-5":
"{{doc-apihelp-example|wbqevcrosscheck}}",
- "wbqev-violations-group": "Name of the group of external validation
violations. Is shown in special page that lists all the violations.",
- "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-violations-group": "Name of the group of external validation
violations. Is shown in special page that lists all the violations.",
+ "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-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-external-values": "Long message that is
shown for violated claims on item page. First parameter are the external
values, second parameter is the number of external values.",
+ "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 4ef73da..8d2fc29 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 123bbe5..e2dfca7
--- a/includes/Violations/CrossCheckViolationContext.php
+++ b/includes/Violations/CrossCheckViolationContext.php
@@ -9,7 +9,6 @@
use ValueFormatters\ValueFormatter;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\Lib\EntityIdFormatter;
-use WikibaseQuality\ExternalValidation\DumpMetaInformation\DumpMetaInformation;
use
WikibaseQuality\ExternalValidation\DumpMetaInformation\DumpMetaInformationRepo;
use WikibaseQuality\Violations\Violation;
use WikibaseQuality\Violations\ViolationContext;
@@ -79,7 +78,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 ) ) {
@@ -94,11 +93,11 @@
* @see ViolationContext::isContextFor
*
* @param Violation $violation
+ *
* @return bool
*/
public function isContextFor( Violation $violation ) {
- $splitConstraintId = explode( Violation::CONSTRAINT_ID_DELIMITER,
$violation->getConstraintId() );
- $prefix = $splitConstraintId[0];
+ $prefix = explode( Violation::CONSTRAINT_ID_DELIMITER,
$violation->getConstraintId() )[0];
return $prefix === $this->getId();
}
@@ -107,6 +106,9 @@
* @see ViolationContext::formatAdditionalInformation
*
* @param Violation $violation
+ *
+ * @throws InvalidArgumentException
+ *
* @return string
*/
public function formatAdditionalInformation( Violation $violation ) {
@@ -115,8 +117,8 @@
}
$additionalInfo = $violation->getAdditionalInfo();
- $output = $this->formatDataSource( $additionalInfo );
- $output .= $this->formatExternalValues( $additionalInfo );
+ $output = $this->buildDataSourceSection( $additionalInfo );
+ $output .= $this->buildExternalValuesSection( $additionalInfo );
return $output;
}
@@ -125,7 +127,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 );
@@ -143,21 +145,31 @@
* @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 ) ) {
$dataValueDeserializer = $this->dataValueDeserializer;
$valueFormatter = $this->valueFormatter;
- $externalValues = array_map(
+ return array_map(
function ( $serializedDataValue ) use (
$dataValueDeserializer, $valueFormatter ) {
$dataValue = $dataValueDeserializer->deserialize(
$serializedDataValue );
return $valueFormatter->format( $dataValue );
},
$additionalInformation['external_values']
- );
-
- return $this->buildSection(
- 'wbqev-violation-header-external-values',
- implode( Html::element( 'br' ), $externalValues )
);
}
}
@@ -186,18 +198,87 @@
/**
* @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 this 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 this 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 this context.' );
+ }
+
+ $dataSourceEntityId = new ItemId(
$violation->getConstraintTypeEntityId() );
+ $dataSource = $this->entityIdFormatter->formatEntityId(
$dataSourceEntityId );
+ $additionalInfo = $violation->getAdditionalInfo();
+ $externalValues = $this->formatExternalValues( $additionalInfo );
+
+ return $this->buildLongMessage( $additionalInfo, $dataSource,
$externalValues );
+ }
+
+ /**
+ * Build long message for item page.
+ *
+ * @param array $additionalInfo
+ * @param string $dataSource
+ * @param string $externalValues
+ * @return string
+ */
+ private function buildLongMessage( array $additionalInfo, $dataSource,
$externalValues ) {
+
+ $message =
+ '<span class="wbq-long-message-headline">'
+ . wfMessage( 'wbqev-violation-long-message-headline' )
+ ->params( $dataSource )
+ ->text()
+ . '</span>';
+
+ if( $externalValues ) {
+ $message .= Html::element( 'br' );
+ $message .= wfMessage(
'wbqev-violation-long-message-external-values' )
+ ->params( implode( ', ', $externalValues ), sizeof(
$additionalInfo['external_values'] ) )
+ ->text();
+ }
+ $message .= Html::element( 'br' );
+
+ $message .= wfMessage( 'wbqev-violation-long-message-solve-issue'
)->text();
+ $message .= Html::element( 'br' );
+
+ $message .=
+ '<div class="wbq-container-mark-as-exception"><a href=""
class="wbq-mark-as-exception">'
+ . wfMessage( 'wbq-violations-mark-as-exception' )->text()
+ . '</a></div>';
+
+ return $message;
+ }
+}
+
diff --git a/tests/phpunit/Violations/CrossCheckViolationContextTest.php
b/tests/phpunit/Violations/CrossCheckViolationContextTest.php
index 146cae0..c51e804 100644
--- a/tests/phpunit/Violations/CrossCheckViolationContextTest.php
+++ b/tests/phpunit/Violations/CrossCheckViolationContextTest.php
@@ -95,6 +95,34 @@
/**
+ * @dataProvider getIconPathDataProvider
+ */
+ public function testGetIconPath( $violation, $expectedException = null ) {
+ $this->setExpectedException( $expectedException );
+
+ $actualResult = $this->violationContext->getIconPath( $violation );
+
+ $this->assertTrue( is_string( $actualResult ) );
+ }
+
+ /**
+ * Test cases for getIconPathDataProvider
+ * @return array
+ */
+ public function getIconPathDataProvider() {
+ return array(
+ array(
+ $this->getViolationMock( new ItemId( 'Q42' ), 'foobar',
'wbqev|foobar' )
+ ),
+ array(
+ $this->getViolationMock( new ItemId( 'Q42' ), 'foobar',
'wbqc|foobar' ),
+ 'InvalidArgumentException'
+ )
+ );
+ }
+
+
+ /**
* @dataProvider formatAdditionalInformationDataProvider
*/
public function testFormatAdditionalInformation( $expectedResult,
$violation, $expectedException = null ) {
@@ -165,26 +193,26 @@
/**
- * @dataProvider getMessageDataProvider
+ * @dataProvider getShortMessageDataProvider
*/
- public function testGetMessage( $expectedResult, $violation,
$expectedException = null ) {
+ public function testGetShortMessage( $expectedResult, $violation,
$expectedException = null ) {
$this->setExpectedException( $expectedException );
global $wgLang;
$wgLang = Language::factory( 'qqx' );
- $actualResult = $this->violationContext->getMessage( $violation );
+ $actualResult = $this->violationContext->getShortMessage( $violation );
$this->assertEquals( $expectedResult, $actualResult );
}
/**
- * Test cases for testGetMessage
+ * Test cases for testGetShortMessage
* @return array
*/
- public function getMessageDataProvider() {
+ public function getShortMessageDataProvider() {
return array(
array(
- '(wbqev-violation-message: Q42)',
+ '(wbqev-violation-short-message: Q42)',
$this->getViolationMock(
new ItemId( 'Q1' ),
'foobar',
@@ -193,7 +221,7 @@
)
),
array(
- '(wbqev-violation-message: Q84)',
+ '(wbqev-violation-short-message: Q84)',
$this->getViolationMock(
new ItemId( 'Q1' ),
'foobar',
@@ -215,6 +243,69 @@
}
+ /**
+ * @dataProvider getLongMessageDataProvider
+ */
+ public function testGetLongMessage( $expectedResult, $violation,
$expectedException = null ){
+ $this->setExpectedException( $expectedException );
+
+ global $wgLang;
+ $wgLang = Language::factory( 'qqx' );
+ $actualResult = $this->violationContext->getLongMessage( $violation );
+
+ $this->assertEquals( $expectedResult, $actualResult );
+ }
+
+ /**
+ * Test cases for testGetLongMessage
+ * @return array
+ */
+ public function getLongMessageDataProvider() {
+ return array(
+ array(
+ '<span
class="wbq-long-message-headline">(wbqev-violation-long-message-headline:
Q84)</span><br />(wbqev-violation-long-message-external-values: bar, 1)<br
/>(wbqev-violation-long-message-solve-issue)<br /><div
class="wbq-container-mark-as-exception"><a href=""
class="wbq-mark-as-exception">(wbq-violations-mark-as-exception)</a></div>',
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'foobar',
+ 'wbqev|foobar',
+ 'Q84',
+ array( 'external_values' => array( 'foo' => 'bar' ) )
+ )
+ ),
+ array(
+ '<span
class="wbq-long-message-headline">(wbqev-violation-long-message-headline:
Q84)</span><br />(wbqev-violation-long-message-external-values: foo, bar, 2)<br
/>(wbqev-violation-long-message-solve-issue)<br /><div
class="wbq-container-mark-as-exception"><a href=""
class="wbq-mark-as-exception">(wbq-violations-mark-as-exception)</a></div>',
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'foobar',
+ 'wbqev|foobar',
+ 'Q84',
+ array( 'external_values' => array( 'foo', 'bar' ) )
+ )
+ ),
+ array(
+ '<span
class="wbq-long-message-headline">(wbqev-violation-long-message-headline:
Q84)</span><br />(wbqev-violation-long-message-solve-issue)<br /><div
class="wbq-container-mark-as-exception"><a href=""
class="wbq-mark-as-exception">(wbq-violations-mark-as-exception)</a></div>',
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'foobar',
+ 'wbqev|foobar',
+ 'Q84',
+ array()
+ )
+ ),
+ array(
+ null,
+ $this->getViolationMock(
+ new ItemId( 'Q1' ),
+ 'foobar',
+ 'wbqc|foobar',
+ 'Q84'
+ ),
+ 'InvalidArgumentException'
+ )
+ );
+ }
+
+
private function getDataValueDeserializerMock() {
$mock = $this->getMockBuilder( 'Deserializers\Deserializer' )
->setMethods( array( 'deserialize' ) )
--
To view, visit https://gerrit.wikimedia.org/r/214329
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I789b0d393699beeb22ea4b7d504eb457478a1c66
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/WikidataQualityExternalValidation
Gerrit-Branch: master
Gerrit-Owner: Dominic.sauer <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Soeren.oldag <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits