r63205 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63204‎ | r63205 | r63206 >
Date:15:10, 3 March 2010
Author:mkroetzsch
Status:deferred
Tags:
Comment:
Introduced too new simpler datatype classes, SimpleWikiPage and ListTypes, and simplified the Type value implementation to treat single type pages only.
Updated assignments of types to implementation objects to fix Bug 22441.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_ListType.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Property.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_SimpleWikiPage.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
@@ -119,7 +119,6 @@
120120
121121 /// Array to cache ids of tables for storing known built-in types. Having
122122 /// this data here shortcuts the search in findTypeTableID() below.
123 - /// @todo Decide what to do with the forms type: it cannot have a page sig *and* live in the special table.
124123 private static $property_table_ids = array(
125124 '_txt' => 'smw_text2', // Text type
126125 '_cod' => 'smw_text2', // Code type
@@ -139,6 +138,7 @@
140139 '_lst' => 'smw_rels2', // Value list type (internal object)
141140 // Special types are not avaialble directly for users (and have no local language name):
142141 '__typ' => 'smw_spec2', // Special type page type
 142+ '__tls' => 'smw_spec2', // Special type list for _lst properties
143143 '__sps' => 'smw_spec2', // Special string type
144144 '__spu' => 'smw_spec2', // Special uri type
145145 '__sup' => 'smw_subp2', // Special subproperty type
@@ -173,11 +173,12 @@
174174 '_lst' => array('tnwt',0,-1),// Value list type (internal object)
175175 // Special types are not avaialble directly for users (and have no local language name):
176176 '__typ' => array('t',0,0), // Special type page type
 177+ '__tls' => array('t',0,0), // Special type page type
177178 '__sps' => array('t',0,0), // Special string type
178179 '__spu' => array('t',0,0), // Special uri type
179180 '__sup' => array('tnwt',3,3), // Special subproperty type
180181 '__suc' => array('tnwt',3,3), // Special subcategory type
181 - '__spf' => array('tnwt',3,3), // Special form type (for Semantic Forms)
 182+ '__spf' => array('t',0,0), // Special form type (for Semantic Forms)
182183 '__sin' => array('tnwt',3,3), // Special instance of type
183184 '__red' => array('tnwt',3,3), // Special redirect type
184185 '__lin' => array('tfu',1,0), // Special linear unit conversion type
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
@@ -62,7 +62,7 @@
6363 $result = new SMWDataValueFactory::$m_typeclasses['__lin']($typeid);
6464 } else { // type really unknown
6565 wfLoadExtensionMessages('SemanticMediaWiki');
66 - return new SMWErrorValue(wfMsgForContent('smw_unknowntype', $typeid ), $value, $caption);
 66+ return new SMWErrorValue(wfMsgForContent('smw_unknowntype', $typeid), $value, $caption);
6767 }
6868 if ($property !== null) $result->setProperty($property);
6969 if ($value !== false) $result->setUserValue($value,$caption);
@@ -116,6 +116,7 @@
117117 '_lst' => 'SMWListValue', // Value list type (replacing former nary properties)
118118 // Special types are not avaialble directly for users (and have no local language name):
119119 '__typ' => 'SMWTypesValue', // Special type page type
 120+ '__tls' => 'SMWListTypesValue', // Special type list for decalring _lst properties
