r88308 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88307‎ | r88308 | r88309 >
Date:14:53, 17 May 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
Removed type ids from data items. The type of the property that a piece of data might be associated with is not part of the dataand therefore should not be stored. Callers have been changed to get this information frmo the context in which the data item is used, or to use something else. In the process, some more outdated API methods have been converted into methods of the temporary SMWCompatibilityHelper class.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_CompatibilityHelpers.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_OrderedListPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_PropertyPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Blob.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Bool.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Concept.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Container.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Error.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_GeoCoord.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Number.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_String.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Time.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_URI.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_WikiPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DataItem.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Bool.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Concept.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Container.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Error.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Import.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Number.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Property.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_SimpleWikiPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_String.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_TypeList.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Types.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_URI.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_WikiPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_Embedded.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_JSONlink.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_QueryResult.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SparqlStoreQueryEngine.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/languages/SMW_Language.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialPageProperty.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php
@@ -77,9 +77,10 @@
7878 $errors[] = wfMsg( 'smw_propertyhardlyused' );
7979 }
8080 if ( $result[0]->isUserDefined() && ( $title !== null ) && $title->exists() ) { // FIXME: this bypasses SMWDataValueFactory; ungood
81 - $types = smwfGetStore()->getPropertyValues( $diWikiPage, new SMWDIProperty( '_TYPE' ) );
 81+ $typeProperty = new SMWDIProperty( '_TYPE' );
 82+ $types = smwfGetStore()->getPropertyValues( $diWikiPage, $typeProperty );
8283 if ( count( $types ) >= 1 ) {
83 - $typeDataValue = SMWDataValueFactory::newDataItemValue( current( $types ) );
 84+ $typeDataValue = SMWDataValueFactory::newDataItemValue( current( $types ), $typeProperty );
8485 $typestring = $typeDataValue->getLongHTMLText( $skin );
8586 }
8687 $proplink = $skin->makeKnownLinkObj( $title, $result[0]->getLabel() );
@@ -96,7 +97,8 @@
9798 global $smwgPDefaultType;
9899 $typepagedbkey = str_replace( ' ', '_', SMWDataValueFactory::findTypeLabel( $smwgPDefaultType ) );
99100 $diTypePage = new SMWDIWikiPage( $typepagedbkey, SMW_NS_TYPE, '', '__typ' );
100 - $dvTypePage = SMWDataValueFactory::newDataItemValue( $diTypePage );
 101+ $dvTypePage = SMWDataValueFactory::newTypeIdValue( '__typ' );
 102+ $dvTypePage->setDataItem( $diTypePage );
101103 $typestring = $dvTypePage->getLongHTMLText( $skin );
102104 if ( ( $title !== null ) && ( $title->exists() ) ) { // print only when we did not print a "nopage" warning yet
103105 $errors[] = wfMsg( 'smw_propertylackstype', $typestring );
Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php
@@ -129,7 +129,7 @@
130130 $diProperties = $data->getProperties();
131131 $noresult = true;
132132 foreach ( $diProperties as $diProperty ) {
133 - $dvProperty = SMWDataValueFactory::newDataItemValue( $diProperty );
 133+ $dvProperty = SMWDataValueFactory::newDataItemValue( $diProperty, null );
134134 $displayline = true;
135135 if ( $dvProperty->isVisible() ) {
136136 $dvProperty->setCaption( $this->getPropertyLabel( $dvProperty, $incoming ) );
@@ -153,7 +153,7 @@
154154 // if there are more incoming values than a certain treshold, display a link to the rest instead
155155 $body .= '<a href="' . $skin->makeSpecialUrl( 'SearchByProperty', 'property=' . urlencode( $dvProperty->getWikiValue() ) . '&value=' . urlencode( $this->subject->getWikiValue() ) ) . '">' . wfMsg( "smw_browse_more" ) . "</a>\n";
156156 } else {
157 - $dv = SMWDataValueFactory::newDataItemValue( $di, false, $diProperty );
 157+ $dv = SMWDataValueFactory::newDataItemValue( $di, $diProperty );
158158 $body .= "<span class=\"smwb-" . $inv . "value\">" .
159159 $this->displayValue( $dvProperty, $dv, $incoming ) . "</span>";
160160 }
@@ -184,16 +184,16 @@
185185 * @param[in] $incoming bool If this is an incoming or outgoing link
186186 * @return string HTML with the link to the article, browse, and search pages
187187 */
188 - private function displayValue( SMWPropertyValue $property, SMWDataValue $value, $incoming ) {
 188+ private function displayValue( SMWPropertyValue $property, SMWDataValue $dataValue, $incoming ) {
189189 global $wgUser;
190190 $skin = $wgUser->getSkin();
191 - $html = $value->getLongHTMLText( $skin );
192 - if ( $value->getTypeID() == '_wpg' ) {
193 - $html .= "&#160;" . SMWInfolink::newBrowsingLink( '+', $value->getLongWikiText() )->getHTML( $skin );
 191+ $html = $dataValue->getLongHTMLText( $skin );
 192+ if ( $dataValue->getTypeID() == '_wpg' ) {
 193+ $html .= "&#160;" . SMWInfolink::newBrowsingLink( '+', $dataValue->getLongWikiText() )->getHTML( $skin );
194194 } elseif ( $incoming && $property->isVisible() ) {
195 - $html .= "&#160;" . SMWInfolink::newInversePropertySearchLink( '+', $value->getTitle(), $property->getText(), 'smwsearch' )->getHTML( $skin );
 195+ $html .= "&#160;" . SMWInfolink::newInversePropertySearchLink( '+', $dataValue->getTitle(), $property->getText(), 'smwsearch' )->getHTML( $skin );
196196 } else {
197 - $html .= $value->getInfolinkText( SMW_OUTPUT_HTML, $skin );
 197+ $html .= $dataValue->getInfolinkText( SMW_OUTPUT_HTML, $skin );
198198 }
199199 return $html;
200200 }
Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialPageProperty.php
@@ -96,9 +96,9 @@
9797 foreach ( $results as $di ) {
9898 $count--;
9999 if ( $count < 1 ) continue;
100 - $dv = SMWDataValueFactory::newDataItemValue( $di );
 100+ $dv = SMWDataValueFactory::newDataItemValue( $di, $property->getDataItem() );
101101 $html .= '<li>' . $dv->getLongHTMLText( $skin ); // do not show infolinks, the magnifier "+" is ambiguous with the browsing '+' for '_wpg' (see below)
102 - if ( $di->getTypeID() == '_wpg' ) {
 102+ if ( $property->getDataItem()->findPropertyTypeID() == '_wpg' ) {
103103 $browselink = SMWInfolink::newBrowsingLink( '+', $dv->getLongWikiText() );
104104 $html .= ' &#160;' . $browselink->getHTML( $skin );
105105 }
Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php
@@ -236,14 +236,15 @@
237237 }
238238
239239 if ( $modifier == '' ) {
240 - $importDis = smwfGetStore()->getPropertyValues( $diWikiPage, new SMWDIProperty( '_IMPO' ) );
 240+ $importProperty = new SMWDIProperty( '_IMPO' );
 241+ $importDis = smwfGetStore()->getPropertyValues( $diWikiPage, $importProperty );
241242 $importURI = ( count( $importDis ) > 0 );
242243 } else {
243244 $importURI = false;
244245 }
245246
246247 if ( $importURI ) {
247 - $importValue = SMWDataValueFactory::newDataItemValue( current( $importDis ) );
 248+ $importValue = SMWDataValueFactory::newDataItemValue( current( $importDis ), $importProperty );
248249 $namespace = $importValue->getNS();
249250 $namespaceId = $importValue->getNSID();
250251 $localName = $importValue->getLocalName();
@@ -576,6 +577,11 @@
577578 *
578579 * For dataitems that do not have such a simplification, the method
579580 * returns null.
 581+ *
 582+ * @note If a helper element is used, then it must be the same as
 583+ * getDataItemHelperExpElement( $dataItem->getSortKeyDataItem() ).
 584+ * Query conditions like ">" use sortkeys for values, and helper
 585+ * elements are always preferred in query answering.
580586 *
581587 * @param $dataItem SMWDataItem
582588 * @return SMWExpElement or null
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
@@ -93,13 +93,6 @@
9494 protected $m_outformat = false;
9595
9696 /**
97 - * Usually unstub() checks if this contains useful content,
98 - * and inits the value with setDBkeys() in this case; false while unused.
99 - * @var mixed
100 - */
101 - protected $m_stubvalues = false;
102 -
103 - /**
10497 * Used to control the addition of the standard search link.
10598 * @var boolean
10699 */
@@ -153,7 +146,6 @@
154147 $this->m_infolinks = array(); // clear links
155148 $this->mHasSearchLink = false;
156149 $this->mHasServiceLinks = false;
157 - $this->m_stubvalues = false;
158150 $this->m_caption = is_string( $caption ) ? trim( $caption ) : false;
159151
160152 // The following checks for markers generated by MediaWiki to handle special content,
@@ -176,41 +168,27 @@
177169 }
178170
179171 /**
180 - * Initialise this object based on an array of values. The contents
181 - * of the array depends on the given datatype. All implementations
182 - * should support round-tripping between this function and getDBkeys().
183 - * However, implementations MUST NOT assume that the provided array
184 - * was generated by their own getDBkeys() function. In particular, it
185 - * may contain fewer entries (but more than one) and their content
186 - * may not be as expected. Implementations must make sure that no
187 - * warnings, errors, notices, etc. occur in such cases.
 172+ * Set the actual data contained in this object. The method returns
 173+ * true if this was successful (requiring the type of the dataitem
 174+ * to match the data value). If false is returned, the data value is
 175+ * left unchanged (the data item was rejected).
 176+ *
 177+ * @note Even if this function returns true, the data value object
 178+ * might become invalid if the content of the data item caused errors
 179+ * in spite of it being of the right basic type. False is only returned
 180+ * if the data item is fundamentally incompatible with the data value.
188181 *
189 - * @param array $args
 182+ * @param $dataitem SMWDataItem
 183+ * @return boolean
190184 */
191 - public function setDBkeys( array $args ) {
192 - throw new Exception( "setDBkeys() must no longer be called." );
 185+ public function setDataItem( SMWDataItem $dataItem ) {
 186+ unset( $this->m_dataitem );
 187+ $this->mErrors = $this->m_infolinks = array();
 188+ $this->mHasErrors = $this->mHasSearchLink = $this->mHasServiceLinks = $this->m_caption = false;
 189+ return $this->loadDataItem( $dataItem );
193190 }
194191
195192 /**
196 - * This function does the acutal processing for loading a datavalue's
197 - * contents from a value array. setDBkeys() merely stores the given
198 - * values, whereas unstub() actually parses and processes them. This
199 - * function usually needs to be called before any outputs can be returned.
200 - * It takes only very little effort if unstubbing is not needed.
201 - */
202 - protected function unstub() {
203 -// if ( $this->m_stubvalues !== false ) {
204 -// wfProfileIn( 'SMWDataValue::unstub-' . $this->m_typeid . ' (SMW)' );
205 -//
206 -// $args = $this->m_stubvalues;
207 -// $this->m_stubvalues = false; // Careful to avoid recursive unstubbing.
208 -// $this->parseDBkeys( $args );
209 -//
210 -// wfProfileOut( 'SMWDataValue::unstub-' . $this->m_typeid . ' (SMW)' );
211 -// }
212 - }
213 -
214 - /**
215193 * Specify the property to which this value refers. Used to generate search links and
216194 * to find custom settings that relate to the property.
217195 *
@@ -267,10 +245,10 @@
268246 $servicelinks = smwfGetStore()->getPropertyValues( $propertyDiWikiPage, new SMWDIProperty( '_SERV' ) );
269247
270248 foreach ( $servicelinks as $dataItem ) {
 249+ if ( !( $dataItem instanceof SMWDIString ) ) continue;
271250 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
272 - $dv = SMWDataValueFactory::newDataItemValue( $dataItem );
273 -
274 - $args[0] = 'smw_service_' . str_replace( ' ', '_', $dv->getWikiValue() ); // messages distinguish ' ' from '_'
 251+
 252+ $args[0] = 'smw_service_' . str_replace( ' ', '_', $dataItem->getString() ); // messages distinguish ' ' from '_'
275253 $text = call_user_func_array( 'wfMsgForContent', $args );
276254 $links = preg_split( "/[\n][\s]?/u", $text );
277255
@@ -330,6 +308,7 @@
331309 * n-ary to do this. Eventually, n-ary should implement its setDBkeys()
332310 * properly so that this function will vanish again.
333311 * @note Do not use this function in external code.
 312+ * @todo Check if we can remove this function again.
334313 */
335314 protected function clearErrors() {
336315 $this->mErrors = array();
@@ -348,17 +327,22 @@
349328 abstract protected function parseUserValue( $value );
350329
351330 /**
352 - * Initialise the datavalue from the given value array.
353 - * The format of this array corresponds to the output of
354 - * getDBkeys() but the method might be called with shorter
355 - * arrays (e.g. if typing information changed since a value
356 - * was stored). However, there will always be at least one
357 - * element in the array.
 331+ * Set the actual data contained in this object. The method returns
 332+ * true if this was successful (requiring the type of the dataitem
 333+ * to match the data value). If false is returned, the data value is
 334+ * left unchanged (the data item was rejected).
 335+ *
 336+ * @note Even if this function returns true, the data value object
 337+ * might become invalid if the content of the data item caused errors
 338+ * in spite of it being of the right basic type. False is only returned
 339+ * if the data item is fundamentally incompatible with the data value.
358340 *
359 - * @param array $args
 341+ * @param $dataitem SMWDataItem
 342+ * @return boolean
360343 */
361 - abstract protected function parseDBkeys( $args );
 344+ abstract protected function loadDataItem( SMWDataItem $dataItem );
362345
 346+
363347 ///// Query support /////
364348
365349 /**
@@ -435,102 +419,6 @@
436420 }
437421
438422 /**
439 - * Set the actual data contained in this object. The method returns
440 - * true if this was successful (requiring the type of the dataitem
441 - * to match the data value). If false is returned, the data value is
442 - * left unchanged (the data item was rejected).
443 - *
444 - * @note Even if this function returns true, the data value object
445 - * might become invalid if the content of the data item caused errors
446 - * in spite of it being of the right basic type. False is only returned
447 - * if the data item is fundamentally incompatible with the data value.
448 - *
449 - * @param $dataitem SMWDataItem
450 - * @return boolean
451 - * @bug This method must get some wrapper to reset basic values of this class. Currently, things like error messages are kept.
452 - */
453 - abstract public function setDataItem( SMWDataItem $dataItem );
454 -
455 - /**
456 - * Return an array of values that characterize the given datavalue
457 - * completely, and that are sufficient to reproduce a value of identical
458 - * content using the function setDBkeys(). The value array must use number
459 - * keys that agree with the array's natural order (in which the data was
460 - * added), and the array MUST contain at least one value in any case.
461 - * Moreover, the order and type of the array's entries must be as described
462 - * in by getSignature(); see its documentation for details. The only
463 - * exception are classes that inherit from SMWContainerValue which must
464 - * adhere to the special format of this class.
465 - *
466 - * The array should only contain components required for storing and
467 - * sorting. It should provide a compact form for the data that is still
468 - * easy to unserialize into a new object. Many datatypes will use arrays
469 - * with only one entry here.
470 - *
471 - * @return array
472 - */
473 - abstract public function getDBkeys();
474 -
475 - /**
476 - * Return a signature string that encodes the order and type of the data
477 - * that is contained in the array given by getDBkeys(). Single letters are
478 - * used to encode different datatypes. The signature is used to determine
479 - * how to store data of this kind. The available type letters are:
480 - * - t for strings of the same maximal length as MediaWiki title names,
481 - * - l for arbitrarily long strings; searching/sorting with such data may
482 - * be limited for performance reasons,
483 - * - w for strings as used in MediaWiki for encoding interwiki prefixes
484 - * - n for namespace numbers (or other similar integers)
485 - * - f for floating point numbers of double precision
486 - * - c for the special container format used by SMWContainerValue; if used
487 - * then the signature must be 'c' without any other fields.
488 - *
489 - * Do not use any other letters in signatures of datavalues. For example,
490 - * a wiki page consists of a title, namespace, interwiki prefix, and a
491 - * sortkey for ordering it, so its signature is "tnwt". The below default
492 - * definition provides a workable fallback, but it is recommended to
493 - * define the signature explicitly in all datavalues that implement
494 - * getDBkeys() anew.
495 - *
496 - * @return string
497 - */
498 - public function getSignature() {
499 - return 't';
500 - }
501 -
502 - /**
503 - * This function specifies the indexes of the DB keys that should be used for
504 - * sorting values of this type. It refers to the array that is returned by
505 - * getDBkeys() and specified by getSignature(), where the first index is 0.
506 - * For example, a wiki page type with signature "tnwt" would set this value
507 - * to 3 so that page are ordered by their sortkey (the second "t" field).
508 - * The order that is used (e.g. numeric or lexicographic) is determined by
509 - * the type of the resepctive field. If no ordering is supported for this
510 - * data value, then -1 can be returned here.
511 - *
512 - * @return integer
513 - */
514 - public function getValueIndex() {
515 - return 0;
516 - }
517 -
518 - /**
519 - * This function specifies the index of the DB key that should be used for
520 - * string-matching values of this type. SMW supports some query conditions
521 - * that involve string patterns. Since numerical sort fields cannot be used
522 - * for this, this index might differ from getValueIndex(). Otherwise, all
523 - * documentation of getValueIndex() applies.
524 - * @note Any given storage implementation might decide to not support
525 - * string matching conditions for the specified value if not available for
526 - * its type.
527 - *
528 - * @return integer
529 - */
530 - public function getLabelIndex() {
531 - return 0;
532 - }
533 -
534 - /**
535423 * Returns a short textual representation for this data value. If the value
536424 * was initialised from a user supplied string, then this original string
537425 * should be reflected in this short version (i.e. no normalisation should
@@ -681,9 +569,8 @@
682570 public function getInfolinks() {
683571 if ( $this->isValid() && ( $this->m_property !== null ) ) {
684572 if ( !$this->mHasSearchLink ) { // add default search link
685 - $propertyDataValue = SMWDataValueFactory::newDataItemValue( $this->m_property );
686573 $this->mHasSearchLink = true;
687 - $this->m_infolinks[] = SMWInfolink::newPropertySearchLink( '+', $propertyDataValue->getWikiValue(), $this->getWikiValue() );
 574+ $this->m_infolinks[] = SMWInfolink::newPropertySearchLink( '+', $this->m_property->getLabel(), $this->getWikiValue() );
688575 }
689576
690577 if ( !$this->mHasServiceLinks ) { // add further service links
@@ -716,16 +603,14 @@
717604 }
718605
719606 /**
720 - * Convenience method that checks if the value that is used to sort data of
721 - * this type is numeric.
 607+ * Convenience method that checks if the value that is used to sort
 608+ * data of this type is numeric. This only works if the value is set.
722609 *
723610 * @return boolean
724611 */
725612 public function isNumeric() {
726 - $sig = $this->getSignature();
727 - $validx = $this->getValueIndex();
728 - if ( ( $validx >= 0 ) && ( $validx < strlen( $sig ) ) ) {
729 - return ( ( $sig{$validx} == 'n' ) || ( $sig{$validx} == 'f' ) );
 613+ if ( isset( $this->m_dataitem ) ) {
 614+ return is_numeric( $this->m_dataitem->getSortKey() );
730615 } else {
731616 return false;
732617 }
@@ -761,7 +646,6 @@
762647 * an empty string if no errors happened.
763648 */
764649 public function getErrorText() {
765 - $this->unstub();
766650 return smwfEncodeMessages( $this->mErrors );
767651 }
768652
@@ -770,7 +654,6 @@
771655 * if no errors occurred.
772656 */
773657 public function getErrors() {
774 - $this->unstub();
775658 return $this->mErrors;
776659 }
777660
@@ -839,4 +722,35 @@
840723 }
841724 }
842725
 726+ /**
 727+ * @deprecated Use SMWDataItem::setDataItem() and SMWCompatibilityHelpers::dataItemFromDBKeys(). Will vanish before SMW 1.7.
 728+ */
 729+ private function setDBkeys( array $args ) {}
 730+ /**
 731+ * @deprecated This function is no longer used and should not be implemented in subclasses.
 732+ */
 733+ protected function parseDBkeys( $args ) {}
 734+ /**
 735+ * @deprecated Use SMWCompatibilityHelpers::getDBkeysFromDataItem(). Will vanish before SMW 1.7.
 736+ */
 737+ public function getDBkeys() {}
 738+ /**
 739+ * @deprecated Use SMWCompatibilityHelpers::getSignatureFromDataItemId(). Will vanish before SMW 1.7.
 740+ */
 741+ public function getSignature() {}
 742+ /**
 743+ * @deprecated Use SMWCompatibilityHelpers::getIndexFromDataItemId(). Will vanish before SMW 1.7.
 744+ */
 745+ public function getValueIndex() {}
 746+ /**
 747+ * @deprecated Use SMWCompatibilityHelpers::getIndexFromDataItemId(). Will vanish before SMW 1.7.
 748+ */
 749+ public function getLabelIndex() {}
 750+ /**
 751+ * @deprecated There is no more unstubbing now. Data is kept in lean
 752+ * data items. If any other fields need costy initialization,
 753+ * subclasses can create their own mechanism.
 754+ */
 755+ public function unstub() {}
 756+
843757 }
\ No newline at end of file
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Import.php
@@ -112,23 +112,12 @@
113113 }
114114 }
115115
116 - protected function parseDBkeys( $args ) {
117 - try {
118 - $dataItem = new SMWDIString( $args[0] );
119 - $this->setDataItem( $dataItem );
120 - } catch ( SMWStringLengthException $e ) {
121 - smwfLoadExtensionMessages( 'SemanticMediaWiki' );
122 - $this->addError( wfMsgForContent( 'smw_maxstring', '"' . $args[0] . '"' ) );
123 - $this->m_dataitem = new SMWDIString( '' );
124 - }
125 - }
126 -
127116 /**
128 - * @see SMWDataValue::setDataItem()
 117+ * @see SMWDataValue::loadDataItem()
129118 * @param $dataitem SMWDataItem
130119 * @return boolean
131120 */
132 - public function setDataItem( SMWDataItem $dataItem ) {
 121+ protected function loadDataItem( SMWDataItem $dataItem ) {
133122 if ( $dataItem->getDIType() == SMWDataItem::TYPE_STRING ) {
134123 $this->m_dataitem = $dataItem;
135124 $parts = explode( ' ', $dataItem->getString(), 3 );
@@ -149,12 +138,10 @@
150139 }
151140
152141 public function getShortWikiText( $linked = null ) {
153 - $this->unstub();
154142 return $this->m_caption;
155143 }
156144
157145 public function getShortHTMLText( $linker = null ) {
158 - $this->unstub();
159146 return htmlspecialchars( $this->m_qname );
160147 }
161148
@@ -174,40 +161,19 @@
175162 }
176163 }
177164
178 - public function getDBkeys() {
179 - $this->unstub();
180 - return array( $this->m_dataitem->getString() );
181 - }
182 -
183 - public function getSignature() {
184 - return 't';
185 - }
186 -
187 - public function getValueIndex() {
188 - return 0;
189 - }
190 -
191 - public function getLabelIndex() {
192 - return 0;
193 - }
194 -
195165 public function getWikiValue() {
196 - $this->unstub();
197166 return $this->m_qname;
198167 }
199168
200169 public function getNS() {
201 - $this->unstub();
202170 return $this->m_uri;
203171 }
204172
205173 public function getNSID() {
206 - $this->unstub();
207174 return $this->m_namespace;
208175 }
209176
210177 public function getLocalName() {
211 - $this->unstub();
212178 return $this->m_section;
213179 }
214180 }
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_SimpleWikiPage.php
@@ -1,5 +1,6 @@
22 <?php
33 /**
 4+ * @deprecated This obsolete file will soon vanish.
45 * @file
56 * @ingroup SMWDataValues
67 */
@@ -21,33 +22,4 @@
2223 */
2324 class SMWSimpleWikiPageValue extends SMWWikiPageValue {
2425
25 - protected function parseDBkeys( $args ) {
26 - $this->m_dbkeyform = $args[0];
27 - $this->m_namespace = $this->m_fixNamespace;
28 - $this->m_interwiki = '';
29 - $this->m_sortkey = $this->m_dbkeyform;
30 - $this->m_textform = str_replace( '_', ' ', $this->m_dbkeyform );
31 - $this->m_id = false;
32 - $this->m_title = null;
33 - $this->m_prefixedtext = false;
34 - $this->m_caption = false;
35 - }
36 -
37 - public function getDBkeys() {
38 - $this->unstub();
39 - return array( $this->m_dbkeyform );
40 - }
41 -
42 - public function getSignature() {
43 - return 't';
44 - }
45 -
46 - public function getValueIndex() {
47 - return 1;
48 - }
49 -
50 - public function getLabelIndex() {
51 - return 1;
52 - }
53 -
5426 }
\ No newline at end of file
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_TypeList.php
@@ -30,16 +30,6 @@
3131 $this->setDataItemFromTypeValues();
3232 }
3333
34 - protected function parseDBkeys( $args ) {
35 - $this->m_typevalues = array();
36 - $ids = explode( ';', $args[0] );
37 - foreach ( $ids as $id ) {
38 - $this->m_typevalues[] = SMWDataValueFactory::newTypeIDValue( '__typ', SMWDataValueFactory::findTypeLabel( $id ) );
39 - }
40 - $this->m_caption = false;
41 - $this->setDataItemFromTypeValues();
42 - }
43 -
4434 /**
4535 * @see SMWDataValue::setDataItem()
4636 * @param $dataitem SMWDataItem
@@ -83,22 +73,6 @@
8474 }
8575 }
8676
87 - public function getDBkeys() {
88 - return array( $this->m_dataitem->getString() );
89 - }
90 -
91 - public function getSignature() {
92 - return 't';
93 - }
94 -
95 - public function getValueIndex() {
96 - return 0;
97 - }
98 -
99 - public function getLabelIndex() {
100 - return 0;
101 - }
102 -
10377 public function getShortWikiText( $linked = null ) {
10478 return ( $this->m_caption !== false ) ? $this->m_caption : $this->makeOutputText( 0, $linked );
10579 }
@@ -120,7 +94,6 @@
12195 }
12296
12397 public function getTypeValues() {
124 - $this->unstub();
12598 return $this->m_typevalues;
12699 }
127100
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php
@@ -89,11 +89,11 @@
9090 }
9191
9292 /**
93 - * @see SMWDataValue::setDataItem()
 93+ * @see SMWDataValue::loadDataItem()
9494 * @param $dataitem SMWDataItem
9595 * @return boolean
9696 */
97 - public function setDataItem( SMWDataItem $dataItem ) {
 97+ protected function loadDataItem( SMWDataItem $dataItem ) {
9898 if ( $dataItem->getDIType() == SMWDataItem::TYPE_CONTAINER ) {
9999 $this->m_dataitem = $dataItem;
100100 return true;
@@ -103,30 +103,6 @@
104104 }
105105
106106 /**
107 - * This function resembles SMWContainerValue::parseDBkeys() but it already unstubs
108 - * the values instead of passing on initialisation strings. This is required since
109 - * the datatype of each entry is not determined by the property here (since we are
110 - * using generic _1, _2, ... properties that can have any type).
111 - */
112 - protected function parseDBkeys( $args ) {
113 - $this->m_data->clear();
114 - $types = $this->getTypeValues();
115 - if ( count( $args ) > 0 ) {
116 - foreach ( reset( $args ) as $value ) {
117 - if ( is_array( $value ) && ( count( $value ) == 2 ) ) {
118 - $property = new SMWDIProperty( reset( $value ) );
119 - $pnum = intval( substr( reset( $value ), 1 ) ); // try to find the number of this property
120 - if ( array_key_exists( $pnum - 1, $types ) ) {
121 - $dv = SMWDataValueFactory::newTypeObjectValue( $types[$pnum - 1] );
122 - $dv->setDBkeys( end( $value ) );
123 - $this->m_data->addPropertyObjectValue( $property, $dv );
124 - }
125 - }
126 - }
127 - }
128 - }
129 -
130 - /**
131107 * Overwrite SMWDataValue::getQueryDescription() to be able to process
132108 * comparators between all values.
133109 */
@@ -185,19 +161,19 @@
186162 $ed = new SMWExpData( SMWExporter::getSpecialNsResource( 'swivt', 'Container' ) );
187163 $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ), $ed );
188164 $count = 0;
189 - foreach ( $this->getDVs() as $value ) {
 165+ foreach ( $this->getDVs() as $dataValue ) {
190166 $count++;
191 - if ( ( $value === null ) || ( !$value->isValid() ) ) {
 167+ if ( ( $dataValue === null ) || ( !$dataValue->isValid() ) ) {
192168 continue;
193169 }
194 - if ( ( $value->getTypeID() == '_wpg' ) || ( $value->getTypeID() == '_uri' ) || ( $value->getTypeID() == '_ema' ) ) {
 170+ if ( ( $dataValue->getTypeID() == '_wpg' ) || ( $dataValue->getTypeID() == '_uri' ) || ( $dataValue->getTypeID() == '_ema' ) ) {
195171 $result->addPropertyObjectValue(
196172 SMWExporter::getSpecialNsResource( 'swivt', 'object' . $count ),
197 - $value->getExportData() );
 173+ $dataValue->getExportData() );
198174 } else {
199175 $result->addPropertyObjectValue(
200176 SMWExporter::getSpecialNsResource( 'swivt', 'value' . $count ),
201 - $value->getExportData() );
 177+ $dataValue->getExportData() );
202178 }
203179 }
204180 return $result;
@@ -322,7 +298,7 @@
323299 $propertyvalues = $this->m_dataitem->getSemanticData()->getPropertyValues( $property ); // combining this with next line violates PHP strict standards
324300 $dataItem = reset( $propertyvalues );
325301 if ( $dataItem !== false ) {
326 - $dataValue = SMWDataValueFactory::newDataItemValue( $dataItem );
 302+ $dataValue = SMWDataValueFactory::newDataItemValue( $dataItem, $property );
327303 $result .= $this->makeValueOutputText( $type, $dataValue, $linker );
328304 } else {
329305 $result .= '?';
@@ -343,8 +319,5 @@
344320 }
345321 }
346322
347 - public function getDBkeys() {
348 - return array();// no longer used
349 - }
350323 }
351324
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Container.php
@@ -1,5 +1,6 @@
22 <?php
33 /**
 4+ * @deprecated This file is obsolete and will soon vanish.
45 * @file
56 * @ingroup SMWDataValues
67 */
@@ -49,18 +50,6 @@
5051 return array( $data );
5152 }
5253
53 - public function getSignature() {
54 - return 'c';
55 - }
56 -
57 - public function getValueIndex() {
58 - return -1;
59 - }
60 -
61 - public function getLabelIndex() {
62 - return -1;
63 - }
64 -
6554 public function getHash() {
6655 if ( $this->isValid() ) {
6756 return $this->m_data->getHash();
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Property.php
@@ -124,32 +124,16 @@
125125 } catch ( SMWDataItemException $e ) { // happens, e.g., when trying to sort queries by property "-"
126126 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
127127 $this->addError( wfMsgForContent( 'smw_noproperty', $value ) );
128 - $this->m_dataitem = new SMWDIProperty( 'ERROR', false, $this->m_typeid ); // just to have something
 128+ $this->m_dataitem = new SMWDIProperty( 'ERROR', false ); // just to have something
129129 }
130130 }
131131
132132 /**
133 - * Extended parsing function to first check whether value is the id of a
134 - * pre-defined property, to resolve property names and aliases, and to set
135 - * internal property id accordingly.
136 - */
137 - protected function parseDBkeys( $args ) {
138 - try {
139 - $dataItem = new SMWDIProperty( $args[0], false, $this->m_typeid );
140 - } catch ( SMWDataItemException $e ) {
141 - smwfLoadExtensionMessages( 'SemanticMediaWiki' );
142 - $this->addError( wfMsgForContent( 'smw_parseerror' ) ); // very rare to get an error here, don't bother with detailed reporting
143 - $dataItem = new SMWDIProperty( 'ERROR', false, $this->m_typeid ); // just to have something
144 - }
145 - $this->setDataItem( $dataItem );
146 - }
147 -
148 - /**
149 - * @see SMWDataValue::setDataItem()
 133+ * @see SMWDataValue::loadDataItem()
150134 * @param $dataitem SMWDataItem
151135 * @return boolean
152136 */
153 - public function setDataItem( SMWDataItem $dataItem ) {
 137+ protected function loadDataItem( SMWDataItem $dataItem ) {
154138 if ( $dataItem->getDIType() == SMWDataItem::TYPE_PROPERTY ) {
155139 $this->m_dataitem = $dataItem;
156140 $this->mPropTypeValue = null;
@@ -171,14 +155,13 @@
172156
173157 public function setOutputFormat( $formatstring ) {
174158 $this->m_outformat = $formatstring;
175 - if ( $this->m_wikipage instanceof SMWDataValue ) { // do not unstub if not needed
 159+ if ( $this->m_wikipage instanceof SMWDataValue ) {
176160 $this->m_wikipage->setOutputFormat( $formatstring );
177161 }
178162 }
179163
180164 public function setInverse( $isinverse ) {
181 - $this->unstub(); // make sure later unstubbing does not overwrite this
182 - return $this->m_dataitem = new SMWDIProperty( $this->m_dataitem->getKey(), ( $isinverse == true ), $this->m_dataitem->getTypeID() );
 165+ return $this->m_dataitem = new SMWDIProperty( $this->m_dataitem->getKey(), ( $isinverse == true ) );
183166 }
184167
185168 /**
@@ -188,11 +171,10 @@
189172 * @return SMWWikiPageValue or null
190173 */
191174 public function getWikiPageValue() {
192 - $this->unstub();
193175 if ( !isset( $this->m_wikipage ) ) {
194176 $diWikiPage = $this->m_dataitem->getDiWikiPage();
195177 if ( $diWikiPage !== null ) {
196 - $this->m_wikipage = SMWDataValueFactory::newDataItemValue( $diWikiPage, $this->m_caption );
 178+ $this->m_wikipage = SMWDataValueFactory::newDataItemValue( $diWikiPage, null, $this->m_caption );
197179 $this->m_wikipage->setOutputFormat( $this->m_outformat );
198180 $this->addError( $this->m_wikipage->getErrors() );
199181 } else { // should rarely happen ($value is only changed if the input $value really was a label for a predefined prop)
@@ -208,7 +190,6 @@
209191 * @note Every user defined property is necessarily visible.
210192 */
211193 public function isVisible() {
212 - $this->unstub();
213194 return ( $this->m_dataitem->isUserDefined() ) || ( $this->m_dataitem->getLabel() != '' );
214195 }
215196
@@ -228,26 +209,6 @@
229210 return $this->isVisible() ? $this->highlightText( $this->getWikiPageValue()->getLongHTMLText( $linker ) ) : '';
230211 }
231212
232 - /**
233 - * Return internal property id or page DBkey, either of which is sufficient for storing property references.
234 - */
235 - public function getDBkeys() {
236 - $this->unstub();
237 - return array( $this->m_dataitem->getKey() );
238 - }
239 -
240 - public function getSignature() {
241 - return 't';
242 - }
243 -
244 - public function getValueIndex() {
245 - return 0;
246 - }
247 -
248 - public function getLabelIndex() {
249 - return 0;
250 - }
251 -
252213 public function getWikiValue() {
253214 return $this->isVisible() ? ( ( $this->isInverse() ? '-' : '' ) . $this->getWikiPageValue()->getWikiValue() ) : '';
254215 }
@@ -257,7 +218,6 @@
258219 * that property. Otherwise return FALSE;
259220 */
260221 public function getPropertyID() {
261 - $this->unstub();
262222 return $this->m_dataitem->isUserDefined() ? false : $this->m_dataitem->getKey();
263223 }
264224
@@ -285,8 +245,8 @@
286246 $result->addError( wfMsgForContent( 'smw_manytypes' ) );
287247 }
288248 } else { // pre-defined property
289 - $result = SMWDataValueFactory::newTypeIDValue( '__typ' );
290 - $result->setDBkeys( array( $this->m_dataitem->getPredefinedPropertyTypeID() ) );
 249+ $propertyTypeId = SMWDIProperty::getPredefinedPropertyTypeId( $this->m_dataitem->getKey() );
 250+ $result = SMWTypesValue::newFromTypeId( $propertyTypeId );
291251 }
292252 $this->mPropTypeValue = $result;
293253 }
@@ -349,7 +309,6 @@
350310 * @deprecated
351311 */
352312 public function isUserDefined() {
353 - $this->unstub();
354313 return $this->m_dataitem->isUserDefined();
355314 }
356315
@@ -358,7 +317,6 @@
359318 * @deprecated
360319 */
361320 public function isShown() {
362 - $this->unstub();
363321 return $this->m_dataitem->isShown();
364322 }
365323
@@ -367,7 +325,6 @@
368326 * @deprecated
369327 */
370328 public function isInverse() {
371 - $this->unstub();
372329 return $this->m_dataitem->isInverse();
373330 }
374331
@@ -379,7 +336,6 @@
380337 * @deprecated
381338 */
382339 public function getDBkey() {
383 - $this->unstub();
384340 return $this->m_dataitem->getKey();
385341 }
386342
@@ -388,7 +344,6 @@
389345 * @deprecated
390346 */
391347 public function getText() {
392 - $this->unstub();
393348 return $this->m_dataitem->getLabel();
394349 }
395350
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Number.php
@@ -117,17 +117,12 @@
118118 }
119119 }
120120
121 - protected function parseDBkeys( $args ) {
122 - $dataItem = SMWDINumber::doUnserialize( $args[0], $this->m_typeid );
123 - $this->setDataItem( $dataItem );
124 - }
125 -
126121 /**
127 - * @see SMWDataValue::setDataItem()
 122+ * @see SMWDataValue::loadDataItem()
128123 * @param $dataitem SMWDataItem
129124 * @return boolean
130125 */
131 - public function setDataItem( SMWDataItem $dataItem ) {
 126+ protected function loadDataItem( SMWDataItem $dataItem ) {
132127 if ( $dataItem->getDIType() == SMWDataItem::TYPE_NUMBER ) {
133128 $this->m_dataitem = $dataItem;
134129 $this->m_caption = false;
@@ -152,7 +147,6 @@
153148 }
154149
155150 public function getShortWikiText( $linked = null ) {
156 - $this->unstub();
157151 if ( ( $linked === null ) || ( $linked === false ) || ( $this->m_outformat == '-' )
158152 || ( $this->m_outformat == '-u' ) || ( $this->m_outformat == '-n' ) || ( !$this->isValid() ) ) {
159153 return $this->m_caption;
@@ -188,7 +182,6 @@
189183 }
190184
191185 public function getLongWikiText( $linked = null ) {
192 - $this->unstub();
193186 if ( !$this->isValid() ) {
194187 return $this->getErrorText();
195188 } else {
@@ -221,30 +214,11 @@
222215 return $this->getLongWikiText( $linker );
223216 }
224217
225 - public function getDBkeys() {
226 - $this->unstub();
227 - return array( $this->m_dataitem->getSerialization(), floatval( $this->m_dataitem->getNumber() ) );
228 - }
229 -
230218 public function getNumber() {
231 - $this->unstub();
232219 return $this->m_dataitem->getNumber();
233220 }
234221
235 - public function getSignature() {
236 - return 'tf';
237 - }
238 -
239 - public function getValueIndex() {
240 - return 1;
241 - }
242 -
243 - public function getLabelIndex() {
244 - return 0;
245 - }
246 -
247222 public function getWikiValue() {
248 - $this->unstub();
249223 $unit = $this->getUnit();
250224 return strval( $this->m_dataitem->getSerialization() ) . ( $unit != '' ? ' ' . $unit : '' );
251225 }
@@ -261,7 +235,6 @@
262236 }
263237
264238 protected function getServiceLinkParams() {
265 - $this->unstub();
266239 // Create links to mapping services based on a wiki-editable message. The parameters
267240 // available to the message are:
268241 // $1: string of numerical value in English punctuation
@@ -270,7 +243,6 @@
271244 }
272245
273246 public function getExportData() {
274 - $this->unstub();
275247 if ( $this->isValid() ) {
276248 $lit = new SMWExpLiteral( $this->m_dataitem->getNumber(), $this, 'http://www.w3.org/2001/XMLSchema#double' );
277249 return new SMWExpData( $lit );
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Error.php
@@ -31,21 +31,12 @@
3232 $this->addError( wfMsgForContent( 'smw_parseerror' ) );
3333 }
3434
35 - protected function parseDBkeys( $args ) {
36 - $this->setUserValue( strval( $args[0] ) ); // compatible syntax
37 - // Note that errors are never a proper result of reading data from the
38 - // store, so it is quite unlikely that the data we get here fits this
39 - // datatype. Normally, it will not be displayed either since this value
40 - // is not valid by default. So keeping the DB key here is rather
41 - // irrelevant.
42 - }
43 -
4435 /**
45 - * @see SMWDataValue::setDataItem()
 36+ * @see SMWDataValue::loadDataItem()
4637 * @param $dataitem SMWDataItem
4738 * @return boolean
4839 */
49 - public function setDataItem( SMWDataItem $dataItem ) {
 40+ protected function loadDataItem( SMWDataItem $dataItem ) {
5041 if ( $dataItem->getDIType() == SMWDataItem::TYPE_ERROR ) {
5142 $this->addError( $dataItem->getErrors() );
5243 $this->m_caption = $this->getErrorText();
@@ -56,7 +47,6 @@
5748 }
5849
5950 public function getShortWikiText( $linked = null ) {
60 - $this->unstub();
6151 return $this->m_caption;
6252 }
6353
@@ -65,19 +55,13 @@
6656 }
6757
6858 public function getLongWikiText( $linked = null ) {
69 - $this->unstub();
7059 return $this->getErrorText();
7160 }
7261
7362 public function getLongHTMLText( $linker = null ) {
74 - $this->unstub();
7563 return $this->getErrorText();
7664 }
7765
78 - public function getDBkeys() {
79 - return array( $this->m_dataitem->getString() );
80 - }
81 -
8266 public function getWikiValue() {
8367 return $this->m_dataitem->getString();
8468 }
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Bool.php
@@ -47,17 +47,12 @@
4848 $this->m_dataitem = new SMWDIBoolean( $boolvalue, $this->m_typeid );
4949 }
5050
51 - protected function parseDBkeys( $args ) {
52 - $this->parseUserValue( $args[0] );
53 - $this->m_caption = $this->getStandardCaption( true ); // use default for this language
54 - }
55 -
5651 /**
57 - * @see SMWDataValue::setDataItem()
 52+ * @see SMWDataValue::loadDataItem()
5853 * @param $dataitem SMWDataItem
5954 * @return boolean
6055 */
61 - public function setDataItem( SMWDataItem $dataItem ) {
 56+ protected function loadDataItem( SMWDataItem $dataItem ) {
6257 if ( $dataItem->getDIType() == SMWDataItem::TYPE_BOOLEAN ) {
6358 $this->m_dataitem = $dataItem;
6459 $this->m_caption = $this->getStandardCaption( true ); // use default for this language
@@ -91,12 +86,10 @@
9287 }
9388
9489 public function getShortWikiText( $linked = null ) {
95 - $this->unstub();
9690 return $this->m_caption;
9791 }
9892
9993 public function getShortHTMLText( $linker = null ) {
100 - $this->unstub();
10194 return $this->m_caption;
10295 }
10396
@@ -108,30 +101,11 @@
109102 return $this->isValid() ? $this->getStandardCaption( true ) : $this->getErrorText();
110103 }
111104
112 - public function getDBkeys() {
113 - $this->unstub();
114 - return $this->m_dataitem->getBoolean() ? array( '1', 1 ) : array( '0', 0 );
115 - }
116 -
117 - public function getSignature() {
118 - return 'tn';
119 - }
120 -
121 - public function getValueIndex() {
122 - return 1;
123 - }
124 -
125 - public function getLabelIndex() {
126 - return 0;
127 - }
128 -
129105 public function getWikiValue() {
130 - $this->unstub();
131106 return $this->getStandardCaption( false );
132107 }
133108
134109 public function getBoolean() {
135 - $this->unstub();
136110 return $this->m_dataitem->getBoolean();
137111 }
138112
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Concept.php
@@ -19,17 +19,12 @@
2020 throw new Exception( 'Concepts cannot be initialised from user-provided strings. This should not happen.' );
2121 }
2222
23 - protected function parseDBkeys( $args ) {
24 - $this->m_caption = $args[0]; // is this useful?
25 - $this->m_dataitem = new SMWDIConcept( $args[0], smwfXMLContentEncode( $args[1] ), $args[2], $args[3], $args[4], $this->m_typeid );
26 - }
27 -
2823 /**
29 - * @see SMWDataValue::setDataItem()
 24+ * @see SMWDataValue::loadDataItem()
3025 * @param $dataitem SMWDataItem
3126 * @return boolean
3227 */
33 - public function setDataItem( SMWDataItem $dataItem ) {
 28+ protected function loadDataItem( SMWDataItem $dataItem ) {
3429 if ( $dataItem->getDIType() == SMWDataItem::TYPE_CONCEPT ) {
3530 $this->m_dataitem = $dataItem;
3631 $this->m_caption = $dataItem->getConceptQuery(); // probably useless
@@ -44,7 +39,6 @@
4540 }
4641
4742 public function getShortWikiText( $linked = null ) {
48 - $this->unstub();
4943 return $this->m_caption;
5044 }
5145
@@ -68,25 +62,7 @@
6963 }
7064 }
7165
72 - public function getDBkeys() {
73 - $this->unstub();
74 - return array( $this->m_dataitem->getConceptQuery(), $this->m_dataitem->getDocumentation(), $this->m_dataitem->getQueryFeatures(), $this->m_dataitem->getSize(), $this->m_dataitem->getDepth() );
75 - }
76 -
77 - public function getSignature() {
78 - return 'llnnn';
79 - }
80 -
81 - public function getValueIndex() {
82 - return 0;
83 - }
84 -
85 - public function getLabelIndex() {
86 - return 0;
87 - }
88 -
8966 public function getWikiValue() {
90 - $this->unstub();
9167 /// This should not be used for anything. This class does not support wiki values.
9268 return str_replace( array( '&lt;', '&gt;', '&amp;' ), array( '<', '>', '&' ), $this->m_dataitem->getConceptQuery() );
9369 }
@@ -184,37 +160,27 @@
185161
186162 /// Return the concept's defining text (in SMW query syntax)
187163 public function getConceptText() {
188 - $this->unstub();
189164 return $this->m_dataitem->getConceptQuery();
190165 }
191166
192167 /// Return the optional concept documentation.
193168 public function getDocu() {
194 - $this->unstub();
195169 return $this->m_dataitem->getDocumentation();
196170 }
197171
198172 /// Return the concept's size (a metric used to estimate computation complexity).
199173 public function getSize() {
200 - $this->unstub();
201174 return $this->m_dataitem->getSize();
202175 }
203176
204177 /// Return the concept's depth (a metric used to estimate computation complexity).
205178 public function getDepth() {
206 - $this->unstub();
207179 return $this->m_dataitem->getDepth();
208180 }
209181
210182 /// Return the concept's query feature bit field (a metric used to estimate computation complexity).
211183 public function getQueryFeatures() {
212 - $this->unstub();
213184 return $this->m_dataitem->getQueryFeatures();
214185 }
215186
216 - /// @deprecated Use setDBkeys(). This method will vanish before SMW 1.6
217 - public function setValues( $concept, $docu, $queryfeatures, $size, $depth ) {
218 - $this->setDBkeys( array( $concept, $docu, $queryfeatures, $size, $depth ) );
219 - }
220 -
221187 }
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php
@@ -574,43 +574,12 @@
575575 }
576576 }
577577
578 - protected function parseDBkeys( $args ) {
579 - $this->m_caption = $this->m_wikivalue = false;
580 - $timedate = explode( 'T', $args[0], 2 );
581 - if ( ( count( $args ) == 2 ) && ( count( $timedate ) == 2 ) ) {
582 - $date = reset( $timedate );
583 - $year = $month = $day = $hours = $minutes = $seconds = $timeoffset = false;
584 - if ( ( end( $timedate ) == '' ) ||
585 - ( self::parseTimeString( end( $timedate ), $hours, $minutes, $seconds, $timeoffset ) == true ) ) {
586 - $d = explode( '/', $date, 3 );
587 - if ( count( $d ) == 3 ) {
588 - list( $year, $month, $day ) = $d;
589 - } elseif ( count( $d ) == 2 ) {
590 - list( $year, $month ) = $d;
591 - } elseif ( count( $d ) == 1 ) {
592 - list( $year ) = $d;
593 - }
594 - //$calendarmodel = ( $year < -4713 ) ? SMWDITime::CM_JULIAN : SMWDITime::CM_GREGORIAN;
595 - $calendarmodel = SMWDITime::CM_GREGORIAN; // now all dates are stored as Gregorian (used to be only the historic ones)
596 - try {
597 - $this->m_dataitem = new SMWDITime( $calendarmodel, $year, $month, $day, $hours, $minutes, $seconds, $this->m_typeid );
598 - return;
599 - } catch ( SMWDataItemException $e ) {
600 - // fall through
601 - }
602 - }
603 - }
604 - smwfLoadExtensionMessages( 'SemanticMediaWiki' );
605 - $this->addError( wfMsgForContent( 'smw_nodatetime', $args[0] ) );
606 - $this->m_dataitem = new SMWDITime( SMWDITime::CM_GREGORIAN, 32202 ); // always default to something
607 - }
608 -
609578 /**
610 - * @see SMWDataValue::setDataItem()
 579+ * @see SMWDataValue::loadDataItem()
611580 * @param $dataitem SMWDataItem
612581 * @return boolean
613582 */
614 - public function setDataItem( SMWDataItem $dataItem ) {
 583+ protected function loadDataItem( SMWDataItem $dataItem ) {
615584 if ( $dataItem->getDIType() == SMWDataItem::TYPE_TIME ) {
616585 $this->m_dataitem = $dataItem;
617586 $this->m_caption = $this->m_wikivalue = false;
@@ -636,30 +605,8 @@
637606 return $this->getLongWikiText( $linker ); // safe in HTML
638607 }
639608
640 - public function getDBkeys() {
641 - $this->unstub();
642 - $xsdvalue = $this->getYear() . "/" .
643 - $this->getMonth( SMWDITime::CM_GREGORIAN, '' ) . "/" .
644 - $this->getDay( SMWDITime::CM_GREGORIAN, '' ) . "T" .
645 - $this->getTimeString( '' );
646 - return array( $xsdvalue, $this->m_dataitem->getSortKey() );
647 - }
648 -
649 - public function getSignature() {
650 - return 'tf';
651 - }
652 -
653 - public function getValueIndex() {
654 - return 1;
655 - }
656 -
657 - public function getLabelIndex() {
658 - return 0;
659 - }
660 -
661609 /// @todo The preferred caption may not be suitable as a wiki value (i.e. not parsable).
662610 public function getWikiValue() {
663 - $this->unstub();
664611 return $this->m_wikivalue ? $this->m_wikivalue : $this->getPreferredCaption();
665612 }
666613
@@ -672,7 +619,7 @@
673620 $lit = new SMWExpLiteral( $this->getISO8601Date(), $this, 'http://www.w3.org/2001/XMLSchema#dateTime' );
674621 return new SMWExpData( $lit );
675622 } else {
676 - return NULL;
 623+ return null;
677624 }
678625 }
679626
@@ -736,7 +683,6 @@
737684 * also be set to false to detect this situation.
738685 */
739686 public function getTimeString( $default = '00:00:00' ) {
740 - $this->unstub();
741687 if ( $this->m_dataitem->getPrecision() < SMWDITime::PREC_YMDT ) {
742688 return $default;
743689 } else {
@@ -747,17 +693,7 @@
748694 }
749695
750696 /**
751 - * Return a representation of this date in canonical dateTime format without timezone, as
752 - * specified in XML Schema Part 2: Datatypes Second Edition (W3C Recommendation, 28 October 2004,
753 - * http://www.w3.org/TR/xmlschema-2). An example would be "2008-01-02T14:30:10". BC(E) years
754 - * are represented by a leading "-" as in "-123-01-02T14:30:10", the 2nd January of the year
755 - * 123 BC(E) at 2:30pm and 10 seconds.
756 - *
757 - * If the date was not fully specified, then the function will use defaults for the omitted values.
758 - * The boolean parameter $mindefault controls if those defaults are chosen minimally. If false, then
759 - * the latest possible value will be chosen instead.
760 - *
761 - * @deprecated This method is now called getISO8601Date().
 697+ * @deprecated This method is now called getISO8601Date(). It will vanish before SMW 1.7.
762698 */
763699 public function getXMLSchemaDate( $mindefault = true ) {
764700 return $this->getISO8601Date( $mindefault );
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_URI.php
@@ -93,7 +93,7 @@
9494 $fragment = ( count( $parts ) == 2 ) ? $parts[1] : '';
9595 } else {
9696 $query = '';
97 - $parts = explode( '?', $parts[0], 2 ); // try to split "hier-part#frag"
 97+ $parts = explode( '#', $parts[0], 2 ); // try to split "hier-part#frag"
9898 $hierpart = $parts[0];
9999 $fragment = ( count( $parts ) == 2 ) ? $parts[1] : '';
100100 }
@@ -158,23 +158,12 @@
159159 return (bool) preg_match( $tel_uri_regex, $s );
160160 }
161161
162 - protected function parseDBkeys( $args ) {
163 - try {
164 - $dataItem = SMWDIUri::doUnserialize( $args[0], $this->m_typeid);
165 - $this->setDataItem( $dataItem );
166 - } catch ( SMWDataItemException $e ) {
167 - $this->addError( wfMsgForContent( 'smw_baduri', $this->m_wikitext ) );
168 - $this->m_dataitem = new SMWDIUri( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value
169 - return;
170 - }
171 - }
172 -
173162 /**
174 - * @see SMWDataValue::setDataItem()
 163+ * @see SMWDataValue::loadDataItem()
175164 * @param $dataitem SMWDataItem
176165 * @return boolean
177166 */
178 - public function setDataItem( SMWDataItem $dataItem ) {
 167+ protected function loadDataItem( SMWDataItem $dataItem ) {
179168 if ( $dataItem->getDIType() == SMWDataItem::TYPE_URI ) {
180169 $this->m_dataitem = $dataItem;
181170 if ( $this->m_mode == SMW_URI_MODE_EMAIL ) {
@@ -192,7 +181,6 @@
193182 }
194183
195184 public function getShortWikiText( $linked = null ) {
196 - $this->unstub();
197185 $url = $this->getURL();
198186 if ( ( $linked === null ) || ( $linked === false ) || ( $this->m_outformat == '-' ) || ( $url == '' ) || ( $this->m_caption == '' ) ) {
199187 return $this->m_caption;
@@ -202,7 +190,6 @@
203191 }
204192
205193 public function getShortHTMLText( $linker = null ) {
206 - $this->unstub();
207194 $url = $this->getURL();
208195 if ( ( $linker === null ) || ( !$this->isValid() ) || ( $this->m_outformat == '-' ) || ( $url == '' ) || ( $this->m_caption == '' ) ) {
209196 return $this->m_caption;
@@ -235,35 +222,15 @@
236223 }
237224 }
238225
239 - public function getDBkeys() {
240 - $this->unstub();
241 - return array( $this->m_dataitem->getSerialization() );
242 - }
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 -
256226 public function getWikiValue() {
257 - $this->unstub();
258227 return $this->m_wikitext;
259228 }
260229
261230 public function getURI() {
262 - $this->unstub();
263231 return $this->m_dataitem->getURI();
264232 }
265233
266234 protected function getServiceLinkParams() {
267 - $this->unstub();
268235 // Create links to mapping services based on a wiki-editable message. The parameters
269236 // available to the message are:
270237 // $1: urlencoded version of URI/URL value (includes mailto: for emails)
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_WikiPage.php
@@ -114,23 +114,12 @@
115115 }
116116 }
117117
118 - protected function parseDBkeys( $args ) {
119 - if ( count( $args ) < 3 ) {
120 - smwfLoadExtensionMessages( 'SemanticMediaWiki' );
121 - $this->addError( wfMsgForContent( 'smw_notitle', $this->getPrefixedText() ) );
122 - $this->m_dataitem = new SMWDIWikiPage( 'ERROR', NS_MAIN, '', $this->m_typeid );
123 - } else {
124 - $dataItem = new SMWDIWikiPage( $args[0], floatval( $args[1] ), $args[2], $this->m_typeid );
125 - $this->setDataItem( $dataItem );
126 - }
127 - }
128 -
129118 /**
130 - * @see SMWDataValue::setDataItem()
 119+ * @see SMWDataValue::loadDataItem()
131120 * @param $dataitem SMWDataItem
132121 * @return boolean
133122 */
134 - public function setDataItem( SMWDataItem $dataItem ) {
 123+ protected function loadDataItem( SMWDataItem $dataItem ) {
135124 if ( $dataItem->getDIType() == SMWDataItem::TYPE_WIKIPAGE ) {
136125 $this->m_dataitem = $dataItem;
137126 $this->m_textform = str_replace( '_', ' ', $dataItem->getDBkey() );
@@ -149,7 +138,6 @@
150139 }
151140
152141 public function getShortWikiText( $linked = null ) {
153 - $this->unstub();
154142 if ( ( $linked === null ) || ( $linked === false ) || ( $this->m_outformat == '-' ) || ( !$this->isValid() ) || ( $this->m_caption === '' ) ) {
155143 return $this->getCaption();
156144 } else {
@@ -159,7 +147,6 @@
160148 }
161149
162150 public function getShortHTMLText( $linker = null ) {
163 - $this->unstub();
164151 if ( ( $linker !== null ) && ( $this->m_caption !== '' ) && ( $this->m_outformat != '-' ) ) $this->getTitle(); // init the Title object, may reveal hitherto unnoticed errors
165152 if ( ( $linker === null ) || ( !$this->isValid() ) || ( $this->m_outformat == '-' ) || ( $this->m_caption === '' ) ) {
166153 return htmlspecialchars( $this->getCaption() );
@@ -176,7 +163,6 @@
177164 * In all other uses, values come from the store and do not have fragments anyway.
178165 */
179166 public function getLongWikiText( $linked = null ) {
180 - $this->unstub();
181167 if ( !$this->isValid() ) {
182168 return $this->getErrorText();
183169 }
@@ -190,7 +176,6 @@
191177 }
192178
193179 public function getLongHTMLText( $linker = null ) {
194 - $this->unstub();
195180 if ( ( $linker !== null ) && ( $this->m_outformat != '-' ) ) { $this->getTitle(); } // init the Title object, may reveal hitherto unnoticed errors
196181 if ( !$this->isValid() ) {
197182 return $this->getErrorText();
@@ -204,25 +189,7 @@
205190 }
206191 }
207192
208 - public function getDBkeys() {
209 - $this->unstub();
210 - return array( $this->m_dataitem->getDBkey(), $this->m_dataitem->getNamespace(), $this->m_dataitem->getInterwiki(), $this->m_dataitem->getDBkey() );
211 - }
212 -
213 - public function getSignature() {
214 - return 'tnwt';
215 - }
216 -
217 - public function getValueIndex() {
218 - return 3;
219 - }
220 -
221 - public function getLabelIndex() {
222 - return 3;
223 - }
224 -
225193 public function getWikiValue() {
226 - $this->unstub();
227194 if ( $this->m_fixNamespace != NS_MAIN ) { // no explicit namespace needed!
228195 return $this->getText();
229196 } elseif ( $this->m_dataitem->getNamespace() == NS_CATEGORY ) {
@@ -234,11 +201,10 @@
235202 }
236203
237204 public function getHash() {
238 - return $this->isValid() ? $this->getPrefixedText():implode( "\t", $this->getErrors() );
 205+ return $this->isValid() ? $this->getPrefixedText() : implode( "\t", $this->getErrors() );
239206 }
240207
241208 protected function getServiceLinkParams() {
242 - $this->unstub();
243209 // Create links to mapping services based on a wiki-editable message. The parameters
244210 // available to the message are:
245211 // $1: urlencoded article name (no namespace)
@@ -292,7 +258,6 @@
293259 * Get MediaWiki's ID for this value, if any.
294260 */
295261 public function getArticleID() {
296 - $this->unstub();
297262 if ( $this->m_id === false ) {
298263 $this->m_id = ( $this->getTitle() !== null ) ? $this->m_title->getArticleID() : 0;
299264 }
@@ -303,7 +268,6 @@
304269 * Get namespace constant for this value.
305270 */
306271 public function getNamespace() {
307 - $this->unstub();
308272 return $this->m_dataitem->getNamespace();
309273 }
310274
@@ -314,20 +278,17 @@
315279 * to use this method in places where only MediaWiki Title keys are allowed.
316280 */
317281 public function getDBkey() {
318 - $this->unstub();
319282 return $this->m_dataitem->getDBkey();
320283 }
321284
322285 /// Get text label for this value.
323286 public function getText() {
324 - $this->unstub();
325287 return str_replace( '_', ' ', $this->m_dataitem->getDBkey() );
326288 }
327289
328290 /// Get the prefixed text for this value, including a localised namespace prefix.
329291 public function getPrefixedText() {
330292 global $wgContLang;
331 - $this->unstub();
332293 if ( $this->m_prefixedtext == '' ) {
333294 $nstext = $wgContLang->getNSText( $this->m_dataitem->getNamespace() );
334295 $this->m_prefixedtext = ( $this->m_dataitem->getInterwiki() != '' ? $this->m_dataitem->getInterwiki() . ':' : '' ) .
@@ -340,7 +301,6 @@
341302 * Get interwiki prefix or empty string.
342303 */
343304 public function getInterwiki() {
344 - $this->unstub();
345305 return $this->m_dataitem->getInterwiki();
346306 }
347307
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Types.php
@@ -16,107 +16,130 @@
1717 * @author Markus Krötzsch
1818 * @ingroup SMWDataValues
1919 */
20 -class SMWTypesValue extends SMWWikiPageValue {
 20+class SMWTypesValue extends SMWDataValue {
 21+ protected $m_isAlias; // record whether this is an alias to another type, used to avoid duplicates when listing page types
 22+ protected $m_realLabel;
 23+ protected $m_givenLabel;
 24+ protected $m_typeId;
2125
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;
 26+ public static function newFromTypeId( $typeId ) {
 27+ $result = new SMWTypesValue( '__typ' );
 28+ try {
 29+ $dataItem = self::getTypeUriFromTypeId( $typeId );
 30+ } catch ( SMWDataItemException $e ) {
 31+ $dataItem = self::getTypeUriFromTypeId( 'notype' );
 32+ }
 33+ $result->setDataItem( $dataItem );
 34+ return $result;
 35+ }
2436
25 - protected function parseUserValue( $value ) {
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;
 37+ public static function getTypeUriFromTypeId( $typeId ) {
 38+ return new SMWDIUri( 'http', '//semantic-mediawiki.org/swivt/1.0', '', $typeId );
2939 }
3040
31 - protected function parseDBkeys( $args ) {
32 - $pagedbkey = str_replace( ' ', '_', SMWDataValueFactory::findTypeLabel( $args[0] ) );
33 - parent::parseDBkeys( array( $pagedbkey, $this->m_fixNamespace, '', $this->m_typeid ) );
34 - $this->m_reallabel = $this->m_textform;
35 - $this->m_isalias = false;
 41+ protected function parseUserValue( $value ) {
 42+ global $wgContLang;
 43+
 44+ if ( $this->m_caption === false ) {
 45+ $this->m_caption = $value;
 46+ }
 47+
 48+ $valueParts = explode( ':', $value, 2 );
 49+ if ( count( $valueParts ) > 1 ) {
 50+ $namespace = smwfNormalTitleText( $valueParts[0] );
 51+ $value = $valueParts[1];
 52+ $typeNamespace = $wgContLang->getNsText( SMW_NS_TYPE );
 53+ if ( $namespace != $typeNamespace ) {
 54+ smwfLoadExtensionMessages( 'SemanticMediaWiki' );
 55+ $this->addError( wfMsgForContent( 'smw_wrong_namespace', $typeNamespace ) );
 56+ }
 57+ }
 58+
 59+ $this->m_givenLabel = smwfNormalTitleText( $value );
 60+ $this->m_typeId = SMWDataValueFactory::findTypeID( $this->m_givenLabel );
 61+ if ( $this->m_typeId == '' ) {
 62+ smwfLoadExtensionMessages( 'SemanticMediaWiki' );
 63+ $this->addError( wfMsgForContent( 'smw_unknowntype', $this->m_givenLabel ) );
 64+ $this->m_realLabel = $this->m_givenLabel;
 65+ } else {
 66+ $this->m_realLabel = SMWDataValueFactory::findTypeLabel( $this->m_typeId );
 67+ }
 68+ $this->m_isAlias = ( $this->m_realLabel === $this->m_givenLabel ) ? false : true;
 69+
 70+ try {
 71+ $this->m_dataitem = self::getTypeUriFromTypeId( $this->m_typeId );
 72+ } catch ( SMWDataItemException $e ) {
 73+ $this->m_dataitem = self::getTypeUriFromTypeId( 'notype' );
 74+ smwfLoadExtensionMessages( 'SemanticMediaWiki' );
 75+ $this->addError( wfMsgForContent( 'smw_parseerror' ) );
 76+ }
3677 }
3778
3879 /**
39 - * @see SMWDataValue::setDataItem()
 80+ * @see SMWDataValue::loadDataItem()
4081 * @param $dataitem SMWDataItem
4182 * @return boolean
4283 */
43 - public function setDataItem( SMWDataItem $dataItem ) {
44 - if ( parent::setDataItem( $dataItem ) ) {
45 - $this->m_reallabel = $this->m_textform;
46 - $this->m_isalias = false;
 84+ protected function loadDataItem( SMWDataItem $dataItem ) {
 85+ if ( ( $dataItem instanceof SMWDIUri ) && ( $dataItem->getScheme() == 'http' ) &&
 86+ ( $dataItem->getHierpart() == '//semantic-mediawiki.org/swivt/1.0' ) &&
 87+ ( $dataItem->getQuery() == '' ) ) {
 88+ $this->m_isAlias = false;
 89+ $this->m_typeId = $dataItem->getFragment();
 90+ $this->m_realLabel = SMWDataValueFactory::findTypeLabel( $this->m_typeId );
 91+ $this->m_caption = $this->m_givenLabel = $this->m_realLabel;
 92+ $this->m_dataitem = $dataItem;
4793 return true;
4894 } else {
4995 return false;
5096 }
5197 }
5298
 99+ public function getShortWikiText( $linked = null ) {
 100+ if ( ( $linked === null ) || ( $linked === false ) || ( $this->m_outformat == '-' ) || ( $this->m_caption == '' ) ) {
 101+ return $this->m_caption;
 102+ } else { // TODO provide a Special page with the functionality of former Type pages, and link to it here
 103+ return $this->m_caption;
 104+ }
 105+ }
 106+
 107+ public function getShortHTMLText( $linker = null ) {
 108+ if ( ( $linked === null ) || ( $linked === false ) || ( $this->m_outformat == '-' ) || ( $this->m_caption == '' ) ) {
 109+ return htmlspecialchars( $this->m_caption );
 110+ } else { // TODO provide a Special page with the functionality of former Type pages, and link to it here
 111+ return htmlspecialchars( $this->m_caption );
 112+ }
 113+ }
 114+
53115 public function getLongWikiText( $linked = null ) {
54 - $this->unstub();
55116 if ( ( $linked === null ) || ( $linked === false ) ) {
56 - return $this->m_reallabel;
57 - } else {
58 - global $wgContLang;
59 - $typenamespace = $wgContLang->getNsText( SMW_NS_TYPE );
60 - $id = SMWDataValueFactory::findTypeID( $this->m_reallabel );
61 - if ( $id { 0 } == '_' ) { // builtin
62 - smwfLoadExtensionMessages( 'SemanticMediaWiki' );
63 - SMWOutputs::requireHeadItem( SMW_HEADER_TOOLTIP );
64 - return '<span class="smwttinline"><span class="smwbuiltin">[[' . $typenamespace . ':' . $this->m_reallabel . '|' . $this->m_reallabel . ']]</span><span class="smwttcontent">' . wfMsgForContent( 'smw_isknowntype' ) . '</span></span>';
65 - } else {
66 - return '[[' . $typenamespace . ':' . $this->m_reallabel . '|' . $this->m_reallabel . ']]';
67 - }
 117+ return $this->m_realLabel;
 118+ } else { // TODO provide a Special page with the functionality of former Type pages, and link to it here
 119+ return $this->m_realLabel;
68120 }
69121 }
70122
71123 public function getLongHTMLText( $linker = null ) {
72 - $this->unstub();
73124 if ( ( $linker === null ) || ( $linker === false ) ) {
74 - return $this->m_reallabel;
75 - } else {
76 - $title = $this->m_isalias ? Title::newFromText( $this->m_reallabel, SMW_NS_TYPE ) : $this->getTitle();
77 - $id = SMWDataValueFactory::findTypeID( $this->m_reallabel );
78 - if ( $id { 0 } == '_' ) { // builtin
79 - smwfLoadExtensionMessages( 'SemanticMediaWiki' );
80 - SMWOutputs::requireHeadItem( SMW_HEADER_TOOLTIP );
81 - return '<span class="smwttinline"><span class="smwbuiltin">' .
82 - $linker->makeLinkObj( $title, htmlspecialchars( $this->m_reallabel ) ) . '</span><span class="smwttcontent">' .
83 - wfMsgForContent( 'smw_isknowntype' ) . '</span></span>';
84 - } else {
85 - return $linker->makeLinkObj( $title, htmlspecialchars( $this->m_reallabel ) );
86 - }
 125+ return htmlspecialchars( $this->m_realLabel );
 126+ } else { // TODO provide a Special page with the functionality of former Type pages, and link to it here
 127+ return htmlspecialchars( $this->m_realLabel );
87128 }
88129 }
89130
90 - public function getDBkeys() {
91 - return ( $this->isValid() ) ? array( $this->getDBkey() ):array( false );
92 - }
93 -
94 - public function getSignature() {
95 - return 't';
96 - }
97 -
98 - public function getValueIndex() {
99 - return 0;
100 - }
101 -
102 - public function getLabelIndex() {
103 - return 0;
104 - }
105 -
106131 public function getWikiValue() {
107 - $this->unstub();
108 - return $this->m_reallabel;
 132+ return $this->m_realLabel;
109133 }
110134
111135 public function getHash() {
112 - $this->unstub();
113 - return $this->m_reallabel;
 136+ return $this->m_realLabel;
114137 }
115138
116139 /**
117140 * This class uses type ids as DB keys.
118141 */
119142 public function getDBkey() {
120 - return ( $this->isValid() ) ? SMWDataValueFactory::findTypeID( $this->m_reallabel ) : '';
 143+ return ( $this->isValid() ) ? SMWDataValueFactory::findTypeID( $this->m_realLabel ) : '';
121144 }
122145
123146 /**
@@ -133,8 +156,7 @@
134157 * explain entries in Special:Types that are found since they have pages.
135158 */
136159 public function isAlias() {
137 - $this->unstub();
138 - return $this->m_isalias;
 160+ return $this->m_isAlias;
139161 }
140162
141163 }
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_String.php
@@ -35,17 +35,12 @@
3636 }
3737 }
3838
39 - protected function parseDBkeys( $args ) {
40 - $this->parseUserValue( $args[0] );
41 - $this->m_caption = $this->m_dataitem->getString(); // this is our output text
42 - }
43 -
4439 /**
45 - * @see SMWDataValue::setDataItem()
 40+ * @see SMWDataValue::loadDataItem()
4641 * @param $dataitem SMWDataItem
4742 * @return boolean
4843 */
49 - public function setDataItem( SMWDataItem $dataItem ) {
 44+ protected function loadDataItem( SMWDataItem $dataItem ) {
5045 $diType = ( ( $this->m_typeid == '_txt' ) || ( $this->m_typeid == '_cod' ) ) ? SMWDataItem::TYPE_BLOB : SMWDataItem::TYPE_STRING;
5146 if ( $dataItem->getDIType() == $diType ) {
5247 $this->m_dataitem = $dataItem;
@@ -61,7 +56,6 @@
6257 }
6358
6459 public function getShortWikiText( $linked = null ) {
65 - $this->unstub();
6660 return $this->m_caption;
6761 }
6862
@@ -83,38 +77,11 @@
8478 return $this->isValid() ? $this->getAbbValue( $linker, smwfXMLContentEncode( $this->m_dataitem->getString() ) ) : $this->getErrorText();
8579 }
8680
87 - public function getDBkeys() {
88 - $this->unstub();
89 - return array( $this->m_dataitem->getString() );
90 - }
91 -
92 - public function getSignature() {
93 - return ( ( $this->m_typeid == '_txt' ) || ( $this->m_typeid == '_cod' ) ) ? 'l':'t';
94 - }
95 -
96 - /**
97 - * For perfomance reasons, long text data like _txt and _cod does not
98 - * support sorting. This class can be subclassed to change this.
99 - */
100 - public function getValueIndex() {
101 - return ( $this->m_typeid == '_txt' || $this->m_typeid == '_cod' ) ? - 1 : 0;
102 - }
103 -
104 - /**
105 - * For perfomance reasons, long text data like _txt and _cod does not
106 - * support string matching. This class can be subclassed to change this.
107 - */
108 - public function getLabelIndex() {
109 - return ( $this->m_typeid == '_txt' || $this->m_typeid == '_cod' ) ? - 1 : 0;
110 - }
111 -
11281 public function getWikiValue() {
113 - $this->unstub();
11482 return $this->m_dataitem->getString();
11583 }
11684
11785 public function getInfolinks() {
118 - $this->unstub();
11986 if ( ( $this->m_typeid != '_txt' ) && ( $this->m_typeid != '_cod' ) ) {
12087 return parent::getInfolinks();
12188 } else {
@@ -123,7 +90,6 @@
12491 }
12592
12693 protected function getServiceLinkParams() {
127 - $this->unstub();
12894 // Create links to mapping services based on a wiki-editable message. The parameters
12995 // available to the message are:
13096 // $1: urlencoded string
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_JSONlink.php
@@ -66,20 +66,20 @@
6767 if ( $pr->getMode() != SMWPrintRequest::PRINT_THIS ) {
6868 $values = array();
6969 $finalvalues = '';
70 - while ( ( $value = $field->getNextDataValue() ) !== false ) {
 70+ while ( ( $dataValue = $field->getNextDataValue() ) !== false ) {
7171 $finalvalues = '';
72 - switch ( $value->getTypeID() ) {
 72+ switch ( $dataValue->getTypeID() ) {
7373 case '_geo':
74 - $values[] = "\"" . $value->getWikiValue() . "\"";
 74+ $values[] = "\"" . $dataValue->getWikiValue() . "\"";
7575 break;
7676 case '_num':
77 - $values[] = "\"" . $value->getValueKey() . "\"";
 77+ $values[] = "\"" . $dataValue->getValueKey() . "\"";
7878 break;
7979 case '_dat':
80 - $values[] = "\"" . $value->getYear() . "-" . str_pad( $value->getMonth(), 2, '0', STR_PAD_LEFT ) . "-" . str_pad( $value->getDay(), 2, '0', STR_PAD_LEFT ) . " " . $value->getTimeString() . "\"";
 80+ $values[] = "\"" . $dataValue->getYear() . "-" . str_pad( $dataValue->getMonth(), 2, '0', STR_PAD_LEFT ) . "-" . str_pad( $dataValue->getDay(), 2, '0', STR_PAD_LEFT ) . " " . $dataValue->getTimeString() . "\"";
8181 break;
8282 default:
83 - $values[] = "\"" . $value->getShortText( $outputmode, null ) . "\"";
 83+ $values[] = "\"" . $dataValue->getShortText( $outputmode, null ) . "\"";
8484 }
8585
8686 if ( sizeof( $values ) > 1 ) {
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_Embedded.php
@@ -68,8 +68,8 @@
6969
7070 // Print all result rows:
7171 foreach ( $res->getResults() as $diWikiPage ) {
72 - if ( $diWikiPage->getTypeID() == '_wpg' ) { // ensure that we deal with title-likes
73 - $dvWikiPage = SMWDataValueFactory::newDataItemValue( $diWikiPage );
 72+ if ( $diWikiPage instanceof SMWDIWikiPage ) { // ensure that we deal with title-likes
 73+ $dvWikiPage = SMWDataValueFactory::newDataItemValue( $diWikiPage, null );
7474 $result .= $embstart;
7575
7676 if ( $this->m_showhead ) {
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php
@@ -43,7 +43,7 @@
4444 $text = '';
4545 if ( wfRunHooks( 'smwShowFactbox', array( &$text, $semdata ) ) ) {
4646 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
47 - $subjectDv = SMWDataValueFactory::newDataItemValue( $semdata->getSubject() );
 47+ $subjectDv = SMWDataValueFactory::newDataItemValue( $semdata->getSubject(), null );
4848 SMWOutputs::requireHeadItem( SMW_HEADER_STYLE );
4949 $rdflink = SMWInfolink::newInternalLink(
5050 wfMsgForContent( 'smw_viewasrdf' ),
@@ -62,7 +62,7 @@
6363 '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' .
6464 '<table class="smwfacttable">' . "\n";
6565 foreach ( $semdata->getProperties() as $propertyDi ) {
66 - $propertyDv = SMWDataValueFactory::newDataItemValue( $propertyDi );
 66+ $propertyDv = SMWDataValueFactory::newDataItemValue( $propertyDi, null );
6767 if ( !$propertyDi->isShown() ) { // showing this is not desired, hide
6868 continue;
6969 } elseif ( $propertyDi->isUserDefined() ) { // user defined property
@@ -87,7 +87,7 @@
8888 }
8989 }
9090 $i += 1;
91 - $dv = SMWDataValueFactory::newDataItemValue( $di, false, $propertyDi );
 91+ $dv = SMWDataValueFactory::newDataItemValue( $di, $propertyDi );
9292 $text .= $dv->getLongWikiText( true ) . $dv->getInfolinkText( SMW_OUTPUT_WIKI );
9393 }
9494 $text .= '</td></tr>';
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_OrderedListPage.php
@@ -54,6 +54,13 @@
5555 protected $skin;
5656
5757 /**
 58+ * Property that the displayed values are for, if any.
 59+ *
 60+ * @var SMWDIProperty
 61+ */
 62+ protected $mProperty = null;
 63+
 64+ /**
5865 * Overwrite view() from Article.php to add additional html to the output.
5966 */
6067 public function view() {
@@ -237,7 +244,7 @@
238245
239246 // output all diWikiPages
240247 for ( $index = $startChunk ; $index < $endChunk && $index < $end; $index++ ) {
241 - $dataValue = SMWDataValueFactory::newDataItemValue( $diWikiPages[$index] );
 248+ $dataValue = SMWDataValueFactory::newDataItemValue( $diWikiPages[$index], $this->mProperty );
242249 // check for change of starting letter or begining of chunk
243250 $sortkey = smwfGetStore()->getWikiPageSortKey( $diWikiPages[$index] );
244251 $start_char = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) );
@@ -287,7 +294,7 @@
288295 protected function shortList( $start, $end, array $diWikiPages ) {
289296 global $wgContLang;
290297
291 - $startDv = SMWDataValueFactory::newDataItemValue( $diWikiPages[$start] );
 298+ $startDv = SMWDataValueFactory::newDataItemValue( $diWikiPages[$start], $this->mProperty );
292299 $sortkey = smwfGetStore()->getWikiPageSortKey( $diWikiPages[$start] );
293300 $start_char = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) );
294301 $r = '<h3>' . htmlspecialchars( $start_char ) . "</h3>\n" .
@@ -295,7 +302,7 @@
296303
297304 $prev_start_char = $start_char;
298305 for ( $index = $start + 1; $index < $end; $index++ ) {
299 - $dataValue = SMWDataValueFactory::newDataItemValue( $diWikiPages[$index] );
 306+ $dataValue = SMWDataValueFactory::newDataItemValue( $diWikiPages[$index], $this->mProperty );
300307 $sortkey = smwfGetStore()->getWikiPageSortKey( $diWikiPages[$index] );
301308 $start_char = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) );
302309
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_PropertyPage.php
@@ -15,7 +15,6 @@
1616 class SMWPropertyPage extends SMWOrderedListPage {
1717
1818 private $subproperties; // list of sub-properties of this property
19 - private $mProperty; // property object
2019
2120 /**
2221 * @see SMWOrderedListPage::initParameters()
@@ -143,7 +142,7 @@
144143
145144 for ( $index = $start; $index < $ac; $index++ ) {
146145 $diWikiPage = $this->diWikiPages[$index];
147 - $dvWikiPage = SMWDataValueFactory::newDataItemValue( $diWikiPage );
 146+ $dvWikiPage = SMWDataValueFactory::newDataItemValue( $diWikiPage, $this->mProperty );
148147 $sortkey = smwfGetStore()->getWikiPageSortKey( $diWikiPage );
149148 $start_char = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) );
150149
@@ -171,7 +170,7 @@
172171 $i++;
173172
174173 if ( $i < $smwgMaxPropertyValues + 1 ) {
175 - $dv = SMWDataValueFactory::newDataItemValue( $di );
 174+ $dv = SMWDataValueFactory::newDataItemValue( $di, $this->mProperty );
176175 $r .= $dv->getLongHTMLText( $this->getSkin() ) . $dv->getInfolinkText( SMW_OUTPUT_HTML, $this->getSkin() );
177176 } else {
178177 $searchlink = SMWInfolink::newInversePropertySearchLink( '…', $dvWikiPage->getWikiValue(), $this->mTitle->getText() );
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
@@ -113,9 +113,9 @@
114114 *
115115 * @return string
116116 */
117 - public function getTypeID() {
118 - return '_wpg';
119 - }
 117+// public function getTypeID() {
 118+// return '_wpg';
 119+// }
120120
121121 /**
122122 * Recursively restrict query to a maximal size and depth as given.
@@ -180,9 +180,9 @@
181181 * processing an SMWSomeProperty object where the property does not specify
182182 * the type.
183183 */
184 - public function getTypeID() {
185 - return '';
186 - }
 184+// public function getTypeID() {
 185+// return '';
 186+// }
187187 }
188188
189189 /**
@@ -216,7 +216,7 @@
217217 public function getQueryString( $asvalue = false ) {
218218 $first = true;
219219 foreach ( $this->m_diWikiPages as $wikiPage ) {
220 - $wikiValue = SMWDataValueFactory::newDataItemValue( $wikiPage );
 220+ $wikiValue = SMWDataValueFactory::newDataItemValue( $wikiPage, null );
221221 if ( $first ) {
222222 $result = '[[' . $wikiValue->getPrefixedText();
223223 $first = false;
@@ -296,7 +296,7 @@
297297 }
298298
299299 public function getQueryString( $asvalue = false ) {
300 - $pageValue = SMWDataValueFactory::newDataItemValue( $this->m_concept );
 300+ $pageValue = SMWDataValueFactory::newDataItemValue( $this->m_concept, null );
301301 $result = '[[' . $pageValue->getPrefixedText() . ']]';
302302 if ( $asvalue ) {
303303 return ' &lt;q&gt;' . $result . '&lt;/q&gt; ';
@@ -414,9 +414,9 @@
415415 return 1;
416416 }
417417
418 - public function getTypeID() {
419 - return $this->m_dataItem->getTypeID();
420 - }
 418+// public function getTypeID() {
 419+// return $this->m_dataItem->getTypeID();
 420+// }
421421
422422 }
423423
@@ -500,13 +500,13 @@
501501 return $depth;
502502 }
503503
504 - public function getTypeID() {
505 - if ( count( $this->m_descriptions ) > 0 ) { // all subdescriptions should have the same type!
506 - return reset( $this->m_descriptions )->getTypeID();
507 - } else {
508 - return ''; // unknown
509 - }
510 - }
 504+// public function getTypeID() {
 505+// if ( count( $this->m_descriptions ) > 0 ) { // all subdescriptions should have the same type!
 506+// return reset( $this->m_descriptions )->getTypeID();
 507+// } else {
 508+// return ''; // unknown
 509+// }
 510+// }
511511
512512 public function getQueryFeatures() {
513513 $result = SMW_CONJUNCTION_QUERY;
@@ -670,13 +670,13 @@
671671 return $depth;
672672 }
673673
674 - public function getTypeID() {
675 - if ( count( $this->m_descriptions ) > 0 ) { // all subdescriptions should have the same type!
676 - return reset( $this->m_descriptions )->getTypeID();
677 - } else {
678 - return ''; // unknown
679 - }
680 - }
 674+// public function getTypeID() {
 675+// if ( count( $this->m_descriptions ) > 0 ) { // all subdescriptions should have the same type!
 676+// return reset( $this->m_descriptions )->getTypeID();
 677+// } else {
 678+// return ''; // unknown
 679+// }
 680+// }
681681
682682 public function getQueryFeatures() {
683683 $result = SMW_DISJUNCTION_QUERY;
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_QueryResult.php
@@ -348,7 +348,12 @@
349349 if ( $di === false ) {
350350 return false;
351351 }
352 - $dv = SMWDataValueFactory::newDataItemValue( $di );
 352+ if ( $this->mPrintRequest->getMode() == SMWPrintRequest::PRINT_PROP ) {
 353+ $diProperty = $this->mPrintRequest->getData()->getDataItem();
 354+ } else {
 355+ $diProperty = null;
 356+ }
 357+ $dv = SMWDataValueFactory::newDataItemValue( $di, $diProperty );
353358 if ( $this->mPrintRequest->getOutputFormat() ) {
354359 $dv->setOutputFormat( $this->mPrintRequest->getOutputFormat() );
355360 }
@@ -368,12 +373,12 @@
369374 * @return string or false
370375 */
371376 public function getNextText( $outputMode, $linker = null ) {
372 - $dv = $this->getNextDataValue();
373 - if ( $dv !== false ) { // Print data values.
374 - if ( ( $dv->getTypeID() == '_wpg' ) || ( $dv->getTypeID() == '__sin' ) ) { // Prefer "long" text for page-values.
375 - return $dv->getLongText( $outputMode, $linker );
 377+ $dataValue = $this->getNextDataValue();
 378+ if ( $dataValue !== false ) { // Print data values.
 379+ if ( ( $dataValue->getTypeID() == '_wpg' ) || ( $dataValue->getTypeID() == '__sin' ) ) { // Prefer "long" text for page-values.
 380+ return $dataValue->getLongText( $outputMode, $linker );
376381 } else {
377 - return $dv->getShortText( $outputMode, $linker );
 382+ return $dataValue->getShortText( $outputMode, $linker );
378383 }
379384 } else {
380385 return false;
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php
@@ -134,9 +134,7 @@
135135
136136 /**
137137 * If this print request refers to some property, return the type id of this property.
138 - * Otherwise return FALSE.
139 - *
140 - * @todo It is unclear why the actual code returns '_wpg' as a default given this documentation.
 138+ * Otherwise return '_wpg' since all other types of print request return wiki pages.
141139 *
142140 * @return string
143141 */
@@ -145,10 +143,10 @@
146144 if ( $this->m_mode == SMWPrintRequest::PRINT_PROP ) {
147145 $this->m_typeid = $this->m_data->getDataItem()->findPropertyTypeID();
148146 } else {
149 - $this->m_typeid = '_wpg'; // return objects might be titles, but anyway
 147+ $this->m_typeid = '_wpg';
150148 }
151149 }
152 -
 150+
153151 return $this->m_typeid;
154152 }
155153
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php
@@ -474,7 +474,7 @@
475475 $this->m_queries[$cqid] = $cquery;
476476 }
477477 } elseif ( $description instanceof SMWValueDescription ) { // Only type '_wpg' objects can appear on query level (essentially as nominal classes).
478 - if ( $description->getDataItem()->getTypeID() == '_wpg' ) {
 478+ if ( $description->getDataItem() instanceof SMWDIWikiPage ) {
479479 if ( $description->getComparator() == SMW_CMP_EQ ) {
480480 $query->type = SMW_SQL2_VALUE;
481481 $oid = $this->m_store->getSMWPageID( $description->getDataItem()->getDBkey(), $description->getDataItem()->getNamespace(), $description->getDataItem()->getInterwiki() );
@@ -575,14 +575,8 @@
576576 */
577577 protected function compilePropertyCondition( SMWSQLStore2Query $query, SMWDIProperty $property, SMWDescription $valuedesc ) {
578578 $tableid = SMWSQLStore2::findPropertyTableID( $property );
 579+ $typeid = $property->findPropertyTypeID();
579580
580 - if ( $tableid == '' ) { // probably a type-polymorphic property
581 - $typeid = $valuedesc->getTypeID();
582 - $tableid = SMWSQLStore2::findTypeTableID( $typeid );
583 - } else { // normal property
584 - $typeid = $property->findPropertyTypeID();
585 - }
586 -
587581 if ( $tableid == '' ) { // Still no table to query? Give up.
588582 $query->type = SMW_SQL2_NOQUERY;
589583 return;
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SparqlStoreQueryEngine.php
@@ -787,44 +787,56 @@
788788 protected function buildValueCondition( SMWValueDescription $description, $joinVariable, $orderByProperty ) {
789789 $dataItem = $description->getDataItem();
790790
791 - $comparator = '';
792791 switch ( $description->getComparator() ) {
793 - case SMW_CMP_EQ: $comparator = '='; break;
 792+ case SMW_CMP_EQ: $comparator = '='; break;
794793 case SMW_CMP_LESS: $comparator = '<'; break;
795794 case SMW_CMP_GRTR: $comparator = '>'; break;
796 - case SMW_CMP_LEQ: $comparator = '<='; break;
797 - case SMW_CMP_GEQ: $comparator = '>='; break;
798 - case SMW_CMP_NEQ: $comparator = '!='; break;
 795+ case SMW_CMP_LEQ: $comparator = '<='; break;
 796+ case SMW_CMP_GEQ: $comparator = '>='; break;
 797+ case SMW_CMP_NEQ: $comparator = '!='; break;
799798 case SMW_CMP_LIKE: $comparator = 'regex'; break;
800 - case SMW_CMP_NLKE: $comparator = '!regex'; break;
 799+ case SMW_CMP_NLKE: $comparator = '!regex'; break;
 800+ default: $comparator = ''; // unkown, unsupported
801801 }
802802
803 - $namespaces = array();
804 - if ( $comparator == '=' ) {
805 - $expElement = SMWExporter::getDataItemExpElement( $dataItem );
806 - $result = new SMWSparqlSingletonCondition( $expElement );
807 - $this->addOrderByDataForProperty( $result, $joinVariable, $orderByProperty, $dataItem->getDIType() );
808 - } elseif ( ( $comparator == 'regex' || $comparator == '!regex' ) && ( $dataItem instanceof SMWDIBlob ) ) {
809 - $pattern = '^' . str_replace( array( '^', '.', '\\', '+', '{', '}', '(', ')', '|', '^', '$', '[', ']', '*', '?' ),
810 - array( '\^', '\.', '\\\\', '\+', '\{', '\}', '\(', '\)', '\|', '\^', '\$', '\[', '\]', '.*', '.' ),
811 - $dataItem->getString() ) . '$';
812 - $result = new SMWSparqlFilterCondition( "$comparator( ?$joinVariable, \"$pattern\", \"s\")", array() );
813 - $this->addOrderByDataForProperty( $result, $joinVariable, $orderByProperty, $dataItem->getDIType() );
814 - } elseif ( $comparator != '' ) {
 803+ if ( $comparator == '' ) {
 804+ $result = $this->buildTrueCondition( $joinVariable, $orderByProperty );
 805+ } elseif ( $comparator == '=' ) {
815806 $expElement = SMWExporter::getDataItemHelperExpElement( $dataItem );
816807 if ( $expElement === null ) {
817808 $expElement = SMWExporter::getDataItemExpElement( $dataItem );
818809 }
 810+ $result = new SMWSparqlSingletonCondition( $expElement );
 811+ $this->addOrderByDataForProperty( $result, $joinVariable, $orderByProperty, $dataItem->getDIType() );
 812+ } elseif ( $comparator == 'regex' || $comparator == '!regex' ) {
 813+ if ( $dataItem instanceof SMWDIBlob ) {
 814+ $pattern = '^' . str_replace( array( '^', '.', '\\', '+', '{', '}', '(', ')', '|', '^', '$', '[', ']', '*', '?' ),
 815+ array( '\^', '\.', '\\\\', '\+', '\{', '\}', '\(', '\)', '\|', '\^', '\$', '\[', '\]', '.*', '.' ),
 816+ $dataItem->getString() ) . '$';
 817+ $result = new SMWSparqlFilterCondition( "$comparator( ?$joinVariable, \"$pattern\", \"s\")", array() );
 818+ $this->addOrderByDataForProperty( $result, $joinVariable, $orderByProperty, $dataItem->getDIType() );
 819+ } else {
 820+ $result = $this->buildTrueCondition( $joinVariable, $orderByProperty );
 821+ }
 822+ } else {
819823 $result = new SMWSparqlFilterCondition( '', array() );
820824 $this->addOrderByData( $result, $joinVariable, $dataItem->getDIType() );
821825 $orderByVariable = $result->orderByVariable;
 826+
 827+ if ( $dataItem instanceof SMWDIWikiPage ) {
 828+ $expElement = SMWExporter::getDataItemExpElement( $dataItem->getSortKeyDataItem() );
 829+ } else {
 830+ $expElement = SMWExporter::getDataItemHelperExpElement( $dataItem );
 831+ if ( $expElement === null ) {
 832+ $expElement = SMWExporter::getDataItemExpElement( $dataItem );
 833+ }
 834+ }
 835+
822836 $valueName = SMWTurtleSerializer::getTurtleNameForExpElement( $expElement );
823837 if ( $expElement instanceof SMWExpNsResource ) {
824838 $result->namespaces[$expElement->getNamespaceId()] = $expElement->getNamespace();
825839 }
826840 $result->filter = "?$orderByVariable $comparator $valueName";
827 - } else {
828 - $result = $this->buildTrueCondition( $joinVariable, $orderByProperty );
829841 }
830842
831843 return $result;
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
@@ -45,7 +45,7 @@
4646 /// Array for keeping property table table data, indexed by table id.
4747 /// Access this only by calling getPropertyTables().
4848 protected static $prop_tables = array();
49 - /// Array to cache "propkey => propid" associations. Built only when needed.
 49+ /// Array to cache "propkey => table id" associations for fixed property tables. Built only when needed.
5050 protected static $fixed_prop_tables = null;
5151
5252 /// Use pre-defined ids for Very Important Properties, avoiding frequent ID lookups for those
@@ -71,76 +71,42 @@
7272 '_4' => 26,
7373 '_5' => 27,
7474 '_LIST' => 28,
 75+ '_MDAT' => 29,
7576 );
7677
77 - /// Array to cache ids of tables for storing known built-in types. Having
78 - /// this data here shortcuts the search in findTypeTableID() below.
79 - protected static $property_table_ids = array(
80 - '_txt' => 'smw_text2', // Text type
81 - '_cod' => 'smw_text2', // Code type
82 - '_str' => 'smw_atts2', // String type
83 - '_ema' => 'smw_atts2', // Email type
84 - '_uri' => 'smw_atts2', // URL/URI type
85 - '_anu' => 'smw_atts2', // Annotation URI type
86 - '_tel' => 'smw_atts2', // Telephone number
87 - '_wpg' => 'smw_rels2', // Page type
88 - '_wpp' => 'smw_rels2', // Property page type
89 - '_wpc' => 'smw_rels2', // Category page type
90 - '_wpf' => 'smw_rels2', // Form page type (for Semantic Forms)
91 - '_num' => 'smw_atts2', // Number type
92 - '_tem' => 'smw_atts2', // Temperature type
93 - '_dat' => 'smw_atts2', // Time type
94 - '_boo' => 'smw_atts2', // Boolean type
95 - '_rec' => 'smw_rels2', // Value list type (internal object)
96 - // Special types are not avaialble directly for users (and have no local language name):
97 - '__typ' => 'smw_spec2', // Special type page type
98 - '__tls' => 'smw_spec2', // Special type list for _rec properties
99 - '__sps' => 'smw_spec2', // Special string type
100 - '__spu' => 'smw_spec2', // Special uri type
101 - '__sup' => 'smw_subp2', // Special subproperty type
102 - '__suc' => 'smw_subs2', // Special subcategory type
103 - '__spf' => 'smw_spec2', // Special form type (for Semantic Forms)
104 - '__sin' => 'smw_inst2', // Special instance of type
105 - '__red' => 'smw_redi2', // Special redirect type
106 - '__lin' => 'smw_spec2', // Special linear unit conversion type
107 - '__imp' => 'smw_spec2', // Special import vocabulary type
108 - '__con' => 'smw_conc2', // Sepcial concept management and caching
109 - '__err' => '', // Special error type, used to indicate that the table could not be determined (happens for type-polymorphic _1, _2, ...)
 78+ /// Use special tables for Very Important Properties
 79+ protected static $special_tables = array(
 80+ '_TYPE' => 'smw_spec2',
 81+ '_URI' => 'smw_spec2',
 82+ '_INST' => 'smw_inst2',
 83+ '_UNIT' => 'smw_spec2',
 84+ '_IMPO' => 'smw_spec2',
 85+ '_CONV' => 'smw_spec2',
 86+ '_SERV' => 'smw_spec2',
 87+ '_PVAL' => 'smw_spec2',
 88+ '_REDI' => 'smw_redi2',
 89+ '_SUBP' => 'smw_subp2',
 90+ '_SUBC' => 'smw_subs2',
 91+ '_CONC' => 'smw_conc2',
 92+ '_SF_DF' => 'smw_spec2', // Semantic Form's default form property
 93+ '_SF_AF' => 'smw_spec2', // Semantic Form's alternate form property
 94+ //'_ERRP','_MDAT', '_SKEY' // no special table
 95+ '_LIST' => 'smw_spec2',
11096 );
11197
112 - /// Array to cache signatures of known built-in types. Having this data
113 - /// here safes us from creating datavalue instances in getTypeSignature().
114 - protected static $type_signatures = array(
115 - '_txt' => array( 'l', -1, -1 ), // Text type
116 - '_cod' => array( 'l', -1, -1 ), // Code type
117 - '_str' => array( 't', 0, 0 ), // String type
118 - '_ema' => array( 't', 0, 0 ), // Email type
119 - '_uri' => array( 't', 0, 0 ), // URL/URI type
120 - '_anu' => array( 't', 0, 0 ), // Annotation URI type
121 - '_tel' => array( 't', 0, 0 ), // Telephone number
122 - '_wpg' => array( 'tnwt', 3, 3 ), // Page type
123 - '_wpp' => array( 'tnwt', 3, 3 ), // Property page type
124 - '_wpc' => array( 'tnwt', 3, 3 ), // Category page type
125 - '_wpf' => array( 'tnwt', 3, 3 ), // Form page type (for Semantic Forms)
126 - '_num' => array( 'tf', 1, 0 ), // Number type
127 - '_tem' => array( 'tf', 1, 0 ), // Temperature type
128 - '_dat' => array( 'tf', 1, 0 ), // Time type
129 - '_boo' => array( 't', 0, 0 ), // Boolean type
130 - '_rec' => array( 'tnwt', 0, -1 ),// Value list type (internal object)
131 - // Special types are not avaialble directly for users (and have no local language name):
132 - '__typ' => array( 't', 0, 0 ), // Special type page type
133 - '__tls' => array( 't', 0, 0 ), // Special type page type
134 - '__sps' => array( 't', 0, 0 ), // Special string type
135 - '__spu' => array( 't', 0, 0 ), // Special uri type
136 - '__sup' => array( 'tnwt', 3, 3 ), // Special subproperty type
137 - '__suc' => array( 'tnwt', 3, 3 ), // Special subcategory type
138 - '__spf' => array( 't', 0, 0 ), // Special form type (for Semantic Forms)
139 - '__sin' => array( 'tnwt', 3, 3 ), // Special instance of type
140 - '__red' => array( 'tnwt', 3, 3 ), // Special redirect type
141 - '__lin' => array( 'tf', 1, 0 ), // Special linear unit conversion type
142 - '__imp' => array( 't', 0, 0 ), // Special import vocabulary type
143 - '__pro' => array( 't', 0, 0 ), // Property page type; never be stored as a value (_wpp is used there) but needed for sorting
144 - '' => array( 'tlnnn', 0, 0 )
 98+ /// Default tables to use for storing data of certain types.
 99+ protected static $di_type_tables = array(
 100+ SMWDataItem::TYPE_NUMBER => 'smw_atts2',
 101+ SMWDataItem::TYPE_STRING => 'smw_atts2',
 102+ SMWDataItem::TYPE_BLOB => 'smw_text2',
 103+ SMWDataItem::TYPE_BOOLEAN => 'smw_atts2',
 104+ SMWDataItem::TYPE_URI => 'smw_atts2',
 105+ SMWDataItem::TYPE_TIME => 'smw_atts2',
 106+ SMWDataItem::TYPE_GEO => 'smw_coords', // currently created only if Semantic Maps are installed
 107+ SMWDataItem::TYPE_CONTAINER => 'smw_rels2', // this is where the bnode is stored
 108+ SMWDataItem::TYPE_WIKIPAGE => 'smw_rels2',
 109+ SMWDataItem::TYPE_CONCEPT => 'smw_conc2', // unlikely to occur as value of a normal property
 110+ SMWDataItem::TYPE_PROPERTY => 'smw_atts2' // unlikely to occur as value of any property
145111 );
146112
147113 ///// Reading methods /////
@@ -444,10 +410,6 @@
445411 $pid = $this->getSMWPropertyID( $property );
446412 $tableid = self::findPropertyTableID( $property );
447413
448 - if ( ( $tableid == '' ) && ( $value !== null ) ) { // maybe a type-polymorphic property like _1; use value to find type
449 - $tableid = self::findTypeTableID( $value->getTypeID() );
450 - }
451 -
452414 if ( ( $pid == 0 ) || ( $tableid == '' ) ) {
453415 wfProfileOut( "SMWSQLStoreLight::getPropertySubjects (SMW)" );
454416 return array();
@@ -519,11 +481,6 @@
520482
521483 foreach ( $semanticData->getProperties() as $subproperty ) {
522484 $tableid = self::findPropertyTableID( $subproperty );
523 -
524 - if ( ( $tableid == '' ) && ( $value !== null ) ) { // maybe a type-polymorphic property like _1; use value to find type
525 - $tableid = self::findTypeTableID( reset( $semanticData->getPropertyValues( $subproperty ) )->getTypeID() );
526 - }
527 -
528485 $subproptable = $proptables[$tableid];
529486
530487 foreach ( $semanticData->getPropertyValues( $subproperty ) as $subvalue ) {
@@ -666,7 +623,6 @@
667624
668625 $db = wfGetDB( DB_SLAVE );
669626 $result = array();
670 - $typeid = $value->getTypeID();
671627
672628 // Potentially need to get more results, since options apply to union.
673629 if ( $requestoptions !== null ) {
@@ -677,10 +633,11 @@
678634 $suboptions = null;
679635 }
680636
681 - foreach ( self::getPropertyTables() as $tid => $proptable ) {
682 - if ( !$this->tableFitsType( $tid, $typeid ) ) continue;
 637+ $tableIds = self::findAllDiTypeTableIds( $value->getDIType() );
 638+ $proptables = self::getPropertyTables();
 639+ foreach ( $tableIds as $tid ) {
 640+ $proptable = $proptables[$tid];
683641 $select = $where = $from = '';
684 -
685642 if ( $proptable->fixedproperty == false ) { // join smw_ids to get property titles
686643 $from = $db->tableName( 'smw_ids' ) . " INNER JOIN " . $db->tableName( $proptable->name ) . " AS t1 ON t1.p_id=smw_id";
687644 $this->prepareValueQuery( $from, $where, $proptable, $value, 1 );
@@ -854,16 +811,6 @@
855812 }
856813
857814 $tableid = self::findPropertyTableID( $property );
858 -
859 - if ( !$tableid ) { // happens when table is not determined by property; use values to find type
860 - $di = reset( $data->getPropertyValues( $property ) );
861 - $tableid = self::findTypeTableID( $di->getTypeID() );
862 - }
863 -
864 - if ( !$tableid ) { // can't store this data, sorry
865 - return $sid;
866 - }
867 -
868815 $proptable = $proptables[$tableid];
869816
870817 foreach ( $data->getPropertyValues( $property ) as $di ) {
@@ -1107,11 +1054,12 @@
11081055 }
11091056
11101057 // properties that have subproperties are considered to be used
1111 - $proptables = self::getPropertyTables();
1112 - $subtable = $proptables[self::findTypeTableID( '__sup' )]; // find the subproperty table, but consider its signature to be known
 1058+ $propertyTables = self::getPropertyTables();
 1059+ $subPropertyTableId = self::$special_tables['_SUBP'];
 1060+ $subPropertyTable = $propertyTables[$subPropertyTableId];
11131061
11141062 // (again we have no fitting MW wrapper here:)
1115 - $db->query( "DELETE $smw_tmp_unusedprops.* FROM $smw_tmp_unusedprops," . $db->tableName( $subtable->name ) .
 1063+ $db->query( "DELETE $smw_tmp_unusedprops.* FROM $smw_tmp_unusedprops," . $db->tableName( $subPropertyTable->name ) .
11161064 " INNER JOIN $smw_ids ON o_id=smw_id WHERE title=smw_title", $fname );
11171065 // properties that are redirects are considered to be used:
11181066 // (a stricter and more costy approach would be to delete only redirects to used properties;
@@ -1153,7 +1101,7 @@
11541102
11551103 // Note that Wanted Properties must have the default type.
11561104 $proptables = self::getPropertyTables();
1157 - $proptable = $proptables[self::findTypeTableID( $smwgPDefaultType )];
 1105+ $proptable = $proptables[self::findTypeTableId( $smwgPDefaultType )];
11581106
11591107 $result = array();
11601108
@@ -1648,14 +1596,14 @@
16491597 }
16501598
16511599 /**
1652 - * Transform input parameters into a suitable string of additional SQL conditions.
1653 - * The parameter $valuecol defines the string name of the column to which
1654 - * value restrictions etc. are to be applied.
 1600+ * Transform input parameters into a suitable string of additional SQL
 1601+ * conditions. The parameter $valuecol defines the string name of the
 1602+ * column to which value restrictions etc. are to be applied.
16551603 *
16561604 * @param $requestoptions object with options
1657 - * @param $valuecol name of SQL column to which conditions apply
1658 - * @param $labelcol name of SQL column to which string conditions apply, if any
1659 - * @param $addand Boolean to indicate whether the string should begin with " AND " if non-empty
 1605+ * @param $valuecol string name of SQL column to which conditions apply
 1606+ * @param $labelcol string name of SQL column to which string conditions apply, if any
 1607+ * @param $addand boolean to indicate whether the string should begin with " AND " if non-empty
16601608 *
16611609 * @return string
16621610 */
@@ -1694,10 +1642,10 @@
16951643
16961644 /**
16971645 * Not in all cases can requestoptions be forwarded to the DB using
1698 - * getSQLConditions() and getSQLOptions(): some data comes from caches that
1699 - * do not respect the options yet. This method takes an array of results
1700 - * (SMWDataValue objects) *of the same type* and applies the given
1701 - * requestoptions as appropriate.
 1646+ * getSQLConditions() and getSQLOptions(): some data comes from caches
 1647+ * that do not respect the options yet. This method takes an array of
 1648+ * results (SMWDataItem objects) *of the same type* and applies the
 1649+ * given requestoptions as appropriate.
17021650 */
17031651 protected function applyRequestOptions( $data, $requestoptions ) {
17041652 wfProfileIn( "SMWSQLStore2::applyRequestOptions (SMW)" );
@@ -1710,18 +1658,22 @@
17111659 $result = array();
17121660 $sortres = array();
17131661
1714 - list( $sig, $valueIndex, $labelIndex ) = self::getTypeSignature( reset( $data )->getTypeID() );
 1662+ $sampleDataItem = reset( $data );
 1663+ $numeric = is_numeric( $sampleDataItem->getSortKey() );
17151664
1716 - $numeric = ( ( $valueIndex >= 0 ) && ( strlen( $sig ) > $valueIndex ) &&
1717 - ( ( $sig { $valueIndex } != 'f' ) || ( $sig { $valueIndex } != 'n' ) ) );
17181665 $i = 0;
17191666
17201667 foreach ( $data as $item ) {
17211668 $ok = true; // keep datavalue only if this remains true
1722 - $keys = SMWCompatibilityHelpers::getDBkeysFromDataItem( $item );
1723 - $value = array_key_exists( $valueIndex, $keys ) ? $keys[$valueIndex] : '';
1724 - $label = array_key_exists( $labelIndex, $keys ) ? $keys[$labelIndex] : '';
17251669
 1670+ if ( $item instanceof SMWDIWikiPage ) {
 1671+ $label = $this->getWikiPageSortKey( $item );
 1672+ $value = $label;
 1673+ } else {
 1674+ $label = ( $item instanceof SMWDIBlob ) ? $item->getString() : '';
 1675+ $value = $item->getSortKey();
 1676+ }
 1677+
17261678 if ( $requestoptions->boundary !== null ) { // apply value boundary
17271679 $strc = $numeric ? 0 : strcmp( $value, $requestoptions->boundary );
17281680
@@ -1762,7 +1714,7 @@
17631715 }
17641716
17651717 if ( $requestoptions->sort ) {
1766 - $flag = $numeric ? SORT_NUMERIC:SORT_LOCALE_STRING;
 1718+ $flag = $numeric ? SORT_NUMERIC : SORT_LOCALE_STRING;
17671719
17681720 if ( $requestoptions->ascending ) {
17691721 asort( $sortres, $flag );
@@ -1811,20 +1763,13 @@
18121764 * appropriate property table and information about sorting/filtering
18131765 * data of this type can be obtained. The result is an array of three
18141766 * entries: a signature string, the index of the value field, and
1815 - * the index of the label label field. These entries correspond to
1816 - * the results of SMWDataValue::getSignature(),
1817 - * SMWDatavalue::getValueIndex(), and SMWDatavalue::getLabelIndex().
1818 - * @todo Custom unit types (SMWLinearValue) have page names as their
1819 - * type id and are not in the array cache. Can we still determine their
1820 - * signature without creating them?
 1767+ * the index of the label label field.
18211768 */
18221769 public static function getTypeSignature( $typeid ) {
1823 - if ( !array_key_exists( $typeid, self::$type_signatures ) ) {
1824 - $dv = SMWDataValueFactory::newTypeIDValue( $typeid );
1825 - self::$type_signatures[$typeid] = array( $dv->getSignature(), $dv->getValueIndex(), $dv->getLabelIndex() );
1826 - }
1827 -
1828 - return self::$type_signatures[$typeid];
 1770+ $dataItemId = SMWDataValueFactory::getDataItemId( $typeid );
 1771+ return array( SMWCompatibilityHelpers::getSignatureFromDataItemId( $dataItemId, $typeid ),
 1772+ SMWCompatibilityHelpers::getIndexFromDataItemId( $dataItemId, $typeid, false ),
 1773+ SMWCompatibilityHelpers::getIndexFromDataItemId( $dataItemId, $typeid, true ) );
18291774 }
18301775
18311776 /**
@@ -1832,68 +1777,98 @@
18331778 * signature, where $signature is as returned by getTypeSignature().
18341779 * @todo Maybe rather use SMWSQLStore2Table object as parameter.
18351780 */
1836 - public static function tableFitsSignature( $tableid, $signature ) {
1837 - $proptables = self::getPropertyTables();
1838 - $tablesig = str_replace( 'p', 'tnwt', $proptables[$tableid]->getFieldSignature() ); // expand internal page type to single fields
1839 - $valuesig = reset( $signature );
1840 - return ( $valuesig == substr( $tablesig, 0, strlen( $valuesig ) ) );
1841 - }
 1781+// private static function tableFitsSignature( $tableid, $signature ) {
 1782+// $proptables = self::getPropertyTables();
 1783+// $tablesig = str_replace( 'p', 'tnwt', $proptables[$tableid]->getFieldSignature() ); // expand internal page type to single fields
 1784+// $valuesig = reset( $signature );
 1785+// return ( $valuesig == substr( $tablesig, 0, strlen( $valuesig ) ) );
 1786+// }
18421787
18431788 /**
18441789 * Check if the given table can be used to store values of the given
1845 - * type.
 1790+ * type. This is needed to apply the type-based filtering in
 1791+ * getSemanticData().
 1792+ *
 1793+ * @param $tableId string
 1794+ * @param $typeId string
 1795+ * @return boolean
18461796 */
1847 - public static function tableFitsType( $tableid, $typeid ) {
1848 - return self::tableFitsSignature( $tableid, self::getTypeSignature( $typeid ) );
 1797+ public static function tableFitsType( $tableId, $typeId ) {
 1798+ $dataItemId = SMWDataValueFactory::getDataItemId( $typeId );
 1799+ if ( $tableId == self::findDiTypeTableId( $dataItemId ) ) {
 1800+ return true;
 1801+ }
 1802+ foreach ( self::$special_tables as $propertyKey => $specialTableId ) {
 1803+ if ( $specialTableId == $tableId ) {
 1804+ $diProperty = new SMWDIProperty( $propertyKey, false );
 1805+ $propertyTypeId = $diProperty->findPropertyTypeId();
 1806+ if ( $typeId == $propertyTypeId ) {
 1807+ return true;
 1808+ }
 1809+ }
 1810+ }
 1811+ return false;
18491812 }
18501813
18511814 /**
18521815 * Find the id of a property table that is suitable for storing values of
18531816 * the given type. The type is specified by an SMW type id such as '_wpg'.
18541817 * An empty string is returned if no matching table could be found.
 1818+ *
 1819+ * @param $typeid string
 1820+ * @return string
18551821 */
1856 - public static function findTypeTableID( $typeid ) {
1857 - if ( !array_key_exists( $typeid, self::$property_table_ids ) ) {
1858 - $signature = self::getTypeSignature( $typeid );
 1822+ public static function findTypeTableId( $typeid ) {
 1823+ $dataItemId = SMWDataValueFactory::getDataItemId( $typeid );
 1824+ return self::findDiTypeTableId( $dataItemId );
 1825+ }
18591826
1860 - foreach ( self::getPropertyTables() as $tid => $proptable ) {
1861 - if ( self::tableFitsSignature( $tid, $signature ) ) {
1862 - self::$property_table_ids[$typeid] = $tid;
1863 - return $tid;
1864 - }
1865 - }
 1827+ /**
 1828+ * Find the id of a property table that is normally used to store
 1829+ * data items of the given type.
 1830+ *
 1831+ * @param $dataItemId integer
 1832+ * @return string
 1833+ */
 1834+ public static function findDiTypeTableId( $dataItemId ) {
 1835+ return self::$di_type_tables[$dataItemId];
 1836+ }
18661837
1867 - self::$property_table_ids[$typeid] = ''; // No matching table found.
 1838+ /**
 1839+ * Find the id of all property tables where data items of the given
 1840+ * type could possibly be stored.
 1841+ *
 1842+ * @param $dataItemId integer
 1843+ * @return array of string
 1844+ */
 1845+ public static function findAllDiTypeTableIds( $dataItemId ) {
 1846+ $result = array( self::findDiTypeTableId( $dataItemId ) );
 1847+
 1848+ foreach ( self::$special_tables as $propertyKey => $specialTableId ) {
 1849+ $diProperty = new SMWDIProperty( $propertyKey, false );
 1850+ $propertyTypeId = $diProperty->findPropertyTypeId();
 1851+ if ( $dataItemId == SMWDataValueFactory::getDataItemId( $dataItemId ) ) {
 1852+ $result[] = $specialTableId;
 1853+ }
18681854 }
18691855
1870 - return self::$property_table_ids[$typeid];
 1856+ return $result;
18711857 }
18721858
18731859 /**
18741860 * Retrieve the id of the property table that is to be used for storing
18751861 * values for the given property object.
 1862+ *
 1863+ * @param $diProperty SMWDIProperty
 1864+ * @return string
18761865 */
1877 - public static function findPropertyTableID( SMWDIProperty $property ) {
1878 - if ( self::$fixed_prop_tables === null ) { // Build lookup array once.
1879 - self::$fixed_prop_tables = array();
1880 -
1881 - foreach ( self::getPropertyTables() as $tid => $proptable ) {
1882 - if ( $proptable->fixedproperty != false ) {
1883 - self::$fixed_prop_tables[$proptable->fixedproperty] = $tid;
1884 - }
1885 - }
 1866+ public static function findPropertyTableID( SMWDIProperty $diProperty ) {
 1867+ $propertyKey = $diProperty->getKey();
 1868+ if ( array_key_exists( $propertyKey, self::$special_tables ) ) {
 1869+ return self::$special_tables[$propertyKey];
 1870+ } else {
 1871+ return self::findTypeTableId( $diProperty->findPropertyTypeID() );
18861872 }
1887 -
1888 - $propertykey = $property->getKey();
1889 - if ( array_key_exists( $propertykey, self::$fixed_prop_tables ) ) {
1890 - $signature = self::getTypeSignature( $property->findPropertyTypeID() );
1891 -
1892 - if ( self::tableFitsSignature( SMWSQLStore2::$fixed_prop_tables[$propertykey], $signature ) ) {
1893 - return self::$fixed_prop_tables[$propertykey];
1894 - }
1895 - } // else: Don't check for non-fitting entries in $fixed_prop_tables: not really important.
1896 -
1897 - return self::findTypeTableID( $property->findPropertyTypeID() );
18981873 }
18991874
19001875 /**
@@ -2455,22 +2430,19 @@
24562431 * indexed by table ids. Note that the ids are only for accessing the data
24572432 * and should not be assumed to agree with the table name.
24582433 *
2459 - * Most function in this class are independent of the available property
2460 - * tables, although the store might not be able to handle proeprty data for
2461 - * which no suitable table is given. Note that the cached tables of
2462 - * SMWSQLStore2::$property_table_ids refer to IDs that should be available.
2463 - * The only other table that must always be available is smw_redi2 for
2464 - * managing redirects.
2465 - *
24662434 * Tables declare value columns ("object fields") by specifying their name
2467 - * and type. Types are given using letters as documented for
2468 - * SMWDataValue::getSignature(), or the additional letter:
 2435+ * and type. Types are given using letters:
 2436+ * - t for strings of the same maximal length as MediaWiki title names,
 2437+ * - l for arbitrarily long strings; searching/sorting with such data may
 2438+ * be limited for performance reasons,
 2439+ * - w for strings as used in MediaWiki for encoding interwiki prefixes
 2440+ * - n for namespace numbers (or other similar integers)
 2441+ * - f for floating point numbers of double precision
 2442+ * - c for the special container format used by SMWContainerValue; if used
 2443+ * then the signature must be 'c' without any other fields.
24692444 * - p for a reference to an SMW ID as stored in the smw_ids table; this
24702445 * corresponds to a data entry of ID "tnwt".
24712446 *
2472 - * This letter is specific to this store's ID referencing and must not be
2473 - * used in SMWDataValue::getSignature()!
2474 - *
24752447 * @return array of SMWSQLStore2Table
24762448 * @todo The concept table should make s_id a primary key; make this possible.
24772449 */
@@ -2539,6 +2511,12 @@
25402512
25412513 wfRunHooks( 'SMWPropertyTables', array( &self::$prop_tables ) );
25422514
 2515+ foreach ( self::$prop_tables as $tid => $proptable ) { // fixed property tables are added to known "special" tables
 2516+ if ( $proptable->fixedproperty != false ) {
 2517+ self::$special_tables[$proptable->fixedproperty] = $tid;
 2518+ }
 2519+ }
 2520+
25432521 return self::$prop_tables;
25442522 }
25452523
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_CompatibilityHelpers.php
@@ -35,18 +35,22 @@
3636 */
3737 static public function dataItemFromDBKeys( $typeid, $dbkeys, $diProperty = null ) {
3838 switch ( SMWDataValueFactory::getDataItemId( $typeid ) ) {
39 - case SMWDataItem::TYPE_ERROR:
 39+ case SMWDataItem::TYPE_ERROR: case SMWDataItem::TYPE_NOTYPE:
4040 break;
4141 case SMWDataItem::TYPE_NUMBER:
42 - return SMWDINumber::doUnserialize( $dbkeys[0], $typeid );
 42+ return SMWDINumber::doUnserialize( $dbkeys[0] );
4343 case SMWDataItem::TYPE_STRING:
44 - return new SMWDIString( $dbkeys[0], $typeid );
 44+ return new SMWDIString( $dbkeys[0] );
4545 case SMWDataItem::TYPE_BLOB:
46 - return new SMWDIBlob( $dbkeys[0], $typeid );
 46+ return new SMWDIBlob( $dbkeys[0] );
4747 case SMWDataItem::TYPE_BOOLEAN:
48 - return new SMWDIBoolean( ( $dbkeys[0] == '1' ), $typeid );
 48+ return new SMWDIBoolean( ( $dbkeys[0] == '1' ) );
4949 case SMWDataItem::TYPE_URI:
50 - return SMWDIUri::doUnserialize( $dbkeys[0], $typeid);
 50+ if ( $typeid == '__typ' && $dbkeys[0]{0} == '_' ) { // b/c: old data stored as type ids
 51+ return SMWTypesValue::getTypeUriFromTypeId( $dbkeys[0] );
 52+ } else {
 53+ return SMWDIUri::doUnserialize( $dbkeys[0]);
 54+ }
5155 case SMWDataItem::TYPE_TIME:
5256 $timedate = explode( 'T', $dbkeys[0], 2 );
5357 if ( ( count( $dbkeys ) == 2 ) && ( count( $timedate ) == 2 ) ) {
@@ -65,12 +69,12 @@
6670 if ( $month == '' ) $month = false;
6771 if ( $day == '' ) $day = false;
6872 $calendarmodel = SMWDITime::CM_GREGORIAN;
69 - return new SMWDITime( $calendarmodel, $year, $month, $day, $hours, $minutes, $seconds, $typeid );
 73+ return new SMWDITime( $calendarmodel, $year, $month, $day, $hours, $minutes, $seconds );
7074 }
7175 }
7276 break;
7377 case SMWDataItem::TYPE_GEO:
74 - return new SMWDIGeoCoord( array( 'lat' => (float)$dbkeys[0], 'lon' => (float)$dbkeys[1] ), $typeid );
 78+ return new SMWDIGeoCoord( array( 'lat' => (float)$dbkeys[0], 'lon' => (float)$dbkeys[1] ) );
7579 case SMWDataItem::TYPE_CONTAINER:
7680 $semanticData = new SMWContainerSemanticData();
7781 if ( $typeid == '_rec' ) {
@@ -94,53 +98,44 @@
9599 }
96100 }
97101 }
98 - return new SMWDIContainer( $semanticData, $typeid );
 102+ return new SMWDIContainer( $semanticData );
99103 case SMWDataItem::TYPE_WIKIPAGE:
100 - if ( $typeid == '__typ' ) { // DBkeys for types values are special (used to be a SMWSimpleWikiPageValue)
 104+ if ( $typeid == '__spf' ) {
101105 $pagedbkey = str_replace( ' ', '_', SMWDataValueFactory::findTypeLabel( $dbkeys[0] ) );
102 - return new SMWDIWikiPage( $pagedbkey, SMW_NS_TYPE, '', $typeid );
103 - } elseif ( $typeid == '__spf' ) {
104 - $pagedbkey = str_replace( ' ', '_', SMWDataValueFactory::findTypeLabel( $dbkeys[0] ) );
105 - return new SMWDIWikiPage( $pagedbkey, SF_NS_FORM, '', $typeid );
 106+ return new SMWDIWikiPage( $pagedbkey, SF_NS_FORM, '' );
106107 } elseif ( count( $dbkeys ) >= 3 ) {
107 - return new SMWDIWikiPage( $dbkeys[0], floatval( $dbkeys[1] ), $dbkeys[2], $typeid );
 108+ return new SMWDIWikiPage( $dbkeys[0], floatval( $dbkeys[1] ), $dbkeys[2] );
108109 }
109110 break;
110111 case SMWDataItem::TYPE_CONCEPT:
111112 if ( count( $dbkeys ) >= 5 ) {
112 - new SMWDIConcept( $dbkeys[0], smwfXMLContentEncode( $dbkeys[1] ), $dbkeys[2], $dbkeys[3], $dbkeys[4], $typeid );
 113+ new SMWDIConcept( $dbkeys[0], smwfXMLContentEncode( $dbkeys[1] ), $dbkeys[2], $dbkeys[3], $dbkeys[4] );
113114 }
114115 break;
115116 case SMWDataItem::TYPE_PROPERTY:
116 - return new SMWDIProperty( $dbkeys[0], false, $typeid );
117 - case SMWDataItem::TYPE_NOTYPE:
118 - if ( ( $typeid != '' ) && ( $typeid{0} != '_' ) ) { // linear conversion type
119 - return SMWDINumber::doUnserialize( $dbkeys[0], $typeid );
120 - }
 117+ return new SMWDIProperty( $dbkeys[0], false );
121118 }
122119 throw new SMWDataItemException( 'Failed to create data item from DB keys.' );
123120 }
124121
125122 /**
126 - * Compatibility function for computing the old getDBkeys() array for the new SMW data items.
 123+ * Compatibility function for computing the old getDBkeys() array for
 124+ * the new SMW data items.
 125+ *
 126+ * @param $dataItem SMWDataItem
 127+ * @return array of mixed
127128 */
128129 public static function getDBkeysFromDataItem( SMWDataItem $dataItem ) {
129 - switch ( $dataItem->getTypeId() ) {
130 - case '_txt': case '_cod': case '_str': case '__sps': case '__tls': case '__imp':
131 - if ( $dataItem->getDIType() !== SMWDataItem::TYPE_STRING ) break;
 130+ switch ( $dataItem->getDIType() ) {
 131+ case SMWDataItem::TYPE_STRING:
132132 return array( $dataItem->getString() );
133 - case '_ema': case '_uri': case '_anu': case '_tel': case '__spu':
134 - if ( $dataItem->getDIType() !== SMWDataItem::TYPE_URI ) break;
 133+ case SMWDataItem::TYPE_URI:
135134 return array( $dataItem->getSerialization() );
136 - case '_wpg': case '_wpp': case '_wpc': case '_wpf': case '__sup':
137 - case '__suc': case '__spf': case '__sin': case '__red':
138 - if ( $dataItem->getDIType() !== SMWDataItem::TYPE_WIKIPAGE ) break;
139 - return array( $dataItem->getDBkey(), $dataItem->getNamespace(), $dataItem->getInterwiki(), $dataItem->getDBkey() );
140 - case '_num': case '_tem': case '__lin':
141 - if ( $dataItem->getDIType() !== SMWDataItem::TYPE_NUMBER ) break;
 135+ case SMWDataItem::TYPE_WIKIPAGE:
 136+ return array( $dataItem->getDBkey(), $dataItem->getNamespace(), $dataItem->getInterwiki(), $dataItem->getSortKey() );
 137+ case SMWDataItem::TYPE_NUMBER:
142138 return array( $dataItem->getSerialization(), floatval( $dataItem->getNumber() ) );
143 - case '_dat':
144 - if ( $dataItem->getDIType() !== SMWDataItem::TYPE_TIME ) break;
 139+ case SMWDataItem::TYPE_TIME:
145140 $xsdvalue = $dataItem->getYear() . "/" .
146141 ( ( $dataItem->getPrecision() >= SMWDITime::PREC_YM ) ? $dataItem->getMonth() : '' ) . "/" .
147142 ( ( $dataItem->getPrecision() >= SMWDITime::PREC_YMD ) ? $dataItem->getDay() : '' ) . "T";
@@ -150,39 +145,87 @@
151146 sprintf( "%02d", $dataItem->getSecond() );
152147 }
153148 return array( $xsdvalue, $dataItem->getSortKey() );
154 - case '_boo':
155 - if ( $dataItem->getDIType() !== SMWDataItem::TYPE_BOOLEAN ) break;
 149+ case SMWDataItem::TYPE_BOOLEAN:
156150 return $dataItem->getBoolean() ? array( '1', 1 ) : array( '0', 0 );
157 - case '_rec':
158 - if ( $dataItem->getDIType() !== SMWDataItem::TYPE_CONTAINER ) break;
 151+ case SMWDataItem::TYPE_CONTAINER:
159152 return array( false );
160 - case '__typ':
161 - if ( $dataItem->getDIType() !== SMWDataItem::TYPE_WIKIPAGE ) break;
162 - return array( SMWDataValueFactory::findTypeID( str_replace( '_', ' ', $dataItem->getDBkey() ) ) );
163 - case '__con':
164 - if ( $dataItem->getDIType() !== SMWDataItem::TYPE_CONCEPT ) break;
 153+ case SMWDataItem::TYPE_CONCEPT:
165154 return array( $dataItem->getConceptQuery(), $dataItem->getDocumentation(), $dataItem->getQueryFeatures(), $dataItem->getSize(), $dataItem->getDepth() );
166 - case '__err':
167 - return array( false );
168 - case '__pro':
169 - if ( $dataItem->getDIType() !== SMWDataItem::TYPE_PROPERTY ) break;
 155+ case SMWDataItem::TYPE_PROPERTY:
170156 return array( $dataItem->getKey() );
171 - case '_geo':
 157+ case SMWDataItem::TYPE_GEO:
172158 $coordinateSet = $dataItem->getCoordinateSet();
173 -
174159 return array(
175160 $coordinateSet['lat'],
176161 $coordinateSet['lon']
177162 );
178 - break;
179163 default:
180 - $typeid = $dataItem->getTypeId();
181 - if ( ( $typeid != '' ) && ( $typeid{0} != '_' ) &&
182 - ( $dataItem->getDIType() == SMWDataItem::TYPE_NUMBER ) ) { // linear conversion type
183 - return array( $dataItem->getSerialization(), floatval( $dataItem->getNumber() ) );
184 - }
 164+ return array( false );
185165 }
186 - return array( false );
187166 }
188167
 168+ /**
 169+ * Compatibility function for computing the old getSignature() string
 170+ * based on dataitem IDs. To maintain full compatibility, the typeid
 171+ * is relevant here, too.
 172+ *
 173+ * @note Use SMWDataValueFactory::getDataItemId() if only the $typeid
 174+ * is known.
 175+ *
 176+ * @param $dataItemId integer
 177+ * @param $typeid string
 178+ * @return string
 179+ */
 180+ public static function getSignatureFromDataItemId( $dataItemId, $typeid ) {
 181+ switch ( $dataItemId ) {
 182+ case SMWDataItem::TYPE_STRING:
 183+ return ( ( $typeid == '_txt' ) || ( $typeid == '_cod' ) ) ? 'l' : 't';
 184+ case SMWDataItem::TYPE_URI: case SMWDataItem::TYPE_PROPERTY:
 185+ return 't';
 186+ case SMWDataItem::TYPE_WIKIPAGE:
 187+ return 'tnwt';
 188+ case SMWDataItem::TYPE_NUMBER: case SMWDataItem::TYPE_TIME:
 189+ return 'tf';
 190+ case SMWDataItem::TYPE_BOOLEAN:
 191+ return 'tn';
 192+ case SMWDataItem::TYPE_CONTAINER:
 193+ return 'c';
 194+ case SMWDataItem::TYPE_CONCEPT:
 195+ return 'llnnn';
 196+ case SMWDataItem::TYPE_GEO:
 197+ return 'ff';
 198+ default:
 199+ return '';
 200+ }
 201+ }
 202+
 203+ /**
 204+ * Compatibility function for computing the old getValueIndex() and
 205+ * getLabelIndex() numbers based on dataitem IDs. To maintain full
 206+ * compatibility, the typeid is relevant here, too.
 207+ *
 208+ * @note Use SMWDataValueFactory::getDataItemId() if only the $typeid
 209+ * is known.
 210+ *
 211+ * @param $dataItemId integer
 212+ * @param $typeid string
 213+ * @param $labelIndex boolean, if true get the label index, else the value index
 214+ * @return string
 215+ */
 216+ public static function getIndexFromDataItemId( $dataItemId, $typeid, $labelIndex = false ) {
 217+ switch ( $dataItemId ) {
 218+ case SMWDataItem::TYPE_STRING:
 219+ return ( ( $typeid == '_txt' ) || ( $typeid == '_cod' ) ) ? -1 : 0;
 220+ case SMWDataItem::TYPE_WIKIPAGE:
 221+ return 3;
 222+ case SMWDataItem::TYPE_NUMBER: case SMWDataItem::TYPE_TIME: case SMWDataItem::TYPE_BOOLEAN:
 223+ return $labelIndex ? 0 : 1;
 224+ case SMWDataItem::TYPE_URI: case SMWDataItem::TYPE_PROPERTY:
 225+ case SMWDataItem::TYPE_CONCEPT: case SMWDataItem::TYPE_GEO:
 226+ return 0;
 227+ case SMWDataItem::TYPE_CONTAINER: default:
 228+ return -1;
 229+ }
 230+ }
 231+
189232 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
@@ -55,6 +55,28 @@
5656 static private $mTypeDataItemIds;
5757
5858 /**
 59+ * Array of default types to use for making datavalues for dataitems.
 60+ *
 61+ * @var array of string
 62+ */
 63+ static private $mDefaultDataItemTypeIds = array(
 64+ SMWDataItem::TYPE_BLOB => '_txt', // Text type
 65+ SMWDataItem::TYPE_STRING => '_str', // String type
 66+ SMWDataItem::TYPE_URI => '_uri', // URL/URI type
 67+ SMWDataItem::TYPE_WIKIPAGE => '_wpg', // Page type
 68+ SMWDataItem::TYPE_NUMBER => '_num', // Number type
 69+ SMWDataItem::TYPE_TIME => '_dat', // Time type
 70+ SMWDataItem::TYPE_BOOLEAN => '_boo', // Boolean type
 71+ SMWDataItem::TYPE_CONTAINER => '_rec', // Value list type (replacing former nary properties)
 72+ SMWDataItem::TYPE_GEO => '_geo', // Geographical coordinates
 73+ SMWDataItem::TYPE_CONCEPT => '__con', // Special concept page type
 74+ SMWDataItem::TYPE_PROPERTY => '__pro', // Property type
 75+ // If either of the following two occurs, we want to see a PHP error:
 76+ //SMWDataItem::TYPE_NOTYPE => '',
 77+ //SMWDataItem::TYPE_ERROR => '',
 78+ );
 79+
 80+ /**
5981 * Create an SMWDataValue object that can hold values for the type that the
6082 * given SMWTypesValue object specifies. If no $value is given, an empty
6183 * container is created, the value of which can be set later on.
@@ -112,14 +134,20 @@
113135 /**
114136 * Create a value for a data item.
115137 *
116 - * @param $typeid SMWDataItem id string for the given type
 138+ * @param $dataItem SMWDataItem
 139+ * @param $property mixed null or SMWDIProperty property object for which this value is made
117140 * @param $caption mixed user-defined caption, or false if none given
118 - * @param $property SMWDIProperty property object for which this value is made, or NULL
119141 *
120142 * @return SMWDataValue
121143 */
122 - static public function newDataItemValue( SMWDataItem $dataItem, $caption = false, $property = null ) {
123 - $result = self::newTypeIdValue( $dataItem->getTypeID(), false, $caption, $property );
 144+ static public function newDataItemValue( SMWDataItem $dataItem, $property, $caption = false ) {
 145+ if ( $property !== null ) {
 146+ $typeid = $property->findPropertyTypeID();
 147+ } else {
 148+ $typeid = self::$mDefaultDataItemTypeIds[$dataItem->getDiType()];
 149+ }
 150+
 151+ $result = self::newTypeIdValue( $typeid, false, $caption, $property );
124152 $result->setDataItem( $dataItem );
125153 if ( $caption !== false ) {
126154 $result->setCaption( $caption );
@@ -236,8 +264,8 @@
237265 '_rec' => SMWDataItem::TYPE_CONTAINER, // Value list type (replacing former nary properties)
238266 '_geo' => SMWDataItem::TYPE_GEO, // Geographical coordinates
239267 // Special types are not avaialble directly for users (and have no local language name):
240 - '__typ' => SMWDataItem::TYPE_WIKIPAGE, // Special type page type
241 - '__tls' => SMWDataItem::TYPE_STRING, // Special type list for decalring _rec properties
 268+ '__typ' => SMWDataItem::TYPE_URI, // Special type page type
 269+ '__tls' => SMWDataItem::TYPE_STRING, // Special type list for declaring _rec properties
242270 '__con' => SMWDataItem::TYPE_CONCEPT, // Special concept page type
243271 '__sps' => SMWDataItem::TYPE_STRING, // Special string type
244272 '__spu' => SMWDataItem::TYPE_URI, // Special uri type
@@ -289,16 +317,15 @@
290318
291319 /**
292320 * Look up the ID that identifies the datatype of the given label
293 - * internally. This id is used for all internal operations. Compound types
294 - * are not supported by this method (decomposition happens earlier). Custom
295 - * types get their DBkeyed label as id. All ids are prefixed by an
296 - * underscore in order to distinguish them from custom types.
 321+ * internally. This id is used for all internal operations. If the
 322+ * label does not bleong to a known type, the empty string is returned.
297323 *
298 - * This method may or may not take aliases into account. For unknown
299 - * labels, the normalised (DB-version) label is used as an ID.
 324+ * This method may or may not take aliases into account, depeding on
 325+ * the parameter $useAlias.
300326 *
301327 * @param string $label
302328 * @param boolean $useAlias
 329+ * @return string
303330 */
304331 static public function findTypeID( $label, $useAlias = true ) {
305332 self::initDatatypes();
@@ -309,30 +336,28 @@
310337 } elseif ( ( $useAlias ) && ( array_key_exists( $label, self::$mTypeAliases ) ) ) {
311338 return self::$mTypeAliases[$label];
312339 } else {
313 - return str_replace( ' ', '_', $label );
 340+ return '';
314341 }
315342 }
316343
317344 /**
318345 * Get the translated user label for a given internal ID. If the ID does
319 - * not have a label associated with it in the current language, the ID
320 - * itself is transformed into a label (appropriate for user defined types).
 346+ * not have a label associated with it in the current language, the
 347+ * empty string is returned. This is the case both for internal type ids
 348+ * and for invalid (unkown) type ids, so this method cannot be used to
 349+ * distinguish the two.
321350 *
322351 * @param string $id
323352 */
324353 static public function findTypeLabel( $id ) {
325354 self::initDatatypes();
326355
327 - if ( $id{0} === '_' ) {
328 - if ( array_key_exists( $id, self::$mTypeLabels ) ) {
329 - return self::$mTypeLabels[$id];
330 - } else { // internal type without translation to user space;
331 - // might also happen for historic types after an upgrade --
332 - // alas, we have no idea what the former label would have been
333 - return str_replace( '_', ' ', $id );
334 - }
335 - } else { // non-builtin type, use id as label
336 - return str_replace( '_', ' ', $id );
 356+ if ( array_key_exists( $id, self::$mTypeLabels ) ) {
 357+ return self::$mTypeLabels[$id];
 358+ } else { // internal type without translation to user space;
 359+ // might also happen for historic types after an upgrade --
 360+ // alas, we have no idea what the former label would have been
 361+ return '';
337362 }
338363 }
339364
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Number.php
@@ -20,8 +20,7 @@
2121 */
2222 protected $m_number;
2323
24 - public function __construct( $number, $typeid = '_num' ) {
25 - parent::__construct( $typeid );
 24+ public function __construct( $number ) {
2625 if ( !is_numeric( $number ) ) {
2726 throw new SMWDataItemException( "Initialisation value '$number' is not a number." );
2827 }
@@ -40,6 +39,14 @@
4140 return $this->m_number;
4241 }
4342
 43+ /**
 44+ * @see SMWDataItem::getSortKeyDataItem()
 45+ * @return SMWDataItem
 46+ */
 47+ public function getSortKeyDataItem() {
 48+ return $this;
 49+ }
 50+
4451 public function getSerialization() {
4552 return strval( $this->m_number );
4653 }
@@ -51,8 +58,8 @@
5259 * validation here (because this would require less efficient parsing).
5360 * @return SMWDINumber
5461 */
55 - public static function doUnserialize( $serialization, $typeid = '_num' ) {
56 - return new SMWDINumber( floatval( $serialization ), $typeid );
 62+ public static function doUnserialize( $serialization ) {
 63+ return new SMWDINumber( floatval( $serialization ) );
5764 }
5865
5966 }
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Error.php
@@ -22,8 +22,7 @@
2323 */
2424 protected $m_errors;
2525
26 - public function __construct( $errors, $typeid = '__err' ) {
27 - parent::__construct( $typeid );
 26+ public function __construct( $errors ) {
2827 $this->m_errors = $errors;
2928 }
3029
@@ -46,10 +45,11 @@
4746 /**
4847 * Create a data item from the provided serialization string and type
4948 * ID.
 49+ * @todo Be more careful with unserialization. It can create E_NOTICEs.
5050 * @return SMWDIError
5151 */
52 - public static function doUnserialize( $serialization, $typeid = '__err' ) {
53 - return new SMWDIError( unserialize( $serialization ), $typeid );
 52+ public static function doUnserialize( $serialization ) {
 53+ return new SMWDIError( unserialize( $serialization ) );
5454 }
5555
5656 }
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Bool.php
@@ -20,8 +20,7 @@
2121 */
2222 protected $m_boolean;
2323
24 - public function __construct( $boolean, $typeid = '_boo' ) {
25 - parent::__construct( $typeid );
 24+ public function __construct( $boolean ) {
2625 $this->m_boolean = ( $boolean == true );
2726 }
2827
@@ -46,11 +45,11 @@
4746 * ID.
4847 * @return SMWDIBoolean
4948 */
50 - public static function doUnserialize( $serialization, $typeid = '_boo' ) {
 49+ public static function doUnserialize( $serialization ) {
5150 if ( $serialization == 't' ) {
52 - return new SMWDIBoolean( true, $typeid );
 51+ return new SMWDIBoolean( true );
5352 } elseif ( $serialization == 'f' ) {
54 - return new SMWDIBoolean( true, $typeid );
 53+ return new SMWDIBoolean( true );
5554 } else {
5655 throw new SMWDataItemException( "Boolean data item unserialised from illegal value '$serialization'" );
5756 }
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Concept.php
@@ -50,9 +50,8 @@
5151 * @param $queryefeatures integer flags about query features
5252 * @param $size integer concept query size
5353 * @param $depth integer concept query depth
54 - * @param $typeid string SMW type id
5554 */
56 - public function __construct( $concept, $docu, $queryfeatures, $size, $depth, $typeid = '__con' ) {
 55+ public function __construct( $concept, $docu, $queryfeatures, $size, $depth ) {
5756 $this->m_concept = $concept;
5857 $this->m_docu = $docu;
5958 $this->m_features = $queryfeatures;
@@ -97,7 +96,7 @@
9897 * ID.
9998 * @return SMWDIConcept
10099 */
101 - public static function doUnserialize( $serialization, $typeid = '__con' ) {
 100+ public static function doUnserialize( $serialization ) {
102101 $result = unserialize( $serialization );
103102 if ( $result === false ) {
104103 throw new SMWDataItemException( "Unserialization failed." );
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DataItem.php
@@ -32,12 +32,10 @@
3333 * is mostly enforced by the API with some minor exceptions).
3434 *
3535 * The set of available data items is fixed and cannot be extended. These are
36 - * the kinds of information that SMW can process. However, a type ID can be held
37 - * by a data item, and this type might determine details of processing in some
38 - * contexts (for example, since it can be used to chose an implementation for
39 - * formatting this value for display in the wiki). Data items do not implement
40 - * such selection procedures -- they are nothing but data and provide only
41 - * minimal interfaces for accessing the stored data (or aspects of it).
 36+ * the kinds of information that SMW can process. Their concrete use and
 37+ * handling might depend on the context in which they are used. In particular,
 38+ * property values may be influences by settings made for their property. This
 39+ * aspect, however, is not part of the data item API.
4240 *
4341 * @since 1.6
4442 *
@@ -73,23 +71,6 @@
7472 const TYPE_ERROR = 12;
7573
7674 /**
77 - * The SMW type ID that governs the handling of this data item.
78 - * This data should not be considered part of the value. It is
79 - * provided merely to assist suitable handling and will not be
80 - * stored with the data.
81 - * @var string
82 - */
83 - protected $m_typeid;
84 -
85 - /**
86 - * Constructor.
87 - * @param $typeid string the SMW type ID that governs the handling of this data item.
88 - */
89 - public function __construct( $typeid ) {
90 - $this->m_typeid = $typeid;
91 - }
92 -
93 - /**
9475 * Convenience method that returns a constant that defines the concrete
9576 * class that implements this data item. Used to switch when processing
9677 * data items.
@@ -98,24 +79,43 @@
9980 abstract public function getDIType();
10081
10182 /**
102 - * Get the SMW type ID that governs the handling of this data item.
103 - * @return string $typeid the SMW type ID
104 - */
105 - public function getTypeID() {
106 - return $this->m_typeid;
107 - }
108 -
109 - /**
11083 * Return a value that can be used for sorting data of this type.
11184 * If the data is of a numerical type, the sorting must be done in
11285 * numerical order. If the data is a string, the data must be sorted
11386 * alphabetically.
 87+ *
 88+ * @note Every data item returns a sort key, even if there is no
 89+ * natural linear order for the type. SMW must order listed data
 90+ * in some way in any case. If there is a natural order (e.g. for
 91+ * Booleans where false < true), then the sortkey must agree with
 92+ * this order (e.g. for Booleans where false maps to 0, and true
 93+ * maps to 1).
11494 *
 95+ * @note Wiki pages are a special case in SMW. They are ordered by a
 96+ * sortkey that is assigned to them as a property value. When pages are
 97+ * sorted, this data should be used if possible.
 98+ *
11599 * @return float or string
116100 */
117101 abstract public function getSortKey();
118102
119103 /**
 104+ * Create a data item that represents the sortkey, i.e. either an
 105+ * SMWDIBlob or an SMWDINumber. For efficiency, these subclasses
 106+ * overwrite this method to return themselves.
 107+ *
 108+ * @return SMWDataItem
 109+ */
 110+ public function getSortKeyDataItem() {
 111+ $sortkey = $this->getSortKey();
 112+ if ( is_numeric( $sortkey ) ) {
 113+ return new SMWDINumber( $sortkey );
 114+ } else {
 115+ return new SMWDIBlob( $sortkey );
 116+ }
 117+ }
 118+
 119+ /**
120120 * Get a UTF-8 encoded string serialization of this data item.
121121 * The serialisation should be concise and need not be pretty, but it
122122 * must allow unserialization. Each subclass of SMWDataItem implements
@@ -143,13 +143,9 @@
144144 * @param $typeid string SMW type ID (optional)
145145 * @return SMWDataItem
146146 */
147 - public static function newFromSerialization( $diType, $serialization, $typeid = '' ) {
 147+ public static function newFromSerialization( $diType, $serialization ) {
148148 $diClass = self::getDataItemClassNameForId( $diType );
149 - if ( $typeid !== '' ) {
150 - return call_user_func( array( $diClass, 'doUnserialize' ), $serialization, $typeid );
151 - } else {
152 - return call_user_func( array( $diClass, 'doUnserialize' ), $serialization );
153 - }
 149+ return call_user_func( array( $diClass, 'doUnserialize' ), $serialization );
154150 }
155151
156152 public static function getDataItemClassNameForId( $diType ) {
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Blob.php
@@ -20,8 +20,7 @@
2121 */
2222 protected $m_string;
2323
24 - public function __construct( $string, $typeid = '_txt' ) {
25 - parent::__construct( $typeid );
 24+ public function __construct( $string ) {
2625 $this->m_string = $string;
2726 }
2827
@@ -37,6 +36,14 @@
3837 return $this->m_string;
3938 }
4039
 40+ /**
 41+ * @see SMWDataItem::getSortKeyDataItem()
 42+ * @return SMWDataItem
 43+ */
 44+ public function getSortKeyDataItem() {
 45+ return $this;
 46+ }
 47+
4148 public function getSerialization() {
4249 return $this->m_string;
4350 }
@@ -46,8 +53,8 @@
4754 * ID.
4855 * @return SMWDIBlob
4956 */
50 - public static function doUnserialize( $serialization, $typeid = '_txt' ) {
51 - return new SMWDIBlob( $serialization, $typeid );
 57+ public static function doUnserialize( $serialization ) {
 58+ return new SMWDIBlob( $serialization );
5259 }
5360
5461 }
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Time.php
@@ -98,19 +98,17 @@
9999 * @param $hour mixed integer number or false
100100 * @param $minute mixed integer number or false
101101 * @param $second mixed integer number or false
102 - * @param $typeid string SMW type id
103102 *
104103 * @todo Implement more validation here.
105104 */
106105 public function __construct( $calendarmodel, $year, $month = false, $day = false,
107 - $hour = false, $minute = false, $second = false, $typeid = '_dat' ) {
 106+ $hour = false, $minute = false, $second = false ) {
108107 if ( ( $calendarmodel != SMWDITime::CM_GREGORIAN ) && ( $calendarmodel != SMWDITime::CM_JULIAN ) ) {
109108 throw new SMWDataItemException( "Unsupported calendar model constant \"$calendarmodel\"." );
110109 }
111110 if ( $year == 0 ) {
112111 throw new SMWDataItemException( "There is no year 0 in Gregorian and Julian calendars." );
113112 }
114 - parent::__construct( $typeid );
115113 $this->m_model = $calendarmodel;
116114 $this->m_year = intval( $year );
117115 $this->m_month = $month != false ? intval( $month ) : 1;
@@ -188,7 +186,7 @@
189187 if ( $calendarmodel == $this->m_model ) {
190188 return $this;
191189 } else {
192 - return SMWDITime::newFromJD( $this->getJD(), $calendarmodel, $this->m_precision, $this->m_typeid );
 190+ return SMWDITime::newFromJD( $this->getJD(), $calendarmodel, $this->m_precision );
193191 }
194192 }
195193
@@ -234,7 +232,7 @@
235233 * ID.
236234 * @return SMWDITime
237235 */
238 - public static function doUnserialize( $serialization, $typeid = '_dat' ) {
 236+ public static function doUnserialize( $serialization ) {
239237 $parts = explode( '/', $serialization, 7 );
240238 $values = array();
241239 for ( $i = 0; $i < 7; $i += 1 ) {
@@ -251,7 +249,7 @@
252250 if ( count( $parts ) <= 1 ) {
253251 throw new SMWDataItemException( "Unserialization failed: the string \"$serialization\" is no valid URI." );
254252 }
255 - return new SMWDITime( $values[0], $values[1], $values[2], $values[3], $values[4], $values[5], $values[6], $typeid );
 253+ return new SMWDITime( $values[0], $values[1], $values[2], $values[3], $values[4], $values[5], $values[6] );
256254 }
257255
258256 /**
@@ -260,10 +258,9 @@
261259 * @param $jdvalue double Julian Day number
262260 * @param $calendarmodel integer either SMWDITime::CM_GREGORIAN or SMWDITime::CM_JULIAN
263261 * @param $precision integer one of SMWDITime::PREC_Y, SMWDITime::PREC_YM, SMWDITime::PREC_YMD, SMWDITime::PREC_YMDT
264 - * @param $typeid string
265262 * @return SMWDITime object
266263 */
267 - public static function newFromJD( $jdvalue, $calendarmodel, $precision, $typeid ) {
 264+ public static function newFromJD( $jdvalue, $calendarmodel, $precision ) {
268265 list( $year, $month, $day ) = SMWDITime::JD2Date( $jdvalue, $calendarmodel );
269266 if ( $precision <= SMWDITime::PREC_YM ) {
270267 $day = false;
@@ -276,7 +273,7 @@
277274 } else {
278275 $hour = $minute = $second = false;
279276 }
280 - return new SMWDITime( $calendarmodel, $year, $month, $day, $hour, $minute, $second, $typeid );
 277+ return new SMWDITime( $calendarmodel, $year, $month, $day, $hour, $minute, $second );
281278 }
282279
283280 /**
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_URI.php
@@ -45,18 +45,16 @@
4646 * @param $hierpart string for the "hierpart"
4747 * @param $query string for the query
4848 * @param $fragment string for the fragment
49 - * @param $typeid string SMW type id
5049 *
5150 * @todo Implement more validation here.
5251 */
53 - public function __construct( $scheme, $hierpart, $query, $fragment, $typeid = '_uri' ) {
 52+ public function __construct( $scheme, $hierpart, $query, $fragment ) {
5453 if ( ( $scheme == '' ) || ( preg_match( '/[^a-zA-Z]/u', $scheme ) ) ) {
5554 throw new SMWDataItemException( "Illegal URI scheme \"$scheme\"." );
5655 }
5756 if ( $hierpart == '' ) {
5857 throw new SMWDataItemException( "Illegal URI hierpart \"$hierpart\"." );
5958 }
60 - parent::__construct( $typeid );
6159 $this->m_scheme = $scheme;
6260 $this->m_hierpart = $hierpart;
6361 $this->m_query = $query;
@@ -103,7 +101,7 @@
104102 * ID.
105103 * @return SMWDIUri
106104 */
107 - public static function doUnserialize( $serialization, $typeid = '_uri' ) {
 105+ public static function doUnserialize( $serialization ) {
108106 $parts = explode( ':', $serialization, 2 ); // try to split "schema:rest"
109107 if ( count( $parts ) <= 1 ) {
110108 throw new SMWDataItemException( "Unserialization failed: the string \"$serialization\" is no valid URI." );
@@ -117,11 +115,11 @@
118116 $fragment = ( count( $parts ) == 2 ) ? $parts[1] : '';
119117 } else {
120118 $query = '';
121 - $parts = explode( '?', $parts[0], 2 ); // try to split "hier-part#frag"
 119+ $parts = explode( '#', $parts[0], 2 ); // try to split "hier-part#frag"
122120 $hierpart = $parts[0];
123121 $fragment = ( count( $parts ) == 2 ) ? $parts[1] : '';
124122 }
125 - return new SMWDIUri( $scheme, $hierpart, $query, $fragment, $typeid );
 123+ return new SMWDIUri( $scheme, $hierpart, $query, $fragment );
126124 }
127125
128126 }
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_WikiPage.php
@@ -38,8 +38,7 @@
3939 * would be more work than it is worth, since callers will usually be
4040 * careful and since errors here do not have major consequences.
4141 */
42 - public function __construct( $dbkey, $namespace, $interwiki, $typeid = '_wpg' ) {
43 - parent::__construct( $typeid );
 42+ public function __construct( $dbkey, $namespace, $interwiki ) {
4443 if ( !is_numeric( $namespace ) ) {
4544 throw new SMWDataItemException( "Given namespace '$namespace' is not an integer." );
4645 }
@@ -102,23 +101,22 @@
103102 * ID.
104103 * @return SMWDIWikiPage
105104 */
106 - public static function doUnserialize( $serialization, $typeid = '_wpg' ) {
 105+ public static function doUnserialize( $serialization ) {
107106 $parts = explode( '#', $serialization, 3 );
108107 if ( count( $parts ) != 3 ) {
109108 throw new SMWDataItemException( "Unserialization failed: the string \"$serialization\" was not understood." );
110109 }
111 - return new SMWDIWikiPage( $parts[0], floatval( $parts[1] ), $parts[2], $typeid );
 110+ return new SMWDIWikiPage( $parts[0], floatval( $parts[1] ), $parts[2] );
112111 }
113112
114113 /**
115114 * Create a data item from a MediaWiki Title.
116115 *
117116 * @param $title Title
118 - * @param $typeid string optional type ID to use
119117 * @return SMWDIWikiPage
120118 */
121 - public static function newFromTitle( Title $title, $typeid = '_wpg' ) {
122 - return new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki(), $typeid );
 119+ public static function newFromTitle( Title $title ) {
 120+ return new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki() );
123121 }
124122
125123 }
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_GeoCoord.php
@@ -21,8 +21,7 @@
2222 * @param $coords array Array with lat and long keys pointing to float values.
2323 * @param $typeid string
2424 */
25 - public function __construct( array $coords, $typeid = '_geo' ) {
26 - parent::__construct( $typeid );
 25+ public function __construct( array $coords ) {
2726 $this->coordinateSet = $coords;
2827 }
2928
@@ -69,14 +68,14 @@
7069 * validation here (because this would require less efficient parsing).
7170 * @return SMWDIGeoCoord
7271 */
73 - public static function doUnserialize( $serialization, $typeid = '_geo' ) {
 72+ public static function doUnserialize( $serialization ) {
7473 $parts = explode( ',', $serialization );
7574
7675 if ( count( $parts ) != 2 ) {
7776 throw new SMWDataItemException( 'Unserialization of coordinates failed' );
7877 }
7978
80 - return new self( array( 'lat' => (float)$parts[0], 'lon' => (float)$parts[1], ), $typeid );
 79+ return new self( array( 'lat' => (float)$parts[0], 'lon' => (float)$parts[1], ) );
8180 }
8281
8382 }
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Container.php
@@ -115,8 +115,7 @@
116116 *
117117 * @param $semanticData SMWContainerSemanticData
118118 */
119 - public function __construct( SMWContainerSemanticData $semanticData, $typeid = '_rec' ) {
120 - parent::__construct( $typeid );
 119+ public function __construct( SMWContainerSemanticData $semanticData ) {
121120 $this->m_semanticData = $semanticData;
122121 $this->m_semanticData->makeImmutable();
123122 }
@@ -151,13 +150,13 @@
152151 * ID.
153152 * @return SMWDIContainer
154153 */
155 - public static function doUnserialize( $serialization, $typeid = '_rec' ) {
 154+ public static function doUnserialize( $serialization ) {
156155 /// TODO May issue an E_NOTICE when problems occur; catch this
157156 $data = unserialize( $serialization );
158157 if ( !( $data instanceof SMWContainerSemanticData ) ) {
159158 throw SMWDataItemException( "Could not unserialize SMWDIContainer from the given string." );
160159 }
161 - return new SMWDIContainer( $data, $typeid );
 160+ return new SMWDIContainer( $data );
162161 }
163162
164163 }
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php
@@ -70,9 +70,8 @@
7171 *
7272 * @param $key string key for the property (internal SMW key or wikipage DB key)
7373 * @param $inverse boolean states if the inverse of the property is constructed
74 - * @param $typeid string SMW type id
7574 */
76 - public function __construct( $key, $inverse = false, $typeid = '__pro' ) {
 75+ public function __construct( $key, $inverse = false ) {
7776 if ( ( $key == '' ) || ( $key{0} == '-' ) ) {
7877 throw new SMWDataItemException( "Illegal property key \"$key\"." );
7978 }
@@ -82,7 +81,6 @@
8382 throw new SMWDataItemException( "There is no predefined property with \"$key\"." );
8483 }
8584 }
86 - parent::__construct( $typeid );
8785 $this->m_key = $key;
8886 $this->m_inverse = ( $inverse == true );
8987 }
@@ -174,21 +172,6 @@
175173 }
176174
177175 /**
178 - * Get the type ID of a predefined property, or '' if the property
179 - * is not predefined.
180 - * The function is guaranteed to return a type ID if isUserDefined()
181 - * returns false.
182 - * @return string type ID
183 - */
184 - public function getPredefinedPropertyTypeID() {
185 - if ( array_key_exists( $this->m_key, SMWDIProperty::$m_prop_types ) ) {
186 - return SMWDIProperty::$m_prop_types[$this->m_key][0];
187 - } else {
188 - return '';
189 - }
190 - }
191 -
192 - /**
193176 * Find the property's type ID, either by looking up its predefined ID
194177 * (if any) or by retrieving the relevant information from the store.
195178 * If no type is stored for a user defined property, the global default
@@ -203,9 +186,9 @@
204187 $diWikiPage = new SMWDIWikiPage( $this->getKey(), SMW_NS_PROPERTY, '' );
205188 $typearray = smwfGetStore()->getPropertyValues( $diWikiPage, new SMWDIProperty( '_TYPE' ) );
206189 if ( count( $typearray ) >= 1 ) { // some types given, pick one (hopefully unique)
207 - $typeString = reset( $typearray );
208 - if ( $typeString instanceOf SMWDIWikiPage ) {
209 - $this->m_proptypeid = SMWDataValueFactory::findTypeID( str_replace( '_', ' ', $typeString->getDBKey() ) );
 190+ $typeDataItem = reset( $typearray );
 191+ if ( $typeDataItem instanceof SMWDIUri ) {
 192+ $this->m_proptypeid = $typeDataItem->getFragment();
210193 } else {
211194 $this->m_proptypeid = '__err';
212195 }
@@ -213,7 +196,7 @@
214197 $this->m_proptypeid = $smwgPDefaultType;
215198 }
216199 } else { // pre-defined property
217 - $this->m_proptypeid = $this->getPredefinedPropertyTypeID();
 200+ $this->m_proptypeid = self::getPredefinedPropertyTypeId( $this->m_key );
218201 }
219202 }
220203 return $this->m_proptypeid;
@@ -229,13 +212,13 @@
230213 * ID.
231214 * @return SMWDIProperty
232215 */
233 - public static function doUnserialize( $serialization, $typeid = '__pro' ) {
 216+ public static function doUnserialize( $serialization ) {
234217 $inverse = false;
235218 if ( $serialization{0} == '-' ) {
236219 $serialization = substr( $serialization, 1 );
237220 $inverse = true;
238221 }
239 - return new SMWDIProperty( $serialization, $inverse, $typeid );
 222+ return new SMWDIProperty( $serialization, $inverse );
240223 }
241224
242225 /**
@@ -250,15 +233,14 @@
251234 *
252235 * @param $label string label for the property
253236 * @param $inverse boolean states if the inverse of the property is constructed
254 - * @param $typeid string SMW type id
255237 * @return SMWDIProperty object
256238 */
257 - public static function newFromUserLabel( $label, $inverse = false, $typeid = '__pro' ) {
 239+ public static function newFromUserLabel( $label, $inverse = false ) {
258240 $id = SMWDIProperty::findPropertyID( $label );
259241 if ( $id === false ) {
260 - return new SMWDIProperty( str_replace( ' ', '_', $label ), $inverse, $typeid );
 242+ return new SMWDIProperty( str_replace( ' ', '_', $label ), $inverse );
261243 } else {
262 - return new SMWDIProperty( $id, $inverse, $typeid );
 244+ return new SMWDIProperty( $id, $inverse );
263245 }
264246 }
265247
@@ -286,6 +268,23 @@
287269 }
288270
289271 /**
 272+ * Get the type ID of a predefined property, or '' if the property
 273+ * is not predefined.
 274+ * The function is guaranteed to return a type ID for keys of
 275+ * properties where isUserDefined() returns false.
 276+ *
 277+ * @param $key string key of the property
 278+ * @return string type ID
 279+ */
 280+ public static function getPredefinedPropertyTypeId( $key ) {
 281+ if ( array_key_exists( $key, SMWDIProperty::$m_prop_types ) ) {
 282+ return SMWDIProperty::$m_prop_types[$key][0];
 283+ } else {
 284+ return '';
 285+ }
 286+ }
 287+
 288+ /**
290289 * Get the translated user label for a given internal property ID.
291290 * Returns false for properties without a translation (these are
292291 * usually internal, generated by SMW but not shown to the user).
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_String.php
@@ -27,11 +27,11 @@
2828
2929 const MAXLENGTH = 255;
3030
31 - public function __construct( $string, $typeid = '_str' ) {
 31+ public function __construct( $string ) {
3232 if ( strlen( $string ) > SMWDIString::MAXLENGTH ) {
3333 throw new SMWStringLengthException( $string );
3434 }
35 - parent::__construct( $string, $typeid );
 35+ parent::__construct( $string );
3636 }
3737
3838 public function getDIType() {
@@ -43,8 +43,8 @@
4444 * ID.
4545 * @return SMWDIString
4646 */
47 - public static function doUnserialize( $serialization, $typeid = '_str' ) {
48 - return new SMWDIString( $serialization, $typeid );
 47+ public static function doUnserialize( $serialization ) {
 48+ return new SMWDIString( $serialization );
4949 }
5050
5151 }
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_Language.php
@@ -62,7 +62,7 @@
6363 'Email' => '_ema',
6464 'Annotation URI' => '_anu',
6565 'Telephone number' => '_tel',
66 - 'Record' => '_rec'
 66+ 'Record' => '_rec'
6767 );
6868 /// Default English aliases for special property names (typically used in all languages)
6969 static protected $enPropertyAliases = array(
@@ -113,8 +113,8 @@
114114 */
115115 function getDatatypeAliases() {
116116 return $this->m_useEnDefaultAliases ?
117 - $this->m_DatatypeAliases + SMWLanguage::$enDatatypeAliases:
118 - $this->m_DatatypeAliases;
 117+ $this->m_DatatypeAliases + SMWLanguage::$enDatatypeAliases :
 118+ $this->m_DatatypeAliases;
119119 }
120120
121121 /**
@@ -129,8 +129,8 @@
130130 */
131131 function getPropertyAliases() {
132132 return $this->m_useEnDefaultAliases ?
133 - $this->m_SpecialPropertyAliases + SMWLanguage::$enPropertyAliases:
134 - $this->m_SpecialPropertyAliases;
 133+ $this->m_SpecialPropertyAliases + SMWLanguage::$enPropertyAliases :
 134+ $this->m_SpecialPropertyAliases;
135135 }
136136
137137 /**
@@ -161,7 +161,7 @@
162162 * Return the name of the month with the given number.
163163 */
164164 function getMonthLabel( $number ) {
165 - return ( ( $number >= 1 ) && ( $number <= 12 ) ) ? $this->m_months[(int)( $number - 1 )]:'';
 165+ return ( ( $number >= 1 ) && ( $number <= 12 ) ) ? $this->m_months[(int)( $number - 1 )] : '';
166166 }
167167
168168 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r112432Removing code thas been commented out almost a year, ping r88308nikerabbit13:07, 26 February 2012

Status & tagging log