Daniel Kinzler has uploaded a new change for review.

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


Change subject: (bug 56684) Show Quantity details in diff.
......................................................................

(bug 56684) Show Quantity details in diff.

This introduces QuantityDetailsFormatter and hooks it up
to be used in diffs.

Change-Id: I8ef2d0f0c96e404afe28e18bd6af839732df719d
---
M lib/WikibaseLib.classes.php
M lib/WikibaseLib.i18n.php
A lib/includes/formatters/QuantityDetailsFormatter.php
M lib/includes/formatters/WikibaseValueFormatterBuilders.php
4 files changed, 92 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/24/98124/1

diff --git a/lib/WikibaseLib.classes.php b/lib/WikibaseLib.classes.php
index 66cfa33..eb577d6 100644
--- a/lib/WikibaseLib.classes.php
+++ b/lib/WikibaseLib.classes.php
@@ -120,6 +120,7 @@
                'Wikibase\Lib\SnakFormatter' => 
'includes/formatters/SnakFormatter.php',
                'Wikibase\Lib\OutputFormatSnakFormatterFactory' => 
'includes/formatters/OutputFormatSnakFormatterFactory.php',
                'Wikibase\Lib\OutputFormatValueFormatterFactory' => 
'includes/formatters/OutputFormatValueFormatterFactory.php',
+               'Wikibase\Lib\QuantityDetailsFormatter' => 
'includes/formatters/QuantityDetailsFormatter.php',
                'Wikibase\Lib\UnDeserializableValueFormatter' => 
'includes/formatters/UnDeserializableValueFormatter.php',
                'Wikibase\Lib\WikibaseSnakFormatterBuilders' => 
'includes/formatters/WikibaseSnakFormatterBuilders.php',
                'Wikibase\Lib\WikibaseValueFormatterBuilders' => 
'includes/formatters/WikibaseValueFormatterBuilders.php',
diff --git a/lib/WikibaseLib.i18n.php b/lib/WikibaseLib.i18n.php
index 95ac27e..3a48fd3 100644
--- a/lib/WikibaseLib.i18n.php
+++ b/lib/WikibaseLib.i18n.php
@@ -45,6 +45,10 @@
        'wikibase-error-ui-link-exists' => 'You cannot link to this page 
because another item already links to it.',
        'wikibase-error-ui-session-failure' => 'Your session has expired. 
Please log in again.',
        'wikibase-error-ui-edit-conflict' => 'There is an edit conflict. Please 
reload and save again.',
+       'wikibase-quantitydetails-amount' => 'Amount',
+       'wikibase-quantitydetails-upperbound' => 'Upper Bound',
+       'wikibase-quantitydetails-lowerbound' => 'Lower Bound',
+       'wikibase-quantitydetails-unit' => 'Unit',
        'wikibase-replicationnote' => 'Please notice that it can take several 
minutes until the changes are visible on all wikis.',
        'wikibase-sitelinks-wikipedia' => 'Wikipedia pages linked to this item',
        'wikibase-sitelinks-sitename-columnheading' => 'Language',
@@ -143,6 +147,10 @@
        'wikibase-error-ui-session-failure' => 'This is a human readable 
version of the API error "wikibase-api-session-failure" which is shown in the 
UI.',
        'wikibase-error-ui-edit-conflict' => 'This is a human readable version 
of the API error "edit-conflict" which is shown in the UI.
 Note that the default message says the user shall "reload and save", but after 
a reload the content that should be saved will be lost.',
+       'wikibase-quantitydetails-amount' => 'Label used for the "amount" field 
of a quantity value when showing a detailed representation of the quantity, 
e.g. in a diff.',
+       'wikibase-quantitydetails-upperbound' => 'Label used for the "upper 
bound" field of a quantity value when showing a detailed representation of the 
quantity, e.g. in a diff.',
+       'wikibase-quantitydetails-lowerbound' => 'Label used for the "lower 
bound" field of a quantity value when showing a detailed representation of the 
quantity, e.g. in a diff.',
+       'wikibase-quantitydetails-unit' => 'Label used for the "unit" field of 
a quantity value when showing a detailed representation of the quantity, e.g. 
in a diff.',
        'wikibase-replicationnote' => 'Note telling the user that it can take a 
