r60782 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60781‎ | r60782 | r60783 >
Date:08:15, 7 January 2010
Author:mkroetzsch
Status:deferred
Tags:
Comment:
Remove obsolete SMWValueList class (was part of the old support for multi-valued properties; now standard description objects can be used when querying those).

Also added getTypeID() functions to descriptions to be able to handle type-poymorphic properties that are used to support multi-valued properties now.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DV_List.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_List.php
@@ -194,6 +194,27 @@
195195 return $result;
196196 }
197197
 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+
198219 ////// Internal helper functions
199220
200221 private function makeOutputText($type = 0, $linker = null) {
@@ -225,46 +246,5 @@
226247 }
227248 }
228249
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 -
270250 }
271251
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
@@ -84,6 +84,16 @@
8585 }
8686
8787 /**
 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+ /**
8898 * Recursively restrict query to a maximal size and depth as given.
8999 * Returns a possibly changed description that should be used as a replacement.
90100 * Reduce values of parameters to account for the returned descriptions size.
@@ -118,6 +128,7 @@
119129 * @ingroup SMWQuery
120130 */
121131 class SMWThingDescription extends SMWDescription {
 132+
122133 public function getQueryString($asvalue = false) {
123134 return '+';
124135 }
@@ -133,6 +144,17 @@
134145 public function prune(&$maxsize, &$maxdepth, &$log) {
135146 return $this;
136147 }
 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+ }
137159 }
138160
139161 /**
@@ -144,7 +166,7 @@
145167 class SMWClassDescription extends SMWDescription {
146168 protected $m_titles;
147169
148 - public function SMWClassDescription($content) {
 170+ public function __construct($content) {
149171 if ($content instanceof Title) {
150172 $this->m_titles = array($content);
151173 } elseif (is_array($content)) {
@@ -271,7 +293,7 @@
272294 class SMWNamespaceDescription extends SMWDescription {
273295 protected $m_namespace;
274296
275 - public function SMWNamespaceDescription($namespace) {
 297+ public function __construct($namespace) {
276298 $this->m_namespace = $namespace;
277299 }
278300
@@ -312,7 +334,7 @@
313335 protected $m_datavalue;
314336 protected $m_comparator;
315337
316 - public function SMWValueDescription(SMWDataValue $datavalue, $comparator = SMW_CMP_EQ) {
 338+ public function __construct(SMWDataValue $datavalue, $comparator = SMW_CMP_EQ) {
317339 $this->m_datavalue = $datavalue;
318340 $this->m_comparator = $comparator;
319341 }
@@ -358,122 +380,13 @@
359381 return 1;
360382 }
361383
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();
379386 }
380387
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 - }
476388 }
477389
 390+
478391 /**
479392 * Description of a collection of many descriptions, all of which
480393 * must be satisfied (AND, conjunction).
@@ -484,7 +397,7 @@
485398 class SMWConjunction extends SMWDescription {
486399 protected $m_descriptions;
487400
488 - public function SMWConjunction($descriptions = array()) {
 401+ public function __construct($descriptions = array()) {
489402 $this->m_descriptions = $descriptions;
490403 }
491404
@@ -547,6 +460,14 @@
548461 return $depth;
549462 }
550463
 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+
551472 public function getQueryFeatures() {
552473 $result = SMW_CONJUNCTION_QUERY;
553474 foreach ($this->m_descriptions as $desc) {
@@ -598,7 +519,7 @@
599520 // disjunctive classes are aggregated therein
600521 protected $m_true = false; // used if disjunction is trivially true already
601522
602 - public function SMWDisjunction($descriptions = array()) {
 523+ public function __construct($descriptions = array()) {
603524 foreach ($descriptions as $desc) {
604525 $this->addDescription($desc);
605526 }
@@ -612,7 +533,7 @@
613534 if ($description instanceof SMWThingDescription) {
614535 $this->m_true = true;
615536 $this->m_descriptions = array(); // no conditions any more
616 - $this->m_catdesc = null;
 537+ $this->m_classdesc = null;
617538 }
618539 if (!$this->m_true) {
619540 if ($description instanceof SMWClassDescription) { // combine class descriptions
@@ -663,8 +584,7 @@
664585 }
665586
666587 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.
669589 if (count($this->m_descriptions) != 1) {
670590 return false;
671591 } else {
@@ -688,6 +608,14 @@
689609 return $depth;
690610 }
691611
 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+
692620 public function getQueryFeatures() {
693621 $result = SMW_DISJUNCTION_QUERY;
694622 foreach ($this->m_descriptions as $desc) {
@@ -739,7 +667,7 @@
740668 protected $m_description;
741669 protected $m_property;
742670
743 - public function SMWSomeProperty(SMWPropertyValue $property, SMWDescription $description) {
 671+ public function __construct(SMWPropertyValue $property, SMWDescription $description) {
744672 $this->m_property = $property;
745673 $this->m_description = $description;
746674 }
@@ -790,3 +718,4 @@
791719 return $result;
792720 }
793721 }
 722+
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php
@@ -172,7 +172,6 @@
173173 $wgAutoloadClasses['SMWConceptDescription'] = $smwgIP . '/includes/storage/SMW_Description.php';
174174 $wgAutoloadClasses['SMWNamespaceDescription'] = $smwgIP . '/includes/storage/SMW_Description.php';
175175 $wgAutoloadClasses['SMWValueDescription'] = $smwgIP . '/includes/storage/SMW_Description.php';
176 - $wgAutoloadClasses['SMWValueList'] = $smwgIP . '/includes/storage/SMW_Description.php';
177176 $wgAutoloadClasses['SMWConjunction'] = $smwgIP . '/includes/storage/SMW_Description.php';
178177 $wgAutoloadClasses['SMWDisjunction'] = $smwgIP . '/includes/storage/SMW_Description.php';
179178 $wgAutoloadClasses['SMWSomeProperty'] = $smwgIP . '/includes/storage/SMW_Description.php';

Status & tagging log