Daniel Kinzler has uploaded a new change for review.
https://gerrit.wikimedia.org/r/176933
Change subject: Introduce DataType for refs to Properties.
......................................................................
Introduce DataType for refs to Properties.
DataType for references to Properties.
Intended for use in constraints defined as statements
on properties.
Bug: T75302
Change-Id: I3e844f30eab145cee7a0a014a817cf306629b7a0
---
M lib/config/WikibaseLib.default.php
M lib/i18n/en.json
M lib/i18n/qqq.json
M lib/includes/Validators/EntityExistsValidator.php
M lib/includes/WikibaseDataTypeBuilders.php
5 files changed, 50 insertions(+), 19 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/33/176933/1
diff --git a/lib/config/WikibaseLib.default.php
b/lib/config/WikibaseLib.default.php
index 1e68026..9234333 100644
--- a/lib/config/WikibaseLib.default.php
+++ b/lib/config/WikibaseLib.default.php
@@ -97,6 +97,7 @@
'time',
'url',
'wikibase-item',
+ 'wikibase-property',
),
// URL schemes allowed for URL values. See UrlSchemeValidators for a
full list.
diff --git a/lib/i18n/en.json b/lib/i18n/en.json
index 126f31a..9b2a825 100644
--- a/lib/i18n/en.json
+++ b/lib/i18n/en.json
@@ -66,6 +66,7 @@
"wikibase-validator-unknown-unit": "Unknown unit: $1",
"wikibase-validator-not-allowed": "Illegal value: $1",
"datatypes-type-wikibase-item": "Item",
+ "datatypes-type-wikibase-property": "Property",
"datatypes-type-commonsMedia": "Commons media file",
"version-wikibase": "Wikibase",
"wikibase-time-precision-Gannum": "$1 billion years CE",
diff --git a/lib/i18n/qqq.json b/lib/i18n/qqq.json
index e26526a..070d7a7 100644
--- a/lib/i18n/qqq.json
+++ b/lib/i18n/qqq.json
@@ -75,6 +75,7 @@
"wikibase-validator-unknown-unit": "Input validation error when the
value has an unknown unit.\n\nParameters:\n* $1 - the unknown
unit\n{{Related|Wikibase-validator}}",
"wikibase-validator-not-allowed": "Input validation error when the
given value is not found in the known list of allowed values.\n\nParameters:\n*
$1 - the illegal value\n{{Related|Wikibase-validator}}",
"datatypes-type-wikibase-item": "The name of a data type for items in
Wikibase.\n{{Identical|Item}}",
+ "datatypes-type-wikibase-property": "The name of a data type for
properties in Wikibase.\n{{Identical|Property}}",
"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).",
"version-wikibase": "Name of the Wikibase extension collection, used on
[[Special:Version]]",
"wikibase-time-precision-Gannum": "!!DO NOT TRANSLATE!! Used to present
a point in time with the precession of 1 billion of
years\n{{Related|Wikibase-time-precision}}",
diff --git a/lib/includes/Validators/EntityExistsValidator.php
b/lib/includes/Validators/EntityExistsValidator.php
index 03a9fb2..0a6e7f4 100644
--- a/lib/includes/Validators/EntityExistsValidator.php
+++ b/lib/includes/Validators/EntityExistsValidator.php
@@ -19,9 +19,14 @@
class EntityExistsValidator implements ValueValidator {
private $entityLookup;
+ /**
+ * @var null
+ */
+ private $entityType;
- public function __construct( EntityLookup $entityLookup ) {
+ public function __construct( EntityLookup $entityLookup, $entityType =
null ) {
$this->entityLookup = $entityLookup;
+ $this->entityType = $entityType;
}
/**
@@ -41,6 +46,10 @@
throw new InvalidArgumentException( "Expected an
EntityId object" );
}
+ if ( $this->entityType !== null && $value->getEntityType() !==
$this->entityType ) {
+ throw new InvalidArgumentException( "Expected type " .
$this->entityType );
+ }
+
if ( !$this->entityLookup->hasEntity( $value ) ) {
return Result::newError( array(
//XXX: we are passing an EntityId as a message
parameter here - make sure to turn it into a string later!
diff --git a/lib/includes/WikibaseDataTypeBuilders.php
b/lib/includes/WikibaseDataTypeBuilders.php
index 3e84ccc..b3414f1 100644
--- a/lib/includes/WikibaseDataTypeBuilders.php
+++ b/lib/includes/WikibaseDataTypeBuilders.php
@@ -6,6 +6,8 @@
use DataValues\TimeValue;
use ValueValidators\ValueValidator;
use Wikibase\DataModel\Entity\EntityIdParser;
+use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\Entity\Property;
use Wikibase\Lib\Store\EntityLookup;
use Wikibase\Utils;
use Wikibase\Validators\CompositeValidator;
@@ -73,26 +75,28 @@
/**
* Data types to data value types mapping:
- * commonsMedia => string (camel case, FIXME maybe?)
- * globe-coordinate => globecoordinate (FIXME!)
- * monolingualtext => monolingualtext
- * multilingualtext => multilingualtext
- * quantity => quantity
- * string => string
- * time => time
- * url => string
- * wikibase-item => wikibase-entityid
+ * commonsMedia => string (camel case, FIXME maybe?)
+ * globe-coordinate => globecoordinate (FIXME!)
+ * monolingualtext => monolingualtext
+ * multilingualtext => multilingualtext
+ * quantity => quantity
+ * string => string
+ * time => time
+ * url => string
+ * wikibase-item => wikibase-entityid
+ * wikibase-property => wikibase-entityid
*/
$types = array(
- 'commonsMedia' => array( $this, 'buildMediaType' ),
- 'globe-coordinate' => array( $this,
'buildCoordinateType' ),
- 'quantity' => array( $this, 'buildQuantityType'
),
- 'string' => array( $this, 'buildStringType' ),
- 'time' => array( $this, 'buildTimeType' ),
- 'url' => array( $this, 'buildUrlType' ),
- 'wikibase-item' => array( $this, 'buildItemType' ),
- 'monolingualtext' => array( $this,
'buildMonolingualTextType' ),
+ 'commonsMedia' => array( $this, 'buildMediaType' ),
+ 'globe-coordinate' => array( $this,
'buildCoordinateType' ),
+ 'quantity' => array( $this,
'buildQuantityType' ),
+ 'string' => array( $this, 'buildStringType'
),
+ 'time' => array( $this, 'buildTimeType' ),
+ 'url' => array( $this, 'buildUrlType' ),
+ 'wikibase-item' => array( $this, 'buildItemType' ),
+ 'wikibase-property' => array( $this,
'buildPropertyType' ),
+ 'monolingualtext' => array( $this,
'buildMonolingualTextType' ),
);
$experimental = array(
@@ -116,7 +120,22 @@
//NOTE: The DataValue in question is going to be an instance of
EntityId!
$validators[] = new TypeValidator(
'Wikibase\DataModel\Entity\EntityIdValue' );
- $validators[] = new EntityExistsValidator( $this->entityLookup
);
+ $validators[] = new EntityExistsValidator( $this->entityLookup,
Item::ENTITY_TYPE );
+
+ return new DataType( $id, 'wikibase-entityid', $validators );
+ }
+
+ /**
+ * @param string $id Data type ID, typically 'wikibase-property'
+ *
+ * @return DataType
+ */
+ public function buildPropertyType( $id ) {
+ $validators = array();
+
+ //NOTE: The DataValue in question is going to be an instance of
EntityId!
+ $validators[] = new TypeValidator(
'Wikibase\DataModel\Entity\EntityIdValue' );
+ $validators[] = new EntityExistsValidator( $this->entityLookup,
Property::ENTITY_TYPE );
return new DataType( $id, 'wikibase-entityid', $validators );
}
--
To view, visit https://gerrit.wikimedia.org/r/176933
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3e844f30eab145cee7a0a014a817cf306629b7a0
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