120121 '__con' => 'SMWConceptValue', // Special concept page type
121122 '__sps' => 'SMWStringValue', // Special string type
122123 '__spu' => 'SMWURIValue', // Special uri type
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_SimpleWikiPage.php
@@ -0,0 +1,51 @@
 2+<?php
 3+/**
 4+ * @file
 5+ * @ingroup SMWDataValues
 6+ */
 7+
 8+/**
 9+ * This datavalue is similiar to SMWWikiPageValue in that it represents pages
 10+ * in the wiki. However, it is tailored for uses where it is enough to store
 11+ * the title string of the page without namespace, interwiki prefix, or
 12+ * sortkey. This is useful for "special" properties like "Has type" where the
 13+ * namespace is fixed, and which do not need any of the other settings. The
 14+ * advantage of the reduction of data is that these important values can be
 15+ * stored in smaller tables that allow for faster direct access than general
 16+ * page type values.
 17+ *
 18+ * @author Markus Krötzsch
 19+ * @ingroup SMWDataValues
 20+ */
 21+class SMWSimpleWikiPageValue extends SMWWikiPageValue {
 22+
 23+ protected function parseDBkeys($args) {
 24+ $this->m_dbkeyform = $args[0];
 25+ $this->m_namespace = $this->m_fixNamespace;
 26+ $this->m_interwiki = '';
 27+ $this->m_sortkey = $this->m_dbkeyform;
 28+ $this->m_textform = str_replace('_', ' ', $this->m_dbkeyform);
 29+ $this->m_id = false;
 30+ $this->m_title = null;
 31+ $this->m_prefixedtext = false;
 32+ $this->m_caption = false;
 33+ }
 34+
 35+ public function getDBkeys() {
 36+ $this->unstub();
 37+ return array($this->m_dbkeyform);
 38+ }
 39+
 40+ public function getSignature() {
 41+ return 't';
 42+ }
 43+
 44+ public function getValueIndex() {
 45+ return 1;
 46+ }
 47+
 48+ public function getLabelIndex() {
 49+ return 1;
 50+ }
 51+
 52+}
\ No newline at end of file
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_SimpleWikiPage.php
___________________________________________________________________
Name: svn:eol-style
153 + native
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_ListType.php
@@ -0,0 +1,119 @@
 2+<?php
 3+/**
 4+ * @file
 5+ * @ingroup SMWDataValues
 6+ */
 7+
 8+/**
 9+ * This datavalue implements special processing suitable for defining the list
 10+ * of types that is required for SMW_ListValue objects. The input is a plain
 11+ * semicolon-separated list of type labels.
 12+ *
 13+ * @author Markus Krötzsch
 14+ * @ingroup SMWDataValues
 15+ */
 16+class SMWListTypesValue extends SMWDataValue {
 17+
 18+ private $m_typevalues = false;
 19+
 20+ protected function parseUserValue($value) {
 21+ $this->m_typevalues = array();
 22+ $types = explode(';', $value);
 23+ foreach ($types as $type) {
 24+ $tval = SMWDataValueFactory::newTypeIDValue('__typ',$type);
 25+ $this->m_typevalues[] = $tval;
 26+ }
 27+ }
 28+
 29+ protected function parseDBkeys($args) {
 30+ $this->m_typevalues = array();
 31+ $ids = explode(';', $args[0]);
 32+ foreach ($ids as $id) {
 33+ $this->m_typevalues[] = SMWDataValueFactory::newTypeIDValue('__typ',SMWDataValueFactory::findTypeLabel($id));
 34+ }
 35+ }
 36+
 37+ /**
 38+ * The special feature of this implementation of getDBkeys is that it uses
 39+ * internal type ids to obtain a short internal value for the type. Note
 40+ * that this also given language independence but that this is of little
 41+ * use: if the value is given in another language in the wiki, then either
 42+ * the value is still understood, or the language-independent database
 43+ * entry is only of temporary use until someine edits the respective page.
 44+ */
 45+ public function getDBkeys() {
 46+ if ( $this->isvalid() ) {
 47+ $result = '';
 48+ foreach ($this->m_typevalues as $tv) {
 49+ if ($result != '') $result .= ';';
 50+ $result .= $tv->getDBkey();
 51+ }
 52+ return array($result);
 53+ } else {
 54+ return array(false);
 55+ }
 56+ }
 57+
 58+ public function getSignature() {
 59+ return 't';
 60+ }
 61+
 62+ public function getValueIndex() {
 63+ return 0;
 64+ }
 65+
 66+ public function getLabelIndex() {
 67+ return 0;
 68+ }
 69+
 70+ public function getShortWikiText($linked = null) {
 71+ return ($this->m_caption !== false) ? $this->m_caption : $this->makeOutputText(0, $linked);
 72+ }
 73+
 74+ public function getShortHTMLText($linker = null) {
 75+ return ($this->m_caption !== false) ? $this->m_caption : $this->makeOutputText(1, $linker);
 76+ }
 77+
 78+ public function getLongWikiText($linked = null) {
 79+ return $this->makeOutputText(2, $linked);
 80+ }
 81+
 82+ public function getLongHTMLText($linker = null) {
 83+ return $this->makeOutputText(3, $linker);
 84+ }
 85+
 86+ public function getWikiValue() {
 87+ return $this->makeOutputText(4);
 88+ }
 89+
 90+ public function getTypeValues() {
 91+ $this->unstub();
 92+ return $this->m_typevalues;
 93+ }
 94+
 95+////// Internal helper functions
 96+
 97+ private function makeOutputText($type = 0, $linker = null) {
 98+ if (!$this->isValid()) {
 99+ return ( ($type == 0)||($type == 1) )? '' : $this->getErrorText();
 100+ }
 101+ $result = '';
 102+ $sep = ( $type == 4 ) ? '; ' : ', ';
 103+ foreach ($this->m_typevalues as $tv) {
 104+ if ($result != '') $result .= $sep;
 105+ $result .= $this->makeValueOutputText($type, $tv, $linker);
 106+ }
 107+ return $result;
 108+ }
 109+
 110+ private function makeValueOutputText($type, $datavalue, $linker) {
 111+ switch ($type) {
 112+ case 0: return $datavalue->getShortWikiText($linker);
 113+ case 1: return $datavalue->getShortHTMLText($linker);
 114+ case 2: return $datavalue->getLongWikiText($linker);
 115+ case 3: return $datavalue->getLongHTMLText($linker);
 116+ case 4: return $datavalue->getWikiValue();
 117+ }
 118+ }
 119+
 120+}
