Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php |
— | — | @@ -119,7 +119,6 @@ |
120 | 120 | |
121 | 121 | /// Array to cache ids of tables for storing known built-in types. Having |
122 | 122 | /// 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. |
124 | 123 | private static $property_table_ids = array( |
125 | 124 | '_txt' => 'smw_text2', // Text type |
126 | 125 | '_cod' => 'smw_text2', // Code type |
— | — | @@ -139,6 +138,7 @@ |
140 | 139 | '_lst' => 'smw_rels2', // Value list type (internal object) |
141 | 140 | // Special types are not avaialble directly for users (and have no local language name): |
142 | 141 | '__typ' => 'smw_spec2', // Special type page type |
| 142 | + '__tls' => 'smw_spec2', // Special type list for _lst properties |
143 | 143 | '__sps' => 'smw_spec2', // Special string type |
144 | 144 | '__spu' => 'smw_spec2', // Special uri type |
145 | 145 | '__sup' => 'smw_subp2', // Special subproperty type |
— | — | @@ -173,11 +173,12 @@ |
174 | 174 | '_lst' => array('tnwt',0,-1),// Value list type (internal object) |
175 | 175 | // Special types are not avaialble directly for users (and have no local language name): |
176 | 176 | '__typ' => array('t',0,0), // Special type page type |
| 177 | + '__tls' => array('t',0,0), // Special type page type |
177 | 178 | '__sps' => array('t',0,0), // Special string type |
178 | 179 | '__spu' => array('t',0,0), // Special uri type |
179 | 180 | '__sup' => array('tnwt',3,3), // Special subproperty type |
180 | 181 | '__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) |
182 | 183 | '__sin' => array('tnwt',3,3), // Special instance of type |
183 | 184 | '__red' => array('tnwt',3,3), // Special redirect type |
184 | 185 | '__lin' => array('tfu',1,0), // Special linear unit conversion type |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php |
— | — | @@ -62,7 +62,7 @@ |
63 | 63 | $result = new SMWDataValueFactory::$m_typeclasses['__lin']($typeid); |
64 | 64 | } else { // type really unknown |
65 | 65 | wfLoadExtensionMessages('SemanticMediaWiki'); |
66 | | - return new SMWErrorValue(wfMsgForContent('smw_unknowntype', $typeid ), $value, $caption); |
| 66 | + return new SMWErrorValue(wfMsgForContent('smw_unknowntype', $typeid), $value, $caption); |
67 | 67 | } |
68 | 68 | if ($property !== null) $result->setProperty($property); |
69 | 69 | if ($value !== false) $result->setUserValue($value,$caption); |
— | — | @@ -116,6 +116,7 @@ |
117 | 117 | '_lst' => 'SMWListValue', // Value list type (replacing former nary properties) |
118 | 118 | // Special types are not avaialble directly for users (and have no local language name): |
119 | 119 | '__typ' => 'SMWTypesValue', // Special type page type |
| 120 | + '__tls' => 'SMWListTypesValue', // Special type list for decalring _lst properties |
120 | 121 | '__con' => 'SMWConceptValue', // Special concept page type |
121 | 122 | '__sps' => 'SMWStringValue', // Special string type |
122 | 123 | '__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 |
1 | 53 | + 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 |
1 | 121 | + native |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Property.php |
— | — | @@ -317,7 +317,11 @@ |
318 | 318 | public function getPropertyTypeID() { |
319 | 319 | if ($this->prop_typeid === null) { |
320 | 320 | $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 | + } |
322 | 326 | } |
323 | 327 | return $this->prop_typeid; |
324 | 328 | } |
— | — | @@ -414,7 +418,7 @@ |
415 | 419 | '_CONC' => array('__con',false), |
416 | 420 | '_MDAT' => array('_dat',false), |
417 | 421 | '_ERRP' => array('_wpp',false), |
418 | | - '_LIST' => array('__typ',true), |
| 422 | + '_LIST' => array('__tls',true), |
419 | 423 | // "virtual" properties for encoding lists in n-ary datatypes (their type must never be used, hence use __err) |
420 | 424 | '_1' => array('__err',false), |
421 | 425 | '_2' => array('__err',false), |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | * @defgroup SMW Semantic MediaWiki |
16 | 16 | */ |
17 | 17 | |
18 | | -define('SMW_VERSION','1.5h-SVN'); |
| 18 | +define('SMW_VERSION','1.5i-SVN'); |
19 | 19 | |
20 | 20 | // constants for displaying the factbox |
21 | 21 | define('SMW_FACTBOX_HIDDEN', 1); |
— | — | @@ -133,24 +133,26 @@ |
134 | 134 | $wgAutoloadClasses['SMWCsvResultPrinter'] = $smwgIP . '/includes/SMW_QP_CSV.php'; |
135 | 135 | $wgAutoloadClasses['SMWJSONResultPrinter'] = $smwgIP . '/includes/SMW_QP_JSONlink.php'; |
136 | 136 | //// 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'; |
155 | 157 | //// export |
156 | 158 | $wgAutoloadClasses['SMWExporter'] = $smwgIP . '/includes/export/SMW_Exporter.php'; |
157 | 159 | $wgAutoloadClasses['SMWExpData'] = $smwgIP . '/includes/export/SMW_Exp_Data.php'; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php |
— | — | @@ -59,6 +59,9 @@ |
60 | 60 | public function __construct($typeid) { |
61 | 61 | parent::__construct($typeid); |
62 | 62 | switch ($typeid) { |
| 63 | + case '__typ': |
| 64 | + $this->m_fixNamespace = SMW_NS_TYPE; |
| 65 | + break; |
63 | 66 | case '_wpp' : case '__sup': |
64 | 67 | $this->m_fixNamespace = SMW_NS_PROPERTY; |
65 | 68 | break; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php |
— | — | @@ -5,175 +5,68 @@ |
6 | 6 | */ |
7 | 7 | |
8 | 8 | /** |
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. |
16 | 16 | * |
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. |
19 | 17 | * @author Markus Krötzsch |
20 | 18 | * @ingroup SMWDataValues |
21 | 19 | */ |
22 | | -class SMWTypesValue extends SMWDataValue { |
| 20 | +class SMWTypesValue extends SMWSimpleWikiPageValue { |
23 | 21 | |
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; |
28 | 24 | |
29 | 25 | 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; |
45 | 29 | } |
46 | 30 | |
47 | 31 | 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; |
49 | 34 | $this->m_isalias = false; |
50 | 35 | } |
51 | 36 | |
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 | | - |
124 | 37 | public function getLongWikiText($linked = null) { |
125 | 38 | $this->unstub(); |
126 | 39 | if ( ($linked === null) || ($linked === false) ) { |
127 | | - return str_replace('_',' ',implode(', ', $this->getTypeLabels())); |
| 40 | + return $this->m_reallabel; |
128 | 41 | } else { |
129 | 42 | global $wgContLang; |
130 | | - $result = ''; |
131 | 43 | $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 . ']]'; |
147 | 51 | } |
148 | | - return $result; |
149 | 52 | } |
150 | 53 | } |
151 | 54 | |
152 | 55 | public function getLongHTMLText($linker = null) { |
153 | 56 | $this->unstub(); |
154 | 57 | if ( ($linker === null) || ($linker === false) ) { |
155 | | - return str_replace('_',' ',implode(', ', $this->getTypeLabels())); |
| 58 | + return $this->m_reallabel; |
156 | 59 | } 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); |
176 | 70 | } |
177 | | - return $result; |
178 | 71 | } |
179 | 72 | } |
180 | 73 | |
— | — | @@ -202,40 +95,13 @@ |
203 | 96 | } |
204 | 97 | |
205 | 98 | /** |
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. |
208 | 100 | */ |
209 | 101 | 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):''; |
223 | 103 | } |
224 | 104 | |
225 | 105 | /** |
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 | | - /** |
240 | 106 | * Is this a built-in datatype shipped with SMW (or an extension of SMW)? |
241 | 107 | * (Alternatively it would be a user-defined derived datatype.) |
242 | 108 | */ |
— | — | @@ -257,9 +123,8 @@ |
258 | 124 | * Retrieve type labels if needed. Can be done lazily. |
259 | 125 | */ |
260 | 126 | 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); |
264 | 129 | } |
265 | 130 | |
266 | 131 | /** |
— | — | @@ -267,39 +132,24 @@ |
268 | 133 | * are different from the labels if type aliases are used. |
269 | 134 | */ |
270 | 135 | 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); |
274 | 138 | } |
275 | 139 | |
276 | 140 | /** |
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 |
278 | 143 | */ |
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); |
290 | 146 | } |
291 | 147 | |
292 | 148 | /** |
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 |
295 | 151 | */ |
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; |
304 | 154 | } |
305 | 155 | |
306 | 156 | } |