few minutes until the made changes are visible on all wikis.
 
 Preceded by any one of the following messages:
diff --git a/lib/includes/formatters/QuantityDetailsFormatter.php 
b/lib/includes/formatters/QuantityDetailsFormatter.php
new file mode 100644
index 0000000..eb91377
--- /dev/null
+++ b/lib/includes/formatters/QuantityDetailsFormatter.php
@@ -0,0 +1,82 @@
+<?php
+
+namespace Wikibase\Lib;
+
+use DataValues\QuantityValue;
+use Html;
+use InvalidArgumentException;
+use ValueFormatters\DecimalFormatter;
+use ValueFormatters\FormatterOptions;
+use ValueFormatters\ValueFormatter;
+use ValueFormatters\ValueFormatterBase;
+
+/**
+ * Formatter for rendering the details of a QuantityValue (most useful for 
diffs) in HTML.
+ *
+ * @since 0.5
+ *
+ * @file
+ * @ingroup WikibaseLib
+ *
+ * @licence GNU GPL v2+
+ * @author Daniel Kinzler
+ */
+class QuantityDetailsFormatter extends ValueFormatterBase {
+
+       /**
+        * @var DecimalFormatter
+        */
+       protected $decimalFormatter;
+
+       /**
+        * @param FormatterOptions $options
+        */
+       public function __construct( FormatterOptions $options ) {
+               parent::__construct( $options );
+
+               $this->decimalFormatter = new DecimalFormatter( $options );
+       }
+
+       /**
+        * Generates HTML representing the details of a QuantityValue,
+        * as an itemized list.
+        *
+        * @since 0.4
+        *
+        * @param QuantityValue $value The ID to format
+        *
+        * @return string
+        * @throws InvalidArgumentException
+        */
+       public function format( $value ) {
+               if ( !( $value instanceof QuantityValue ) ) {
+                       throw new InvalidArgumentException( 'Data value type 
mismatch. Expected an QuantityValue.' );
+               }
+
+               $html = '';
+               $html .= Html::openElement( 'dl', array( 'class' => 
'wikibase-details wikibase-details-quantity' ) );
+
+               $html .= Html::element( 'dt', array(), $this->getFieldLabel( 
'amount' )->text() );
+               $html .= Html::element( 'dd', array(), 
$this->decimalFormatter->format( $value->getAmount() ) );
+
+               $html .= Html::element( 'dt', array(), $this->getFieldLabel( 
'upperBound' )->text() );
+               $html .= Html::element( 'dd', array(), 
$this->decimalFormatter->format( $value->getUpperBound() ) );
+
+               $html .= Html::element( 'dt', array(), $this->getFieldLabel( 
'lowerBound' )->text() );
+               $html .= Html::element( 'dd', array(), 
$this->decimalFormatter->format( $value->getLowerBound() ) );
+
+               $html .= Html::element( 'dt', array(), $this->getFieldLabel( 
'unit' )->text() );
+               $html .= Html::element( 'dd', array(), $value->getUnit() ); // 
localize unit?...
+
+               $html .= Html::closeElement( 'dl' );
+
+               return $html;
+       }
+
+       protected function getFieldLabel( $field ) {
+               $lang = $this->getOption( ValueFormatter::OPT_LANG );
+
+               $key = 'wikibase-quantitydetails-' . strtolower( $field );
+               return wfMessage( $key )->inLanguage( $lang );
+       }
+}
diff --git a/lib/includes/formatters/WikibaseValueFormatterBuilders.php 
b/lib/includes/formatters/WikibaseValueFormatterBuilders.php
index b5b4ff7..b3c2908 100644
--- a/lib/includes/formatters/WikibaseValueFormatterBuilders.php
+++ b/lib/includes/formatters/WikibaseValueFormatterBuilders.php
@@ -93,6 +93,7 @@
                // Formatters to use for HTML in diffs.
                // Falls back to HTML display formatters.
                SnakFormatter::FORMAT_HTML_DIFF => array(
+                       'PT:quantity' => 
'Wikibase\Lib\QuantityDetailsFormatter',
                ),
        );
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8ef2d0f0c96e404afe28e18bd6af839732df719d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de>

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

Reply via email to