\ No newline at end of file
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_ListType.php
___________________________________________________________________
Name: svn:eol-style
1121 + native
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Property.php
@@ -317,7 +317,11 @@
318318 public function getPropertyTypeID() {
319319 if ($this->prop_typeid === null) {
320320 $type = $this->getTypesValue();
321 - $this->prop_typeid = $type->getDBkey();
 321+ if ($type instanceof SMWTypesValue) {
 322+ $this->prop_typeid = $type->getDBkey();
 323+ } else {
 324+ $this->prop_typeid = '__err';
 325+ }
322326 }
323327 return $this->prop_typeid;
324328 }
@@ -414,7 +418,7 @@
415419 '_CONC' => array('__con',false),
416420 '_MDAT' => array('_dat',false),
417421 '_ERRP' => array('_wpp',false),
418 - '_LIST' => array('__typ',true),
 422+ '_LIST' => array('__tls',true),
419423 // "virtual" properties for encoding lists in n-ary datatypes (their type must never be used, hence use __err)
420424 '_1' => array('__err',false),
421425 '_2' => array('__err',false),
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php
@@ -14,7 +14,7 @@
1515 * @defgroup SMW Semantic MediaWiki
1616 */
1717
18 -define('SMW_VERSION','1.5h-SVN');
 18+define('SMW_VERSION','1.5i-SVN');
