r86517 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86516‎ | r86517 | r86518 >
Date:18:05, 20 April 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
improved datatype registration
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
@@ -50,14 +50,6 @@
5151 /**
5252 * Array of data item classes, indexed by type id.
5353 *
54 - * @note This is only used for transition. Data items will not be created directly by SMWDataValueFactory in the future.
55 - * @var array of string
56 - */
57 - static private $mTypeDiClasses;
58 -
59 - /**
60 - * Array of data item classes, indexed by type id.
61 - *
6254 * @var array of integer
6355 */
6456 static private $mTypeDataItemIds;
@@ -224,41 +216,6 @@
225217 '__key' => 'SMWStringValue', // Sort key of a page
226218 );
227219
228 - self::$mTypeDiClasses = array(
229 - '_txt' => 'SMWDIBlob', // Text type
230 - '_cod' => 'SMWDIBlob', // Code type
231 - '_str' => 'SMWDIString', // String type
232 - '_ema' => 'SMWDIUri', // Email type
233 - '_uri' => 'SMWDIUri', // URL/URI type
234 - '_anu' => 'SMWDIUri', // Annotation URI type
235 - '_tel' => 'SMWDIUri', // Phone number (URI) type
236 - '_wpg' => 'SMWDIWikiPage', // Page type
237 - '_wpp' => 'SMWDIWikiPage', // Property page type TODO: make available to user space
238 - '_wpc' => 'SMWDIWikiPage', // Category page type TODO: make available to user space
239 - '_wpf' => 'SMWDIWikiPage', // Form page type for Semantic Forms
240 - '_num' => 'SMWDINumber', // Number type
241 - '_tem' => 'SMWDINumber', // Temperature type
242 - '_dat' => 'SMWDITime', // Time type
243 - '_boo' => 'SMWDIBoolean', // Boolean type
244 - '_rec' => 'SMWDIContainer', // Value list type (replacing former nary properties)
245 - // Special types are not avaialble directly for users (and have no local language name):
246 - '__typ' => 'SMWDIWikiPage', // Special type page type
247 - '__tls' => 'SMWDIString', // Special type list for decalring _rec properties
248 - '__con' => 'SMWDIConcept', // Special concept page type
249 - '__sps' => 'SMWDIString', // Special string type
250 - '__spu' => 'SMWDIUri', // Special uri type
251 - '__sup' => 'SMWDIWikiPage', // Special subproperty type
252 - '__suc' => 'SMWDIWikiPage', // Special subcategory type
253 - '__spf' => 'SMWDIWikiPage', // Special Form page type for Semantic Forms
254 - '__sin' => 'SMWDIWikiPage', // Special instance of type
255 - '__red' => 'SMWDIWikiPage', // Special redirect type
256 - '__lin' => 'SMWDINumber', // Special linear unit conversion type
257 - '__err' => 'SMWDIString', // Special error type
258 - '__imp' => 'SMWDIString', // Special import vocabulary type
259 - '__pro' => 'SMWDIProperty', // Property type (possibly predefined, no always based on a page)
260 - '__key' => 'SMWDIString', // Sort key of a page
261 - );
262 -
263220 self::$mTypeDataItemIds = array(
264221 '_txt' => SMWDataItem::TYPE_BLOB, // Text type
265222 '_cod' => SMWDataItem::TYPE_BLOB, // Code type
@@ -298,34 +255,17 @@
299256 }
300257
301258 /**
302 - * A function for associating SMW dataitems with type IDs. This should
303 - * be called from within the hook 'smwInitDatatypes' only.
304 - *
305 - * The dataitem must be one of SMW's data item classes. There is no
306 - * support for adding new datat item classes to SMW. Moreover, note
307 - * that the dataitem is indirectly determined by the datavalue class of
308 - * the type ID. So both must be set/changed to be compatible.
309 - *
310 - * @todo This function should take a dataitem ID instead of a class
311 - * name to prevent new classes from being registered here.
312 - *
313 - * @param $id string
314 - * @param $className string
315 - */
316 - static public function registerDataItem( $id, $className ) {
317 - self::$mTypeDiClasses[$id] = $className;
318 - }
319 -
320 - /**
321259 * A function for registering/overwriting datatypes for SMW. Should be
322260 * called from within the hook 'smwInitDatatypes'.
323261 *
324 - * @param string $id
325 - * @param string $className
326 - * @param mixed $label
 262+ * @param $id string type ID for which this datatype is registered
 263+ * @param $className string name of the according subclass of SMWDataValue
 264+ * @param $dataItemId integer ID of the data item class that this data value uses, see SMWDataItem
 265+ * @param $label mixed string label or false for types that cannot be accessed by users
327266 */
328 - static public function registerDatatype( $id, $className, $label = false ) {
 267+ static public function registerDatatype( $id, $className, $dataItemId, $label = false ) {
329268 self::$mTypeClasses[$id] = $className;
 269+ self::$mTypeDataItemIds[$id] = $dataItemId;
330270
331271 if ( $label != false ) {
332272 self::$mTypeLabels[$id] = $label;

Status & tagging log