Aude has uploaded a new change for review.
https://gerrit.wikimedia.org/r/88050
Change subject: (bug 55348) Handle formatting of undeserializable values
......................................................................
(bug 55348) Handle formatting of undeserializable values
this is a super simple solution that "unbreaks" diff display
It would be nice to display the more details about the "bad" value
Change-Id: I0eaa6a2b49b21e9ead1a0c6f3ebdd6616479b458
---
M lib/WikibaseLib.classes.php
M lib/WikibaseLib.i18n.php
A lib/includes/formatters/UnDeserializableValueFormatter.php
M lib/includes/formatters/WikibaseSnakFormatterBuilders.php
A lib/tests/phpunit/formatters/UnDeserializableValueFormatterTest.php
5 files changed, 111 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/50/88050/1
diff --git a/lib/WikibaseLib.classes.php b/lib/WikibaseLib.classes.php
index ca402ab..a884676 100644
--- a/lib/WikibaseLib.classes.php
+++ b/lib/WikibaseLib.classes.php
@@ -103,6 +103,7 @@
'Wikibase\Lib\SnakFormatter' =>
'includes/formatters/SnakFormatter.php',
'Wikibase\Lib\OutputFormatSnakFormatterFactory' =>
'includes/formatters/OutputFormatSnakFormatterFactory.php',
'Wikibase\Lib\OutputFormatValueFormatterFactory' =>
'includes/formatters/OutputFormatValueFormatterFactory.php',
+ 'Wikibase\Lib\UnDeserializableValueFormatter' =>
'includes/formatters/UnDeserializableValueFormatter.php',
'Wikibase\Lib\WikibaseSnakFormatterBuilders' =>
'includes/formatters/WikibaseSnakFormatterBuilders.php',
// includes/IO
diff --git a/lib/WikibaseLib.i18n.php b/lib/WikibaseLib.i18n.php
index 79c056f..432100e 100644
--- a/lib/WikibaseLib.i18n.php
+++ b/lib/WikibaseLib.i18n.php
@@ -53,6 +53,7 @@
'wikibase-sitelinks-siteid-columnheading' => 'Code',
'wikibase-sitelinks-link-columnheading' => 'Linked article',
'wikibase-tooltip-error-details' => 'Details',
+ 'wikibase-undeserializable-value' => 'Undeserializable value',
'wikibase-validator-bad-type' => '$2 instead of $1',
'wikibase-validator-too-long' => 'Must be no more than {{PLURAL:$1|one
character|$1 characters}} long',
'wikibase-validator-too-short' => 'Must be at least {{PLURAL:$1|one
character|$1 characters}} long',
@@ -155,6 +156,7 @@
'wikibase-sitelinks-link-columnheading' => 'Site links table column
heading for the column containg the title/link of/to the referenced (wiki)
page.',
'wikibase-tooltip-error-details' => 'Link within an error tooltip that
will unfold additional information regarding the error (i.e. the more specific
error message returned from the underlying API).
{{Identical|Detail}}',
+ 'wikibase-undeserializable-value' => 'Message to display for any data
values that are invalid and cannot be deserialized. The message is displayed
in such places as when users view a diff.',
'wikibase-validator-bad-type' => 'Input validation error shown when the
input has the wrong type.
Parameters:
@@ -830,6 +832,7 @@
* @author Se4598
*/
$messages['de'] = array(
+ 'wikibase-undeserializable-value' => 'Undeserializable value de!!!',
'wikibase-lib-desc' => 'Stellt dem Repositorium strukturierter Daten
Funktionen bereit',
'wikibase-entity-item' => 'Datenobjekt',
'wikibase-entity-property' => 'Eigenschaft',
diff --git a/lib/includes/formatters/UnDeserializableValueFormatter.php
b/lib/includes/formatters/UnDeserializableValueFormatter.php
new file mode 100644
index 0000000..47eddcf
--- /dev/null
+++ b/lib/includes/formatters/UnDeserializableValueFormatter.php
@@ -0,0 +1,57 @@
+<?php
+
+namespace Wikibase\Lib;
+
+use Message;
+use ValueFormatters\FormatterOptions;
+use ValueFormatters\ValueFormatter;
+use ValueFormatters\ValueFormatterBase;
+
+/**
+ * Formatter for UnDeserializableValue
+ *
+ * @since 0.5
+ *
+ * @licence GNU GPL v2+
+ * @author Katie Filbert < [email protected] >
+ */
+class UnDeserializableValueFormatter extends ValueFormatterBase {
+
+ const MESSAGE = 'message';
+
+ /**
+ * @param FormatterOptions $options
+ */
+ public function __construct( FormatterOptions $options ) {
+ $this->options = $options;
+
+ $this->options->defaultOption(
+ self::OPT_LANG,
+ 'en'
+ );
+
+ $this->options->defaultOption(
+ self::MESSAGE,
+ new Message( 'wikibase-undeserializable-value' )
+ );
+ }
+
+ /**
+ * Formats an UnDeserializableValue
+ *
+ * @since 0.5
+ *
+ * @param UnDeserializableValue
+ *
+ * @return string
+ */
+ public function format( $dataValue ) {
+ $langCode = $this->options->getOption( self::OPT_LANG );
+
+ $msg = $this->options->getOption( self::MESSAGE );
+ $msg = $msg->inLanguage( $langCode );
+
+ return $msg->text();
+ }
+
+}
diff --git a/lib/includes/formatters/WikibaseSnakFormatterBuilders.php
b/lib/includes/formatters/WikibaseSnakFormatterBuilders.php
index 7f364cc..61791ab 100644
--- a/lib/includes/formatters/WikibaseSnakFormatterBuilders.php
+++ b/lib/includes/formatters/WikibaseSnakFormatterBuilders.php
@@ -72,6 +72,7 @@
'VT:globecoordinate' =>
'ValueFormatters\GlobeCoordinateFormatter',
'VT:time' => 'Wikibase\Lib\MwTimeIsoFormatter',
'VT:wikibase-entityid' => array(
'Wikibase\Lib\WikibaseSnakFormatterBuilders', 'newEntityIdFormatter' ),
+ 'VT:bad' =>
'Wikibase\Lib\UnDeserializableValueFormatter'
),
// Formatters to use for wiki text output.
diff --git
a/lib/tests/phpunit/formatters/UnDeserializableValueFormatterTest.php
b/lib/tests/phpunit/formatters/UnDeserializableValueFormatterTest.php
new file mode 100644
index 0000000..6161836
--- /dev/null
+++ b/lib/tests/phpunit/formatters/UnDeserializableValueFormatterTest.php
@@ -0,0 +1,49 @@
+<?php
+namespace Wikibase\Lib\Test;
+
+use Message;
+use DataValues\UnDeserializableValue;
+use ValueFormatters\FormatterOptions;
+use ValueFormatters\ValueFormatter;
+use Wikibase\Lib\UnDeserializableValueFormatter;
+
+/**
+ * @covers Wikibase\Lib\UnDeserializableValueFormatter
+ *
+ * @since 0.5
+ *
+ * @ingroup WikibaseLibTest
+ *
+ * @group WikibaseLib
+ *
+ * @licence GNU GPL v2+
+ * @author Katie Filbert < [email protected] >
+ */
+class UnDeserializableValueFormatterTest extends \PHPUnit_Framework_TestCase {
+
+ public function testFormat() {
+ $message = $this->getMock( 'Message',
+ array( 'text' ),
+ array( 'wikibase-undeserializable-value' )
+ );
+
+ $message->expects( $this->any() )
+ ->method( 'text' )
+ ->will( $this->returnValue( 'bad value' ) );
+
+ $options = new FormatterOptions( array(
+ ValueFormatter::OPT_LANG => 'en',
+ UnDeserializableValueFormatter::MESSAGE => $message
+ ) );
+
+ $formatter = new UnDeserializableValueFormatter( $options );
+ $value = new UnDeserializableValue(
+ 'cookie',
+ 'string',
+ 'cannot understand!'
+ );
+
+ $this->assertEquals( $message->text(), $formatter->format(
$value ) );
+ }
+
+}
--
To view, visit https://gerrit.wikimedia.org/r/88050
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0eaa6a2b49b21e9ead1a0c6f3ebdd6616479b458
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits