http://www.mediawiki.org/wiki/Special:Code/MediaWiki/60782
Revision: 60782 Author: mkroetzsch Date: 2010-01-07 08:15:15 +0000 (Thu, 07 Jan 2010) Log Message: ----------- 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 trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_List.php =================================================================== --- trunk/extensions/SemanticMediaWiki/includes/SMW_DV_List.php 2010-01-07 08:09:24 UTC (rev 60781) +++ trunk/extensions/SemanticMediaWiki/includes/SMW_DV_List.php 2010-01-07 08:15:15 UTC (rev 60782) @@ -194,6 +194,27 @@ return $result; } + /** + * Return the array (list) of datatypes that the individual entries of this datatype consist of. + * @todo Add some check to account for maximal number of list entries (maybe this should go to a + * variant of the SMWTypesValue). + */ + public function getTypeValues() { + if ($this->m_typevalues !== null) return $this->m_typevalues; // local cache + if ( ($this->m_property === null) || ($this->m_property->getWikiPageValue() === null) ) { + $this->m_typevalues = array(); // no property known -> no types + } else { // query for type values + $typelist = smwfGetStore()->getPropertyValues($this->m_property->getWikiPageValue(), SMWPropertyValue::makeProperty('_LIST')); + if (count($typelist) == 1) { + $this->m_typevalues = reset($typelist)->getTypeValues(); + } else { ///TODO internalionalize + $this->addError('List type not properly specified for this property.'); + $this->m_typevalues = array(); + } + } + return $this->m_typevalues; + } + ////// Internal helper functions private function makeOutputText($type = 0, $linker = null) { @@ -225,46 +246,5 @@ } } -////// Custom functions for old n-aries; may become obsolete. - - /** - * Return the array (list) of datatypes that the individual entries of this datatype consist of. - * @todo Add some check to account for maximal number of list entries (maybe this should go to a - * variant of the SMWTypesValue). - */ - public function getTypeValues() { - if ($this->m_typevalues !== null) return $this->m_typevalues; // local cache - if ( ($this->m_property === null) || ($this->m_property->getWikiPageValue() === null) ) { - $this->m_typevalues = array(); // no property known -> no types - } else { // query for type values - $typelist = smwfGetStore()->getPropertyValues($this->m_property->getWikiPageValue(), SMWPropertyValue::makeProperty('_LIST')); - if (count($typelist) == 1) { - $this->m_typevalues = reset($typelist)->getTypeValues(); - } else { ///TODO internalionalize - $this->addError('List type not properly specified for this property.'); - $this->m_typevalues = array(); - } - } - return $this->m_typevalues; - } - - /** - * If valid and in querymode, build a suitable SMWValueList description from the - * given input or return NULL if no such description was given. This requires the - * input to be given to setUserValue(). Otherwise bad things will happen. - */ - public function getValueList() { - $vl = new SMWValueList(); - if (!$this->isValid() || !$this->m_querysyntax) { - return null; - } - for ($i=0; $i < $this->m_count; $i++) { - if ($this->m_values[$i] !== null) { - $vl->setDescription($i,new SMWValueDescription($this->m_values[$i], $this->m_comparators[$i])); - } - } - return $vl; - } - } Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php =================================================================== --- trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php 2010-01-07 08:09:24 UTC (rev 60781) +++ trunk/extensions/SemanticMediaWiki/includes/SMW_GlobalFunctions.php 2010-01-07 08:15:15 UTC (rev 60782) @@ -172,7 +172,6 @@ $wgAutoloadClasses['SMWConceptDescription'] = $smwgIP . '/includes/storage/SMW_Description.php'; $wgAutoloadClasses['SMWNamespaceDescription'] = $smwgIP . '/includes/storage/SMW_Description.php'; $wgAutoloadClasses['SMWValueDescription'] = $smwgIP . '/includes/storage/SMW_Description.php'; - $wgAutoloadClasses['SMWValueList'] = $smwgIP . '/includes/storage/SMW_Description.php'; $wgAutoloadClasses['SMWConjunction'] = $smwgIP . '/includes/storage/SMW_Description.php'; $wgAutoloadClasses['SMWDisjunction'] = $smwgIP . '/includes/storage/SMW_Description.php'; $wgAutoloadClasses['SMWSomeProperty'] = $smwgIP . '/includes/storage/SMW_Description.php'; Modified: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php =================================================================== --- trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php 2010-01-07 08:09:24 UTC (rev 60781) +++ trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php 2010-01-07 08:15:15 UTC (rev 60782) @@ -84,6 +84,16 @@ } /** + * Determine the datatype of the values that are described by this object. + * Most descriptins can only describe wiki pages, so this is the default, + * but some descriptions may refer to other datatypes, and overwrite this + * function accordingly. + */ + public function getTypeID() { + return '_wpg'; + } + + /** * Recursively restrict query to a maximal size and depth as given. * Returns a possibly changed description that should be used as a replacement. * Reduce values of parameters to account for the returned descriptions size. @@ -118,6 +128,7 @@ * @ingroup SMWQuery */ class SMWThingDescription extends SMWDescription { + public function getQueryString($asvalue = false) { return '+'; } @@ -133,6 +144,17 @@ public function prune(&$maxsize, &$maxdepth, &$log) { return $this; } + + /** + * Return an empty type id since we cannot know the datatype of values that + * are described by this description. This type should not be relevant in + * any place, since description types are currently only necessary for + * processing an SMWSomeProperty object where the property does not specify + * the type. + */ + public function getTypeID() { + return ''; + } } /** @@ -144,7 +166,7 @@ class SMWClassDescription extends SMWDescription { protected $m_titles; - public function SMWClassDescription($content) { + public function __construct($content) { if ($content instanceof Title) { $this->m_titles = array($content); } elseif (is_array($content)) { @@ -271,7 +293,7 @@ class SMWNamespaceDescription extends SMWDescription { protected $m_namespace; - public function SMWNamespaceDescription($namespace) { + public function __construct($namespace) { $this->m_namespace = $namespace; } @@ -312,7 +334,7 @@ protected $m_datavalue; protected $m_comparator; - public function SMWValueDescription(SMWDataValue $datavalue, $comparator = SMW_CMP_EQ) { + public function __construct(SMWDataValue $datavalue, $comparator = SMW_CMP_EQ) { $this->m_datavalue = $datavalue; $this->m_comparator = $comparator; } @@ -358,122 +380,13 @@ return 1; } -} - - -/** - * Description of an ordered list of SMWDescription objects, used as - * values for some n-ary property. NULL values are to be used for - * unspecifed values. Corresponds to the built-in support for n-ary - * properties, i.e. can be viewed as a macro in OWL and RDF. - * @ingroup SMWQuery - */ -class SMWValueList extends SMWDescription { - protected $m_descriptions; - protected $m_size; - - public function SMWValueList($descriptions = array()) { - $this->m_descriptions = array_values($descriptions); - $this->m_size = count($descriptions); + public function getTypeID() { + return $this->m_datavalue->getTypeID(); } - public function getCount() { - return $this->m_size; - } - - public function getDescriptions() { - return $this->m_descriptions; - } - - public function setDescription($index, $description) { - $this->m_descriptions[$index] = $description; - if ($index >= $this->m_size) { // fill other places with NULL - for ($i=$this->m_size; $i<$index; $i++) { - $this->m_descriptions[$i] = null; - } - $this->m_size = $index+1; - } - } - - public function getDescription($index) { - if ($index < $this->m_size) { - return $this->m_descriptions[$index]; - } else { - return null; - } - } - - public function getQueryString($asvalue = false) { - $result = ''; - $first = true; - $nonempty = false; - for ($i=0; $i<$this->m_size; $i++) { - if ($first) { - $first = false; - } else { - $result .= ';'; - } - if ($this->m_descriptions[$i] !== null) { - $nonempty = true; - $result .= $this->m_descriptions[$i]->getQueryString(); - } - } - if (!$nonempty) { - return '+'; - } else { - return $result; - } - } - - public function isSingleton() { - return false; - } - - public function getSize() { - $size = 1; - foreach ($this->m_descriptions as $desc) { - if ($desc !== null) { - $size += $desc->getSize(); - } - } - return $size; - } - - public function getDepth() { - $depth = 0; - foreach ($this->m_descriptions as $desc) { - if ($desc !== null) { - $depth = max($depth, $desc->getDepth()); - } - } - return $depth; - } - - public function prune(&$maxsize, &$maxdepth, &$log) { - if ($maxsize <= 0) { - $log[] = $this->getQueryString(); - return new SMWThingDescription(); - } - $maxsize--; - $prunelog = array(); - $newdepth = $maxdepth; - $result = new SMWValueList(); - $result->setPrintRequests($this->getPrintRequests()); - for ($i=0; $i<$this->m_size; $i++) { - if ($this->m_descriptions[$i] !== null) { - $restdepth = $maxdepth; - $result->setDescription($i, $this->m_descriptions[$i]->prune($maxsize, $restdepth, $prunelog)); - $newdepth = min($newdepth, $restdepth); - } else { - $result->setDescription($i, null); - } - } - $log = array_merge($log, $prunelog); - $maxdepth = $newdepth; - return $result; - } } + /** * Description of a collection of many descriptions, all of which * must be satisfied (AND, conjunction). @@ -484,7 +397,7 @@ class SMWConjunction extends SMWDescription { protected $m_descriptions; - public function SMWConjunction($descriptions = array()) { + public function __construct($descriptions = array()) { $this->m_descriptions = $descriptions; } @@ -547,6 +460,14 @@ return $depth; } + public function getTypeID() { + if (count($this->m_descriptions) > 0) { // all subdescriptions should have the same type! + return reset($this->m_descriptions)->getTypeID(); + } else { + return ''; // unknown + } + } + public function getQueryFeatures() { $result = SMW_CONJUNCTION_QUERY; foreach ($this->m_descriptions as $desc) { @@ -598,7 +519,7 @@ // disjunctive classes are aggregated therein protected $m_true = false; // used if disjunction is trivially true already - public function SMWDisjunction($descriptions = array()) { + public function __construct($descriptions = array()) { foreach ($descriptions as $desc) { $this->addDescription($desc); } @@ -612,7 +533,7 @@ if ($description instanceof SMWThingDescription) { $this->m_true = true; $this->m_descriptions = array(); // no conditions any more - $this->m_catdesc = null; + $this->m_classdesc = null; } if (!$this->m_true) { if ($description instanceof SMWClassDescription) { // combine class descriptions @@ -663,8 +584,7 @@ } public function isSingleton() { - // NOTE: this neglects the case where several disjuncts describe the same object. - // I think I cannot really make myself care about this issue ... -- mak + /// NOTE: this neglects the unimportant case where several disjuncts describe the same object. if (count($this->m_descriptions) != 1) { return false; } else { @@ -688,6 +608,14 @@ return $depth; } + public function getTypeID() { + if (count($this->m_descriptions) > 0) { // all subdescriptions should have the same type! + return reset($this->m_descriptions)->getTypeID(); + } else { + return ''; // unknown + } + } + public function getQueryFeatures() { $result = SMW_DISJUNCTION_QUERY; foreach ($this->m_descriptions as $desc) { @@ -739,7 +667,7 @@ protected $m_description; protected $m_property; - public function SMWSomeProperty(SMWPropertyValue $property, SMWDescription $description) { + public function __construct(SMWPropertyValue $property, SMWDescription $description) { $this->m_property = $property; $this->m_description = $description; } @@ -790,3 +718,4 @@ return $result; } } + _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs