Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_List.php |
— | — | @@ -194,6 +194,27 @@ |
195 | 195 | return $result; |
196 | 196 | } |
197 | 197 | |
| 198 | + /** |
| 199 | + * Return the array (list) of datatypes that the individual entries of this datatype consist of. |
| 200 | + * @todo Add some check to account for maximal number of list entries (maybe this should go to a |
| 201 | + * variant of the SMWTypesValue). |
| 202 | + */ |
| 203 | + public function getTypeValues() { |
| 204 | + if ($this->m_typevalues !== null) return $this->m_typevalues; // local cache |
| 205 | + if ( ($this->m_property === null) || ($this->m_property->getWikiPageValue() === null) ) { |
| 206 | + $this->m_typevalues = array(); // no property known -> no types |
| 207 | + } else { // query for type values |
| 208 | + $typelist = smwfGetStore()->getPropertyValues($this->m_property->getWikiPageValue(), SMWPropertyValue::makeProperty('_LIST')); |
| 209 | + if (count($typelist) == 1) { |
| 210 | + $this->m_typevalues = reset($typelist)->getTypeValues(); |
| 211 | + } else { ///TODO internalionalize |
| 212 | + $this->addError('List type not properly specified for this property.'); |
| 213 | + $this->m_typevalues = array(); |
| 214 | + } |
| 215 | + } |
| 216 | + return $this->m_typevalues; |
| 217 | + } |
| 218 | + |
198 | 219 | ////// Internal helper functions |
199 | 220 | |
200 | 221 | private function makeOutputText($type = 0, $linker = null) { |
— | — | @@ -225,46 +246,5 @@ |
226 | 247 | } |
227 | 248 | } |
228 | 249 | |
229 | | -////// Custom functions for old n-aries; may become obsolete. |
230 | | - |
231 | | - /** |
232 | | - * Return the array (list) of datatypes that the individual entries of this datatype consist of. |
233 | | - * @todo Add some check to account for maximal number of list entries (maybe this should go to a |
234 | | - * variant of the SMWTypesValue). |
235 | | - */ |
236 | | - public function getTypeValues() { |
237 | | - if ($this->m_typevalues !== null) return $this->m_typevalues; // local cache |
238 | | - if ( ($this->m_property === null) || ($this->m_property->getWikiPageValue() === null) ) { |
239 | | - $this->m_typevalues = array(); // no property known -> no types |
240 | | - } else { // query for type values |
241 | | - $typelist = smwfGetStore()->getPropertyValues($this->m_property->getWikiPageValue(), SMWPropertyValue::makeProperty('_LIST')); |
242 | | - if (count($typelist) == 1) { |
243 | | - $this->m_typevalues = reset($typelist)->getTypeValues(); |
244 | | - } else { ///TODO internalionalize |
245 | | - $this->addError('List type not properly specified for this property.'); |
246 | | - $this->m_typevalues = array(); |
247 | | - } |
248 | | - } |
249 | | - return $this->m_typevalues; |
250 | | - } |
251 | | - |
252 | | - /** |
253 | | - * If valid and in querymode, build a suitable SMWValueList description from the |
254 | | - * given input or return NULL if no such description was given. This requires the |
255 | | - * input to be given to setUserValue(). Otherwise bad things will happen. |
256 | | - */ |
257 | | - public function getValueList() { |
258 | | - $vl = new SMWValueList(); |
259 | | - if (!$this->isValid() || !$this->m_querysyntax) { |
260 | | - return null; |
261 | | - } |
262 | | - for ($i=0; $i < $this->m_count; $i++) { |
263 | | - if ($this->m_values[$i] !== null) { |
264 | | - $vl->setDescription($i,new SMWValueDescription($this->m_values[$i], $this->m_comparators[$i])); |
265 | | - } |
266 | | - } |
267 | | - return $vl; |
268 | | - } |
269 | | - |
270 | 250 | } |
271 | 251 | |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php |
— | — | @@ -84,6 +84,16 @@ |
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
| 88 | + * Determine the datatype of the values that are described by this object. |
| 89 | + * Most descriptins can only describe wiki pages, so this is the default, |
| 90 | + * but some descriptions may refer to other datatypes, and overwrite this |
| 91 | + * function accordingly. |
| 92 | + */ |
| 93 | + public function getTypeID() { |
| 94 | + return '_wpg'; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
88 | 98 | * Recursively restrict query to a maximal size and depth as given. |
89 | 99 | * Returns a possibly changed description that should be used as a replacement. |
90 | 100 | * Reduce values of parameters to account for the returned descriptions size. |
— | — | @@ -118,6 +128,7 @@ |
119 | 129 | * @ingroup SMWQuery |
120 | 130 | */ |
121 | 131 | class SMWThingDescription extends SMWDescription { |
| 132 | + |
122 | 133 | public function getQueryString($asvalue = false) { |
123 | 134 | return '+'; |
124 | 135 | } |
— | — | @@ -133,6 +144,17 @@ |
134 | 145 | public function prune(&$maxsize, &$maxdepth, &$log) { |
135 | 146 | return $this; |
136 | 147 | } |
| 148 | + |
| 149 | + /** |
| 150 | + * Return an empty type id since we cannot know the datatype of values that |
| 151 | + * are described by this description. This type should not be relevant in |
| 152 | + * any place, since description types are currently only necessary for |
| 153 | + * processing an SMWSomeProperty object where the property does not specify |
| 154 | + * the type. |
| 155 | + */ |
| 156 | + public function getTypeID() { |
| 157 | + return ''; |
| 158 | + } |
137 | 159 | } |
138 | 160 | |
139 | 161 | /** |
— | — | @@ -144,7 +166,7 @@ |
145 | 167 | class SMWClassDescription extends SMWDescription { |
146 | 168 | protected $m_titles; |
147 | 169 | |
148 | | - public function SMWClassDescription($content) { |
| 170 | + public function __construct($content) { |
149 | 171 | if ($content instanceof Title) { |
150 | 172 | $this->m_titles = array($content); |
151 | 173 | } elseif (is_array($content)) { |
— | — | @@ -271,7 +293,7 @@ |
272 | 294 | class SMWNamespaceDescription extends SMWDescription { |
273 | 295 | protected $m_namespace; |
274 | 296 | |
275 | | - public function SMWNamespaceDescription($namespace) { |
| 297 | + public function __construct($namespace) { |
276 | 298 | $this->m_namespace = $namespace; |
277 | 299 | } |
278 | 300 | |
— | — | @@ -312,7 +334,7 @@ |
313 | 335 | protected $m_datavalue; |
314 | 336 | protected $m_comparator; |
315 | 337 | |
316 | | - public function SMWValueDescription(SMWDataValue $datavalue, $comparator = SMW_CMP_EQ) { |
| 338 | + public function __construct(SMWDataValue $datavalue, $comparator = SMW_CMP_EQ) { |
317 | 339 | $this->m_datavalue = $datavalue; |
318 | 340 | $this->m_comparator = $comparator; |
319 | 341 | } |
— | — | @@ -358,122 +380,13 @@ |
359 | 381 | return 1; |
360 | 382 | } |
361 | 383 | |
362 | | -} |
363 | | - |
364 | | - |
365 | | -/** |
366 | | - * Description of an ordered list of SMWDescription objects, used as |
367 | | - * values for some n-ary property. NULL values are to be used for |
368 | | - * unspecifed values. Corresponds to the built-in support for n-ary |
369 | | - * properties, i.e. can be viewed as a macro in OWL and RDF. |
370 | | - * @ingroup SMWQuery |
371 | | - */ |
372 | | -class SMWValueList extends SMWDescription { |
373 | | - protected $m_descriptions; |
374 | | - protected $m_size; |
375 | | - |
376 | | - public function SMWValueList($descriptions = array()) { |
377 | | - $this->m_descriptions = array_values($descriptions); |
378 | | - $this->m_size = count($descriptions); |
| 384 | + public function getTypeID() { |
| 385 | + return $this->m_datavalue->getTypeID(); |
379 | 386 | } |
380 | 387 | |
381 | | - public function getCount() { |
382 | | - return $this->m_size; |
383 | | - } |
384 | | - |
385 | | - public function getDescriptions() { |
386 | | - return $this->m_descriptions; |
387 | | - } |
388 | | - |
389 | | - public function setDescription($index, $description) { |
390 | | - $this->m_descriptions[$index] = $description; |
391 | | - if ($index >= $this->m_size) { // fill other places with NULL |
392 | | - for ($i=$this->m_size; $i<$index; $i++) { |
393 | | - $this->m_descriptions[$i] = null; |
394 | | - } |
395 | | - $this->m_size = $index+1; |
396 | | - } |
397 | | - } |
398 | | - |
399 | | - public function getDescription($index) { |
400 | | - if ($index < $this->m_size) { |
401 | | - return $this->m_descriptions[$index]; |
402 | | - } else { |
403 | | - return null; |
404 | | - } |
405 | | - } |
406 | | - |
407 | | - public function getQueryString($asvalue = false) { |
408 | | - $result = ''; |
409 | | - $first = true; |
410 | | - $nonempty = false; |
411 | | - for ($i=0; $i<$this->m_size; $i++) { |
412 | | - if ($first) { |
413 | | - $first = false; |
414 | | - } else { |
415 | | - $result .= ';'; |
416 | | - } |
417 | | - if ($this->m_descriptions[$i] !== null) { |
418 | | - $nonempty = true; |
419 | | - $result .= $this->m_descriptions[$i]->getQueryString(); |
420 | | - } |
421 | | - } |
422 | | - if (!$nonempty) { |
423 | | - return '+'; |
424 | | - } else { |
425 | | - return $result; |
426 | | - } |
427 | | - } |
428 | | - |
429 | | - public function isSingleton() { |
430 | | - return false; |
431 | | - } |
432 | | - |
433 | | - public function getSize() { |
434 | | - $size = 1; |
435 | | - foreach ($this->m_descriptions as $desc) { |
436 | | - if ($desc !== null) { |
437 | | - $size += $desc->getSize(); |
438 | | - } |
439 | | - } |
440 | | - return $size; |
441 | | - } |
442 | | - |
443 | | - public function getDepth() { |
444 | | - $depth = 0; |
445 | | - foreach ($this->m_descriptions as $desc) { |
446 | | - if ($desc !== null) { |
447 | | - $depth = max($depth, $desc->getDepth()); |
448 | | - } |
449 | | - } |
450 | | - return $depth; |
451 | | - } |
452 | | - |
453 | | - public function prune(&$maxsize, &$maxdepth, &$log) { |
454 | | - if ($maxsize <= 0) { |
455 | | - $log[] = $this->getQueryString(); |
456 | | - return new SMWThingDescription(); |
457 | | - } |
458 | | - $maxsize--; |
459 | | - $prunelog = array(); |
460 | | - $newdepth = $maxdepth; |
461 | | - $result = new SMWValueList(); |
462 | | - $result->setPrintRequests($this->getPrintRequests()); |
463 | | - for ($i=0; $i<$this->m_size; $i++) { |
464 | | - if ($this->m_descriptions[$i] !== null) { |
465 | | - $restdepth = $maxdepth; |
466 | | - $result->setDescription($i, $this->m_descriptions[$i]->prune($maxsize, $restdepth, $prunelog)); |
467 | | - $newdepth = min($newdepth, $restdepth); |
468 | | - } else { |
469 | | - $result->setDescription($i, null); |
470 | | - } |
471 | | - } |
472 | | - $log = array_merge($log, $prunelog); |
473 | | - $maxdepth = $newdepth; |
474 | | - return $result; |
475 | | - } |
476 | 388 | } |
477 | 389 | |
| 390 | + |
478 | 391 | /** |
479 | 392 | * Description of a collection of many descriptions, all of which |
480 | 393 | * must be satisfied (AND, conjunction). |
— | — | @@ -484,7 +397,7 @@ |
485 | 398 | class SMWConjunction extends SMWDescription { |
486 | 399 | protected $m_descriptions; |
487 | 400 | |
488 | | - public function SMWConjunction($descriptions = array()) { |
| 401 | + public function __construct($descriptions = array()) { |
489 | 402 | $this->m_descriptions = $descriptions; |
490 | 403 | } |
491 | 404 | |
— | — | @@ -547,6 +460,14 @@ |
548 | 461 | return $depth; |
549 | 462 | } |
550 | 463 | |
| 464 | + public function getTypeID() { |
| 465 | + if (count($this->m_descriptions) > 0) { // all subdescriptions should have the same type! |
| 466 | + return reset($this->m_descriptions)->getTypeID(); |
| 467 | + } else { |
| 468 | + return ''; // unknown |
| 469 | + } |
| 470 | + } |
| 471 | + |
551 | 472 | public function getQueryFeatures() { |
552 | 473 | $result = SMW_CONJUNCTION_QUERY; |
553 | 474 | foreach ($this->m_descriptions as $desc) { |
— | — | @@ -598,7 +519,7 @@ |
599 | 520 | // disjunctive classes are aggregated therein |
600 | 521 | protected $m_true = false; // used if disjunction is trivially true already |
601 | 522 | |
602 | | - public function SMWDisjunction($descriptions = array()) { |
| 523 | + public function __construct($descriptions = array()) { |
603 | 524 | foreach ($descriptions as $desc) { |
604 | 525 | $this->addDescription($desc); |
605 | 526 | } |
— | — | @@ -612,7 +533,7 @@ |
613 | 534 | if ($description instanceof SMWThingDescription) { |
614 | 535 | $this->m_true = true; |
615 | 536 | $this->m_descriptions = array(); // no conditions any more |
616 | | - $this->m_catdesc = null; |
| 537 | + $this->m_classdesc = null; |
617 | 538 | } |
618 | 539 | if (!$this->m_true) { |
619 | 540 | if ($description instanceof SMWClassDescription) { // combine class descriptions |
— | — | @@ -663,8 +584,7 @@ |
664 | 585 | } |
665 | 586 | |
666 | 587 | public function isSingleton() { |
667 | | - // NOTE: this neglects the case where several disjuncts describe the same object. |
668 | | - // I think I cannot really make myself care about this issue ... -- mak |
| 588 | + /// NOTE: this neglects the unimportant case where several disjuncts describe the same object. |
669 | 589 | if (count($this->m_descriptions) != 1) { |
670 | 590 | return false; |
671 | 591 | } else { |
— | — | @@ -688,6 +608,14 @@ |
689 | 609 | return $depth; |
690 | 610 | } |
691 | 611 | |
| 612 | + public function getTypeID() { |
| 613 | + if (count($this->m_descriptions) > 0) { // all subdescriptions should have the same type! |
| 614 | + return reset($this->m_descriptions)->getTypeID(); |
| 615 | + } else { |
| 616 | + return ''; // unknown |
| 617 | + } |
| 618 | + } |
| 619 | + |
692 | 620 | public function getQueryFeatures() { |
693 | 621 | $result = SMW_DISJUNCTION_QUERY; |
694 | 622 | foreach ($this->m_descriptions as $desc) { |
— | — | @@ -739,7 +667,7 @@ |
740 | 668 | protected $m_description; |
741 | 669 | protected $m_property; |
742 | 670 | |
743 | | - public function SMWSomeProperty(SMWPropertyValue $property, SMWDescription $description) { |
| 671 | + public function __construct(SMWPropertyValue $property, SMWDescription $description) { |
744 | 672 | $this->m_property = $property; |
745 | 673 | $this->m_description = $description; |
746 | 674 | } |
— | — | @@ -790,3 +718,4 @@ |
791 | 719 | return $result; |
792 | 720 | } |
793 | 721 | } |
| 722 | + |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php |
— | — | @@ -172,7 +172,6 @@ |
173 | 173 | $wgAutoloadClasses['SMWConceptDescription'] = $smwgIP . '/includes/storage/SMW_Description.php'; |
174 | 174 | $wgAutoloadClasses['SMWNamespaceDescription'] = $smwgIP . '/includes/storage/SMW_Description.php'; |
175 | 175 | $wgAutoloadClasses['SMWValueDescription'] = $smwgIP . '/includes/storage/SMW_Description.php'; |
176 | | - $wgAutoloadClasses['SMWValueList'] = $smwgIP . '/includes/storage/SMW_Description.php'; |
177 | 176 | $wgAutoloadClasses['SMWConjunction'] = $smwgIP . '/includes/storage/SMW_Description.php'; |
178 | 177 | $wgAutoloadClasses['SMWDisjunction'] = $smwgIP . '/includes/storage/SMW_Description.php'; |
179 | 178 | $wgAutoloadClasses['SMWSomeProperty'] = $smwgIP . '/includes/storage/SMW_Description.php'; |