Daniel Kinzler has uploaded a new change for review.
https://gerrit.wikimedia.org/r/84120
Change subject: (bug 52916) Baseline for Quantity data type.
......................................................................
(bug 52916) Baseline for Quantity data type.
No UI support yet.
Rendering support is hackish/incomplete. Will be fixed
once the SnakFormatter stuff is in.
Change-Id: Ib6b217aff752b64a46dd872510d49525f5578063
---
M lib/WikibaseLib.i18n.php
M lib/config/WikibaseLib.default.php
M lib/includes/ClaimDifferenceVisualizer.php
M lib/includes/WikibaseDataTypeBuilders.php
M repo/includes/EntityView.php
5 files changed, 44 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/20/84120/1
diff --git a/lib/WikibaseLib.i18n.php b/lib/WikibaseLib.i18n.php
index 7823af7..2dcfaf2 100644
--- a/lib/WikibaseLib.i18n.php
+++ b/lib/WikibaseLib.i18n.php
@@ -69,6 +69,7 @@
'wikibase-validator-bad-mailto-url' => 'Malformed mailto URL: $1',
'datatypes-type-wikibase-item' => 'Item',
'datatypes-type-commonsMedia' => 'Commons media file',
+ 'datatypes-type-quantity' => 'Quantity',
'version-wikibase' => 'Wikibase',
);
@@ -234,6 +235,7 @@
'datatypes-type-wikibase-item' => 'The name of a data type for items in
Wikibase.
{{Identical|Item}}',
'datatypes-type-commonsMedia' => 'The name of a data type for media
files on Wikimedia Commons (proper name, capitalised in English; first letter
capitalised anyway in this message and relatives).',
+ 'datatypes-type-quantity' => 'The name of a data type for quantities
(proper name, capitalised in English; first letter capitalised anyway in this
message and relatives).',
'version-wikibase' => 'Name of the Wikibase extension collection, used
on [[Special:Version]]',
);
diff --git a/lib/config/WikibaseLib.default.php
b/lib/config/WikibaseLib.default.php
index aa58ca2..81cf15d 100644
--- a/lib/config/WikibaseLib.default.php
+++ b/lib/config/WikibaseLib.default.php
@@ -128,8 +128,8 @@
// experimental data types
$defaults['dataTypes'] = array_merge( $defaults['dataTypes'],
array(
'quantity',
- 'monolingual-text',
- 'multilingual-text',
+ //'monolingual-text',
+ //'multilingual-text',
) );
}
diff --git a/lib/includes/ClaimDifferenceVisualizer.php
b/lib/includes/ClaimDifferenceVisualizer.php
index cd35dc5..8b16130 100644
--- a/lib/includes/ClaimDifferenceVisualizer.php
+++ b/lib/includes/ClaimDifferenceVisualizer.php
@@ -1,6 +1,7 @@
<?php
namespace Wikibase;
+use DataValues\QuantityValue;
use DataValues\TimeValue;
use Diff\DiffOpAdd;
use Diff\DiffOpChange;
@@ -8,6 +9,7 @@
use Html;
use Diff\Diff;
use RuntimeException;
+use Wikibase\DataModel\Entity\EntityIdValue;
use Wikibase\Lib\EntityIdFormatter;
/**
@@ -279,12 +281,16 @@
$dataValue = $snak->getDataValue();
// FIXME! should use some value formatter
- if ( $dataValue instanceof EntityId ) {
+ if ( $dataValue instanceof EntityIdValue ) {
$diffValueString = $this->getEntityLabel(
$dataValue );
} else if ( $dataValue instanceof TimeValue ) {
// TODO: this will just display the plain
ISO8601-string,
// we should instead use a decent formatter
$diffValueString = $dataValue->getTime();
+ } else if ( $dataValue instanceof QuantityValue ) {
+ // TODO: this will just display the plain
ISO31-string,
+ // we should instead use a decent formatter
+ $diffValueString = $dataValue->getAmount();
} else {
$diffValueString = $dataValue->getValue();
}
diff --git a/lib/includes/WikibaseDataTypeBuilders.php
b/lib/includes/WikibaseDataTypeBuilders.php
index d41f50b..215c7b6 100644
--- a/lib/includes/WikibaseDataTypeBuilders.php
+++ b/lib/includes/WikibaseDataTypeBuilders.php
@@ -3,7 +3,9 @@
namespace Wikibase\Lib;
use DataTypes\DataType;
+use DataValues\QuantityValue;
use Parser;
+use ValueValidators\RangeValidator;
use Wikibase\Client\WikibaseClient;
use Wikibase\EntityLookup;
use Wikibase\Item;
@@ -81,7 +83,7 @@
);
$experimental = array(
- // 'quantity'=> array( $this, 'buildQuantityType' ),
+ 'quantity'=> array( $this, 'buildQuantityType' ),
// 'monolingual-text' => array( $this,
'buildMonolingualTextType' ),
// 'multilingual-text' => array( $this,
'buildMultilingualTextType' ),
);
@@ -211,4 +213,29 @@
return new DataType( $id, 'string', array(), array(), array(
new TypeValidator( 'DataValues\DataValue' ), $topValidator ) );
}
+ public function buildQuantityType( $id ) {
+ $validators = array();
+ $validators[] = new TypeValidator( 'array' );
+
+ // the 'amount' field is already validated by QuantityValue's
constructor
+ // the 'digits' field is already validated by QuantityValue's
constructor
+
+ // impose some extra restrictions on units:
+
+ $unitValidators = array(
+ new TypeValidator( gettype( null ) ), // We don't allow
units yet!
+ );
+
+ $validators[] = new DataFieldValidator( 'unit', // Note:
validate the 'calendarmodel' field
+ new CompositeValidator( $unitValidators, true ) //Note:
each validator is fatal
+ );
+
+ // top validator
+ $topValidator = new DataValueValidator( //Note: validate the
DataValue's native value.
+ new CompositeValidator( $validators, true ) //Note:
each validator is fatal
+ );
+
+ return new DataType( $id, 'quantity', array(), array(), array(
new TypeValidator( 'DataValues\QuantityValue' ), $topValidator ) );
+ }
+
}
diff --git a/repo/includes/EntityView.php b/repo/includes/EntityView.php
index fcc9953..aba141e 100644
--- a/repo/includes/EntityView.php
+++ b/repo/includes/EntityView.php
@@ -644,9 +644,13 @@
if ( $valueFormatter !== null ) {
$value = $valueFormatter->format( $value );
} else {
+ $type = $value->getType();
+
// If value representation is a string, just
display that one as a
// fallback for values not having a formatter
implemented yet.
- if ( is_string( $value->getValue() ) ) {
+ if ( $type === 'quantity' ) {
+ $value = $value->getAmount();
+ } elseif ( is_string( $value->getValue() ) ) {
$value = $value->getValue();
} elseif ( $value instanceof
\DataValues\UnDeserializableValue ) {
$value = $value->getReason();
--
To view, visit https://gerrit.wikimedia.org/r/84120
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib6b217aff752b64a46dd872510d49525f5578063
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits