Daniel Werner has submitted this change and it was merged.

Change subject: (bug #55513) Baseline for Quantity data type.
......................................................................


(bug #55513) Baseline for Quantity data type.

CAVEAT: No UI support yet (bug #55515)

IMPORTANT: Requires I1d1cb7367d7de3

Change-Id: Ib6b217aff752b64a46dd872510d49525f5578063
---
M lib/WikibaseLib.i18n.php
M lib/config/WikibaseLib.default.php
M lib/includes/WikibaseDataTypeBuilders.php
M lib/tests/phpunit/WikibaseDataTypeBuildersTest.php
4 files changed, 37 insertions(+), 3 deletions(-)

Approvals:
  Daniel Werner: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/WikibaseLib.i18n.php b/lib/WikibaseLib.i18n.php
index ea602ff..791b51a 100644
--- a/lib/WikibaseLib.i18n.php
+++ b/lib/WikibaseLib.i18n.php
@@ -73,6 +73,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',
 );
 
@@ -249,6 +250,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 f53d7ab..2efc8d9 100644
--- a/lib/config/WikibaseLib.default.php
+++ b/lib/config/WikibaseLib.default.php
@@ -130,8 +130,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/WikibaseDataTypeBuilders.php 
b/lib/includes/WikibaseDataTypeBuilders.php
index c0aa899..37570b8 100644
--- a/lib/includes/WikibaseDataTypeBuilders.php
+++ b/lib/includes/WikibaseDataTypeBuilders.php
@@ -4,6 +4,7 @@
 
 use DataTypes\DataType;
 use DataValues\TimeValue;
+use DataValues\QuantityValue;
 use Parser;
 use Wikibase\EntityLookup;
 use Wikibase\Item;
@@ -79,7 +80,7 @@
                );
 
                $experimental = array(
-                       // 'quantity'=> array( $this, 'buildQuantityType' ),
+                       'quantity'=> array( $this, 'buildQuantityType' ),
                        // 'monolingual-text' => array( $this, 
'buildMonolingualTextType' ),
                        // 'multilingual-text' => array( $this, 
'buildMultilingualTextType' ),
                );
@@ -231,4 +232,29 @@
                return new DataType( $id, 'string', 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
+
+               // only allow the '1' unit for now:
+               $unitValidators = array(
+                       new TypeValidator( 'string' ),
+                       new RegexValidator( '/^1$/', false, 'unknown-unit' ),
+               );
+
+               $validators[] = new DataFieldValidator( 'unit', // Note: 
validate the 'unit' 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( new TypeValidator( 
'DataValues\QuantityValue' ), $topValidator ) );
+       }
+
 }
diff --git a/lib/tests/phpunit/WikibaseDataTypeBuildersTest.php 
b/lib/tests/phpunit/WikibaseDataTypeBuildersTest.php
index 311cd94..dd2d880 100644
--- a/lib/tests/phpunit/WikibaseDataTypeBuildersTest.php
+++ b/lib/tests/phpunit/WikibaseDataTypeBuildersTest.php
@@ -7,6 +7,7 @@
 use DataValues\GlobeCoordinateValue;
 use DataValues\LatLongValue;
 use DataValues\NumberValue;
+use DataValues\QuantityValue;
 use DataValues\StringValue;
 use DataValues\TimeValue;
 use ValueParsers\ParserOptions;
@@ -158,6 +159,11 @@
 
                if ( defined( 'WB_EXPERIMENTAL_FEATURES' ) && 
WB_EXPERIMENTAL_FEATURES ) {
                        $cases = array_merge( $cases, array(
+                               //quantity
+                               array( 'quantity', 
QuantityValue::newFromNumber( 5 ), true, 'Simple integer' ),
+                               array( 'quantity', 
QuantityValue::newFromNumber( 5, 'm' ), false, 'We don\'t support units yet' ),
+                               array( 'quantity', 
QuantityValue::newFromDecimal( '-11.234', '1', '-10', '-12' ), true, 'decimal 
strings' ),
+
                                // ....
                        ) );
                }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib6b217aff752b64a46dd872510d49525f5578063
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: Denny Vrandecic <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to