1919
2020 // constants for displaying the factbox
2121 define('SMW_FACTBOX_HIDDEN', 1);
@@ -133,24 +133,26 @@
134134 $wgAutoloadClasses['SMWCsvResultPrinter'] = $smwgIP . '/includes/SMW_QP_CSV.php';
135135 $wgAutoloadClasses['SMWJSONResultPrinter'] = $smwgIP . '/includes/SMW_QP_JSONlink.php';
136136 //// datavalues
137 - $wgAutoloadClasses['SMWDataValueFactory'] = $smwgIP . '/includes/SMW_DataValueFactory.php';
138 - $wgAutoloadClasses['SMWDataValue'] = $smwgIP . '/includes/SMW_DataValue.php';
139 - $wgAutoloadClasses['SMWContainerValue'] = $smwgIP . '/includes/SMW_DV_Container.php';
140 - $wgAutoloadClasses['SMWListValue'] = $smwgIP . '/includes/SMW_DV_List.php';
141 - $wgAutoloadClasses['SMWErrorvalue'] = $smwgIP . '/includes/SMW_DV_Error.php';
142 - $wgAutoloadClasses['SMWStringValue'] = $smwgIP . '/includes/SMW_DV_String.php';
143 - $wgAutoloadClasses['SMWWikiPageValue'] = $smwgIP . '/includes/SMW_DV_WikiPage.php';
144 - $wgAutoloadClasses['SMWPropertyValue'] = $smwgIP . '/includes/SMW_DV_Property.php';
145 - $wgAutoloadClasses['SMWURIValue'] = $smwgIP . '/includes/SMW_DV_URI.php';
146 - $wgAutoloadClasses['SMWTypesValue'] = $smwgIP . '/includes/SMW_DV_Types.php';
147 - $wgAutoloadClasses['SMWErrorValue'] = $smwgIP . '/includes/SMW_DV_Error.php';
148 - $wgAutoloadClasses['SMWNumberValue'] = $smwgIP . '/includes/SMW_DV_Number.php';
149 - $wgAutoloadClasses['SMWTemperatureValue'] = $smwgIP . '/includes/SMW_DV_Temperature.php';
150 - $wgAutoloadClasses['SMWLinearValue'] = $smwgIP . '/includes/SMW_DV_Linear.php';
151 - $wgAutoloadClasses['SMWTimeValue'] = $smwgIP . '/includes/SMW_DV_Time.php';
152 - $wgAutoloadClasses['SMWBoolValue'] = $smwgIP . '/includes/SMW_DV_Bool.php';
153 - $wgAutoloadClasses['SMWConceptValue'] = $smwgIP . '/includes/SMW_DV_Concept.php';
154 - $wgAutoloadClasses['SMWImportValue'] = $smwgIP . '/includes/SMW_DV_Import.php';
 137+ $wgAutoloadClasses['SMWDataValueFactory'] = $smwgIP . '/includes/SMW_DataValueFactory.php';
 138+ $wgAutoloadClasses['SMWDataValue'] = $smwgIP . '/includes/SMW_DataValue.php';
 139+ $wgAutoloadClasses['SMWContainerValue'] = $smwgIP . '/includes/SMW_DV_Container.php';
 140+ $wgAutoloadClasses['SMWListValue'] = $smwgIP . '/includes/SMW_DV_List.php';
 141+ $wgAutoloadClasses['SMWErrorvalue'] = $smwgIP . '/includes/SMW_DV_Error.php';
 142+ $wgAutoloadClasses['SMWStringValue'] = $smwgIP . '/includes/SMW_DV_String.php';
 143+ $wgAutoloadClasses['SMWWikiPageValue'] = $smwgIP . '/includes/SMW_DV_WikiPage.php';
 144+ $wgAutoloadClasses['SMWSimpleWikiPageValue'] = $smwgIP . '/includes/SMW_DV_SimpleWikiPage.php';
 145+ $wgAutoloadClasses['SMWPropertyValue'] = $smwgIP . '/includes/SMW_DV_Property.php';
 146+ $wgAutoloadClasses['SMWURIValue'] = $smwgIP . '/includes/SMW_DV_URI.php';
 147+ $wgAutoloadClasses['SMWTypesValue'] = $smwgIP . '/includes/SMW_DV_Types.php';
 148+ $wgAutoloadClasses['SMWListTypesValue'] = $smwgIP . '/includes/SMW_DV_ListType.php';
 149+ $wgAutoloadClasses['SMWErrorValue'] = $smwgIP . '/includes/SMW_DV_Error.php';
 150+ $wgAutoloadClasses['SMWNumberValue'] = $smwgIP . '/includes/SMW_DV_Number.php';
 151+ $wgAutoloadClasses['SMWTemperatureValue'] = $smwgIP . '/includes/SMW_DV_Temperature.php';
 152+ $wgAutoloadClasses['SMWLinearValue'] = $smwgIP . '/includes/SMW_DV_Linear.php';
 153+ $wgAutoloadClasses['SMWTimeValue'] = $smwgIP . '/includes/SMW_DV_Time.php';
 154+ $wgAutoloadClasses['SMWBoolValue'] = $smwgIP . '/includes/SMW_DV_Bool.php';
 155+ $wgAutoloadClasses['SMWConceptValue'] = $smwgIP . '/includes/SMW_DV_Concept.php';
 156+ $wgAutoloadClasses['SMWImportValue'] = $smwgIP . '/includes/SMW_DV_Import.php';
