Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php |
— | — | @@ -258,7 +258,80 @@ |
259 | 259 | |
260 | 260 | ///// Get methods ///// |
261 | 261 | |
| 262 | + |
262 | 263 | /** |
| 264 | + * Return an array of values that characterize the given datavalue |
| 265 | + * completely, and that are sufficient to reproduce a value of identical |
| 266 | + * content using the function setDBkeys(). The value array must use number |
| 267 | + * keys that agree with the array's natural order (in which the data was |
| 268 | + * added), and the array MUST contain at least one value in any case. |
| 269 | + * Moreover, the order and type of the array's entries must be as described |
| 270 | + * in by getSignature(); see its documentation for details. The only |
| 271 | + * exception are classes that inherit from SMWContainerValue which must |
| 272 | + * adhere to the special format of this class. |
| 273 | + * |
| 274 | + * The array should only contain components required for storing and |
| 275 | + * sorting. It should provide a compact form for the data that is still |
| 276 | + * easy to unserialize into a new object. Many datatypes will use arrays |
| 277 | + * with only one entry here. |
| 278 | + */ |
| 279 | + abstract public function getDBkeys(); |
| 280 | + |
| 281 | + /** |
| 282 | + * Return a signature string that encodes the order and type of the data |
| 283 | + * that is contained in the array given by getDBkeys(). Single letters are |
| 284 | + * used to encode different datatypes. The signature is used to determine |
| 285 | + * how to store data of this kind. The available type letters are: |
| 286 | + * - t for strings of the same maximal length as MediaWiki title names, |
| 287 | + * - l for arbitrarily long strings; searching/sorting with such data may |
| 288 | + * be limited for performance reasons, |
| 289 | + * - w for strings as used in MediaWiki for encoding interwiki prefixes |
| 290 | + * - u for short ("unit") strings; used for units of measurement in SMW |
| 291 | + * - n for namespace numbers (or other similar integers) |
| 292 | + * - f for floating point numbers of double precision |
| 293 | + * - c for the special container format used by SMWContainerValue; if used |
| 294 | + * then the signature must be 'c' without any other fields. |
| 295 | + * |
| 296 | + * Do not use any other letters in signatures of datavalues. For example, |
| 297 | + * a wiki page consists of a title, namespace, interwiki prefix, and a |
| 298 | + * sortkey for ordering it, so its signature is "tnwt". The below default |
| 299 | + * definition provides a workable fallback, but it is recommended to |
| 300 | + * define the signature explicitly in all datavalues that implement |
| 301 | + * getDBkeys() anew. |
| 302 | + */ |
| 303 | + public function getSignature() { |
| 304 | + return 't'; |
| 305 | + } |
| 306 | + |
| 307 | + /** |
| 308 | + * This function specifies the index of the DB key that should be used for |
| 309 | + * sorting values of this type. It refers to the array that is returned by |
| 310 | + * getDBkeys() and specified by getSignature(), where the first index is 0. |
| 311 | + * For example, a wiki page type with signature "tnwt" would set this value |
| 312 | + * to 3 so that page are ordered by their sortkey (the second "t" field). |
| 313 | + * The order that is used (e.g. numeric or lexicographic) is determined by |
| 314 | + * the type of the resepctive field. If no ordering is supported for this |
| 315 | + * data value, then -1 can be returned here. |
| 316 | + */ |
| 317 | + public function getValueIndex() { |
| 318 | + return 0; |
| 319 | + } |
| 320 | + |
| 321 | + /** |
| 322 | + * This function specifies the index of the DB key that should be used for |
| 323 | + * string-matching values of this type. SMW supports some query conditions |
| 324 | + * that involve string patterns. Since numerical sort fields cannot be used |
| 325 | + * for this, this index might differ from getValueIndex(). Otherwise, all |
| 326 | + * documentation of getValueIndex() applies. |
| 327 | + * @note Any given storage implementation might decide to not support |
| 328 | + * string matching conditions for the specified value if not available for |
| 329 | + * its type. |
| 330 | + */ |
| 331 | + public function getLabelIndex() { |
| 332 | + return 0; |
| 333 | + } |
| 334 | + |
| 335 | + /** |
263 | 336 | * Returns a short textual representation for this data value. If the value |
264 | 337 | * was initialised from a user supplied string, then this original string |
265 | 338 | * should be reflected in this short version (i.e. no normalisation should |
— | — | @@ -372,21 +445,6 @@ |
373 | 446 | } |
374 | 447 | |
375 | 448 | /** |
376 | | - * Return an array of values that characterize the given datavalue completely, |
377 | | - * and that are sufficient to reproduce a value of identical content using the |
378 | | - * function setDBkeys(). The value array must use number keys that agree with |
379 | | - * the array's natural order (in which the data was added), and the array MUST |
380 | | - * contain at least one value in any case. |
381 | | - * Moreover, each entry of the array must be of a basic type, typically string |
382 | | - * or int. Do not use arrays or objects! |
383 | | - * The array should only contain components required for storing, but no derived |
384 | | - * versions of the value. It should provide a compact form for the data that is |
385 | | - * still easy to unserialize into a new object. Many datatypes will use arrays |
386 | | - * with only one entry here. |
387 | | - */ |
388 | | - abstract public function getDBkeys(); |
389 | | - |
390 | | - /** |
391 | 449 | * Return the plain wiki version of the value, or |
392 | 450 | * FALSE if no such version is available. The returned |
393 | 451 | * string suffices to reobtain the same DataValue |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_GeoCoords.php |
— | — | @@ -193,6 +193,18 @@ |
194 | 194 | return array($this->m_lat . ',' . $this->m_long); |
195 | 195 | } |
196 | 196 | |
| 197 | + public function getSignature() { |
| 198 | + return 't'; |
| 199 | + } |
| 200 | + |
| 201 | + public function getValueIndex() { |
| 202 | + return 0; |
| 203 | + } |
| 204 | + |
| 205 | + public function getLabelIndex() { |
| 206 | + return 0; |
| 207 | + } |
| 208 | + |
197 | 209 | public function getWikiValue(){ |
198 | 210 | $this->unstub(); |
199 | 211 | return $this->m_wikivalue; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_URI.php |
— | — | @@ -245,6 +245,18 @@ |
246 | 246 | return array($this->m_uri); |
247 | 247 | } |
248 | 248 | |
| 249 | + public function getSignature() { |
| 250 | + return 't'; |
| 251 | + } |
| 252 | + |
| 253 | + public function getValueIndex() { |
| 254 | + return 0; |
| 255 | + } |
| 256 | + |
| 257 | + public function getLabelIndex() { |
| 258 | + return 0; |
| 259 | + } |
| 260 | + |
249 | 261 | public function getWikiValue(){ |
250 | 262 | $this->unstub(); |
251 | 263 | return $this->m_value; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_String.php |
— | — | @@ -67,6 +67,18 @@ |
68 | 68 | return array($this->m_value); |
69 | 69 | } |
70 | 70 | |
| 71 | + public function getSignature() { |
| 72 | + return 't'; |
| 73 | + } |
| 74 | + |
| 75 | + public function getValueIndex() { |
| 76 | + return 0; |
| 77 | + } |
| 78 | + |
| 79 | + public function getLabelIndex() { |
| 80 | + return 0; |
| 81 | + } |
| 82 | + |
71 | 83 | public function getWikiValue(){ |
72 | 84 | $this->unstub(); |
73 | 85 | return $this->m_value; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Import.php |
— | — | @@ -157,6 +157,18 @@ |
158 | 158 | return array($this->m_namespace . ' ' . $this->m_section . ' ' . $this->m_uri); |
159 | 159 | } |
160 | 160 | |
| 161 | + public function getSignature() { |
| 162 | + return 't'; |
| 163 | + } |
| 164 | + |
| 165 | + public function getValueIndex() { |
| 166 | + return 0; |
| 167 | + } |
| 168 | + |
| 169 | + public function getLabelIndex() { |
| 170 | + return 0; |
| 171 | + } |
| 172 | + |
161 | 173 | public function getWikiValue(){ |
162 | 174 | $this->unstub(); |
163 | 175 | return $this->m_value; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Container.php |
— | — | @@ -65,6 +65,18 @@ |
66 | 66 | return array($data); |
67 | 67 | } |
68 | 68 | |
| 69 | + public function getSignature() { |
| 70 | + return 'c'; |
| 71 | + } |
| 72 | + |
| 73 | + public function getValueIndex() { |
| 74 | + return -1; |
| 75 | + } |
| 76 | + |
| 77 | + public function getLabelIndex() { |
| 78 | + return -1; |
| 79 | + } |
| 80 | + |
69 | 81 | public function getHash() { |
70 | 82 | if ( $this->isValid() ) { |
71 | 83 | return $this->m_data->getHash(); |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Property.php |
— | — | @@ -240,6 +240,18 @@ |
241 | 241 | return $this->isVisible()?array($this->m_wikipage->getDBkey()):array($this->m_propertyid); |
242 | 242 | } |
243 | 243 | |
| 244 | + public function getSignature() { |
| 245 | + return 't'; |
| 246 | + } |
| 247 | + |
| 248 | + public function getValueIndex() { |
| 249 | + return 0; |
| 250 | + } |
| 251 | + |
| 252 | + public function getLabelIndex() { |
| 253 | + return 0; |
| 254 | + } |
| 255 | + |
244 | 256 | public function getWikiValue() { |
245 | 257 | return $this->isVisible()?(($this->isInverse()?'-':'') . $this->m_wikipage->getWikiValue()):''; |
246 | 258 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Number.php |
— | — | @@ -76,7 +76,7 @@ |
77 | 77 | |
78 | 78 | protected function parseDBkeys($args) { |
79 | 79 | $this->m_value = $args[0]; |
80 | | - $this->m_unit = array_key_exists(1,$args)?$args[1]:''; |
| 80 | + $this->m_unit = array_key_exists(2,$args)?$args[2]:''; |
81 | 81 | $this->m_caption = false; |
82 | 82 | $this->m_unitin = false; |
83 | 83 | $this->makeUserValue(); |
— | — | @@ -88,7 +88,7 @@ |
89 | 89 | $this->m_outformat = $formatstring; |
90 | 90 | if ( ($formatstring != $oldformat) && $this->isValid() ) { |
91 | 91 | // recompute conversion if outputformat is changed after initialisation |
92 | | - $this->m_stubvalues = array($this->m_value, $this->m_unit); |
| 92 | + $this->m_stubvalues = array($this->m_value, $this->m_value, $this->m_unit); |
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
— | — | @@ -163,9 +163,21 @@ |
164 | 164 | public function getDBkeys() { |
165 | 165 | $this->unstub(); |
166 | 166 | $this->convertToMainUnit(); |
167 | | - return array($this->m_value, $this->m_unit); |
| 167 | + return array($this->m_value, intval($this->m_value), $this->m_unit); |
168 | 168 | } |
169 | 169 | |
| 170 | + public function getSignature() { |
| 171 | + return 'tfu'; |
| 172 | + } |
| 173 | + |
| 174 | + public function getValueIndex() { |
| 175 | + return 1; |
| 176 | + } |
| 177 | + |
| 178 | + public function getLabelIndex() { |
| 179 | + return 0; |
| 180 | + } |
| 181 | + |
170 | 182 | public function getWikiValue(){ |
171 | 183 | $this->unstub(); |
172 | 184 | return $this->m_wikivalue; |
— | — | @@ -179,7 +191,7 @@ |
180 | 192 | |
181 | 193 | public function getUnit() { |
182 | 194 | $values = $this->getDBkeys(); |
183 | | - return $values[1]; |
| 195 | + return $values[2]; |
184 | 196 | } |
185 | 197 | |
186 | 198 | public function getHash() { |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Bool.php |
— | — | @@ -92,26 +92,30 @@ |
93 | 93 | } |
94 | 94 | |
95 | 95 | public function getLongWikiText($linked = NULL) { |
96 | | - if (!$this->isValid()) { |
97 | | - return $this->getErrorText(); |
98 | | - } else { |
99 | | - return $this->m_stdcaption; |
100 | | - } |
| 96 | + return $this->isValid()?$this->m_stdcaption:$this->getErrorText(); |
101 | 97 | } |
102 | 98 | |
103 | 99 | public function getLongHTMLText($linker = NULL) { |
104 | | - if (!$this->isValid()) { |
105 | | - return $this->getErrorText(); |
106 | | - } else { |
107 | | - return $this->m_stdcaption; |
108 | | - } |
| 100 | + return $this->isValid()?$this->m_stdcaption:$this->getErrorText(); |
109 | 101 | } |
110 | 102 | |
111 | 103 | public function getDBkeys() { |
112 | 104 | $this->unstub(); |
113 | | - return $this->m_value?array('1'):array('0'); |
| 105 | + return $this->m_value?array('1',1):array('0',0); |
114 | 106 | } |
115 | 107 | |
| 108 | + public function getSignature() { |
| 109 | + return 'tn'; |
| 110 | + } |
| 111 | + |
| 112 | + public function getValueIndex() { |
| 113 | + return 1; |
| 114 | + } |
| 115 | + |
| 116 | + public function getLabelIndex() { |
| 117 | + return 0; |
| 118 | + } |
| 119 | + |
116 | 120 | public function getWikiValue(){ |
117 | 121 | $this->unstub(); |
118 | 122 | return $this->m_stdcaption; |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Concept.php |
— | — | @@ -75,6 +75,18 @@ |
76 | 76 | return array($this->m_concept, $this->m_docu, $this->m_queryfeatures, $this->m_size, $this->m_depth); |
77 | 77 | } |
78 | 78 | |
| 79 | + public function getSignature() { |
| 80 | + return 'tllnnn'; |
| 81 | + } |
| 82 | + |
| 83 | + public function getValueIndex() { |
| 84 | + return 0; |
| 85 | + } |
| 86 | + |
| 87 | + public function getLabelIndex() { |
| 88 | + return 0; |
| 89 | + } |
| 90 | + |
79 | 91 | public function getWikiValue(){ |
80 | 92 | $this->unstub(); |
81 | 93 | return str_replace(array('<','>','&'),array('<','>','&'), $this->m_concept); |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Time.php |
— | — | @@ -362,9 +362,22 @@ |
363 | 363 | if ($this->m_xsdvalue === false) { |
364 | 364 | $this->m_xsdvalue = $this->m_year."/".$this->m_month."/".$this->m_day."T".$this->m_time; |
365 | 365 | } |
366 | | - return array($this->m_xsdvalue); |
| 366 | + $this->createJD(); |
| 367 | + return array($this->m_xsdvalue,$this->m_jd); |
367 | 368 | } |
368 | 369 | |
| 370 | + public function getSignature() { |
| 371 | + return 'tf'; |
| 372 | + } |
| 373 | + |
| 374 | + public function getValueIndex() { |
| 375 | + return 1; |
| 376 | + } |
| 377 | + |
| 378 | + public function getLabelIndex() { |
| 379 | + return 0; |
| 380 | + } |
| 381 | + |
369 | 382 | public function getNumericValue() { |
370 | 383 | $this->unstub(); |
371 | 384 | $this->createJD(); |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_WikiPage.php |
— | — | @@ -185,6 +185,18 @@ |
186 | 186 | return array($this->m_dbkeyform, $this->m_namespace, $this->m_interwiki, $this->getSortkey()); |
187 | 187 | } |
188 | 188 | |
| 189 | + public function getSignature() { |
| 190 | + return 'tnwt'; |
| 191 | + } |
| 192 | + |
| 193 | + public function getValueIndex() { |
| 194 | + return 3; |
| 195 | + } |
| 196 | + |
| 197 | + public function getLabelIndex() { |
| 198 | + return 3; |
| 199 | + } |
| 200 | + |
189 | 201 | public function getWikiValue() { |
190 | 202 | $this->unstub(); |
191 | 203 | if ($this->m_fixNamespace != NS_MAIN) { // no explicit namespace needed! |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_Types.php |
— | — | @@ -181,6 +181,18 @@ |
182 | 182 | return ($this->isValid())?array($this->getDBkey()):array(false); |
183 | 183 | } |
184 | 184 | |
| 185 | + public function getSignature() { |
| 186 | + return 't'; |
| 187 | + } |
| 188 | + |
| 189 | + public function getValueIndex() { |
| 190 | + return 0; |
| 191 | + } |
| 192 | + |
| 193 | + public function getLabelIndex() { |
| 194 | + return 0; |
| 195 | + } |
| 196 | + |
185 | 197 | public function getWikiValue() { |
186 | 198 | return implode('; ', $this->getTypeLabels()); |
187 | 199 | } |