Wikibase
MediaWiki Wikibase extension
|
This document describes the concept of property data types as used by Wikibase.
Property data types in Wikibase are rather insubstantial * they are modeled by DataType objects, but such objects do not define any functionality of themselves. They merely act as a type safe ID for the data type.
Property data types are used to declare which kinds of values can be associated with a Property in a Snak. For each data type, the following things are defined:
Property data types are defined in definition arrays maintained by the Repo and Client. These arrays are constructed at bootstrap time in WikibaseRepo resp. WikibaseClient based on the information returned when including the files WikibaseLib.datatypes.php, WikibaseRepo.datatypes.php, and WikibaseClient.datatypes.php, respectively. The definition arrays can be further modified using the WikibaseRepoDataTypes
resp. WikibaseClientDataTypes
hooks. They are associative arrays that map property data types and value types to a set of constructor callbacks (aka factory methods).
Property data types and value types are used as keys in the definition arrays. They are distinguished by the prefixes “VT:” and “PT:”. For instance, the string value type would use the key “VT:string”, while the url data type would use the key “PT:url”.
Logically, the value type defines the structure of the value, while the property data type defines the interpretation of the value. Property data types may impose additional constraints on the values, or impact how they are rendered or exported.
Each key is associated with a map that provides the following fields:
Since for each property data type the associated value type is known, this provides a convenient fallback mechanism * If a desired callback field isn't defined for a given property data type, we can fall back to using the callback that is defined for the value type. For example, if there is no formatter-factory-callback field associated with the PT:url key, we may use the one defined for VT:string, since the url property data type is based on the string value type.
Extensions that wish to register a data type should use the WikibaseRepoDataTypes resp. WikibaseClientDataTypes hooks to provide additional data type definitions.
Information about data types can be accessed programmatically using the appropriate service objects.
The data type definitions themselves are wrapped by a DataTypeDefinitions object* the DataType objects can be obtained from the DataTypeFactory service available via WikibaseRepo::getDataTypeFactory() and WikibaseClient::getDataTypeFactory()
WikibaseRepo also has WikibaseRepo::getDataTypeValidatorFactory() which returns a DataTypeValidatorFactory for obtaining the validators for each data type.
getSnakFormatterFactory()
does not yet use $wgWikibaseDataTypeDefinitions
.