Index: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php |
— | — | @@ -77,9 +77,10 @@ |
78 | 78 | $errors[] = wfMsg( 'smw_propertyhardlyused' ); |
79 | 79 | } |
80 | 80 | 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 ); |
82 | 83 | if ( count( $types ) >= 1 ) { |
83 | | - $typeDataValue = SMWDataValueFactory::newDataItemValue( current( $types ) ); |
| 84 | + $typeDataValue = SMWDataValueFactory::newDataItemValue( current( $types ), $typeProperty ); |
84 | 85 | $typestring = $typeDataValue->getLongHTMLText( $skin ); |
85 | 86 | } |
86 | 87 | $proplink = $skin->makeKnownLinkObj( $title, $result[0]->getLabel() ); |
— | — | @@ -96,7 +97,8 @@ |
97 | 98 | global $smwgPDefaultType; |
98 | 99 | $typepagedbkey = str_replace( ' ', '_', SMWDataValueFactory::findTypeLabel( $smwgPDefaultType ) ); |
99 | 100 | $diTypePage = new SMWDIWikiPage( $typepagedbkey, SMW_NS_TYPE, '', '__typ' ); |
100 | | - $dvTypePage = SMWDataValueFactory::newDataItemValue( $diTypePage ); |
| 101 | + $dvTypePage = SMWDataValueFactory::newTypeIdValue( '__typ' ); |
| 102 | + $dvTypePage->setDataItem( $diTypePage ); |
101 | 103 | $typestring = $dvTypePage->getLongHTMLText( $skin ); |
102 | 104 | if ( ( $title !== null ) && ( $title->exists() ) ) { // print only when we did not print a "nopage" warning yet |
103 | 105 | $errors[] = wfMsg( 'smw_propertylackstype', $typestring ); |
Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php |
— | — | @@ -129,7 +129,7 @@ |
130 | 130 | $diProperties = $data->getProperties(); |
131 | 131 | $noresult = true; |
132 | 132 | foreach ( $diProperties as $diProperty ) { |
133 | | - $dvProperty = SMWDataValueFactory::newDataItemValue( $diProperty ); |
| 133 | + $dvProperty = SMWDataValueFactory::newDataItemValue( $diProperty, null ); |
134 | 134 | $displayline = true; |
135 | 135 | if ( $dvProperty->isVisible() ) { |
136 | 136 | $dvProperty->setCaption( $this->getPropertyLabel( $dvProperty, $incoming ) ); |
— | — | @@ -153,7 +153,7 @@ |
154 | 154 | // if there are more incoming values than a certain treshold, display a link to the rest instead |
155 | 155 | $body .= '<a href="' . $skin->makeSpecialUrl( 'SearchByProperty', 'property=' . urlencode( $dvProperty->getWikiValue() ) . '&value=' . urlencode( $this->subject->getWikiValue() ) ) . '">' . wfMsg( "smw_browse_more" ) . "</a>\n"; |
156 | 156 | } else { |
157 | | - $dv = SMWDataValueFactory::newDataItemValue( $di, false, $diProperty ); |
| 157 | + $dv = SMWDataValueFactory::newDataItemValue( $di, $diProperty ); |
158 | 158 | $body .= "<span class=\"smwb-" . $inv . "value\">" . |
159 | 159 | $this->displayValue( $dvProperty, $dv, $incoming ) . "</span>"; |
160 | 160 | } |
— | — | @@ -184,16 +184,16 @@ |
185 | 185 | * @param[in] $incoming bool If this is an incoming or outgoing link |
186 | 186 | * @return string HTML with the link to the article, browse, and search pages |
187 | 187 | */ |
188 | | - private function displayValue( SMWPropertyValue $property, SMWDataValue $value, $incoming ) { |
| 188 | + private function displayValue( SMWPropertyValue $property, SMWDataValue $dataValue, $incoming ) { |
189 | 189 | global $wgUser; |
190 | 190 | $skin = $wgUser->getSkin(); |
191 | | - $html = $value->getLongHTMLText( $skin ); |
192 | | - if ( $value->getTypeID() == '_wpg' ) { |
193 | | - $html .= " " . SMWInfolink::newBrowsingLink( '+', $value->getLongWikiText() )->getHTML( $skin ); |
| 191 | + $html = $dataValue->getLongHTMLText( $skin ); |
| 192 | + if ( $dataValue->getTypeID() == '_wpg' ) { |
| 193 | + $html .= " " . SMWInfolink::newBrowsingLink( '+', $dataValue->getLongWikiText() )->getHTML( $skin ); |
194 | 194 | } elseif ( $incoming && $property->isVisible() ) { |
195 | | - $html .= " " . SMWInfolink::newInversePropertySearchLink( '+', $value->getTitle(), $property->getText(), 'smwsearch' )->getHTML( $skin ); |
| 195 | + $html .= " " . SMWInfolink::newInversePropertySearchLink( '+', $dataValue->getTitle(), $property->getText(), 'smwsearch' )->getHTML( $skin ); |
196 | 196 | } else { |
197 | | - $html .= $value->getInfolinkText( SMW_OUTPUT_HTML, $skin ); |
| 197 | + $html .= $dataValue->getInfolinkText( SMW_OUTPUT_HTML, $skin ); |
198 | 198 | } |
199 | 199 | return $html; |
200 | 200 | } |
Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialPageProperty.php |
— | — | @@ -96,9 +96,9 @@ |
97 | 97 | foreach ( $results as $di ) { |
98 | 98 | $count--; |
99 | 99 | if ( $count < 1 ) continue; |
100 | | - $dv = SMWDataValueFactory::newDataItemValue( $di ); |
| 100 | + $dv = SMWDataValueFactory::newDataItemValue( $di, $property->getDataItem() ); |
101 | 101 | $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' ) { |
103 | 103 | $browselink = SMWInfolink::newBrowsingLink( '+', $dv->getLongWikiText() ); |
104 | 104 | $html .= '  ' . $browselink->getHTML( $skin ); |
105 | 105 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php |
— | — | @@ -236,14 +236,15 @@ |
237 | 237 | } |
238 | 238 | |
239 | 239 | if ( $modifier == '' ) { |
240 | | - $importDis = smwfGetStore()->getPropertyValues( $diWikiPage, new SMWDIProperty( '_IMPO' ) ); |
| 240 | + $importProperty = new SMWDIProperty( '_IMPO' ); |
| 241 | + $importDis = smwfGetStore()->getPropertyValues( $diWikiPage, $importProperty ); |
241 | 242 | $importURI = ( count( $importDis ) > 0 ); |
242 | 243 | } else { |
243 | 244 | $importURI = false; |
244 | 245 | } |
245 | 246 | |
246 | 247 | if ( $importURI ) { |
247 | | - $importValue = SMWDataValueFactory::newDataItemValue( current( $importDis ) ); |
| 248 | + $importValue = SMWDataValueFactory::newDataItemValue( current( $importDis ), $importProperty ); |
248 | 249 | $namespace = $importValue->getNS(); |
249 | 250 | $namespaceId = $importValue->getNSID(); |
250 | 251 | $localName = $importValue->getLocalName(); |
— | — | @@ -576,6 +577,11 @@ |
577 | 578 | * |
578 | 579 | * For dataitems that do not have such a simplification, the method |
579 | 580 | * 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. |
580 | 586 | * |
581 | 587 | * @param $dataItem SMWDataItem |
582 | 588 | * @return SMWExpElement or null |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php |
— | — | @@ -93,13 +93,6 @@ |
94 | 94 | protected $m_outformat = false; |
95 | 95 | |
96 | 96 | /** |
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 | | - /** |
104 | 97 | * Used to control the addition of the standard search link. |
105 | 98 | * @var boolean |
106 | 99 | */ |
— | — | @@ -153,7 +146,6 @@ |
154 | 147 | $this->m_infolinks = array(); // clear links |
155 | 148 | $this->mHasSearchLink = false; |
156 | 149 | $this->mHasServiceLinks = false; |
157 | | - $this->m_stubvalues = false; |
158 | 150 | $this->m_caption = is_string( $caption ) ? trim( $caption ) : false; |
159 | 151 | |
160 | 152 | // The following checks for markers generated by MediaWiki to handle special content, |
— | — | @@ -176,41 +168,27 @@ |
177 | 169 | } |
178 | 170 | |
179 | 171 | /** |
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. |
188 | 181 | * |
189 | | - * @param array $args |
| 182 | + * @param $dataitem SMWDataItem |
| 183 | + * @return boolean |
190 | 184 | */ |
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 ); |
193 | 190 | } |
194 | 191 | |
195 | 192 | /** |
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 | | - /** |
215 | 193 | * Specify the property to which this value refers. Used to generate search links and |
216 | 194 | * to find custom settings that relate to the property. |
217 | 195 | * |
— | — | @@ -267,10 +245,10 @@ |
268 | 246 | $servicelinks = smwfGetStore()->getPropertyValues( $propertyDiWikiPage, new SMWDIProperty( '_SERV' ) ); |
269 | 247 | |
270 | 248 | foreach ( $servicelinks as $dataItem ) { |
| 249 | + if ( !( $dataItem instanceof SMWDIString ) ) continue; |
271 | 250 | 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 '_' |
275 | 253 | $text = call_user_func_array( 'wfMsgForContent', $args ); |
276 | 254 | $links = preg_split( "/[\n][\s]?/u", $text ); |
277 | 255 | |
— | — | @@ -330,6 +308,7 @@ |
331 | 309 | * n-ary to do this. Eventually, n-ary should implement its setDBkeys() |
332 | 310 | * properly so that this function will vanish again. |
333 | 311 | * @note Do not use this function in external code. |
| 312 | + * @todo Check if we can remove this function again. |
334 | 313 | */ |
335 | 314 | protected function clearErrors() { |
336 | 315 | $this->mErrors = array(); |
— | — | @@ -348,17 +327,22 @@ |
349 | 328 | abstract protected function parseUserValue( $value ); |
350 | 329 | |
351 | 330 | /** |
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. |
358 | 340 | * |
359 | | - * @param array $args |
| 341 | + * @param $dataitem SMWDataItem |
| 342 | + * @return boolean |
360 | 343 | */ |
361 | | - abstract protected function parseDBkeys( $args ); |
| 344 | + abstract protected function loadDataItem( SMWDataItem $dataItem ); |
362 | 345 | |
| 346 | + |
363 | 347 | ///// Query support ///// |
364 | 348 | |
365 | 349 | /** |
— | — | @@ -435,102 +419,6 @@ |
436 | 420 | } |
437 | 421 | |
438 | 422 | /** |
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 | | - /** |
535 | 423 | * Returns a short textual representation for this data value. If the value |
536 | 424 | * was initialised from a user supplied string, then this original string |
537 | 425 | * should be reflected in this short version (i.e. no normalisation should |
— | — | @@ -681,9 +569,8 @@ |
682 | 570 | public function getInfolinks() { |
683 | 571 | if ( $this->isValid() && ( $this->m_property !== null ) ) { |
684 | 572 | if ( !$this->mHasSearchLink ) { // add default search link |
685 | | - $propertyDataValue = SMWDataValueFactory::newDataItemValue( $this->m_property ); |
686 | 573 | $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() ); |
688 | 575 | } |
689 | 576 | |
690 | 577 | if ( !$this->mHasServiceLinks ) { // add further service links |
— | — | @@ -716,16 +603,14 @@ |
717 | 604 | } |
718 | 605 | |
719 | 606 | /** |
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. |
722 | 609 | * |
723 | 610 | * @return boolean |
724 | 611 | */ |
725 | 612 | 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() ); |
730 | 615 | } else { |
731 | 616 | return false; |
732 | 617 | } |
— | — | @@ -761,7 +646,6 @@ |
762 | 647 | * an empty string if no errors happened. |
763 | 648 | */ |
764 | 649 | public function getErrorText() { |
765 | | - $this->unstub(); |
766 | 650 | return smwfEncodeMessages( $this->mErrors ); |
767 | 651 | } |
768 | 652 | |
— | — | @@ -770,7 +654,6 @@ |
771 | 655 | * if no errors occurred. |
772 | 656 | */ |
773 | 657 | public function getErrors() { |
774 | | - $this->unstub(); |
775 | 658 | return $this->mErrors; |
776 | 659 | } |
777 | 660 | |
— | — | @@ -839,4 +722,35 @@ |
840 | 723 | } |
841 | 724 | } |
842 | 725 | |
| 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 | + |
843 | 757 | } |
\ No newline at end of file |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Import.php |
— | — | @@ -112,23 +112,12 @@ |
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
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 | | - |
127 | 116 | /** |
128 | | - * @see SMWDataValue::setDataItem() |
| 117 | + * @see SMWDataValue::loadDataItem() |
129 | 118 | * @param $dataitem SMWDataItem |
130 | 119 | * @return boolean |
131 | 120 | */ |
132 | | - public function setDataItem( SMWDataItem $dataItem ) { |
| 121 | + protected function loadDataItem( SMWDataItem $dataItem ) { |
133 | 122 | if ( $dataItem->getDIType() == SMWDataItem::TYPE_STRING ) { |
134 | 123 | $this->m_dataitem = $dataItem; |
135 | 124 | $parts = explode( ' ', $dataItem->getString(), 3 ); |
— | — | @@ -149,12 +138,10 @@ |
150 | 139 | } |
151 | 140 | |
152 | 141 | public function getShortWikiText( $linked = null ) { |
153 | | - $this->unstub(); |
154 | 142 | return $this->m_caption; |
155 | 143 | } |
156 | 144 | |
157 | 145 | public function getShortHTMLText( $linker = null ) { |
158 | | - $this->unstub(); |
159 | 146 | return htmlspecialchars( $this->m_qname ); |
160 | 147 | } |
161 | 148 | |
— | — | @@ -174,40 +161,19 @@ |
175 | 162 | } |
176 | 163 | } |
177 | 164 | |
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 | | - |
195 | 165 | public function getWikiValue() { |
196 | | - $this->unstub(); |
197 | 166 | return $this->m_qname; |
198 | 167 | } |
199 | 168 | |
200 | 169 | public function getNS() { |
201 | | - $this->unstub(); |
202 | 170 | return $this->m_uri; |
203 | 171 | } |
204 | 172 | |
205 | 173 | public function getNSID() { |
206 | | - $this->unstub(); |
207 | 174 | return $this->m_namespace; |
208 | 175 | } |
209 | 176 | |
210 | 177 | public function getLocalName() { |
211 | | - $this->unstub(); |
212 | 178 | return $this->m_section; |
213 | 179 | } |
214 | 180 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_SimpleWikiPage.php |
— | — | @@ -1,5 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
| 4 | + * @deprecated This obsolete file will soon vanish. |
4 | 5 | * @file |
5 | 6 | * @ingroup SMWDataValues |
6 | 7 | */ |
— | — | @@ -21,33 +22,4 @@ |
22 | 23 | */ |
23 | 24 | class SMWSimpleWikiPageValue extends SMWWikiPageValue { |
24 | 25 | |
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 | | - |
54 | 26 | } |
\ No newline at end of file |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_TypeList.php |
— | — | @@ -30,16 +30,6 @@ |
31 | 31 | $this->setDataItemFromTypeValues(); |
32 | 32 | } |
33 | 33 | |
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 | | - |
44 | 34 | /** |
45 | 35 | * @see SMWDataValue::setDataItem() |
46 | 36 | * @param $dataitem SMWDataItem |
— | — | @@ -83,22 +73,6 @@ |
84 | 74 | } |
85 | 75 | } |
86 | 76 | |
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 | | - |
103 | 77 | public function getShortWikiText( $linked = null ) { |
104 | 78 | return ( $this->m_caption !== false ) ? $this->m_caption : $this->makeOutputText( 0, $linked ); |
105 | 79 | } |
— | — | @@ -120,7 +94,6 @@ |
121 | 95 | } |
122 | 96 | |
123 | 97 | public function getTypeValues() { |
124 | | - $this->unstub(); |
125 | 98 | return $this->m_typevalues; |
126 | 99 | } |
127 | 100 | |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php |
— | — | @@ -89,11 +89,11 @@ |
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | | - * @see SMWDataValue::setDataItem() |
| 93 | + * @see SMWDataValue::loadDataItem() |
94 | 94 | * @param $dataitem SMWDataItem |
95 | 95 | * @return boolean |
96 | 96 | */ |
97 | | - public function setDataItem( SMWDataItem $dataItem ) { |
| 97 | + protected function loadDataItem( SMWDataItem $dataItem ) { |
98 | 98 | if ( $dataItem->getDIType() == SMWDataItem::TYPE_CONTAINER ) { |
99 | 99 | $this->m_dataitem = $dataItem; |
100 | 100 | return true; |
— | — | @@ -103,30 +103,6 @@ |
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
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 | | - /** |
131 | 107 | * Overwrite SMWDataValue::getQueryDescription() to be able to process |
132 | 108 | * comparators between all values. |
133 | 109 | */ |
— | — | @@ -185,19 +161,19 @@ |
186 | 162 | $ed = new SMWExpData( SMWExporter::getSpecialNsResource( 'swivt', 'Container' ) ); |
187 | 163 | $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ), $ed ); |
188 | 164 | $count = 0; |
189 | | - foreach ( $this->getDVs() as $value ) { |
| 165 | + foreach ( $this->getDVs() as $dataValue ) { |
190 | 166 | $count++; |
191 | | - if ( ( $value === null ) || ( !$value->isValid() ) ) { |
| 167 | + if ( ( $dataValue === null ) || ( !$dataValue->isValid() ) ) { |
192 | 168 | continue; |
193 | 169 | } |
194 | | - if ( ( $value->getTypeID() == '_wpg' ) || ( $value->getTypeID() == '_uri' ) || ( $value->getTypeID() == '_ema' ) ) { |
| 170 | + if ( ( $dataValue->getTypeID() == '_wpg' ) || ( $dataValue->getTypeID() == '_uri' ) || ( $dataValue->getTypeID() == '_ema' ) ) { |
195 | 171 | $result->addPropertyObjectValue( |
196 | 172 | SMWExporter::getSpecialNsResource( 'swivt', 'object' . $count ), |
197 | | - $value->getExportData() ); |
| 173 | + $dataValue->getExportData() ); |
198 | 174 | } else { |
199 | 175 | $result->addPropertyObjectValue( |
200 | 176 | SMWExporter::getSpecialNsResource( 'swivt', 'value' . $count ), |
201 | | - $value->getExportData() ); |
| 177 | + $dataValue->getExportData() ); |
202 | 178 | } |
203 | 179 | } |
204 | 180 | return $result; |
— | — | @@ -322,7 +298,7 @@ |
323 | 299 | $propertyvalues = $this->m_dataitem->getSemanticData()->getPropertyValues( $property ); // combining this with next line violates PHP strict standards |
324 | 300 | $dataItem = reset( $propertyvalues ); |
325 | 301 | if ( $dataItem !== false ) { |
326 | | - $dataValue = SMWDataValueFactory::newDataItemValue( $dataItem ); |
| 302 | + $dataValue = SMWDataValueFactory::newDataItemValue( $dataItem, $property ); |
327 | 303 | $result .= $this->makeValueOutputText( $type, $dataValue, $linker ); |
328 | 304 | } else { |
329 | 305 | $result .= '?'; |
— | — | @@ -343,8 +319,5 @@ |
344 | 320 | } |
345 | 321 | } |
346 | 322 | |
347 | | - public function getDBkeys() { |
348 | | - return array();// no longer used |
349 | | - } |
350 | 323 | } |
351 | 324 | |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Container.php |
— | — | @@ -1,5 +1,6 @@ |
2 | 2 | <?php |
3 | 3 | /** |
| 4 | + * @deprecated This file is obsolete and will soon vanish. |
4 | 5 | * @file |
5 | 6 | * @ingroup SMWDataValues |
6 | 7 | */ |
— | — | @@ -49,18 +50,6 @@ |
50 | 51 | return array( $data ); |
51 | 52 | } |
52 | 53 | |
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 | | - |
65 | 54 | public function getHash() { |
66 | 55 | if ( $this->isValid() ) { |
67 | 56 | return $this->m_data->getHash(); |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Property.php |
— | — | @@ -124,32 +124,16 @@ |
125 | 125 | } catch ( SMWDataItemException $e ) { // happens, e.g., when trying to sort queries by property "-" |
126 | 126 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
127 | 127 | $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 |
129 | 129 | } |
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
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() |
150 | 134 | * @param $dataitem SMWDataItem |
151 | 135 | * @return boolean |
152 | 136 | */ |
153 | | - public function setDataItem( SMWDataItem $dataItem ) { |
| 137 | + protected function loadDataItem( SMWDataItem $dataItem ) { |
154 | 138 | if ( $dataItem->getDIType() == SMWDataItem::TYPE_PROPERTY ) { |
155 | 139 | $this->m_dataitem = $dataItem; |
156 | 140 | $this->mPropTypeValue = null; |
— | — | @@ -171,14 +155,13 @@ |
172 | 156 | |
173 | 157 | public function setOutputFormat( $formatstring ) { |
174 | 158 | $this->m_outformat = $formatstring; |
175 | | - if ( $this->m_wikipage instanceof SMWDataValue ) { // do not unstub if not needed |
| 159 | + if ( $this->m_wikipage instanceof SMWDataValue ) { |
176 | 160 | $this->m_wikipage->setOutputFormat( $formatstring ); |
177 | 161 | } |
178 | 162 | } |
179 | 163 | |
180 | 164 | 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 ) ); |
183 | 166 | } |
184 | 167 | |
185 | 168 | /** |
— | — | @@ -188,11 +171,10 @@ |
189 | 172 | * @return SMWWikiPageValue or null |
190 | 173 | */ |
191 | 174 | public function getWikiPageValue() { |
192 | | - $this->unstub(); |
193 | 175 | if ( !isset( $this->m_wikipage ) ) { |
194 | 176 | $diWikiPage = $this->m_dataitem->getDiWikiPage(); |
195 | 177 | if ( $diWikiPage !== null ) { |
196 | | - $this->m_wikipage = SMWDataValueFactory::newDataItemValue( $diWikiPage, $this->m_caption ); |
| 178 | + $this->m_wikipage = SMWDataValueFactory::newDataItemValue( $diWikiPage, null, $this->m_caption ); |
197 | 179 | $this->m_wikipage->setOutputFormat( $this->m_outformat ); |
198 | 180 | $this->addError( $this->m_wikipage->getErrors() ); |
199 | 181 | } else { // should rarely happen ($value is only changed if the input $value really was a label for a predefined prop) |
— | — | @@ -208,7 +190,6 @@ |
209 | 191 | * @note Every user defined property is necessarily visible. |
210 | 192 | */ |
211 | 193 | public function isVisible() { |
212 | | - $this->unstub(); |
213 | 194 | return ( $this->m_dataitem->isUserDefined() ) || ( $this->m_dataitem->getLabel() != '' ); |
214 | 195 | } |
215 | 196 | |
— | — | @@ -228,26 +209,6 @@ |
229 | 210 | return $this->isVisible() ? $this->highlightText( $this->getWikiPageValue()->getLongHTMLText( $linker ) ) : ''; |
230 | 211 | } |
231 | 212 | |
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 | | - |
252 | 213 | public function getWikiValue() { |
253 | 214 | return $this->isVisible() ? ( ( $this->isInverse() ? '-' : '' ) . $this->getWikiPageValue()->getWikiValue() ) : ''; |
254 | 215 | } |
— | — | @@ -257,7 +218,6 @@ |
258 | 219 | * that property. Otherwise return FALSE; |
259 | 220 | */ |
260 | 221 | public function getPropertyID() { |
261 | | - $this->unstub(); |
262 | 222 | return $this->m_dataitem->isUserDefined() ? false : $this->m_dataitem->getKey(); |
263 | 223 | } |
264 | 224 | |
— | — | @@ -285,8 +245,8 @@ |
286 | 246 | $result->addError( wfMsgForContent( 'smw_manytypes' ) ); |
287 | 247 | } |
288 | 248 | } 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 ); |
291 | 251 | } |
292 | 252 | $this->mPropTypeValue = $result; |
293 | 253 | } |
— | — | @@ -349,7 +309,6 @@ |
350 | 310 | * @deprecated |
351 | 311 | */ |
352 | 312 | public function isUserDefined() { |
353 | | - $this->unstub(); |
354 | 313 | return $this->m_dataitem->isUserDefined(); |
355 | 314 | } |
356 | 315 | |
— | — | @@ -358,7 +317,6 @@ |
359 | 318 | * @deprecated |
360 | 319 | */ |
361 | 320 | public function isShown() { |
362 | | - $this->unstub(); |
363 | 321 | return $this->m_dataitem->isShown(); |
364 | 322 | } |
365 | 323 | |
— | — | @@ -367,7 +325,6 @@ |
368 | 326 | * @deprecated |
369 | 327 | */ |
370 | 328 | public function isInverse() { |
371 | | - $this->unstub(); |
372 | 329 | return $this->m_dataitem->isInverse(); |
373 | 330 | } |
374 | 331 | |
— | — | @@ -379,7 +336,6 @@ |
380 | 337 | * @deprecated |
381 | 338 | */ |
382 | 339 | public function getDBkey() { |
383 | | - $this->unstub(); |
384 | 340 | return $this->m_dataitem->getKey(); |
385 | 341 | } |
386 | 342 | |
— | — | @@ -388,7 +344,6 @@ |
389 | 345 | * @deprecated |
390 | 346 | */ |
391 | 347 | public function getText() { |
392 | | - $this->unstub(); |
393 | 348 | return $this->m_dataitem->getLabel(); |
394 | 349 | } |
395 | 350 | |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Number.php |
— | — | @@ -117,17 +117,12 @@ |
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
121 | | - protected function parseDBkeys( $args ) { |
122 | | - $dataItem = SMWDINumber::doUnserialize( $args[0], $this->m_typeid ); |
123 | | - $this->setDataItem( $dataItem ); |
124 | | - } |
125 | | - |
126 | 121 | /** |
127 | | - * @see SMWDataValue::setDataItem() |
| 122 | + * @see SMWDataValue::loadDataItem() |
128 | 123 | * @param $dataitem SMWDataItem |
129 | 124 | * @return boolean |
130 | 125 | */ |
131 | | - public function setDataItem( SMWDataItem $dataItem ) { |
| 126 | + protected function loadDataItem( SMWDataItem $dataItem ) { |
132 | 127 | if ( $dataItem->getDIType() == SMWDataItem::TYPE_NUMBER ) { |
133 | 128 | $this->m_dataitem = $dataItem; |
134 | 129 | $this->m_caption = false; |
— | — | @@ -152,7 +147,6 @@ |
153 | 148 | } |
154 | 149 | |
155 | 150 | public function getShortWikiText( $linked = null ) { |
156 | | - $this->unstub(); |
157 | 151 | if ( ( $linked === null ) || ( $linked === false ) || ( $this->m_outformat == '-' ) |
158 | 152 | || ( $this->m_outformat == '-u' ) || ( $this->m_outformat == '-n' ) || ( !$this->isValid() ) ) { |
159 | 153 | return $this->m_caption; |
— | — | @@ -188,7 +182,6 @@ |
189 | 183 | } |
190 | 184 | |
191 | 185 | public function getLongWikiText( $linked = null ) { |
192 | | - $this->unstub(); |
193 | 186 | if ( !$this->isValid() ) { |
194 | 187 | return $this->getErrorText(); |
195 | 188 | } else { |
— | — | @@ -221,30 +214,11 @@ |
222 | 215 | return $this->getLongWikiText( $linker ); |
223 | 216 | } |
224 | 217 | |
225 | | - public function getDBkeys() { |
226 | | - $this->unstub(); |
227 | | - return array( $this->m_dataitem->getSerialization(), floatval( $this->m_dataitem->getNumber() ) ); |
228 | | - } |
229 | | - |
230 | 218 | public function getNumber() { |
231 | | - $this->unstub(); |
232 | 219 | return $this->m_dataitem->getNumber(); |
233 | 220 | } |
234 | 221 | |
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 | | - |
247 | 222 | public function getWikiValue() { |
248 | | - $this->unstub(); |
249 | 223 | $unit = $this->getUnit(); |
250 | 224 | return strval( $this->m_dataitem->getSerialization() ) . ( $unit != '' ? ' ' . $unit : '' ); |
251 | 225 | } |
— | — | @@ -261,7 +235,6 @@ |
262 | 236 | } |
263 | 237 | |
264 | 238 | protected function getServiceLinkParams() { |
265 | | - $this->unstub(); |
266 | 239 | // Create links to mapping services based on a wiki-editable message. The parameters |
267 | 240 | // available to the message are: |
268 | 241 | // $1: string of numerical value in English punctuation |
— | — | @@ -270,7 +243,6 @@ |
271 | 244 | } |
272 | 245 | |
273 | 246 | public function getExportData() { |
274 | | - $this->unstub(); |
275 | 247 | if ( $this->isValid() ) { |
276 | 248 | $lit = new SMWExpLiteral( $this->m_dataitem->getNumber(), $this, 'http://www.w3.org/2001/XMLSchema#double' ); |
277 | 249 | return new SMWExpData( $lit ); |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Error.php |
— | — | @@ -31,21 +31,12 @@ |
32 | 32 | $this->addError( wfMsgForContent( 'smw_parseerror' ) ); |
33 | 33 | } |
34 | 34 | |
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 | | - |
44 | 35 | /** |
45 | | - * @see SMWDataValue::setDataItem() |
| 36 | + * @see SMWDataValue::loadDataItem() |
46 | 37 | * @param $dataitem SMWDataItem |
47 | 38 | * @return boolean |
48 | 39 | */ |
49 | | - public function setDataItem( SMWDataItem $dataItem ) { |
| 40 | + protected function loadDataItem( SMWDataItem $dataItem ) { |
50 | 41 | if ( $dataItem->getDIType() == SMWDataItem::TYPE_ERROR ) { |
51 | 42 | $this->addError( $dataItem->getErrors() ); |
52 | 43 | $this->m_caption = $this->getErrorText(); |
— | — | @@ -56,7 +47,6 @@ |
57 | 48 | } |
58 | 49 | |
59 | 50 | public function getShortWikiText( $linked = null ) { |
60 | | - $this->unstub(); |
61 | 51 | return $this->m_caption; |
62 | 52 | } |
63 | 53 | |
— | — | @@ -65,19 +55,13 @@ |
66 | 56 | } |
67 | 57 | |
68 | 58 | public function getLongWikiText( $linked = null ) { |
69 | | - $this->unstub(); |
70 | 59 | return $this->getErrorText(); |
71 | 60 | } |
72 | 61 | |
73 | 62 | public function getLongHTMLText( $linker = null ) { |
74 | | - $this->unstub(); |
75 | 63 | return $this->getErrorText(); |
76 | 64 | } |
77 | 65 | |
78 | | - public function getDBkeys() { |
79 | | - return array( $this->m_dataitem->getString() ); |
80 | | - } |
81 | | - |
82 | 66 | public function getWikiValue() { |
83 | 67 | return $this->m_dataitem->getString(); |
84 | 68 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Bool.php |
— | — | @@ -47,17 +47,12 @@ |
48 | 48 | $this->m_dataitem = new SMWDIBoolean( $boolvalue, $this->m_typeid ); |
49 | 49 | } |
50 | 50 | |
51 | | - protected function parseDBkeys( $args ) { |
52 | | - $this->parseUserValue( $args[0] ); |
53 | | - $this->m_caption = $this->getStandardCaption( true ); // use default for this language |
54 | | - } |
55 | | - |
56 | 51 | /** |
57 | | - * @see SMWDataValue::setDataItem() |
| 52 | + * @see SMWDataValue::loadDataItem() |
58 | 53 | * @param $dataitem SMWDataItem |
59 | 54 | * @return boolean |
60 | 55 | */ |
61 | | - public function setDataItem( SMWDataItem $dataItem ) { |
| 56 | + protected function loadDataItem( SMWDataItem $dataItem ) { |
62 | 57 | if ( $dataItem->getDIType() == SMWDataItem::TYPE_BOOLEAN ) { |
63 | 58 | $this->m_dataitem = $dataItem; |
64 | 59 | $this->m_caption = $this->getStandardCaption( true ); // use default for this language |
— | — | @@ -91,12 +86,10 @@ |
92 | 87 | } |
93 | 88 | |
94 | 89 | public function getShortWikiText( $linked = null ) { |
95 | | - $this->unstub(); |
96 | 90 | return $this->m_caption; |
97 | 91 | } |
98 | 92 | |
99 | 93 | public function getShortHTMLText( $linker = null ) { |
100 | | - $this->unstub(); |
101 | 94 | return $this->m_caption; |
102 | 95 | } |
103 | 96 | |
— | — | @@ -108,30 +101,11 @@ |
109 | 102 | return $this->isValid() ? $this->getStandardCaption( true ) : $this->getErrorText(); |
110 | 103 | } |
111 | 104 | |
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 | | - |
129 | 105 | public function getWikiValue() { |
130 | | - $this->unstub(); |
131 | 106 | return $this->getStandardCaption( false ); |
132 | 107 | } |
133 | 108 | |
134 | 109 | public function getBoolean() { |
135 | | - $this->unstub(); |
136 | 110 | return $this->m_dataitem->getBoolean(); |
137 | 111 | } |
138 | 112 | |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Concept.php |
— | — | @@ -19,17 +19,12 @@ |
20 | 20 | throw new Exception( 'Concepts cannot be initialised from user-provided strings. This should not happen.' ); |
21 | 21 | } |
22 | 22 | |
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 | | - |
28 | 23 | /** |
29 | | - * @see SMWDataValue::setDataItem() |
| 24 | + * @see SMWDataValue::loadDataItem() |
30 | 25 | * @param $dataitem SMWDataItem |
31 | 26 | * @return boolean |
32 | 27 | */ |
33 | | - public function setDataItem( SMWDataItem $dataItem ) { |
| 28 | + protected function loadDataItem( SMWDataItem $dataItem ) { |
34 | 29 | if ( $dataItem->getDIType() == SMWDataItem::TYPE_CONCEPT ) { |
35 | 30 | $this->m_dataitem = $dataItem; |
36 | 31 | $this->m_caption = $dataItem->getConceptQuery(); // probably useless |
— | — | @@ -44,7 +39,6 @@ |
45 | 40 | } |
46 | 41 | |
47 | 42 | public function getShortWikiText( $linked = null ) { |
48 | | - $this->unstub(); |
49 | 43 | return $this->m_caption; |
50 | 44 | } |
51 | 45 | |
— | — | @@ -68,25 +62,7 @@ |
69 | 63 | } |
70 | 64 | } |
71 | 65 | |
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 | | - |
89 | 66 | public function getWikiValue() { |
90 | | - $this->unstub(); |
91 | 67 | /// This should not be used for anything. This class does not support wiki values. |
92 | 68 | return str_replace( array( '<', '>', '&' ), array( '<', '>', '&' ), $this->m_dataitem->getConceptQuery() ); |
93 | 69 | } |
— | — | @@ -184,37 +160,27 @@ |
185 | 161 | |
186 | 162 | /// Return the concept's defining text (in SMW query syntax) |
187 | 163 | public function getConceptText() { |
188 | | - $this->unstub(); |
189 | 164 | return $this->m_dataitem->getConceptQuery(); |
190 | 165 | } |
191 | 166 | |
192 | 167 | /// Return the optional concept documentation. |
193 | 168 | public function getDocu() { |
194 | | - $this->unstub(); |
195 | 169 | return $this->m_dataitem->getDocumentation(); |
196 | 170 | } |
197 | 171 | |
198 | 172 | /// Return the concept's size (a metric used to estimate computation complexity). |
199 | 173 | public function getSize() { |
200 | | - $this->unstub(); |
201 | 174 | return $this->m_dataitem->getSize(); |
202 | 175 | } |
203 | 176 | |
204 | 177 | /// Return the concept's depth (a metric used to estimate computation complexity). |
205 | 178 | public function getDepth() { |
206 | | - $this->unstub(); |
207 | 179 | return $this->m_dataitem->getDepth(); |
208 | 180 | } |
209 | 181 | |
210 | 182 | /// Return the concept's query feature bit field (a metric used to estimate computation complexity). |
211 | 183 | public function getQueryFeatures() { |
212 | | - $this->unstub(); |
213 | 184 | return $this->m_dataitem->getQueryFeatures(); |
214 | 185 | } |
215 | 186 | |
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 | | - |
221 | 187 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php |
— | — | @@ -574,43 +574,12 @@ |
575 | 575 | } |
576 | 576 | } |
577 | 577 | |
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 | | - |
609 | 578 | /** |
610 | | - * @see SMWDataValue::setDataItem() |
| 579 | + * @see SMWDataValue::loadDataItem() |
611 | 580 | * @param $dataitem SMWDataItem |
612 | 581 | * @return boolean |
613 | 582 | */ |
614 | | - public function setDataItem( SMWDataItem $dataItem ) { |
| 583 | + protected function loadDataItem( SMWDataItem $dataItem ) { |
615 | 584 | if ( $dataItem->getDIType() == SMWDataItem::TYPE_TIME ) { |
616 | 585 | $this->m_dataitem = $dataItem; |
617 | 586 | $this->m_caption = $this->m_wikivalue = false; |
— | — | @@ -636,30 +605,8 @@ |
637 | 606 | return $this->getLongWikiText( $linker ); // safe in HTML |
638 | 607 | } |
639 | 608 | |
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 | | - |
661 | 609 | /// @todo The preferred caption may not be suitable as a wiki value (i.e. not parsable). |
662 | 610 | public function getWikiValue() { |
663 | | - $this->unstub(); |
664 | 611 | return $this->m_wikivalue ? $this->m_wikivalue : $this->getPreferredCaption(); |
665 | 612 | } |
666 | 613 | |
— | — | @@ -672,7 +619,7 @@ |
673 | 620 | $lit = new SMWExpLiteral( $this->getISO8601Date(), $this, 'http://www.w3.org/2001/XMLSchema#dateTime' ); |
674 | 621 | return new SMWExpData( $lit ); |
675 | 622 | } else { |
676 | | - return NULL; |
| 623 | + return null; |
677 | 624 | } |
678 | 625 | } |
679 | 626 | |
— | — | @@ -736,7 +683,6 @@ |
737 | 684 | * also be set to false to detect this situation. |
738 | 685 | */ |
739 | 686 | public function getTimeString( $default = '00:00:00' ) { |
740 | | - $this->unstub(); |
741 | 687 | if ( $this->m_dataitem->getPrecision() < SMWDITime::PREC_YMDT ) { |
742 | 688 | return $default; |
743 | 689 | } else { |
— | — | @@ -747,17 +693,7 @@ |
748 | 694 | } |
749 | 695 | |
750 | 696 | /** |
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. |
762 | 698 | */ |
763 | 699 | public function getXMLSchemaDate( $mindefault = true ) { |
764 | 700 | return $this->getISO8601Date( $mindefault ); |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_URI.php |
— | — | @@ -93,7 +93,7 @@ |
94 | 94 | $fragment = ( count( $parts ) == 2 ) ? $parts[1] : ''; |
95 | 95 | } else { |
96 | 96 | $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" |
98 | 98 | $hierpart = $parts[0]; |
99 | 99 | $fragment = ( count( $parts ) == 2 ) ? $parts[1] : ''; |
100 | 100 | } |
— | — | @@ -158,23 +158,12 @@ |
159 | 159 | return (bool) preg_match( $tel_uri_regex, $s ); |
160 | 160 | } |
161 | 161 | |
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 | | - |
173 | 162 | /** |
174 | | - * @see SMWDataValue::setDataItem() |
| 163 | + * @see SMWDataValue::loadDataItem() |
175 | 164 | * @param $dataitem SMWDataItem |
176 | 165 | * @return boolean |
177 | 166 | */ |
178 | | - public function setDataItem( SMWDataItem $dataItem ) { |
| 167 | + protected function loadDataItem( SMWDataItem $dataItem ) { |
179 | 168 | if ( $dataItem->getDIType() == SMWDataItem::TYPE_URI ) { |
180 | 169 | $this->m_dataitem = $dataItem; |
181 | 170 | if ( $this->m_mode == SMW_URI_MODE_EMAIL ) { |
— | — | @@ -192,7 +181,6 @@ |
193 | 182 | } |
194 | 183 | |
195 | 184 | public function getShortWikiText( $linked = null ) { |
196 | | - $this->unstub(); |
197 | 185 | $url = $this->getURL(); |
198 | 186 | if ( ( $linked === null ) || ( $linked === false ) || ( $this->m_outformat == '-' ) || ( $url == '' ) || ( $this->m_caption == '' ) ) { |
199 | 187 | return $this->m_caption; |
— | — | @@ -202,7 +190,6 @@ |
203 | 191 | } |
204 | 192 | |
205 | 193 | public function getShortHTMLText( $linker = null ) { |
206 | | - $this->unstub(); |
207 | 194 | $url = $this->getURL(); |
208 | 195 | if ( ( $linker === null ) || ( !$this->isValid() ) || ( $this->m_outformat == '-' ) || ( $url == '' ) || ( $this->m_caption == '' ) ) { |
209 | 196 | return $this->m_caption; |
— | — | @@ -235,35 +222,15 @@ |
236 | 223 | } |
237 | 224 | } |
238 | 225 | |
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 | | - |
256 | 226 | public function getWikiValue() { |
257 | | - $this->unstub(); |
258 | 227 | return $this->m_wikitext; |
259 | 228 | } |
260 | 229 | |
261 | 230 | public function getURI() { |
262 | | - $this->unstub(); |
263 | 231 | return $this->m_dataitem->getURI(); |
264 | 232 | } |
265 | 233 | |
266 | 234 | protected function getServiceLinkParams() { |
267 | | - $this->unstub(); |
268 | 235 | // Create links to mapping services based on a wiki-editable message. The parameters |
269 | 236 | // available to the message are: |
270 | 237 | // $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 @@ |
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
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 | | - |
129 | 118 | /** |
130 | | - * @see SMWDataValue::setDataItem() |
| 119 | + * @see SMWDataValue::loadDataItem() |
131 | 120 | * @param $dataitem SMWDataItem |
132 | 121 | * @return boolean |
133 | 122 | */ |
134 | | - public function setDataItem( SMWDataItem $dataItem ) { |
| 123 | + protected function loadDataItem( SMWDataItem $dataItem ) { |
135 | 124 | if ( $dataItem->getDIType() == SMWDataItem::TYPE_WIKIPAGE ) { |
136 | 125 | $this->m_dataitem = $dataItem; |
137 | 126 | $this->m_textform = str_replace( '_', ' ', $dataItem->getDBkey() ); |
— | — | @@ -149,7 +138,6 @@ |
150 | 139 | } |
151 | 140 | |
152 | 141 | public function getShortWikiText( $linked = null ) { |
153 | | - $this->unstub(); |
154 | 142 | if ( ( $linked === null ) || ( $linked === false ) || ( $this->m_outformat == '-' ) || ( !$this->isValid() ) || ( $this->m_caption === '' ) ) { |
155 | 143 | return $this->getCaption(); |
156 | 144 | } else { |
— | — | @@ -159,7 +147,6 @@ |
160 | 148 | } |
161 | 149 | |
162 | 150 | public function getShortHTMLText( $linker = null ) { |
163 | | - $this->unstub(); |
164 | 151 | if ( ( $linker !== null ) && ( $this->m_caption !== '' ) && ( $this->m_outformat != '-' ) ) $this->getTitle(); // init the Title object, may reveal hitherto unnoticed errors |
165 | 152 | if ( ( $linker === null ) || ( !$this->isValid() ) || ( $this->m_outformat == '-' ) || ( $this->m_caption === '' ) ) { |
166 | 153 | return htmlspecialchars( $this->getCaption() ); |
— | — | @@ -176,7 +163,6 @@ |
177 | 164 | * In all other uses, values come from the store and do not have fragments anyway. |
178 | 165 | */ |
179 | 166 | public function getLongWikiText( $linked = null ) { |
180 | | - $this->unstub(); |
181 | 167 | if ( !$this->isValid() ) { |
182 | 168 | return $this->getErrorText(); |
183 | 169 | } |
— | — | @@ -190,7 +176,6 @@ |
191 | 177 | } |
192 | 178 | |
193 | 179 | public function getLongHTMLText( $linker = null ) { |
194 | | - $this->unstub(); |
195 | 180 | if ( ( $linker !== null ) && ( $this->m_outformat != '-' ) ) { $this->getTitle(); } // init the Title object, may reveal hitherto unnoticed errors |
196 | 181 | if ( !$this->isValid() ) { |
197 | 182 | return $this->getErrorText(); |
— | — | @@ -204,25 +189,7 @@ |
205 | 190 | } |
206 | 191 | } |
207 | 192 | |
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 | | - |
225 | 193 | public function getWikiValue() { |
226 | | - $this->unstub(); |
227 | 194 | if ( $this->m_fixNamespace != NS_MAIN ) { // no explicit namespace needed! |
228 | 195 | return $this->getText(); |
229 | 196 | } elseif ( $this->m_dataitem->getNamespace() == NS_CATEGORY ) { |
— | — | @@ -234,11 +201,10 @@ |
235 | 202 | } |
236 | 203 | |
237 | 204 | public function getHash() { |
238 | | - return $this->isValid() ? $this->getPrefixedText():implode( "\t", $this->getErrors() ); |
| 205 | + return $this->isValid() ? $this->getPrefixedText() : implode( "\t", $this->getErrors() ); |
239 | 206 | } |
240 | 207 | |
241 | 208 | protected function getServiceLinkParams() { |
242 | | - $this->unstub(); |
243 | 209 | // Create links to mapping services based on a wiki-editable message. The parameters |
244 | 210 | // available to the message are: |
245 | 211 | // $1: urlencoded article name (no namespace) |
— | — | @@ -292,7 +258,6 @@ |
293 | 259 | * Get MediaWiki's ID for this value, if any. |
294 | 260 | */ |
295 | 261 | public function getArticleID() { |
296 | | - $this->unstub(); |
297 | 262 | if ( $this->m_id === false ) { |
298 | 263 | $this->m_id = ( $this->getTitle() !== null ) ? $this->m_title->getArticleID() : 0; |
299 | 264 | } |
— | — | @@ -303,7 +268,6 @@ |
304 | 269 | * Get namespace constant for this value. |
305 | 270 | */ |
306 | 271 | public function getNamespace() { |
307 | | - $this->unstub(); |
308 | 272 | return $this->m_dataitem->getNamespace(); |
309 | 273 | } |
310 | 274 | |
— | — | @@ -314,20 +278,17 @@ |
315 | 279 | * to use this method in places where only MediaWiki Title keys are allowed. |
316 | 280 | */ |
317 | 281 | public function getDBkey() { |
318 | | - $this->unstub(); |
319 | 282 | return $this->m_dataitem->getDBkey(); |
320 | 283 | } |
321 | 284 | |
322 | 285 | /// Get text label for this value. |
323 | 286 | public function getText() { |
324 | | - $this->unstub(); |
325 | 287 | return str_replace( '_', ' ', $this->m_dataitem->getDBkey() ); |
326 | 288 | } |
327 | 289 | |
328 | 290 | /// Get the prefixed text for this value, including a localised namespace prefix. |
329 | 291 | public function getPrefixedText() { |
330 | 292 | global $wgContLang; |
331 | | - $this->unstub(); |
332 | 293 | if ( $this->m_prefixedtext == '' ) { |
333 | 294 | $nstext = $wgContLang->getNSText( $this->m_dataitem->getNamespace() ); |
334 | 295 | $this->m_prefixedtext = ( $this->m_dataitem->getInterwiki() != '' ? $this->m_dataitem->getInterwiki() . ':' : '' ) . |
— | — | @@ -340,7 +301,6 @@ |
341 | 302 | * Get interwiki prefix or empty string. |
342 | 303 | */ |
343 | 304 | public function getInterwiki() { |
344 | | - $this->unstub(); |
345 | 305 | return $this->m_dataitem->getInterwiki(); |
346 | 306 | } |
347 | 307 | |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Types.php |
— | — | @@ -16,107 +16,130 @@ |
17 | 17 | * @author Markus Krötzsch |
18 | 18 | * @ingroup SMWDataValues |
19 | 19 | */ |
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; |
21 | 25 | |
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 | + } |
24 | 36 | |
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 ); |
29 | 39 | } |
30 | 40 | |
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 | + } |
36 | 77 | } |
37 | 78 | |
38 | 79 | /** |
39 | | - * @see SMWDataValue::setDataItem() |
| 80 | + * @see SMWDataValue::loadDataItem() |
40 | 81 | * @param $dataitem SMWDataItem |
41 | 82 | * @return boolean |
42 | 83 | */ |
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; |
47 | 93 | return true; |
48 | 94 | } else { |
49 | 95 | return false; |
50 | 96 | } |
51 | 97 | } |
52 | 98 | |
| 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 | + |
53 | 115 | public function getLongWikiText( $linked = null ) { |
54 | | - $this->unstub(); |
55 | 116 | 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; |
68 | 120 | } |
69 | 121 | } |
70 | 122 | |
71 | 123 | public function getLongHTMLText( $linker = null ) { |
72 | | - $this->unstub(); |
73 | 124 | 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 ); |
87 | 128 | } |
88 | 129 | } |
89 | 130 | |
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 | | - |
106 | 131 | public function getWikiValue() { |
107 | | - $this->unstub(); |
108 | | - return $this->m_reallabel; |
| 132 | + return $this->m_realLabel; |
109 | 133 | } |
110 | 134 | |
111 | 135 | public function getHash() { |
112 | | - $this->unstub(); |
113 | | - return $this->m_reallabel; |
| 136 | + return $this->m_realLabel; |
114 | 137 | } |
115 | 138 | |
116 | 139 | /** |
117 | 140 | * This class uses type ids as DB keys. |
118 | 141 | */ |
119 | 142 | public function getDBkey() { |
120 | | - return ( $this->isValid() ) ? SMWDataValueFactory::findTypeID( $this->m_reallabel ) : ''; |
| 143 | + return ( $this->isValid() ) ? SMWDataValueFactory::findTypeID( $this->m_realLabel ) : ''; |
121 | 144 | } |
122 | 145 | |
123 | 146 | /** |
— | — | @@ -133,8 +156,7 @@ |
134 | 157 | * explain entries in Special:Types that are found since they have pages. |
135 | 158 | */ |
136 | 159 | public function isAlias() { |
137 | | - $this->unstub(); |
138 | | - return $this->m_isalias; |
| 160 | + return $this->m_isAlias; |
139 | 161 | } |
140 | 162 | |
141 | 163 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_String.php |
— | — | @@ -35,17 +35,12 @@ |
36 | 36 | } |
37 | 37 | } |
38 | 38 | |
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 | | - |
44 | 39 | /** |
45 | | - * @see SMWDataValue::setDataItem() |
| 40 | + * @see SMWDataValue::loadDataItem() |
46 | 41 | * @param $dataitem SMWDataItem |
47 | 42 | * @return boolean |
48 | 43 | */ |
49 | | - public function setDataItem( SMWDataItem $dataItem ) { |
| 44 | + protected function loadDataItem( SMWDataItem $dataItem ) { |
50 | 45 | $diType = ( ( $this->m_typeid == '_txt' ) || ( $this->m_typeid == '_cod' ) ) ? SMWDataItem::TYPE_BLOB : SMWDataItem::TYPE_STRING; |
51 | 46 | if ( $dataItem->getDIType() == $diType ) { |
52 | 47 | $this->m_dataitem = $dataItem; |
— | — | @@ -61,7 +56,6 @@ |
62 | 57 | } |
63 | 58 | |
64 | 59 | public function getShortWikiText( $linked = null ) { |
65 | | - $this->unstub(); |
66 | 60 | return $this->m_caption; |
67 | 61 | } |
68 | 62 | |
— | — | @@ -83,38 +77,11 @@ |
84 | 78 | return $this->isValid() ? $this->getAbbValue( $linker, smwfXMLContentEncode( $this->m_dataitem->getString() ) ) : $this->getErrorText(); |
85 | 79 | } |
86 | 80 | |
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 | | - |
112 | 81 | public function getWikiValue() { |
113 | | - $this->unstub(); |
114 | 82 | return $this->m_dataitem->getString(); |
115 | 83 | } |
116 | 84 | |
117 | 85 | public function getInfolinks() { |
118 | | - $this->unstub(); |
119 | 86 | if ( ( $this->m_typeid != '_txt' ) && ( $this->m_typeid != '_cod' ) ) { |
120 | 87 | return parent::getInfolinks(); |
121 | 88 | } else { |
— | — | @@ -123,7 +90,6 @@ |
124 | 91 | } |
125 | 92 | |
126 | 93 | protected function getServiceLinkParams() { |
127 | | - $this->unstub(); |
128 | 94 | // Create links to mapping services based on a wiki-editable message. The parameters |
129 | 95 | // available to the message are: |
130 | 96 | // $1: urlencoded string |
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_JSONlink.php |
— | — | @@ -66,20 +66,20 @@ |
67 | 67 | if ( $pr->getMode() != SMWPrintRequest::PRINT_THIS ) { |
68 | 68 | $values = array(); |
69 | 69 | $finalvalues = ''; |
70 | | - while ( ( $value = $field->getNextDataValue() ) !== false ) { |
| 70 | + while ( ( $dataValue = $field->getNextDataValue() ) !== false ) { |
71 | 71 | $finalvalues = ''; |
72 | | - switch ( $value->getTypeID() ) { |
| 72 | + switch ( $dataValue->getTypeID() ) { |
73 | 73 | case '_geo': |
74 | | - $values[] = "\"" . $value->getWikiValue() . "\""; |
| 74 | + $values[] = "\"" . $dataValue->getWikiValue() . "\""; |
75 | 75 | break; |
76 | 76 | case '_num': |
77 | | - $values[] = "\"" . $value->getValueKey() . "\""; |
| 77 | + $values[] = "\"" . $dataValue->getValueKey() . "\""; |
78 | 78 | break; |
79 | 79 | 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() . "\""; |
81 | 81 | break; |
82 | 82 | default: |
83 | | - $values[] = "\"" . $value->getShortText( $outputmode, null ) . "\""; |
| 83 | + $values[] = "\"" . $dataValue->getShortText( $outputmode, null ) . "\""; |
84 | 84 | } |
85 | 85 | |
86 | 86 | if ( sizeof( $values ) > 1 ) { |
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_Embedded.php |
— | — | @@ -68,8 +68,8 @@ |
69 | 69 | |
70 | 70 | // Print all result rows: |
71 | 71 | 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 ); |
74 | 74 | $result .= $embstart; |
75 | 75 | |
76 | 76 | if ( $this->m_showhead ) { |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php |
— | — | @@ -43,7 +43,7 @@ |
44 | 44 | $text = ''; |
45 | 45 | if ( wfRunHooks( 'smwShowFactbox', array( &$text, $semdata ) ) ) { |
46 | 46 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
47 | | - $subjectDv = SMWDataValueFactory::newDataItemValue( $semdata->getSubject() ); |
| 47 | + $subjectDv = SMWDataValueFactory::newDataItemValue( $semdata->getSubject(), null ); |
48 | 48 | SMWOutputs::requireHeadItem( SMW_HEADER_STYLE ); |
49 | 49 | $rdflink = SMWInfolink::newInternalLink( |
50 | 50 | wfMsgForContent( 'smw_viewasrdf' ), |
— | — | @@ -62,7 +62,7 @@ |
63 | 63 | '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' . |
64 | 64 | '<table class="smwfacttable">' . "\n"; |
65 | 65 | foreach ( $semdata->getProperties() as $propertyDi ) { |
66 | | - $propertyDv = SMWDataValueFactory::newDataItemValue( $propertyDi ); |
| 66 | + $propertyDv = SMWDataValueFactory::newDataItemValue( $propertyDi, null ); |
67 | 67 | if ( !$propertyDi->isShown() ) { // showing this is not desired, hide |
68 | 68 | continue; |
69 | 69 | } elseif ( $propertyDi->isUserDefined() ) { // user defined property |
— | — | @@ -87,7 +87,7 @@ |
88 | 88 | } |
89 | 89 | } |
90 | 90 | $i += 1; |
91 | | - $dv = SMWDataValueFactory::newDataItemValue( $di, false, $propertyDi ); |
| 91 | + $dv = SMWDataValueFactory::newDataItemValue( $di, $propertyDi ); |
92 | 92 | $text .= $dv->getLongWikiText( true ) . $dv->getInfolinkText( SMW_OUTPUT_WIKI ); |
93 | 93 | } |
94 | 94 | $text .= '</td></tr>'; |
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_OrderedListPage.php |
— | — | @@ -54,6 +54,13 @@ |
55 | 55 | protected $skin; |
56 | 56 | |
57 | 57 | /** |
| 58 | + * Property that the displayed values are for, if any. |
| 59 | + * |
| 60 | + * @var SMWDIProperty |
| 61 | + */ |
| 62 | + protected $mProperty = null; |
| 63 | + |
| 64 | + /** |
58 | 65 | * Overwrite view() from Article.php to add additional html to the output. |
59 | 66 | */ |
60 | 67 | public function view() { |
— | — | @@ -237,7 +244,7 @@ |
238 | 245 | |
239 | 246 | // output all diWikiPages |
240 | 247 | for ( $index = $startChunk ; $index < $endChunk && $index < $end; $index++ ) { |
241 | | - $dataValue = SMWDataValueFactory::newDataItemValue( $diWikiPages[$index] ); |
| 248 | + $dataValue = SMWDataValueFactory::newDataItemValue( $diWikiPages[$index], $this->mProperty ); |
242 | 249 | // check for change of starting letter or begining of chunk |
243 | 250 | $sortkey = smwfGetStore()->getWikiPageSortKey( $diWikiPages[$index] ); |
244 | 251 | $start_char = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) ); |
— | — | @@ -287,7 +294,7 @@ |
288 | 295 | protected function shortList( $start, $end, array $diWikiPages ) { |
289 | 296 | global $wgContLang; |
290 | 297 | |
291 | | - $startDv = SMWDataValueFactory::newDataItemValue( $diWikiPages[$start] ); |
| 298 | + $startDv = SMWDataValueFactory::newDataItemValue( $diWikiPages[$start], $this->mProperty ); |
292 | 299 | $sortkey = smwfGetStore()->getWikiPageSortKey( $diWikiPages[$start] ); |
293 | 300 | $start_char = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) ); |
294 | 301 | $r = '<h3>' . htmlspecialchars( $start_char ) . "</h3>\n" . |
— | — | @@ -295,7 +302,7 @@ |
296 | 303 | |
297 | 304 | $prev_start_char = $start_char; |
298 | 305 | for ( $index = $start + 1; $index < $end; $index++ ) { |
299 | | - $dataValue = SMWDataValueFactory::newDataItemValue( $diWikiPages[$index] ); |
| 306 | + $dataValue = SMWDataValueFactory::newDataItemValue( $diWikiPages[$index], $this->mProperty ); |
300 | 307 | $sortkey = smwfGetStore()->getWikiPageSortKey( $diWikiPages[$index] ); |
301 | 308 | $start_char = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) ); |
302 | 309 | |
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_PropertyPage.php |
— | — | @@ -15,7 +15,6 @@ |
16 | 16 | class SMWPropertyPage extends SMWOrderedListPage { |
17 | 17 | |
18 | 18 | private $subproperties; // list of sub-properties of this property |
19 | | - private $mProperty; // property object |
20 | 19 | |
21 | 20 | /** |
22 | 21 | * @see SMWOrderedListPage::initParameters() |
— | — | @@ -143,7 +142,7 @@ |
144 | 143 | |
145 | 144 | for ( $index = $start; $index < $ac; $index++ ) { |
146 | 145 | $diWikiPage = $this->diWikiPages[$index]; |
147 | | - $dvWikiPage = SMWDataValueFactory::newDataItemValue( $diWikiPage ); |
| 146 | + $dvWikiPage = SMWDataValueFactory::newDataItemValue( $diWikiPage, $this->mProperty ); |
148 | 147 | $sortkey = smwfGetStore()->getWikiPageSortKey( $diWikiPage ); |
149 | 148 | $start_char = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) ); |
150 | 149 | |
— | — | @@ -171,7 +170,7 @@ |
172 | 171 | $i++; |
173 | 172 | |
174 | 173 | if ( $i < $smwgMaxPropertyValues + 1 ) { |
175 | | - $dv = SMWDataValueFactory::newDataItemValue( $di ); |
| 174 | + $dv = SMWDataValueFactory::newDataItemValue( $di, $this->mProperty ); |
176 | 175 | $r .= $dv->getLongHTMLText( $this->getSkin() ) . $dv->getInfolinkText( SMW_OUTPUT_HTML, $this->getSkin() ); |
177 | 176 | } else { |
178 | 177 | $searchlink = SMWInfolink::newInversePropertySearchLink( '…', $dvWikiPage->getWikiValue(), $this->mTitle->getText() ); |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php |
— | — | @@ -113,9 +113,9 @@ |
114 | 114 | * |
115 | 115 | * @return string |
116 | 116 | */ |
117 | | - public function getTypeID() { |
118 | | - return '_wpg'; |
119 | | - } |
| 117 | +// public function getTypeID() { |
| 118 | +// return '_wpg'; |
| 119 | +// } |
120 | 120 | |
121 | 121 | /** |
122 | 122 | * Recursively restrict query to a maximal size and depth as given. |
— | — | @@ -180,9 +180,9 @@ |
181 | 181 | * processing an SMWSomeProperty object where the property does not specify |
182 | 182 | * the type. |
183 | 183 | */ |
184 | | - public function getTypeID() { |
185 | | - return ''; |
186 | | - } |
| 184 | +// public function getTypeID() { |
| 185 | +// return ''; |
| 186 | +// } |
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
— | — | @@ -216,7 +216,7 @@ |
217 | 217 | public function getQueryString( $asvalue = false ) { |
218 | 218 | $first = true; |
219 | 219 | foreach ( $this->m_diWikiPages as $wikiPage ) { |
220 | | - $wikiValue = SMWDataValueFactory::newDataItemValue( $wikiPage ); |
| 220 | + $wikiValue = SMWDataValueFactory::newDataItemValue( $wikiPage, null ); |
221 | 221 | if ( $first ) { |
222 | 222 | $result = '[[' . $wikiValue->getPrefixedText(); |
223 | 223 | $first = false; |
— | — | @@ -296,7 +296,7 @@ |
297 | 297 | } |
298 | 298 | |
299 | 299 | public function getQueryString( $asvalue = false ) { |
300 | | - $pageValue = SMWDataValueFactory::newDataItemValue( $this->m_concept ); |
| 300 | + $pageValue = SMWDataValueFactory::newDataItemValue( $this->m_concept, null ); |
301 | 301 | $result = '[[' . $pageValue->getPrefixedText() . ']]'; |
302 | 302 | if ( $asvalue ) { |
303 | 303 | return ' <q>' . $result . '</q> '; |
— | — | @@ -414,9 +414,9 @@ |
415 | 415 | return 1; |
416 | 416 | } |
417 | 417 | |
418 | | - public function getTypeID() { |
419 | | - return $this->m_dataItem->getTypeID(); |
420 | | - } |
| 418 | +// public function getTypeID() { |
| 419 | +// return $this->m_dataItem->getTypeID(); |
| 420 | +// } |
421 | 421 | |
422 | 422 | } |
423 | 423 | |
— | — | @@ -500,13 +500,13 @@ |
501 | 501 | return $depth; |
502 | 502 | } |
503 | 503 | |
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 | +// } |
511 | 511 | |
512 | 512 | public function getQueryFeatures() { |
513 | 513 | $result = SMW_CONJUNCTION_QUERY; |
— | — | @@ -670,13 +670,13 @@ |
671 | 671 | return $depth; |
672 | 672 | } |
673 | 673 | |
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 | +// } |
681 | 681 | |
682 | 682 | public function getQueryFeatures() { |
683 | 683 | $result = SMW_DISJUNCTION_QUERY; |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_QueryResult.php |
— | — | @@ -348,7 +348,12 @@ |
349 | 349 | if ( $di === false ) { |
350 | 350 | return false; |
351 | 351 | } |
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 ); |
353 | 358 | if ( $this->mPrintRequest->getOutputFormat() ) { |
354 | 359 | $dv->setOutputFormat( $this->mPrintRequest->getOutputFormat() ); |
355 | 360 | } |
— | — | @@ -368,12 +373,12 @@ |
369 | 374 | * @return string or false |
370 | 375 | */ |
371 | 376 | 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 ); |
376 | 381 | } else { |
377 | | - return $dv->getShortText( $outputMode, $linker ); |
| 382 | + return $dataValue->getShortText( $outputMode, $linker ); |
378 | 383 | } |
379 | 384 | } else { |
380 | 385 | return false; |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php |
— | — | @@ -134,9 +134,7 @@ |
135 | 135 | |
136 | 136 | /** |
137 | 137 | * 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. |
141 | 139 | * |
142 | 140 | * @return string |
143 | 141 | */ |
— | — | @@ -145,10 +143,10 @@ |
146 | 144 | if ( $this->m_mode == SMWPrintRequest::PRINT_PROP ) { |
147 | 145 | $this->m_typeid = $this->m_data->getDataItem()->findPropertyTypeID(); |
148 | 146 | } else { |
149 | | - $this->m_typeid = '_wpg'; // return objects might be titles, but anyway |
| 147 | + $this->m_typeid = '_wpg'; |
150 | 148 | } |
151 | 149 | } |
152 | | - |
| 150 | + |
153 | 151 | return $this->m_typeid; |
154 | 152 | } |
155 | 153 | |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php |
— | — | @@ -474,7 +474,7 @@ |
475 | 475 | $this->m_queries[$cqid] = $cquery; |
476 | 476 | } |
477 | 477 | } 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 ) { |
479 | 479 | if ( $description->getComparator() == SMW_CMP_EQ ) { |
480 | 480 | $query->type = SMW_SQL2_VALUE; |
481 | 481 | $oid = $this->m_store->getSMWPageID( $description->getDataItem()->getDBkey(), $description->getDataItem()->getNamespace(), $description->getDataItem()->getInterwiki() ); |
— | — | @@ -575,14 +575,8 @@ |
576 | 576 | */ |
577 | 577 | protected function compilePropertyCondition( SMWSQLStore2Query $query, SMWDIProperty $property, SMWDescription $valuedesc ) { |
578 | 578 | $tableid = SMWSQLStore2::findPropertyTableID( $property ); |
| 579 | + $typeid = $property->findPropertyTypeID(); |
579 | 580 | |
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 | | - |
587 | 581 | if ( $tableid == '' ) { // Still no table to query? Give up. |
588 | 582 | $query->type = SMW_SQL2_NOQUERY; |
589 | 583 | return; |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SparqlStoreQueryEngine.php |
— | — | @@ -787,44 +787,56 @@ |
788 | 788 | protected function buildValueCondition( SMWValueDescription $description, $joinVariable, $orderByProperty ) { |
789 | 789 | $dataItem = $description->getDataItem(); |
790 | 790 | |
791 | | - $comparator = ''; |
792 | 791 | switch ( $description->getComparator() ) { |
793 | | - case SMW_CMP_EQ: $comparator = '='; break; |
| 792 | + case SMW_CMP_EQ: $comparator = '='; break; |
794 | 793 | case SMW_CMP_LESS: $comparator = '<'; break; |
795 | 794 | 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; |
799 | 798 | 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 |
801 | 801 | } |
802 | 802 | |
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 == '=' ) { |
815 | 806 | $expElement = SMWExporter::getDataItemHelperExpElement( $dataItem ); |
816 | 807 | if ( $expElement === null ) { |
817 | 808 | $expElement = SMWExporter::getDataItemExpElement( $dataItem ); |
818 | 809 | } |
| 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 { |
819 | 823 | $result = new SMWSparqlFilterCondition( '', array() ); |
820 | 824 | $this->addOrderByData( $result, $joinVariable, $dataItem->getDIType() ); |
821 | 825 | $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 | + |
822 | 836 | $valueName = SMWTurtleSerializer::getTurtleNameForExpElement( $expElement ); |
823 | 837 | if ( $expElement instanceof SMWExpNsResource ) { |
824 | 838 | $result->namespaces[$expElement->getNamespaceId()] = $expElement->getNamespace(); |
825 | 839 | } |
826 | 840 | $result->filter = "?$orderByVariable $comparator $valueName"; |
827 | | - } else { |
828 | | - $result = $this->buildTrueCondition( $joinVariable, $orderByProperty ); |
829 | 841 | } |
830 | 842 | |
831 | 843 | return $result; |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php |
— | — | @@ -45,7 +45,7 @@ |
46 | 46 | /// Array for keeping property table table data, indexed by table id. |
47 | 47 | /// Access this only by calling getPropertyTables(). |
48 | 48 | 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. |
50 | 50 | protected static $fixed_prop_tables = null; |
51 | 51 | |
52 | 52 | /// Use pre-defined ids for Very Important Properties, avoiding frequent ID lookups for those |
— | — | @@ -71,76 +71,42 @@ |
72 | 72 | '_4' => 26, |
73 | 73 | '_5' => 27, |
74 | 74 | '_LIST' => 28, |
| 75 | + '_MDAT' => 29, |
75 | 76 | ); |
76 | 77 | |
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', |
110 | 96 | ); |
111 | 97 | |
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 |
145 | 111 | ); |
146 | 112 | |
147 | 113 | ///// Reading methods ///// |
— | — | @@ -444,10 +410,6 @@ |
445 | 411 | $pid = $this->getSMWPropertyID( $property ); |
446 | 412 | $tableid = self::findPropertyTableID( $property ); |
447 | 413 | |
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 | | - |
452 | 414 | if ( ( $pid == 0 ) || ( $tableid == '' ) ) { |
453 | 415 | wfProfileOut( "SMWSQLStoreLight::getPropertySubjects (SMW)" ); |
454 | 416 | return array(); |
— | — | @@ -519,11 +481,6 @@ |
520 | 482 | |
521 | 483 | foreach ( $semanticData->getProperties() as $subproperty ) { |
522 | 484 | $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 | | - |
528 | 485 | $subproptable = $proptables[$tableid]; |
529 | 486 | |
530 | 487 | foreach ( $semanticData->getPropertyValues( $subproperty ) as $subvalue ) { |
— | — | @@ -666,7 +623,6 @@ |
667 | 624 | |
668 | 625 | $db = wfGetDB( DB_SLAVE ); |
669 | 626 | $result = array(); |
670 | | - $typeid = $value->getTypeID(); |
671 | 627 | |
672 | 628 | // Potentially need to get more results, since options apply to union. |
673 | 629 | if ( $requestoptions !== null ) { |
— | — | @@ -677,10 +633,11 @@ |
678 | 634 | $suboptions = null; |
679 | 635 | } |
680 | 636 | |
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]; |
683 | 641 | $select = $where = $from = ''; |
684 | | - |
685 | 642 | if ( $proptable->fixedproperty == false ) { // join smw_ids to get property titles |
686 | 643 | $from = $db->tableName( 'smw_ids' ) . " INNER JOIN " . $db->tableName( $proptable->name ) . " AS t1 ON t1.p_id=smw_id"; |
687 | 644 | $this->prepareValueQuery( $from, $where, $proptable, $value, 1 ); |
— | — | @@ -854,16 +811,6 @@ |
855 | 812 | } |
856 | 813 | |
857 | 814 | $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 | | - |
868 | 815 | $proptable = $proptables[$tableid]; |
869 | 816 | |
870 | 817 | foreach ( $data->getPropertyValues( $property ) as $di ) { |
— | — | @@ -1107,11 +1054,12 @@ |
1108 | 1055 | } |
1109 | 1056 | |
1110 | 1057 | // 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]; |
1113 | 1061 | |
1114 | 1062 | // (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 ) . |
1116 | 1064 | " INNER JOIN $smw_ids ON o_id=smw_id WHERE title=smw_title", $fname ); |
1117 | 1065 | // properties that are redirects are considered to be used: |
1118 | 1066 | // (a stricter and more costy approach would be to delete only redirects to used properties; |
— | — | @@ -1153,7 +1101,7 @@ |
1154 | 1102 | |
1155 | 1103 | // Note that Wanted Properties must have the default type. |
1156 | 1104 | $proptables = self::getPropertyTables(); |
1157 | | - $proptable = $proptables[self::findTypeTableID( $smwgPDefaultType )]; |
| 1105 | + $proptable = $proptables[self::findTypeTableId( $smwgPDefaultType )]; |
1158 | 1106 | |
1159 | 1107 | $result = array(); |
1160 | 1108 | |
— | — | @@ -1648,14 +1596,14 @@ |
1649 | 1597 | } |
1650 | 1598 | |
1651 | 1599 | /** |
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. |
1655 | 1603 | * |
1656 | 1604 | * @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 |
1660 | 1608 | * |
1661 | 1609 | * @return string |
1662 | 1610 | */ |
— | — | @@ -1694,10 +1642,10 @@ |
1695 | 1643 | |
1696 | 1644 | /** |
1697 | 1645 | * 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. |
1702 | 1650 | */ |
1703 | 1651 | protected function applyRequestOptions( $data, $requestoptions ) { |
1704 | 1652 | wfProfileIn( "SMWSQLStore2::applyRequestOptions (SMW)" ); |
— | — | @@ -1710,18 +1658,22 @@ |
1711 | 1659 | $result = array(); |
1712 | 1660 | $sortres = array(); |
1713 | 1661 | |
1714 | | - list( $sig, $valueIndex, $labelIndex ) = self::getTypeSignature( reset( $data )->getTypeID() ); |
| 1662 | + $sampleDataItem = reset( $data ); |
| 1663 | + $numeric = is_numeric( $sampleDataItem->getSortKey() ); |
1715 | 1664 | |
1716 | | - $numeric = ( ( $valueIndex >= 0 ) && ( strlen( $sig ) > $valueIndex ) && |
1717 | | - ( ( $sig { $valueIndex } != 'f' ) || ( $sig { $valueIndex } != 'n' ) ) ); |
1718 | 1665 | $i = 0; |
1719 | 1666 | |
1720 | 1667 | foreach ( $data as $item ) { |
1721 | 1668 | $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] : ''; |
1725 | 1669 | |
| 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 | + |
1726 | 1678 | if ( $requestoptions->boundary !== null ) { // apply value boundary |
1727 | 1679 | $strc = $numeric ? 0 : strcmp( $value, $requestoptions->boundary ); |
1728 | 1680 | |
— | — | @@ -1762,7 +1714,7 @@ |
1763 | 1715 | } |
1764 | 1716 | |
1765 | 1717 | if ( $requestoptions->sort ) { |
1766 | | - $flag = $numeric ? SORT_NUMERIC:SORT_LOCALE_STRING; |
| 1718 | + $flag = $numeric ? SORT_NUMERIC : SORT_LOCALE_STRING; |
1767 | 1719 | |
1768 | 1720 | if ( $requestoptions->ascending ) { |
1769 | 1721 | asort( $sortres, $flag ); |
— | — | @@ -1811,20 +1763,13 @@ |
1812 | 1764 | * appropriate property table and information about sorting/filtering |
1813 | 1765 | * data of this type can be obtained. The result is an array of three |
1814 | 1766 | * 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. |
1821 | 1768 | */ |
1822 | 1769 | 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 ) ); |
1829 | 1774 | } |
1830 | 1775 | |
1831 | 1776 | /** |
— | — | @@ -1832,68 +1777,98 @@ |
1833 | 1778 | * signature, where $signature is as returned by getTypeSignature(). |
1834 | 1779 | * @todo Maybe rather use SMWSQLStore2Table object as parameter. |
1835 | 1780 | */ |
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 | +// } |
1842 | 1787 | |
1843 | 1788 | /** |
1844 | 1789 | * 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 |
1846 | 1796 | */ |
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; |
1849 | 1812 | } |
1850 | 1813 | |
1851 | 1814 | /** |
1852 | 1815 | * Find the id of a property table that is suitable for storing values of |
1853 | 1816 | * the given type. The type is specified by an SMW type id such as '_wpg'. |
1854 | 1817 | * An empty string is returned if no matching table could be found. |
| 1818 | + * |
| 1819 | + * @param $typeid string |
| 1820 | + * @return string |
1855 | 1821 | */ |
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 | + } |
1859 | 1826 | |
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 | + } |
1866 | 1837 | |
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 | + } |
1868 | 1854 | } |
1869 | 1855 | |
1870 | | - return self::$property_table_ids[$typeid]; |
| 1856 | + return $result; |
1871 | 1857 | } |
1872 | 1858 | |
1873 | 1859 | /** |
1874 | 1860 | * Retrieve the id of the property table that is to be used for storing |
1875 | 1861 | * values for the given property object. |
| 1862 | + * |
| 1863 | + * @param $diProperty SMWDIProperty |
| 1864 | + * @return string |
1876 | 1865 | */ |
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() ); |
1886 | 1872 | } |
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() ); |
1898 | 1873 | } |
1899 | 1874 | |
1900 | 1875 | /** |
— | — | @@ -2455,22 +2430,19 @@ |
2456 | 2431 | * indexed by table ids. Note that the ids are only for accessing the data |
2457 | 2432 | * and should not be assumed to agree with the table name. |
2458 | 2433 | * |
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 | | - * |
2466 | 2434 | * 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. |
2469 | 2444 | * - p for a reference to an SMW ID as stored in the smw_ids table; this |
2470 | 2445 | * corresponds to a data entry of ID "tnwt". |
2471 | 2446 | * |
2472 | | - * This letter is specific to this store's ID referencing and must not be |
2473 | | - * used in SMWDataValue::getSignature()! |
2474 | | - * |
2475 | 2447 | * @return array of SMWSQLStore2Table |
2476 | 2448 | * @todo The concept table should make s_id a primary key; make this possible. |
2477 | 2449 | */ |
— | — | @@ -2539,6 +2511,12 @@ |
2540 | 2512 | |
2541 | 2513 | wfRunHooks( 'SMWPropertyTables', array( &self::$prop_tables ) ); |
2542 | 2514 | |
| 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 | + |
2543 | 2521 | return self::$prop_tables; |
2544 | 2522 | } |
2545 | 2523 | |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_CompatibilityHelpers.php |
— | — | @@ -35,18 +35,22 @@ |
36 | 36 | */ |
37 | 37 | static public function dataItemFromDBKeys( $typeid, $dbkeys, $diProperty = null ) { |
38 | 38 | switch ( SMWDataValueFactory::getDataItemId( $typeid ) ) { |
39 | | - case SMWDataItem::TYPE_ERROR: |
| 39 | + case SMWDataItem::TYPE_ERROR: case SMWDataItem::TYPE_NOTYPE: |
40 | 40 | break; |
41 | 41 | case SMWDataItem::TYPE_NUMBER: |
42 | | - return SMWDINumber::doUnserialize( $dbkeys[0], $typeid ); |
| 42 | + return SMWDINumber::doUnserialize( $dbkeys[0] ); |
43 | 43 | case SMWDataItem::TYPE_STRING: |
44 | | - return new SMWDIString( $dbkeys[0], $typeid ); |
| 44 | + return new SMWDIString( $dbkeys[0] ); |
45 | 45 | case SMWDataItem::TYPE_BLOB: |
46 | | - return new SMWDIBlob( $dbkeys[0], $typeid ); |
| 46 | + return new SMWDIBlob( $dbkeys[0] ); |
47 | 47 | case SMWDataItem::TYPE_BOOLEAN: |
48 | | - return new SMWDIBoolean( ( $dbkeys[0] == '1' ), $typeid ); |
| 48 | + return new SMWDIBoolean( ( $dbkeys[0] == '1' ) ); |
49 | 49 | 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 | + } |
51 | 55 | case SMWDataItem::TYPE_TIME: |
52 | 56 | $timedate = explode( 'T', $dbkeys[0], 2 ); |
53 | 57 | if ( ( count( $dbkeys ) == 2 ) && ( count( $timedate ) == 2 ) ) { |
— | — | @@ -65,12 +69,12 @@ |
66 | 70 | if ( $month == '' ) $month = false; |
67 | 71 | if ( $day == '' ) $day = false; |
68 | 72 | $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 ); |
70 | 74 | } |
71 | 75 | } |
72 | 76 | break; |
73 | 77 | 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] ) ); |
75 | 79 | case SMWDataItem::TYPE_CONTAINER: |
76 | 80 | $semanticData = new SMWContainerSemanticData(); |
77 | 81 | if ( $typeid == '_rec' ) { |
— | — | @@ -94,53 +98,44 @@ |
95 | 99 | } |
96 | 100 | } |
97 | 101 | } |
98 | | - return new SMWDIContainer( $semanticData, $typeid ); |
| 102 | + return new SMWDIContainer( $semanticData ); |
99 | 103 | case SMWDataItem::TYPE_WIKIPAGE: |
100 | | - if ( $typeid == '__typ' ) { // DBkeys for types values are special (used to be a SMWSimpleWikiPageValue) |
| 104 | + if ( $typeid == '__spf' ) { |
101 | 105 | $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, '' ); |
106 | 107 | } 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] ); |
108 | 109 | } |
109 | 110 | break; |
110 | 111 | case SMWDataItem::TYPE_CONCEPT: |
111 | 112 | 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] ); |
113 | 114 | } |
114 | 115 | break; |
115 | 116 | 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 ); |
121 | 118 | } |
122 | 119 | throw new SMWDataItemException( 'Failed to create data item from DB keys.' ); |
123 | 120 | } |
124 | 121 | |
125 | 122 | /** |
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 |
127 | 128 | */ |
128 | 129 | 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: |
132 | 132 | 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: |
135 | 134 | 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: |
142 | 138 | return array( $dataItem->getSerialization(), floatval( $dataItem->getNumber() ) ); |
143 | | - case '_dat': |
144 | | - if ( $dataItem->getDIType() !== SMWDataItem::TYPE_TIME ) break; |
| 139 | + case SMWDataItem::TYPE_TIME: |
145 | 140 | $xsdvalue = $dataItem->getYear() . "/" . |
146 | 141 | ( ( $dataItem->getPrecision() >= SMWDITime::PREC_YM ) ? $dataItem->getMonth() : '' ) . "/" . |
147 | 142 | ( ( $dataItem->getPrecision() >= SMWDITime::PREC_YMD ) ? $dataItem->getDay() : '' ) . "T"; |
— | — | @@ -150,39 +145,87 @@ |
151 | 146 | sprintf( "%02d", $dataItem->getSecond() ); |
152 | 147 | } |
153 | 148 | return array( $xsdvalue, $dataItem->getSortKey() ); |
154 | | - case '_boo': |
155 | | - if ( $dataItem->getDIType() !== SMWDataItem::TYPE_BOOLEAN ) break; |
| 149 | + case SMWDataItem::TYPE_BOOLEAN: |
156 | 150 | 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: |
159 | 152 | 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: |
165 | 154 | 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: |
170 | 156 | return array( $dataItem->getKey() ); |
171 | | - case '_geo': |
| 157 | + case SMWDataItem::TYPE_GEO: |
172 | 158 | $coordinateSet = $dataItem->getCoordinateSet(); |
173 | | - |
174 | 159 | return array( |
175 | 160 | $coordinateSet['lat'], |
176 | 161 | $coordinateSet['lon'] |
177 | 162 | ); |
178 | | - break; |
179 | 163 | 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 ); |
185 | 165 | } |
186 | | - return array( false ); |
187 | 166 | } |
188 | 167 | |
| 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 | + |
189 | 232 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php |
— | — | @@ -55,6 +55,28 @@ |
56 | 56 | static private $mTypeDataItemIds; |
57 | 57 | |
58 | 58 | /** |
| 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 | + /** |
59 | 81 | * Create an SMWDataValue object that can hold values for the type that the |
60 | 82 | * given SMWTypesValue object specifies. If no $value is given, an empty |
61 | 83 | * container is created, the value of which can be set later on. |
— | — | @@ -112,14 +134,20 @@ |
113 | 135 | /** |
114 | 136 | * Create a value for a data item. |
115 | 137 | * |
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 |
117 | 140 | * @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 |
119 | 141 | * |
120 | 142 | * @return SMWDataValue |
121 | 143 | */ |
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 ); |
124 | 152 | $result->setDataItem( $dataItem ); |
125 | 153 | if ( $caption !== false ) { |
126 | 154 | $result->setCaption( $caption ); |
— | — | @@ -236,8 +264,8 @@ |
237 | 265 | '_rec' => SMWDataItem::TYPE_CONTAINER, // Value list type (replacing former nary properties) |
238 | 266 | '_geo' => SMWDataItem::TYPE_GEO, // Geographical coordinates |
239 | 267 | // 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 |
242 | 270 | '__con' => SMWDataItem::TYPE_CONCEPT, // Special concept page type |
243 | 271 | '__sps' => SMWDataItem::TYPE_STRING, // Special string type |
244 | 272 | '__spu' => SMWDataItem::TYPE_URI, // Special uri type |
— | — | @@ -289,16 +317,15 @@ |
290 | 318 | |
291 | 319 | /** |
292 | 320 | * 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. |
297 | 323 | * |
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. |
300 | 326 | * |
301 | 327 | * @param string $label |
302 | 328 | * @param boolean $useAlias |
| 329 | + * @return string |
303 | 330 | */ |
304 | 331 | static public function findTypeID( $label, $useAlias = true ) { |
305 | 332 | self::initDatatypes(); |
— | — | @@ -309,30 +336,28 @@ |
310 | 337 | } elseif ( ( $useAlias ) && ( array_key_exists( $label, self::$mTypeAliases ) ) ) { |
311 | 338 | return self::$mTypeAliases[$label]; |
312 | 339 | } else { |
313 | | - return str_replace( ' ', '_', $label ); |
| 340 | + return ''; |
314 | 341 | } |
315 | 342 | } |
316 | 343 | |
317 | 344 | /** |
318 | 345 | * 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. |
321 | 350 | * |
322 | 351 | * @param string $id |
323 | 352 | */ |
324 | 353 | static public function findTypeLabel( $id ) { |
325 | 354 | self::initDatatypes(); |
326 | 355 | |
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 ''; |
337 | 362 | } |
338 | 363 | } |
339 | 364 | |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Number.php |
— | — | @@ -20,8 +20,7 @@ |
21 | 21 | */ |
22 | 22 | protected $m_number; |
23 | 23 | |
24 | | - public function __construct( $number, $typeid = '_num' ) { |
25 | | - parent::__construct( $typeid ); |
| 24 | + public function __construct( $number ) { |
26 | 25 | if ( !is_numeric( $number ) ) { |
27 | 26 | throw new SMWDataItemException( "Initialisation value '$number' is not a number." ); |
28 | 27 | } |
— | — | @@ -40,6 +39,14 @@ |
41 | 40 | return $this->m_number; |
42 | 41 | } |
43 | 42 | |
| 43 | + /** |
| 44 | + * @see SMWDataItem::getSortKeyDataItem() |
| 45 | + * @return SMWDataItem |
| 46 | + */ |
| 47 | + public function getSortKeyDataItem() { |
| 48 | + return $this; |
| 49 | + } |
| 50 | + |
44 | 51 | public function getSerialization() { |
45 | 52 | return strval( $this->m_number ); |
46 | 53 | } |
— | — | @@ -51,8 +58,8 @@ |
52 | 59 | * validation here (because this would require less efficient parsing). |
53 | 60 | * @return SMWDINumber |
54 | 61 | */ |
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 ) ); |
57 | 64 | } |
58 | 65 | |
59 | 66 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Error.php |
— | — | @@ -22,8 +22,7 @@ |
23 | 23 | */ |
24 | 24 | protected $m_errors; |
25 | 25 | |
26 | | - public function __construct( $errors, $typeid = '__err' ) { |
27 | | - parent::__construct( $typeid ); |
| 26 | + public function __construct( $errors ) { |
28 | 27 | $this->m_errors = $errors; |
29 | 28 | } |
30 | 29 | |
— | — | @@ -46,10 +45,11 @@ |
47 | 46 | /** |
48 | 47 | * Create a data item from the provided serialization string and type |
49 | 48 | * ID. |
| 49 | + * @todo Be more careful with unserialization. It can create E_NOTICEs. |
50 | 50 | * @return SMWDIError |
51 | 51 | */ |
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 ) ); |
54 | 54 | } |
55 | 55 | |
56 | 56 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Bool.php |
— | — | @@ -20,8 +20,7 @@ |
21 | 21 | */ |
22 | 22 | protected $m_boolean; |
23 | 23 | |
24 | | - public function __construct( $boolean, $typeid = '_boo' ) { |
25 | | - parent::__construct( $typeid ); |
| 24 | + public function __construct( $boolean ) { |
26 | 25 | $this->m_boolean = ( $boolean == true ); |
27 | 26 | } |
28 | 27 | |
— | — | @@ -46,11 +45,11 @@ |
47 | 46 | * ID. |
48 | 47 | * @return SMWDIBoolean |
49 | 48 | */ |
50 | | - public static function doUnserialize( $serialization, $typeid = '_boo' ) { |
| 49 | + public static function doUnserialize( $serialization ) { |
51 | 50 | if ( $serialization == 't' ) { |
52 | | - return new SMWDIBoolean( true, $typeid ); |
| 51 | + return new SMWDIBoolean( true ); |
53 | 52 | } elseif ( $serialization == 'f' ) { |
54 | | - return new SMWDIBoolean( true, $typeid ); |
| 53 | + return new SMWDIBoolean( true ); |
55 | 54 | } else { |
56 | 55 | throw new SMWDataItemException( "Boolean data item unserialised from illegal value '$serialization'" ); |
57 | 56 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Concept.php |
— | — | @@ -50,9 +50,8 @@ |
51 | 51 | * @param $queryefeatures integer flags about query features |
52 | 52 | * @param $size integer concept query size |
53 | 53 | * @param $depth integer concept query depth |
54 | | - * @param $typeid string SMW type id |
55 | 54 | */ |
56 | | - public function __construct( $concept, $docu, $queryfeatures, $size, $depth, $typeid = '__con' ) { |
| 55 | + public function __construct( $concept, $docu, $queryfeatures, $size, $depth ) { |
57 | 56 | $this->m_concept = $concept; |
58 | 57 | $this->m_docu = $docu; |
59 | 58 | $this->m_features = $queryfeatures; |
— | — | @@ -97,7 +96,7 @@ |
98 | 97 | * ID. |
99 | 98 | * @return SMWDIConcept |
100 | 99 | */ |
101 | | - public static function doUnserialize( $serialization, $typeid = '__con' ) { |
| 100 | + public static function doUnserialize( $serialization ) { |
102 | 101 | $result = unserialize( $serialization ); |
103 | 102 | if ( $result === false ) { |
104 | 103 | throw new SMWDataItemException( "Unserialization failed." ); |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DataItem.php |
— | — | @@ -32,12 +32,10 @@ |
33 | 33 | * is mostly enforced by the API with some minor exceptions). |
34 | 34 | * |
35 | 35 | * 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. |
42 | 40 | * |
43 | 41 | * @since 1.6 |
44 | 42 | * |
— | — | @@ -73,23 +71,6 @@ |
74 | 72 | const TYPE_ERROR = 12; |
75 | 73 | |
76 | 74 | /** |
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 | | - /** |
94 | 75 | * Convenience method that returns a constant that defines the concrete |
95 | 76 | * class that implements this data item. Used to switch when processing |
96 | 77 | * data items. |
— | — | @@ -98,24 +79,43 @@ |
99 | 80 | abstract public function getDIType(); |
100 | 81 | |
101 | 82 | /** |
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 | | - /** |
110 | 83 | * Return a value that can be used for sorting data of this type. |
111 | 84 | * If the data is of a numerical type, the sorting must be done in |
112 | 85 | * numerical order. If the data is a string, the data must be sorted |
113 | 86 | * 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). |
114 | 94 | * |
| 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 | + * |
115 | 99 | * @return float or string |
116 | 100 | */ |
117 | 101 | abstract public function getSortKey(); |
118 | 102 | |
119 | 103 | /** |
| 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 | + /** |
120 | 120 | * Get a UTF-8 encoded string serialization of this data item. |
121 | 121 | * The serialisation should be concise and need not be pretty, but it |
122 | 122 | * must allow unserialization. Each subclass of SMWDataItem implements |
— | — | @@ -143,13 +143,9 @@ |
144 | 144 | * @param $typeid string SMW type ID (optional) |
145 | 145 | * @return SMWDataItem |
146 | 146 | */ |
147 | | - public static function newFromSerialization( $diType, $serialization, $typeid = '' ) { |
| 147 | + public static function newFromSerialization( $diType, $serialization ) { |
148 | 148 | $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 ); |
154 | 150 | } |
155 | 151 | |
156 | 152 | public static function getDataItemClassNameForId( $diType ) { |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Blob.php |
— | — | @@ -20,8 +20,7 @@ |
21 | 21 | */ |
22 | 22 | protected $m_string; |
23 | 23 | |
24 | | - public function __construct( $string, $typeid = '_txt' ) { |
25 | | - parent::__construct( $typeid ); |
| 24 | + public function __construct( $string ) { |
26 | 25 | $this->m_string = $string; |
27 | 26 | } |
28 | 27 | |
— | — | @@ -37,6 +36,14 @@ |
38 | 37 | return $this->m_string; |
39 | 38 | } |
40 | 39 | |
| 40 | + /** |
| 41 | + * @see SMWDataItem::getSortKeyDataItem() |
| 42 | + * @return SMWDataItem |
| 43 | + */ |
| 44 | + public function getSortKeyDataItem() { |
| 45 | + return $this; |
| 46 | + } |
| 47 | + |
41 | 48 | public function getSerialization() { |
42 | 49 | return $this->m_string; |
43 | 50 | } |
— | — | @@ -46,8 +53,8 @@ |
47 | 54 | * ID. |
48 | 55 | * @return SMWDIBlob |
49 | 56 | */ |
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 ); |
52 | 59 | } |
53 | 60 | |
54 | 61 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Time.php |
— | — | @@ -98,19 +98,17 @@ |
99 | 99 | * @param $hour mixed integer number or false |
100 | 100 | * @param $minute mixed integer number or false |
101 | 101 | * @param $second mixed integer number or false |
102 | | - * @param $typeid string SMW type id |
103 | 102 | * |
104 | 103 | * @todo Implement more validation here. |
105 | 104 | */ |
106 | 105 | 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 ) { |
108 | 107 | if ( ( $calendarmodel != SMWDITime::CM_GREGORIAN ) && ( $calendarmodel != SMWDITime::CM_JULIAN ) ) { |
109 | 108 | throw new SMWDataItemException( "Unsupported calendar model constant \"$calendarmodel\"." ); |
110 | 109 | } |
111 | 110 | if ( $year == 0 ) { |
112 | 111 | throw new SMWDataItemException( "There is no year 0 in Gregorian and Julian calendars." ); |
113 | 112 | } |
114 | | - parent::__construct( $typeid ); |
115 | 113 | $this->m_model = $calendarmodel; |
116 | 114 | $this->m_year = intval( $year ); |
117 | 115 | $this->m_month = $month != false ? intval( $month ) : 1; |
— | — | @@ -188,7 +186,7 @@ |
189 | 187 | if ( $calendarmodel == $this->m_model ) { |
190 | 188 | return $this; |
191 | 189 | } else { |
192 | | - return SMWDITime::newFromJD( $this->getJD(), $calendarmodel, $this->m_precision, $this->m_typeid ); |
| 190 | + return SMWDITime::newFromJD( $this->getJD(), $calendarmodel, $this->m_precision ); |
193 | 191 | } |
194 | 192 | } |
195 | 193 | |
— | — | @@ -234,7 +232,7 @@ |
235 | 233 | * ID. |
236 | 234 | * @return SMWDITime |
237 | 235 | */ |
238 | | - public static function doUnserialize( $serialization, $typeid = '_dat' ) { |
| 236 | + public static function doUnserialize( $serialization ) { |
239 | 237 | $parts = explode( '/', $serialization, 7 ); |
240 | 238 | $values = array(); |
241 | 239 | for ( $i = 0; $i < 7; $i += 1 ) { |
— | — | @@ -251,7 +249,7 @@ |
252 | 250 | if ( count( $parts ) <= 1 ) { |
253 | 251 | throw new SMWDataItemException( "Unserialization failed: the string \"$serialization\" is no valid URI." ); |
254 | 252 | } |
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] ); |
256 | 254 | } |
257 | 255 | |
258 | 256 | /** |
— | — | @@ -260,10 +258,9 @@ |
261 | 259 | * @param $jdvalue double Julian Day number |
262 | 260 | * @param $calendarmodel integer either SMWDITime::CM_GREGORIAN or SMWDITime::CM_JULIAN |
263 | 261 | * @param $precision integer one of SMWDITime::PREC_Y, SMWDITime::PREC_YM, SMWDITime::PREC_YMD, SMWDITime::PREC_YMDT |
264 | | - * @param $typeid string |
265 | 262 | * @return SMWDITime object |
266 | 263 | */ |
267 | | - public static function newFromJD( $jdvalue, $calendarmodel, $precision, $typeid ) { |
| 264 | + public static function newFromJD( $jdvalue, $calendarmodel, $precision ) { |
268 | 265 | list( $year, $month, $day ) = SMWDITime::JD2Date( $jdvalue, $calendarmodel ); |
269 | 266 | if ( $precision <= SMWDITime::PREC_YM ) { |
270 | 267 | $day = false; |
— | — | @@ -276,7 +273,7 @@ |
277 | 274 | } else { |
278 | 275 | $hour = $minute = $second = false; |
279 | 276 | } |
280 | | - return new SMWDITime( $calendarmodel, $year, $month, $day, $hour, $minute, $second, $typeid ); |
| 277 | + return new SMWDITime( $calendarmodel, $year, $month, $day, $hour, $minute, $second ); |
281 | 278 | } |
282 | 279 | |
283 | 280 | /** |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_URI.php |
— | — | @@ -45,18 +45,16 @@ |
46 | 46 | * @param $hierpart string for the "hierpart" |
47 | 47 | * @param $query string for the query |
48 | 48 | * @param $fragment string for the fragment |
49 | | - * @param $typeid string SMW type id |
50 | 49 | * |
51 | 50 | * @todo Implement more validation here. |
52 | 51 | */ |
53 | | - public function __construct( $scheme, $hierpart, $query, $fragment, $typeid = '_uri' ) { |
| 52 | + public function __construct( $scheme, $hierpart, $query, $fragment ) { |
54 | 53 | if ( ( $scheme == '' ) || ( preg_match( '/[^a-zA-Z]/u', $scheme ) ) ) { |
55 | 54 | throw new SMWDataItemException( "Illegal URI scheme \"$scheme\"." ); |
56 | 55 | } |
57 | 56 | if ( $hierpart == '' ) { |
58 | 57 | throw new SMWDataItemException( "Illegal URI hierpart \"$hierpart\"." ); |
59 | 58 | } |
60 | | - parent::__construct( $typeid ); |
61 | 59 | $this->m_scheme = $scheme; |
62 | 60 | $this->m_hierpart = $hierpart; |
63 | 61 | $this->m_query = $query; |
— | — | @@ -103,7 +101,7 @@ |
104 | 102 | * ID. |
105 | 103 | * @return SMWDIUri |
106 | 104 | */ |
107 | | - public static function doUnserialize( $serialization, $typeid = '_uri' ) { |
| 105 | + public static function doUnserialize( $serialization ) { |
108 | 106 | $parts = explode( ':', $serialization, 2 ); // try to split "schema:rest" |
109 | 107 | if ( count( $parts ) <= 1 ) { |
110 | 108 | throw new SMWDataItemException( "Unserialization failed: the string \"$serialization\" is no valid URI." ); |
— | — | @@ -117,11 +115,11 @@ |
118 | 116 | $fragment = ( count( $parts ) == 2 ) ? $parts[1] : ''; |
119 | 117 | } else { |
120 | 118 | $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" |
122 | 120 | $hierpart = $parts[0]; |
123 | 121 | $fragment = ( count( $parts ) == 2 ) ? $parts[1] : ''; |
124 | 122 | } |
125 | | - return new SMWDIUri( $scheme, $hierpart, $query, $fragment, $typeid ); |
| 123 | + return new SMWDIUri( $scheme, $hierpart, $query, $fragment ); |
126 | 124 | } |
127 | 125 | |
128 | 126 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_WikiPage.php |
— | — | @@ -38,8 +38,7 @@ |
39 | 39 | * would be more work than it is worth, since callers will usually be |
40 | 40 | * careful and since errors here do not have major consequences. |
41 | 41 | */ |
42 | | - public function __construct( $dbkey, $namespace, $interwiki, $typeid = '_wpg' ) { |
43 | | - parent::__construct( $typeid ); |
| 42 | + public function __construct( $dbkey, $namespace, $interwiki ) { |
44 | 43 | if ( !is_numeric( $namespace ) ) { |
45 | 44 | throw new SMWDataItemException( "Given namespace '$namespace' is not an integer." ); |
46 | 45 | } |
— | — | @@ -102,23 +101,22 @@ |
103 | 102 | * ID. |
104 | 103 | * @return SMWDIWikiPage |
105 | 104 | */ |
106 | | - public static function doUnserialize( $serialization, $typeid = '_wpg' ) { |
| 105 | + public static function doUnserialize( $serialization ) { |
107 | 106 | $parts = explode( '#', $serialization, 3 ); |
108 | 107 | if ( count( $parts ) != 3 ) { |
109 | 108 | throw new SMWDataItemException( "Unserialization failed: the string \"$serialization\" was not understood." ); |
110 | 109 | } |
111 | | - return new SMWDIWikiPage( $parts[0], floatval( $parts[1] ), $parts[2], $typeid ); |
| 110 | + return new SMWDIWikiPage( $parts[0], floatval( $parts[1] ), $parts[2] ); |
112 | 111 | } |
113 | 112 | |
114 | 113 | /** |
115 | 114 | * Create a data item from a MediaWiki Title. |
116 | 115 | * |
117 | 116 | * @param $title Title |
118 | | - * @param $typeid string optional type ID to use |
119 | 117 | * @return SMWDIWikiPage |
120 | 118 | */ |
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() ); |
123 | 121 | } |
124 | 122 | |
125 | 123 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_GeoCoord.php |
— | — | @@ -21,8 +21,7 @@ |
22 | 22 | * @param $coords array Array with lat and long keys pointing to float values. |
23 | 23 | * @param $typeid string |
24 | 24 | */ |
25 | | - public function __construct( array $coords, $typeid = '_geo' ) { |
26 | | - parent::__construct( $typeid ); |
| 25 | + public function __construct( array $coords ) { |
27 | 26 | $this->coordinateSet = $coords; |
28 | 27 | } |
29 | 28 | |
— | — | @@ -69,14 +68,14 @@ |
70 | 69 | * validation here (because this would require less efficient parsing). |
71 | 70 | * @return SMWDIGeoCoord |
72 | 71 | */ |
73 | | - public static function doUnserialize( $serialization, $typeid = '_geo' ) { |
| 72 | + public static function doUnserialize( $serialization ) { |
74 | 73 | $parts = explode( ',', $serialization ); |
75 | 74 | |
76 | 75 | if ( count( $parts ) != 2 ) { |
77 | 76 | throw new SMWDataItemException( 'Unserialization of coordinates failed' ); |
78 | 77 | } |
79 | 78 | |
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], ) ); |
81 | 80 | } |
82 | 81 | |
83 | 82 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Container.php |
— | — | @@ -115,8 +115,7 @@ |
116 | 116 | * |
117 | 117 | * @param $semanticData SMWContainerSemanticData |
118 | 118 | */ |
119 | | - public function __construct( SMWContainerSemanticData $semanticData, $typeid = '_rec' ) { |
120 | | - parent::__construct( $typeid ); |
| 119 | + public function __construct( SMWContainerSemanticData $semanticData ) { |
121 | 120 | $this->m_semanticData = $semanticData; |
122 | 121 | $this->m_semanticData->makeImmutable(); |
123 | 122 | } |
— | — | @@ -151,13 +150,13 @@ |
152 | 151 | * ID. |
153 | 152 | * @return SMWDIContainer |
154 | 153 | */ |
155 | | - public static function doUnserialize( $serialization, $typeid = '_rec' ) { |
| 154 | + public static function doUnserialize( $serialization ) { |
156 | 155 | /// TODO May issue an E_NOTICE when problems occur; catch this |
157 | 156 | $data = unserialize( $serialization ); |
158 | 157 | if ( !( $data instanceof SMWContainerSemanticData ) ) { |
159 | 158 | throw SMWDataItemException( "Could not unserialize SMWDIContainer from the given string." ); |
160 | 159 | } |
161 | | - return new SMWDIContainer( $data, $typeid ); |
| 160 | + return new SMWDIContainer( $data ); |
162 | 161 | } |
163 | 162 | |
164 | 163 | } |
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php |
— | — | @@ -70,9 +70,8 @@ |
71 | 71 | * |
72 | 72 | * @param $key string key for the property (internal SMW key or wikipage DB key) |
73 | 73 | * @param $inverse boolean states if the inverse of the property is constructed |
74 | | - * @param $typeid string SMW type id |
75 | 74 | */ |
76 | | - public function __construct( $key, $inverse = false, $typeid = '__pro' ) { |
| 75 | + public function __construct( $key, $inverse = false ) { |
77 | 76 | if ( ( $key == '' ) || ( $key{0} == '-' ) ) { |
78 | 77 | throw new SMWDataItemException( "Illegal property key \"$key\"." ); |
79 | 78 | } |
— | — | @@ -82,7 +81,6 @@ |
83 | 82 | throw new SMWDataItemException( "There is no predefined property with \"$key\"." ); |
84 | 83 | } |
85 | 84 | } |
86 | | - parent::__construct( $typeid ); |
87 | 85 | $this->m_key = $key; |
88 | 86 | $this->m_inverse = ( $inverse == true ); |
89 | 87 | } |
— | — | @@ -174,21 +172,6 @@ |
175 | 173 | } |
176 | 174 | |
177 | 175 | /** |
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 | | - /** |
193 | 176 | * Find the property's type ID, either by looking up its predefined ID |
194 | 177 | * (if any) or by retrieving the relevant information from the store. |
195 | 178 | * If no type is stored for a user defined property, the global default |
— | — | @@ -203,9 +186,9 @@ |
204 | 187 | $diWikiPage = new SMWDIWikiPage( $this->getKey(), SMW_NS_PROPERTY, '' ); |
205 | 188 | $typearray = smwfGetStore()->getPropertyValues( $diWikiPage, new SMWDIProperty( '_TYPE' ) ); |
206 | 189 | 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(); |
210 | 193 | } else { |
211 | 194 | $this->m_proptypeid = '__err'; |
212 | 195 | } |
— | — | @@ -213,7 +196,7 @@ |
214 | 197 | $this->m_proptypeid = $smwgPDefaultType; |
215 | 198 | } |
216 | 199 | } else { // pre-defined property |
217 | | - $this->m_proptypeid = $this->getPredefinedPropertyTypeID(); |
| 200 | + $this->m_proptypeid = self::getPredefinedPropertyTypeId( $this->m_key ); |
218 | 201 | } |
219 | 202 | } |
220 | 203 | return $this->m_proptypeid; |
— | — | @@ -229,13 +212,13 @@ |
230 | 213 | * ID. |
231 | 214 | * @return SMWDIProperty |
232 | 215 | */ |
233 | | - public static function doUnserialize( $serialization, $typeid = '__pro' ) { |
| 216 | + public static function doUnserialize( $serialization ) { |
234 | 217 | $inverse = false; |
235 | 218 | if ( $serialization{0} == '-' ) { |
236 | 219 | $serialization = substr( $serialization, 1 ); |
237 | 220 | $inverse = true; |
238 | 221 | } |
239 | | - return new SMWDIProperty( $serialization, $inverse, $typeid ); |
| 222 | + return new SMWDIProperty( $serialization, $inverse ); |
240 | 223 | } |
241 | 224 | |
242 | 225 | /** |
— | — | @@ -250,15 +233,14 @@ |
251 | 234 | * |
252 | 235 | * @param $label string label for the property |
253 | 236 | * @param $inverse boolean states if the inverse of the property is constructed |
254 | | - * @param $typeid string SMW type id |
255 | 237 | * @return SMWDIProperty object |
256 | 238 | */ |
257 | | - public static function newFromUserLabel( $label, $inverse = false, $typeid = '__pro' ) { |
| 239 | + public static function newFromUserLabel( $label, $inverse = false ) { |
258 | 240 | $id = SMWDIProperty::findPropertyID( $label ); |
259 | 241 | if ( $id === false ) { |
260 | | - return new SMWDIProperty( str_replace( ' ', '_', $label ), $inverse, $typeid ); |
| 242 | + return new SMWDIProperty( str_replace( ' ', '_', $label ), $inverse ); |
261 | 243 | } else { |
262 | | - return new SMWDIProperty( $id, $inverse, $typeid ); |
| 244 | + return new SMWDIProperty( $id, $inverse ); |
263 | 245 | } |
264 | 246 | } |
265 | 247 | |
— | — | @@ -286,6 +268,23 @@ |
287 | 269 | } |
288 | 270 | |
289 | 271 | /** |
| 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 | + /** |
290 | 289 | * Get the translated user label for a given internal property ID. |
291 | 290 | * Returns false for properties without a translation (these are |
292 | 291 | * 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 @@ |
28 | 28 | |
29 | 29 | const MAXLENGTH = 255; |
30 | 30 | |
31 | | - public function __construct( $string, $typeid = '_str' ) { |
| 31 | + public function __construct( $string ) { |
32 | 32 | if ( strlen( $string ) > SMWDIString::MAXLENGTH ) { |
33 | 33 | throw new SMWStringLengthException( $string ); |
34 | 34 | } |
35 | | - parent::__construct( $string, $typeid ); |
| 35 | + parent::__construct( $string ); |
36 | 36 | } |
37 | 37 | |
38 | 38 | public function getDIType() { |
— | — | @@ -43,8 +43,8 @@ |
44 | 44 | * ID. |
45 | 45 | * @return SMWDIString |
46 | 46 | */ |
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 ); |
49 | 49 | } |
50 | 50 | |
51 | 51 | } |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_Language.php |
— | — | @@ -62,7 +62,7 @@ |
63 | 63 | 'Email' => '_ema', |
64 | 64 | 'Annotation URI' => '_anu', |
65 | 65 | 'Telephone number' => '_tel', |
66 | | - 'Record' => '_rec' |
| 66 | + 'Record' => '_rec' |
67 | 67 | ); |
68 | 68 | /// Default English aliases for special property names (typically used in all languages) |
69 | 69 | static protected $enPropertyAliases = array( |
— | — | @@ -113,8 +113,8 @@ |
114 | 114 | */ |
115 | 115 | function getDatatypeAliases() { |
116 | 116 | return $this->m_useEnDefaultAliases ? |
117 | | - $this->m_DatatypeAliases + SMWLanguage::$enDatatypeAliases: |
118 | | - $this->m_DatatypeAliases; |
| 117 | + $this->m_DatatypeAliases + SMWLanguage::$enDatatypeAliases : |
| 118 | + $this->m_DatatypeAliases; |
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
— | — | @@ -129,8 +129,8 @@ |
130 | 130 | */ |
131 | 131 | function getPropertyAliases() { |
132 | 132 | return $this->m_useEnDefaultAliases ? |
133 | | - $this->m_SpecialPropertyAliases + SMWLanguage::$enPropertyAliases: |
134 | | - $this->m_SpecialPropertyAliases; |
| 133 | + $this->m_SpecialPropertyAliases + SMWLanguage::$enPropertyAliases : |
| 134 | + $this->m_SpecialPropertyAliases; |
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
— | — | @@ -161,7 +161,7 @@ |
162 | 162 | * Return the name of the month with the given number. |
163 | 163 | */ |
164 | 164 | 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 )] : ''; |
166 | 166 | } |
167 | 167 | |
168 | 168 | } |