155157 //// export
156158 $wgAutoloadClasses['SMWExporter'] = $smwgIP . '/includes/export/SMW_Exporter.php';
157159 $wgAutoloadClasses['SMWExpData'] = $smwgIP . '/includes/export/SMW_Exp_Data.php';
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php
@@ -59,6 +59,9 @@
6060 public function __construct($typeid) {
6161 parent::__construct($typeid);
6262 switch ($typeid) {
 63+ case '__typ':
 64+ $this->m_fixNamespace = SMW_NS_TYPE;
 65+ break;
6366 case '_wpp' : case '__sup':
6467 $this->m_fixNamespace = SMW_NS_PROPERTY;
6568 break;
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php
@@ -5,175 +5,68 @@
66 */
77
88 /**
9 - * This datavalue implements special processing suitable for defining
10 - * types of properties (n-ary or binary).
11 - * Two main use-cases exist for this class:
12 - * - to parse and format a use-provided string in a rather tolerant way
13 - * - to efficiently be generated from DB keys and to provide according
14 - * wiki values, in order to support speedy creation of datavalues in
15 - * SMWDataValueFactory.
 9+ * This datavalue implements special processing suitable for defining types of
 10+ * properties. Types behave largely like values of type SMWSimpleWikiPageValue
 11+ * with three main differnces. First, they actively check if a value is an
 12+ * alias for another type, modifying the internal representation accordingly.
 13+ * Second, they have a modified display for emphasizing if some type is defined
 14+ * in SMW (built-in). Third, they use type ids for storing data (DB keys)
 15+ * instead of using page titles.
1616 *
17 - * @todo This class has an own stubbing mechanism that is older than the
18 - * current one used in SMWDataValue. It is confusing to have two.
1917 * @author Markus Krötzsch
2018 * @ingroup SMWDataValues
2119 */
22 -class SMWTypesValue extends SMWDataValue {
 20+class SMWTypesValue extends SMWSimpleWikiPageValue {
2321
24 - private $m_typelabels = false;
25 - private $m_typecaptions = false;
26 - private $m_xsdvalue = false;
27 - private $m_isalias = false; // record whether this is an alias to another type, used to avoid duplicates when listing page types
 22+ private $m_isalias; // record whether this is an alias to another type, used to avoid duplicates when listing page types
 23+ protected $m_reallabel;
2824
2925 protected function parseUserValue($value) {
30 - // no use for being lazy here: plain user values are never useful
31 - $this->m_typelabels = array();
32 - $this->m_typecaptions = array();
33 - $types = explode(';', $value);
34 - foreach ($types as $type) {
35 - $type = ltrim($type, ' [');
36 - $type = rtrim($type, ' ]');
37 - $ttype = Title::newFromText($type,SMW_NS_TYPE);
38 - if ( ($ttype !== null) && ($ttype->getNamespace() == SMW_NS_TYPE) ) {
39 - $this->m_typecaptions[] = $type;
40 - $label = SMWDataValueFactory::findTypeLabel(SMWDataValueFactory::findTypeID($ttype->getText()));
41 - $this->m_typelabels[] = $label;
42 - $this->m_isalias = ($label === $ttype->getText())?false:true;
43 - } // else: wrong namespace or invalid title given -- what now? TODO
44 - }
 26+ parent::parseUserValue($value);
 27+ $this->m_reallabel = SMWDataValueFactory::findTypeLabel(SMWDataValueFactory::findTypeID($this->m_textform));
 28+ $this->m_isalias = ($this->m_reallabel === $this->m_textform)?false:true;
4529 }
4630
4731 protected function parseDBkeys($args) {
48 - $this->m_xsdvalue = $args[0]; // lazy parsing
 32+ parent::parseDBkeys( array(str_replace(' ', '_', SMWDataValueFactory::findTypeLabel($args[0]))) );
 33+ $this->m_reallabel = $this->m_textform;
4934 $this->m_isalias = false;
5035 }
5136
52 - public function getShortWikiText($linked = null) {
53 - $this->unstub();
54 - if ( ($linked === null) || ($linked === false) || ($this->m_caption === '') ) {
55 - if ($this->m_caption !== false) {
56 - return $this->m_caption;
57 - } else {
58 - return str_replace('_',' ',implode(', ', $this->getTypeCaptions()));
59 - }
60 - } else {
61 - global $wgContLang;
62 - $typenamespace = $wgContLang->getNsText(SMW_NS_TYPE);
63 - if ($this->m_caption !== false) {
64 - if ($this->isUnary()) {
65 - return '[[' . $typenamespace . ':' . $this->getWikiValue() . '|' . $this->m_caption . ']]';
66 - } else {
67 - return $this->m_caption;
68 - }
69 - }
70 - $result = '';
71 - $first = true;
72 - $captions = $this->getTypeCaptions();
73 - reset($captions);
74 - foreach ($this->getTypeLabels() as $type) {
75 - $caption = current($captions);
76 - if ($first) {
77 - $first = false;
78 - } else {
79 - $result .= ', ';
80 - }
81 - $result .= '[[' . $typenamespace . ':' . $type . '|' . $caption . ']]';
82 - next($captions);
83 - }
84 - return $result;
85 - }
86 - }
87 -
88 - public function getShortHTMLText($linker = null) {
89 - $this->unstub();
90 - if ( ($linker === null) || ($linker === false) || ($this->m_caption === '') ) {
91 - if ($this->m_caption !== false) {
92 - return htmlspecialchars($this->m_caption);
93 - } else {
94 - return str_replace('_',' ',implode(', ', $this->getTypeCaptions()));
95 - }
96 - } else {
97 - if ($this->m_caption !== false) {
98 - if ($this->isUnary()) {
99 - $title = Title::newFromText($this->getWikiValue(), SMW_NS_TYPE);
100 - return $linker->makeLinkObj($title, $this->m_caption);
101 - } else {
102 - return htmlspecialchars($this->m_caption);
103 - }
104 - }
105 - $result = '';
106 - $first = true;
107 - $captions = $this->getTypeCaptions();
108 - reset($captions);
109 - foreach ($this->getTypeLabels() as $type) {
110 - $caption = current($captions);
111 - if ($first) {
112 - $first = false;
113 - } else {
114 - $result .= ', ';
115 - }
116 - $title = Title::newFromText($type, SMW_NS_TYPE);
117 - $result .= $linker->makeLinkObj( $title, $caption);
118 - next($captions);
119 - }
120 - return $result;
121 - }
122 - }
123 -
12437 public function getLongWikiText($linked = null) {
12538 $this->unstub();
12639 if ( ($linked === null) || ($linked === false) ) {
127 - return str_replace('_',' ',implode(', ', $this->getTypeLabels()));
 40+ return $this->m_reallabel;
12841 } else {
12942 global $wgContLang;
130 - $result = '';
13143 $typenamespace = $wgContLang->getNsText(SMW_NS_TYPE);
132 - $first = true;
133 - foreach ($this->getTypeLabels() as $type) {
134 - if ($first) {
135 - $first = false;
136 - } else {
137 - $result .= ', ';
138 - }
139 - $id = SMWDataValueFactory::findTypeID($type);
140 - if ($id{0} == '_') { // builtin
141 - wfLoadExtensionMessages('SemanticMediaWiki');
142 - SMWOutputs::requireHeadItem(SMW_HEADER_TOOLTIP);
143 - $result .= '<span class="smwttinline"><span class="smwbuiltin">[[' . $typenamespace . ':' . $type . '|' . $type . ']]</span><span class="smwttcontent">' . wfMsgForContent('smw_isknowntype') . '</span></span>';
144 - } else {
145 - $result .= '[[' . $typenamespace . ':' . $type . '|' . $type . ']]';
146 - }
 44+ $id = SMWDataValueFactory::findTypeID($this->m_reallabel);
 45+ if ($id{0} == '_') { // builtin
 46+ wfLoadExtensionMessages('SemanticMediaWiki');
 47+ SMWOutputs::requireHeadItem(SMW_HEADER_TOOLTIP);
 48+ return '<span class="smwttinline"><span class="smwbuiltin">[[' . $typenamespace . ':' . $this->m_reallabel . '|' . $this->m_reallabel . ']]</span><span class="smwttcontent">' . wfMsgForContent('smw_isknowntype') . '</span></span>';
 49+ } else {
 50+ return '[[' . $typenamespace . ':' . $this->m_reallabel . '|' . $this->m_reallabel . ']]';
14751 }
148 - return $result;
14952 }
15053 }
15154
15255 public function getLongHTMLText($linker = null) {
15356 $this->unstub();
15457 if ( ($linker === null) || ($linker === false) ) {
155 - return str_replace('_',' ',implode(', ', $this->getTypeLabels()));
 58+ return $this->m_reallabel;
15659 } else {
157 - $result = '';
158 - $first = true;
159 - foreach ($this->getTypeLabels() as $type) {
160 - if ($first) {
161 - $first = false;
162 - } else {
163 - $result .= ', ';
164 - }
165 - $title = Title::newFromText($type, SMW_NS_TYPE);
166 - $id = SMWDataValueFactory::findTypeID($type);
167 - if ($id{0} == '_') { // builtin
168 - wfLoadExtensionMessages('SemanticMediaWiki');
169 - SMWOutputs::requireHeadItem(SMW_HEADER_TOOLTIP);
170 - $result .= '<span class="smwttinline"><span class="smwbuiltin">' .
171 - $linker->makeLinkObj( $title, $type) . '</span><span class="smwttcontent">' .
172 - wfMsgForContent('smw_isknowntype') . '</span></span>';
173 - } else {
174 - $result .= $linker->makeLinkObj( $title, $type);
175 - }
 60+ $title = $this->m_isalias ? Title::newFromText($this->m_reallabel, SMW_NS_TYPE) : $this->getTitle();
 61+ $id = SMWDataValueFactory::findTypeID($this->m_reallabel);
 62+ if ($id{0} == '_') { // builtin
 63+ wfLoadExtensionMessages('SemanticMediaWiki');
 64+ SMWOutputs::requireHeadItem(SMW_HEADER_TOOLTIP);
 65+ return '<span class="smwttinline"><span class="smwbuiltin">' .
 66+ $linker->makeLinkObj( $title, $this->m_reallabel) . '</span><span class="smwttcontent">' .
 67+ wfMsgForContent('smw_isknowntype') . '</span></span>';
 68+ } else {
 69+ return $linker->makeLinkObj( $title, $this->m_reallabel);
17670 }
177 - return $result;
17871 }
17972 }
18073
@@ -202,40 +95,13 @@
20396 }
20497
20598 /**
206 - * Convenience method to obtain the (single) DB key as a string (not in an array).
207 - * Provided since many callers can use this hash for type recognition and registry.
 99+ * This class uses type ids as DB keys.
208100 */
209101 public function getDBkey() {
210 - if ( $this->isvalid() && ($this->m_xsdvalue === false) ) {
211 - $first = true;
212 - $this->m_xsdvalue = '';
213 - foreach ($this->m_typelabels as $label) {
214 - if ($first) {
215 - $first = false;
216 - } else {
217 - $this->m_xsdvalue .= ';';
218 - }
219 - $this->m_xsdvalue .= SMWDataValueFactory::findTypeID($label);
220 - }
221 - }
222 - return $this->m_xsdvalue;
 102+ return ($this->isValid())?SMWDataValueFactory::findTypeID($this->m_reallabel):'';
223103 }
224104
225105 /**
226 - * Is this a simple unary type or some composed n-ary type?
227 - */
228 - public function isUnary() {
229 - $this->unstub();
230 - if ($this->m_typelabels !== false) {
231 - return (count($this->m_typelabels) == 1);
232 - } elseif ($this->m_xsdvalue !== false) {
233 - return (count(explode(';', $this->getDBkey(),2)) == 1);
234 - } else { //invalid
235 - return false;
236 - }
237 - }
238 -
239 - /**
240106 * Is this a built-in datatype shipped with SMW (or an extension of SMW)?
241107 * (Alternatively it would be a user-defined derived datatype.)
242108 */
@@ -257,9 +123,8 @@
258124 * Retrieve type labels if needed. Can be done lazily.
259125 */
260126 public function getTypeLabels() {
261 - $this->initTypeData();
262 - // fallback to array() for unary callers
263 - return ($this->m_typelabels === false)?array():$this->m_typelabels;
 127+ $this->unstub();
 128+ return array($this->m_reallabel);
264129 }
265130
266131 /**
@@ -267,39 +132,24 @@
268133 * are different from the labels if type aliases are used.
269134 */
270135 public function getTypeCaptions() {
271 - $this->initTypeData();
272 - // fallback to array() for unary callers
273 - return ($this->m_typecaptions === false)?array():$this->m_typecaptions;
 136+ $this->unstub();
 137+ return array($this->m_textform);
274138 }
275139
276140 /**
277 - * Internal method to extract data from DB representation. Called lazily.
 141+ * Retrieve type values.
 142+ * @deprecated This method is no longer meaningful and will vanish before SMW 1.6
278143 */
279 - protected function initTypeData() {
280 - $this->unstub();
281 - if ( ($this->m_typelabels === false) && ($this->m_xsdvalue !== false) ) {
282 - $this->m_typelabels = array();
283 - $ids = explode(';', $this->m_xsdvalue);
284 - foreach ($ids as $id) {
285 - $label = SMWDataValueFactory::findTypeLabel($id);
286 - $this->m_typelabels[] = $label;
287 - $this->m_typecaptions[] = $label;
288 - }
289 - }
 144+ public function getTypeValues() {
 145+ return array($this);
290146 }
291147
292148 /**
293 - * Retrieve type values.
294 - * @bug This implementation is inefficient.
 149+ * Is this a simple unary type or some composed n-ary type?
 150+ * @deprecated This method is no longer meaningful and will vanish before SMW 1.6
295151 */
296 - public function getTypeValues() {
297 - $result = array();
298 - $i = 0;
299 - foreach ($this->getTypeLabels() as $tl) {
300 - $result[$i] = SMWDataValueFactory::newPropertyObjectValue(SMWPropertyValue::makeProperty('_TYPE'), $tl);
301 - $i++;
302 - }
303 - return $result;
 152+ public function isUnary() {
 153+ return true;
304154 }
305155
306156 }

Status & tagging log