r85865 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85864‎ | r85865 | r85866 >
Date:06:45, 12 April 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
Rolling out the new data item code: dataitems are small, immutable data containers that replace the previous datavalues in most uses. Datavalues are built around dataitmes to add user input parsing and output formatting (as before) but these parts are not relevant when passing around data.

This is a first commit which already has most SMW functions working as before. The dataitem architecture is not completely rewritten yet, and some features are temporaily disabled or will cause errors if used.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Compatibility_Helpers.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryParser.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Record_Descriptions.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_SetupLight.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_OrderedListPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_PropertyPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_TypePage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Blob.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Bool.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Concept.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Error.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Number.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Time.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_URI.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_WikiPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DataItem.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Bool.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Concept.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Error.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Import.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Linear.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Number.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Property.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_String.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_TypeList.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Types.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_URI.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_WikiPage.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/export/SMW_ExportController.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Concept.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_JSONlink.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_RDF.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_Table.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_QueryResult.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStoreLight.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_TestStore.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialAsk.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialUnusedProperties.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialPageProperty.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialAsk.php
@@ -422,7 +422,7 @@
423423 }
424424
425425 if ( !isset( $this->m_params[$desckey] ) ) {
426 - $dv = end( smwfGetStore()->getPropertyValues( SMWWikiPageValue::makePageFromTitle( $concept ), SMWPropertyValue::makeProperty( '_CONC' ) ) );
 426+ $dv = end( smwfGetStore()->getPropertyValues( SMWWikiPageValue::makePageFromTitle( $concept ), new SMWDIProperty( '_CONC' ) ) );
427427 if ( $dv instanceof SMWConceptValue ) {
428428 $this->m_params[$desckey] = $dv->getDocu();
429429 }
Index: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialProperties.php
@@ -72,7 +72,7 @@
7373 $errors[] = wfMsg( 'smw_propertyhardlyused' );
7474 }
7575 if ( $result[0]->isUserDefined() && $result[0]->getWikiPageValue()->getTitle()->exists() ) { // FIXME: this bypasses SMWDataValueFactory; ungood
76 - $types = smwfGetStore()->getPropertyValues( $result[0]->getWikiPageValue(), SMWPropertyValue::makeProperty( '_TYPE' ) );
 76+ $types = smwfGetStore()->getPropertyValues( $result[0]->getDiWikiPage(), new SMWDIProperty( '_TYPE' ) );
7777 if ( count( $types ) >= 1 ) {
7878 $typestring = current( $types )->getLongHTMLText( $skin );
7979 }
@@ -87,7 +87,7 @@
8888 $proplink = $result[0]->getLongHTMLText( $skin );
8989 }
9090 if ( $typestring == '' ) {
91 - $type = SMWDataValueFactory::newPropertyObjectValue( SMWPropertyValue::makeProperty( '_TYPE' ) );
 91+ $type = SMWDataValueFactory::newPropertyObjectValue( new SMWDIProperty( '_TYPE' ) );
9292 $type->setDBkeys( array( '_wpg' ) );
9393 $typestring = $type->getLongHTMLText( $skin );
9494 if ( $result[0]->getWikiPageValue()->getTitle()->exists() ) { // print only when we did not print a "nopage" warning yet
Index: trunk/extensions/SemanticMediaWiki/specials/QueryPages/SMW_SpecialUnusedProperties.php
@@ -83,7 +83,7 @@
8484 function formatResult( $skin, $result ) {
8585 global $wgLang;
8686 $proplink = $skin->makeKnownLinkObj( $result->getWikiPageValue()->getTitle(), $result->getWikiValue() );
87 - $types = smwfGetStore()->getPropertyValues( $result->getWikiPageValue(), SMWPropertyValue::makeProperty( '_TYPE' ) ); // TODO: do not bypass SMWDataValueFactory!
 87+ $types = smwfGetStore()->getPropertyValues( $result->getWikiPageValue(), new SMWDIProperty( '_TYPE' ) ); // TODO: do not bypass SMWDataValueFactory!
8888 $errors = array();
8989 if ( count( $types ) >= 1 ) {
9090 $typestring = current( $types )->getLongHTMLText( $skin );
Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialBrowse.php
@@ -91,7 +91,7 @@
9292
9393 $html .= $this->displayHead();
9494 if ( $this->showoutgoing ) {
95 - $data = smwfGetStore()->getSemanticData( $this->subject );
 95+ $data = smwfGetStore()->getSemanticData( $this->subject->getDataItem() );
9696 $html .= $this->displayData( $data, $leftside );
9797 $html .= $this->displayCenter();
9898 }
@@ -126,16 +126,17 @@
127127 // In this case, there is an "i" after the "smwb-". This is set here.
128128 $inv = $left ? '':'i';
129129 $html = "<table class=\"smwb-" . $inv . "factbox\" cellpadding=\"0\" cellspacing=\"0\">\n";
130 - $properties = $data->getProperties();
 130+ $diProperties = $data->getProperties();
131131 $noresult = true;
132 - foreach ( $properties as $property ) {
 132+ foreach ( $diProperties as $diProperty ) {
 133+ $dvProperty = SMWDataValueFactory::newDataItemValue( $diProperty );
133134 $displayline = true;
134 - if ( $property->isVisible() ) {
135 - $property->setCaption( $this->getPropertyLabel( $property, $incoming ) );
136 - $proptext = $property->getShortHTMLText( $skin ) . "\n";
137 - } elseif ( $property->getPropertyID() == '_INST' ) {
 135+ if ( $dvProperty->isVisible() ) {
 136+ $dvProperty->setCaption( $this->getPropertyLabel( $dvProperty, $incoming ) );
 137+ $proptext = $dvProperty->getShortHTMLText( $skin ) . "\n";
 138+ } elseif ( $diProperty->getKey() == '_INST' ) {
138139 $proptext = $skin->specialLink( 'Categories' );
139 - } elseif ( $property->getPropertyID() == '_REDI' ) {
 140+ } elseif ( $diProperty->getKey() == '_REDI' ) {
140141 $proptext = $skin->specialLink( 'Listredirects', 'isredirect' );
141142 } else {
142143 $displayline = false;
@@ -144,16 +145,17 @@
145146 $head = "<th>" . $proptext . "</th>\n";
146147 // display values
147148 $body = "<td>\n";
148 - $values = $data->getPropertyValues( $property );
 149+ $values = $data->getPropertyValues( $diProperty );
149150 $count = count( $values );
150151 $more = ( $count >= SMWSpecialBrowse::$incomingvaluescount );
151 - foreach ( $values as $value ) {
 152+ foreach ( $values as $di ) {
152153 if ( ( $count == 1 ) && $more && $incoming ) {
153154 // if there are more incoming values than a certain treshold, display a link to the rest instead
154 - $body .= '<a href="' . $skin->makeSpecialUrl( 'SearchByProperty', 'property=' . urlencode( $property->getWikiValue() ) . '&value=' . urlencode( $data->getSubject()->getWikiValue() ) ) . '">' . wfMsg( "smw_browse_more" ) . "</a>\n";
 155+ $body .= '<a href="' . $skin->makeSpecialUrl( 'SearchByProperty', 'property=' . urlencode( $dvProperty->getWikiValue() ) . '&value=' . urlencode( $this->subject->getWikiValue() ) ) . '">' . wfMsg( "smw_browse_more" ) . "</a>\n";
155156 } else {
 157+ $dv = SMWDataValueFactory::newDataItemValue( $di );
156158 $body .= "<span class=\"smwb-" . $inv . "value\">" .
157 - $this->displayValue( $property, $value, $incoming ) . "</span>";
 159+ $this->displayValue( $dvProperty, $dv, $incoming ) . "</span>";
158160 }
159161 $count--;
160162 $body .= ( $count > 0 ) ? ", \n":"\n";
@@ -279,19 +281,19 @@
280282 * @return array(SMWSemanticData, bool) The semantic data including all inproperties, and if there are more inproperties left
281283 */
282284 private function getInData() {
283 - $indata = new SMWSemanticData( $this->subject );
 285+ $indata = new SMWSemanticData( $this->subject->getDataItem() );
284286 $options = new SMWRequestOptions();
285287 $options->sort = true;
286288 $options->limit = SMWSpecialBrowse::$incomingpropertiescount;
287289 if ( $this->offset > 0 ) $options->offset = $this->offset;
288 - $inproperties = smwfGetStore()->getInProperties( $this->subject, $options );
 290+ $inproperties = smwfGetStore()->getInProperties( $this->subject->getDataItem(), $options );
289291 $more = ( count( $inproperties ) == SMWSpecialBrowse::$incomingpropertiescount );
290292 if ( $more ) array_pop( $inproperties ); // drop the last one
291293 $valoptions = new SMWRequestOptions();
292294 $valoptions->sort = true;
293295 $valoptions->limit = SMWSpecialBrowse::$incomingvaluescount;
294296 foreach ( $inproperties as $property ) {
295 - $values = smwfGetStore()->getPropertySubjects( $property, $this->subject, $valoptions );
 297+ $values = smwfGetStore()->getPropertySubjects( $property, $this->subject->getDataItem(), $valoptions );
296298 foreach ( $values as $value ) {
297299 $indata->addPropertyObjectValue( $property, $value );
298300 }
@@ -311,7 +313,7 @@
312314 private function getPropertyLabel( SMWPropertyValue $property, $incoming = false ) {
313315 global $smwgBrowseShowInverse;
314316 if ( $incoming && $smwgBrowseShowInverse ) {
315 - $oppositeprop = SMWPropertyValue::makeProperty( wfMsg( 'smw_inverse_label_property' ) );
 317+ $oppositeprop = SMWPropertyValue::makeUserProperty( wfMsg( 'smw_inverse_label_property' ) );
316318 $labelarray = &smwfGetStore()->getPropertyValues( $property->getWikiPageValue(), $oppositeprop );
317319 $rv = ( count( $labelarray ) > 0 ) ? $labelarray[0]->getLongWikiText():
318320 wfMsg( 'smw_inverse_label_default', $property->getWikiValue() );
Index: trunk/extensions/SemanticMediaWiki/specials/SearchTriple/SMW_SpecialPageProperty.php
@@ -50,9 +50,9 @@
5151 }
5252
5353 $subject = SMWDataValueFactory::newTypeIDValue( '_wpg', $pagename );
54 - $pagename = $subject->isValid() ? $subject->getText():'';
 54+ $pagename = $subject->isValid() ? $subject->getText() : '';
5555 $property = SMWPropertyValue::makeUserProperty( $propname );
56 - $propname = $property->isvalid() ? $property->getWikiValue():'';
 56+ $propname = $property->isvalid() ? $property->getWikiValue() : '';
5757
5858 // Produce output
5959 $html = '';
@@ -66,7 +66,7 @@
6767 $options->limit = $limit + 1;
6868 $options->offset = $offset;
6969 $options->sort = true;
70 - $results = smwfGetStore()->getPropertyValues( $pagename != '' ? $subject:NULL, $property, $options );
 70+ $results = smwfGetStore()->getPropertyValues( $pagename != '' ? $subject->getDataItem() : null, $property->getDataItem(), $options );
7171
7272 // prepare navigation bar if needed
7373 if ( ( $offset > 0 ) || ( count( $results ) > $limit ) ) {
@@ -93,12 +93,13 @@
9494 } else {
9595 $html .= "<ul>\n";
9696 $count = $limit + 1;
97 - foreach ( $results as $result ) {
 97+ foreach ( $results as $di ) {
9898 $count--;
9999 if ( $count < 1 ) continue;
100 - $html .= '<li>' . $result->getLongHTMLText( $skin ); // do not show infolinks, the magnifier "+" is ambiguous with the browsing '+' for '_wpg' (see below)
101 - if ( $result->getTypeID() == '_wpg' ) {
102 - $browselink = SMWInfolink::newBrowsingLink( '+', $result->getLongWikiText() );
 100+ $dv = SMWDataValueFactory::newDataItemValue( $di );
 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' ) {
 103+ $browselink = SMWInfolink::newBrowsingLink( '+', $dv->getLongWikiText() );
103104 $html .= ' &#160;' . $browselink->getHTML( $skin );
104105 }
105106 $html .= "</li> \n";
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParseData.php
@@ -53,7 +53,7 @@
5454 * This function retrieves the SMW data from a given parser, and creates
5555 * a new empty container if it is not initiated yet.
5656 *
57 - * @retun SMWSemanticData
 57+ * @return SMWSemanticData
5858 */
5959 static public function getSMWdata( $parser ) {
6060 $output = self::getOutput( $parser );
@@ -66,7 +66,7 @@
6767
6868 // No data container yet.
6969 if ( !isset( $output->mSMWData ) ) {
70 - $output->mSMWData = new SMWSemanticData( SMWWikiPageValue::makePageFromTitle( $title ) );
 70+ $output->mSMWData = new SMWSemanticData( new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki() ) );
7171 }
7272
7373 return $output->mSMWData;
@@ -85,7 +85,7 @@
8686 return;
8787 }
8888
89 - $output->mSMWData = new SMWSemanticData( SMWWikiPageValue::makePageFromTitle( $title ) );
 89+ $output->mSMWData = new SMWSemanticData( new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki() ) );
9090 }
9191
9292 /**
@@ -108,18 +108,18 @@
109109 global $smwgContLang;
110110
111111 // See if this property is a special one, such as e.g. "has type".
112 - $property = SMWPropertyValue::makeUserProperty( $propertyName );
113 - $result = SMWDataValueFactory::newPropertyObjectValue( $property, $value, $caption );
 112+ $propertyDv = SMWPropertyValue::makeUserProperty( $propertyName );
 113+ $propertyDi = $propertyDv->getDataItem();
 114+ $result = SMWDataValueFactory::newPropertyObjectValue( $propertyDi, $value, $caption );
114115
115 - if ( $property->isInverse() ) {
 116+ if ( $propertyDi->isInverse() ) {
116117 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
117118 $result->addError( wfMsgForContent( 'smw_noinvannot' ) );
118119 } elseif ( $storeAnnotation && ( self::getSMWData( $parser ) !== null ) ) {
119 - self::getSMWData( $parser )->addPropertyObjectValue( $property, $result );
120 -
 120+ self::getSMWData( $parser )->addPropertyObjectValue( $propertyDi, $result->getDataItem() );
121121 // Take note of the error for storage (do this here and not in storage, thus avoiding duplicates).
122122 if ( !$result->isValid() ) {
123 - self::getSMWData( $parser )->addPropertyObjectValue( SMWPropertyValue::makeProperty( '_ERRP' ), $property->getWikiPageValue() );
 123+ self::getSMWData( $parser )->addPropertyObjectValue( new SMWDIProperty( '_ERRP' ), $propertyDi->getDiWikiPage() );
124124 }
125125 }
126126
@@ -156,16 +156,18 @@
157157 $processSemantics = smwfIsSemanticsProcessed( $namespace );
158158
159159 if ( !isset( $semdata ) ) { // no data at all?
160 - $semdata = new SMWSemanticData( SMWWikiPageValue::makePageFromTitle( $title ) );
 160+ $semdata = new SMWSemanticData( new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki() ) );
161161 }
162162
163163 if ( $processSemantics ) {
164 - $pmdat = SMWPropertyValue::makeProperty( '_MDAT' );
 164+ $pmdat = new SMWDIProperty( '_MDAT' );
165165
166166 if ( count( $semdata->getPropertyValues( $pmdat ) ) == 0 ) { // no article data present yet, add it here
167167 $timestamp = $smwgMW_1_14 ? Revision::getTimeStampFromID( $title, $title->getLatestRevID() ) : Revision::getTimeStampFromID( $title->getLatestRevID() );
168 - $dv = SMWDataValueFactory::newPropertyObjectValue( $pmdat, $wgContLang->sprintfDate( 'd M Y G:i:s', $timestamp ) );
169 - $semdata->addPropertyObjectValue( $pmdat, $dv );
 168+ $di = self::getDataItemFromMWTimestamp( $timestamp );
 169+ if ( $di !== null ) {
 170+ $semdata->addPropertyObjectValue( $pmdat, $di );
 171+ }
170172 }
171173 } else { // data found, but do all operations as if it was empty
172174 $semdata = new SMWSemanticData( $semdata->getSubject() );
@@ -180,7 +182,7 @@
181183
182184 if ( $makejobs && $smwgEnableUpdateJobs && ( $namespace == SMW_NS_PROPERTY ) ) {
183185 // If it is a property, then we need to check if the type or the allowed values have been changed.
184 - $ptype = SMWPropertyValue::makeProperty( '_TYPE' );
 186+ $ptype = new SMWDIProperty( '_TYPE' );
185187 $oldtype = smwfGetStore()->getPropertyValues( $title, $ptype );
186188 $newtype = $semdata->getPropertyValues( $ptype );
187189
@@ -188,7 +190,7 @@
189191 $updatejobflag = true;
190192 } else {
191193 foreach ( $smwgDeclarationProperties as $prop ) {
192 - $pv = SMWPropertyValue::makeProperty( $prop );
 194+ $pv = new SMWDIProperty( $prop );
193195 $oldvalues = smwfGetStore()->getPropertyValues( $semdata->getSubject(), $pv );
194196 $newvalues = $semdata->getPropertyValues( $pv );
195197 $updatejobflag = !self::equalDatavalues( $oldvalues, $newvalues );
@@ -196,7 +198,7 @@
197199 }
198200
199201 if ( $updatejobflag ) {
200 - $prop = SMWPropertyValue::makeProperty( $title->getDBkey() );
 202+ $prop = new SMWDIProperty( $title->getDBkey() );
201203 $subjects = smwfGetStore()->getAllPropertySubjects( $prop );
202204
203205 foreach ( $subjects as $subject ) {
@@ -204,7 +206,7 @@
205207 }
206208 wfRunHooks( 'smwUpdatePropertySubjects', array( &$jobs ) );
207209
208 - $subjects = smwfGetStore()->getPropertySubjects( SMWPropertyValue::makeProperty( '_ERRP' ), $prop->getWikiPageValue() );
 210+ $subjects = smwfGetStore()->getPropertySubjects( new SMWDIProperty( '_ERRP' ), $prop->getWikiPageValue() );
209211
210212 foreach ( $subjects as $subject ) {
211213 $jobs[] = new SMWUpdateJob( $subject->getTitle() );
@@ -212,8 +214,8 @@
213215 }
214216 } elseif ( $makejobs && $smwgEnableUpdateJobs && ( $namespace == SMW_NS_TYPE ) ) {
215217 // if it is a type we need to check if the conversion factors have been changed
216 - $pconv = SMWPropertyValue::makeProperty( '_CONV' );
217 - $ptype = SMWPropertyValue::makeProperty( '_TYPE' );
 218+ $pconv = new SMWDIProperty( '_CONV' );
 219+ $ptype = new SMWDIProperty( '_TYPE' );
218220
219221 $oldfactors = smwfGetStore()->getPropertyValues( $semdata->getSubject(), $pconv );
220222 $newfactors = $semdata->getPropertyValues( $pconv );
@@ -228,7 +230,7 @@
229231
230232 foreach ( $proppages as $proppage ) {
231233 $jobs[] = new SMWUpdateJob( $proppage->getTitle() );
232 - $prop = SMWPropertyValue::makeProperty( $proppage->getDBkey() );
 234+ $prop = new SMWDIProperty( $proppage->getDBkey() );
233235 $subjects = $store->getAllPropertySubjects( $prop );
234236
235237 foreach ( $subjects as $subject ) {
@@ -236,7 +238,7 @@
237239 }
238240
239241 $subjects = smwfGetStore()->getPropertySubjects(
240 - SMWPropertyValue::makeProperty( '_ERRP' ),
 242+ new SMWDIProperty( '_ERRP' ),
241243 $prop->getWikiPageValue()
242244 );
243245
@@ -309,6 +311,7 @@
310312 /**
311313 * Hook function fetches category information and other final settings from parser output,
312314 * so that they are also replicated in SMW for more efficient querying.
 315+ * @bug Sortkey currently not stored. Needs to be done differently now.
313316 */
314317 static public function onParserAfterTidy( &$parser, &$text ) {
315318 global $smwgUseCategoryHierarchy, $smwgCategoriesAsInstances;
@@ -318,25 +321,23 @@
319322 }
320323
321324 $categories = $parser->mOutput->getCategoryLinks();
322 -
323 - foreach ( $categories as $name ) {
 325+ foreach ( $categories as $catname ) {
324326 if ( $smwgCategoriesAsInstances && ( self::getSMWData( $parser )->getSubject()->getNamespace() != NS_CATEGORY ) ) {
325 - $pinst = SMWPropertyValue::makeProperty( '_INST' );
326 - $dv = SMWDataValueFactory::newPropertyObjectValue( $pinst );
327 - $dv->setValues( $name, NS_CATEGORY );
328 - self::getSMWData( $parser )->addPropertyObjectValue( $pinst, $dv );
 327+ $pinst = new SMWDIProperty( '_INST' );
 328+ $categoryDi = new SMWDIWikiPage( $catname, NS_CATEGORY, '' );
 329+ self::getSMWData( $parser )->addPropertyObjectValue( $pinst, $categoryDi );
329330 }
330331
331332 if ( $smwgUseCategoryHierarchy && ( self::getSMWData( $parser )->getSubject()->getNamespace() == NS_CATEGORY ) ) {
332 - $psubc = SMWPropertyValue::makeProperty( '_SUBC' );
333 - $dv = SMWDataValueFactory::newPropertyObjectValue( $psubc );
334 - $dv->setValues( $name, NS_CATEGORY );
335 - self::getSMWData( $parser )->addPropertyObjectValue( $psubc, $dv );
 333+ $psubc = new SMWDIProperty( '_SUBC' );
 334+ $categoryDi = new SMWDIWikiPage( $catname, NS_CATEGORY, '' );
 335+ self::getSMWData( $parser )->addPropertyObjectValue( $psubc, $categoryDi );
336336 }
337337 }
338338
339 - $sortkey = ( $parser->mDefaultSort ? $parser->mDefaultSort : self::getSMWData( $parser )->getSubject()->getText() );
340 - self::getSMWData( $parser )->getSubject()->setSortkey( $sortkey );
 339+// $sortkey = ( $parser->mDefaultSort ? $parser->mDefaultSort :
 340+// str_replace( '_', ' ', self::getSMWData( $parser )->getSubject()->getDBkey() ) );
 341+// self::getSMWData( $parser )->getSubject()->setSortkey( $sortkey );
341342
342343 return true;
343344 }
@@ -363,7 +364,7 @@
364365 return true; // nothing we can do
365366 }
366367 if ( !isset( $output->mSMWData ) ) { // no data container yet, make one
367 - $output->mSMWData = new SMWSemanticData( SMWWikiPageValue::makePageFromTitle( $title ) );
 368+ $output->mSMWData = new SMWSemanticData( new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki() ) );
368369 }
369370
370371 $semdata = $output->mSMWData;
@@ -371,20 +372,13 @@
372373 return true;
373374 }
374375
375 - $pmdat = SMWPropertyValue::makeProperty( '_MDAT' );
376 -
377 - // create a date string that is certainly parsable in the current language:
 376+ $pmdat = new SMWDIProperty( '_MDAT' );
378377 $timestamp = $article->getTimestamp();
 378+ $di = self::getDataItemFromMWTimestamp( $timestamp );
 379+ if ( $di !== null ) {
 380+ $semdata->addPropertyObjectValue( $pmdat, $di );
 381+ }
379382
380 - $date = $wgContLang->sprintfDate( 'd ', $timestamp ) .
381 - $smwgContLang->getMonthLabel( ( $wgContLang->sprintfDate( 'm', $timestamp ) + 0 ) ) .
382 - $wgContLang->sprintfDate( ' Y G:i:s', $timestamp );
383 - $dv = SMWDataValueFactory::newPropertyObjectValue( $pmdat, $date );
384 -
385 - // The below method is not safe, since "M" as used in MW may not be the month label as used in SMW if SMW falls back to some other language:
386 - // $dv = SMWDataValueFactory::newPropertyObjectValue( $pmdat, $wgContLang->sprintfDate( 'd M Y G:i:s', $article->getTimestamp() ) );
387 - $semdata->addPropertyObjectValue( $pmdat, $dv );
388 -
389383 return true;
390384 }
391385
@@ -426,4 +420,27 @@
427421 return true; // always return true, in order not to stop MW's hook processing!
428422 }
429423
 424+ /**
 425+ * Create an SMWDITime object from a MediaWiki timestamp. A timestamp
 426+ * is a 14 character string YYYYMMDDhhmmss.
 427+ *
 428+ * @param $timestamp string MediaWiki timestamp
 429+ * @return SWMDITime object or null if errors occurred
 430+ */
 431+ static protected function getDataItemFromMWTimestamp( $timestamp ) {
 432+ $year = intval( substr( $timestamp, 0, 4 ) );
 433+ $month = intval( substr( $timestamp, 4, 2 ) );
 434+ $day = intval( substr( $timestamp, 6, 2 ) );
 435+ $hour = intval( substr( $timestamp, 8, 2 ) );
 436+ $min = intval( substr( $timestamp, 10, 2 ) );
 437+ $sec = intval( substr( $timestamp, 12, 2 ) );
 438+ try {
 439+ return new SMWDITime( $year, $month, $day, $hour, $min, $sec );
 440+ } catch ( SMWDataItemException $e ) {
 441+ // we rely on MW timestamp format above -- if it ever changes,
 442+ // exceptions might possibly occur but this should not prevent editing
 443+ return null;
 444+ }
 445+ }
 446+
430447 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Record_Descriptions.php
@@ -77,7 +77,7 @@
7878 protected $m_position;
7979
8080 public function __construct( $position, SMWDescription $description ) {
81 - parent::__construct( SMWPropertyValue::makeProperty( '_' . ( $position + 1 ) ), $description );
 81+ parent::__construct( new SMWDIProperty( '_' . ( $position + 1 ) ), $description );
8282 $this->m_position = $position;
8383 }
8484
Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_ExportController.php
@@ -136,23 +136,23 @@
137137 * features like recursive export or backlinks that are available for this
138138 * type of data.
139139 *
140 - * @param SMWWikiPageValue $value specifying the page to be exported
 140+ * @param SMWDIWikiPage $diWikiPage specifying the page to be exported
141141 * @param integer $recursiondepth specifying the depth of recursion, see
142142 * SMWSmallTitle::$recdepth
143143 */
144 - protected function serializePage( SMWWikiPageValue $value, $recursiondepth = 1 ) {
 144+ protected function serializePage( SMWDIWikiPage $diWikiPage, $recursiondepth = 1 ) {
145145 $st = new SMWSmallTitle();
146 - $st->dbkey = $value->getDBKey();
147 - $st->namespace = $value->getNamespace();
 146+ $st->dbkey = $diWikiPage->getDBKey();
 147+ $st->namespace = $diWikiPage->getNamespace();
148148 $st->recdepth = $recursiondepth;
149149 if ( $this->isDone( $st ) ) return; // do not export twice
150150 $this->markAsDone( $st );
151 - $data = SMWExporter::makeExportData( $this->getSemanticData( $value, ( $recursiondepth == 0 ) ) );
 151+ $data = SMWExporter::makeExportData( $this->getSemanticData( $diWikiPage, ( $recursiondepth == 0 ) ) );
152152 $this->serializer->serializeExpData( $data, $recursiondepth );
153153
154154 // let other extensions add additional RDF data for this page
155155 $additionalDataArray = array();
156 - wfRunHooks( 'smwAddToRDFExport', array( $value->getTitle(), &$additionalDataArray, ( $recursiondepth != 0 ), $this->add_backlinks ) );
 156+ wfRunHooks( 'smwAddToRDFExport', array( $diWikiPage, &$additionalDataArray, ( $recursiondepth != 0 ), $this->add_backlinks ) );
157157 foreach ( $additionalDataArray as $additionalData ) {
158158 $this->serializer->serializeExpData( $additionalData ); // serialise
159159 }
@@ -186,12 +186,13 @@
187187 // if they were serialised at recdepth 0 only).
188188 if ( $this->add_backlinks ) {
189189 wfProfileIn( "RDF::PrintPages::GetBacklinks" );
190 - $inprops = smwfGetStore()->getInProperties( $value );
 190+ $inprops = smwfGetStore()->getInProperties( $diWikiPage );
191191 foreach ( $inprops as $inprop ) {
192 - if ( $inprop->getWikiPageValue() instanceof SMWWikiPageValue ) {
193 - $this->queuePage( $inprop->getWikiPageValue(), 0 ); // no real recursion along properties
 192+ $propWikiPage = $inprop->getDiWikiPage();
 193+ if ( $propWikiPage !== null ) {
 194+ $this->queuePage( $propWikiPage, 0 ); // no real recursion along properties
194195 }
195 - $inSubs = smwfGetStore()->getPropertySubjects( $inprop, $value );
 196+ $inSubs = smwfGetStore()->getPropertySubjects( $inprop, $diWikiPage );
196197 foreach ( $inSubs as $inSub ) {
197198 $stb = new SMWSmallTitle();
198199 $stb->dbkey = $inSub->getDBkey();
@@ -199,18 +200,18 @@
200201 $stb->recdepth = $subrecdepth;
201202 if ( !$this->isDone($stb) ) {
202203 $semdata = $this->getSemanticData( $inSub, true );
203 - $semdata->addPropertyObjectValue( $inprop, $value );
 204+ $semdata->addPropertyObjectValue( $inprop, $diWikiPage );
204205 $data = SMWExporter::makeExportData( $semdata );
205206 $this->serializer->serializeExpData( $data, $subrecdepth );
206207 }
207208 }
208209 }
209210
210 - if ( NS_CATEGORY === $value->getNamespace() ) { // also print elements of categories
 211+ if ( NS_CATEGORY === $diWikiPage->getNamespace() ) { // also print elements of categories
211212 $options = new SMWRequestOptions();
212213 $options->limit = 100; // Categories can be large, always use limit
213 - $instances = smwfGetStore()->getPropertySubjects( SMWPropertyValue::makeProperty( '_INST' ), $value, $options );
214 - $pinst = SMWPropertyValue::makeProperty( '_INST' );
 214+ $instances = smwfGetStore()->getPropertySubjects( new SMWDIProperty( '_INST' ), $diWikiPage, $options );
 215+ $pinst = new SMWDIProperty( '_INST' );
215216
216217 foreach ( $instances as $instance ) {
217218 $stb = new SMWSmallTitle();
@@ -219,20 +220,20 @@
220221
221222 if ( !array_key_exists( $stb->getHash(), $this->element_done ) ) {
222223 $semdata = $this->getSemanticData( $instance, true );
223 - $semdata->addPropertyObjectValue( $pinst, $value );
 224+ $semdata->addPropertyObjectValue( $pinst, $diWikiPage );
224225 $data = SMWExporter::makeExportData( $semdata );
225226 $this->serializer->serializeExpData( $data, $subrecdepth );
226227 }
227228 }
228 - } elseif ( SMW_NS_CONCEPT === $value->getNamespace() ) { // print concept members (slightly different code)
229 - $desc = new SMWConceptDescription( $value->getTitle() );
 229+ } elseif ( SMW_NS_CONCEPT === $diWikiPage->getNamespace() ) { // print concept members (slightly different code)
 230+ $desc = new SMWConceptDescription( $diWikiPage );
230231 $desc->addPrintRequest( new SMWPrintRequest( SMWPrintRequest::PRINT_THIS, '' ) );
231232 $query = new SMWQuery( $desc );
232233 $query->setLimit( 100 );
233234
234235 $res = smwfGetStore()->getQueryResult( $query );
235236 $resarray = $res->getNext();
236 - $pinst = SMWPropertyValue::makeProperty( '_INST' );
 237+ $pinst = new SMWDIProperty( '_INST' );
237238
238239 while ( $resarray !== false ) {
239240 $instance = end( $resarray )->getNextObject();
@@ -243,7 +244,7 @@
244245
245246 if ( !array_key_exists( $stb->getHash(), $this->element_done ) ) {
246247 $semdata = $this->getSemanticData( $instance, true );
247 - $semdata->addPropertyObjectValue( $pinst, $value );
 248+ $semdata->addPropertyObjectValue( $pinst, $diWikiPage );
248249 $data = SMWExporter::makeExportData( $semdata );
249250 $this->serializer->serializeExpData( $data );
250251 }
@@ -263,17 +264,17 @@
264265 */
265266 protected function serializeSmallTitle( SMWSmallTitle $st ) {
266267 if ( $this->isDone( $st ) ) return; // do not export twice
267 - $value = SMWWikiPageValue::makePage( $st->dbkey, $st->namespace );
268 - $this->serializePage( $value, $st->recdepth );
 268+ $diWikiPage = new SMWDIWikiPage( $st->dbkey, $st->namespace, '' );
 269+ $this->serializePage( $diWikiPage, $st->recdepth );
269270 }
270271
271272 /**
272 - * Add a given SMWWikiPageValue to the export queue if needed.
 273+ * Add a given SMWDIWikiPage to the export queue if needed.
273274 */
274 - protected function queuePage( SMWWikiPageValue $pagevalue, $recursiondepth ) {
 275+ protected function queuePage( SMWDIWikiPage $diWikiPage, $recursiondepth ) {
275276 $spt = new SMWSmallTitle();
276 - $spt->dbkey = $pagevalue->getDBkey();
277 - $spt->namespace = $pagevalue->getNamespace();
 277+ $spt->dbkey = $diWikiPage->getDBkey();
 278+ $spt->namespace = $diWikiPage->getNamespace();
278279 $spt->recdepth = $recursiondepth;
279280 if ( !$this->isDone( $spt ) ) {
280281 $this->element_queue[$spt->getHash()] = $spt;
@@ -318,12 +319,12 @@
319320 * and we do not want to modify the store's result which may be used for
320321 * caching purposes elsewhere.
321322 */
322 - protected function getSemanticData( $pagevalue, $core_props_only ) {
323 - $semdata = smwfGetStore()->getSemanticData( $pagevalue, $core_props_only ? array( '__spu', '__typ', '__imp' ) : false ); // advise store to retrieve only core things
 323+ protected function getSemanticData( SMWDIWikiPage $diWikiPage, $core_props_only ) {
 324+ $semdata = smwfGetStore()->getSemanticData( $diWikiPage, $core_props_only ? array( '__spu', '__typ', '__imp' ) : false ); // advise store to retrieve only core things
324325 if ( $core_props_only ) { // be sure to filter all non-relevant things that may still be present in the retrieved
325 - $result = new SMWSemanticData( $pagevalue );
 326+ $result = new SMWSemanticData( $diWikiPage );
326327 foreach ( array( '_URI', '_TYPE', '_IMPO' ) as $propid ) {
327 - $prop = SMWPropertyValue::makeProperty( $propid );
 328+ $prop = new SMWDIProperty( $propid );
328329 $values = $semdata->getPropertyValues( $prop );
329330 foreach ( $values as $dv ) {
330331 $result->addPropertyObjectValue( $prop, $dv );
Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php
@@ -48,7 +48,7 @@
4949 SMWExporter::initBaseURIs();
5050 $subject = $semdata->getSubject();
5151 if ( $subject->getNamespace() == SMW_NS_PROPERTY ) {
52 - $types = $semdata->getPropertyValues( SMWPropertyValue::makeProperty( '_TYPE' ) );
 52+ $types = $semdata->getPropertyValues( new SMWDIProperty( '_TYPE' ) );
5353 } else {
5454 $types = array();
5555 }
@@ -66,10 +66,10 @@
6767 * can be used to pass a particular SMWTypesValue object that is used
6868 * for determining the OWL type for property pages.
6969 *
70 - * @param SMWWikiPageValue $subject
 70+ * @param SMWDIWikiPage $subject
7171 * @param mixed $typesvalueforproperty either an SMWTypesValue or null
7272 */
73 - static public function makeExportDataForSubject( SMWWikiPageValue $subject, $typesvalueforproperty = null ) {
 73+ static public function makeExportDataForSubject( SMWDIWikiPage $subject, $typesvalueforproperty = null ) {
7474 $result = $subject->getExportData();
7575 switch ( $subject->getNamespace() ) {
7676 case NS_CATEGORY: case SMW_NS_CONCEPT:
@@ -78,7 +78,7 @@
7979 break;
8080 case SMW_NS_PROPERTY:
8181 if ( $typesvalueforproperty == null ) {
82 - $types = smwfGetStore()->getPropertyValues( $subject, SMWPropertyValue::makeProperty( '_TYPE' ) );
 82+ $types = smwfGetStore()->getPropertyValues( $subject, new SMWDIProperty( '_TYPE' ) );
8383 $typesvalueforproperty = end( $types );
8484 }
8585 $maintype_pe = SMWExporter::getSpecialElement( 'owl', SMWExporter::getOWLPropertyType( $typesvalueforproperty ) );
@@ -103,14 +103,14 @@
104104
105105 /**
106106 * Extend a given SMWExpData element by adding export data for the
107 - * specified property values. This method is called when constructing
108 - * export data structures from SMWSemanticData objects.
 107+ * specified property data itme. This method is called when
 108+ * constructing export data structures from SMWSemanticData objects.
109109 *
110 - * @param SMWPropertyValue $property
 110+ * @param SMWDIProperty $property
111111 * @param array $values of SMWDataValue objects for the given property
112112 * @param SMWExpData $data to add the data to
113113 */
114 - static public function addPropertyValues(SMWPropertyValue $property, $values, SMWExpData &$data) {
 114+ static public function addPropertyValues(SMWDIProperty $property, $values, SMWExpData &$data) {
115115 if ( $property->isUserDefined() ) {
116116 $pe = SMWExporter::getResourceElement( $property );
117117 foreach ( $values as $dv ) {
@@ -161,7 +161,7 @@
162162 if ( $pe === null ) return; // unknown special property, not exported
163163 foreach ( $values as $dv ) {
164164 if ( $cat_only ) {
165 - if ( !( $dv instanceof SMWWikiPageValue ) || ( $dv->getNamespace() != NS_CATEGORY ) ) {
 165+ if ( !( $dv instanceof SMWDIWikiPage ) || ( $dv->getNamespace() != NS_CATEGORY ) ) {
166166 continue;
167167 }
168168 }
@@ -185,25 +185,23 @@
186186 }
187187
188188 /**
189 - * Create an SMWExpElement for some internal resource, given by a Title or
190 - * SMWWikiPageValue object. Returns null on error.
 189+ * Create an SMWExpElement for some internal resource, given by an
 190+ * SMWDIWikiPage or SMWDIProperty object. Returns null on error.
191191 * This is the one place in the code where URIs of wiki pages and
192192 * properties are defined.
193193 *
194 - * @param mixed Title or SMWWikiPagevalue or SMWPropertyValues
195 - * @return SMWExpResource
 194+ * @param mixed SMWDIWikiPage or SMWDIProperty
 195+ * @return SMWExpResource or null
196196 */
197 - static public function getResourceElement( $resource ) {
198 - if ( $resource instanceof SMWWikiPageValue ) {
 197+ static public function getResourceElement( SMWDataItem $resource ) {
 198+ if ( $resource instanceof SMWDIWikiPage ) {
199199 $dv = $resource;
200 - } elseif ( $resource instanceof SMWPropertyValue ) {
 200+ } elseif ( $resource instanceof SMWDIProperty ) {
201201 $dv = $resource->getWikiPageValue();
202 - } elseif ( $resource instanceof Title ) {
203 - $dv = SMWWikiPageValue::makePageFromTitle( $resource );
204202 } else {
205203 return null;
206204 }
207 - $idvs = smwfGetStore()->getPropertyValues( $dv, SMWPropertyValue::makeProperty( '_IMPO' ) );
 205+ $idvs = smwfGetStore()->getPropertyValues( $dv, new SMWDIProperty( '_IMPO' ) );
208206 if ( count( $idvs ) > 0 ) {
209207 $namespace = current( $idvs )->getNS();
210208 $namespaceid = current( $idvs )->getNSID();
@@ -326,5 +324,63 @@
327325 return $data;
328326 }
329327
 328+ /**
 329+ * Create an SWMExpData container that encodes the data of the given
 330+ * datavalue object.
 331+ *
 332+ * @param SMWDataValue $dv the datavalue to encode
 333+ */
 334+ static public function getDVExpData( SMWDataValue $dv ) {
 335+ if ( !$dv->isValid() ) return null;
330336
 337+ switch ( $dv->getBaseType() ) {
 338+ case SMWDataValue::TYPE_NUMBER:
 339+ $lit = new SMWExpLiteral( $dv->getNumber(), $dv, 'http://www.w3.org/2001/XMLSchema#double' );
 340+ return new SMWExpData( $lit );
 341+ break;
 342+ case SMWDataValue::TYPE_STRING: case SMWDataValue::TYPE_BLOB:
 343+ $lit = new SMWExpLiteral( smwfHTMLtoUTF8( $dv->getWikiText() ), $dv, 'http://www.w3.org/2001/XMLSchema#string' );
 344+ return new SMWExpData( $lit );
 345+ break;
 346+ case SMWDataValue::TYPE_BOOL:
 347+ $xsdvalue = $dv->getBoolean() ? 'true' : 'false';
 348+ $lit = new SMWExpLiteral( $xsdvalue, $dv, 'http://www.w3.org/2001/XMLSchema#boolean' );
 349+ return new SMWExpData( $lit );
 350+ break;
 351+ case SMWDataValue::TYPE_URI:
 352+ /// TODO This escaping seems very odd. The serialisation should handle such things.
 353+ $res = new SMWExpResource( str_replace( '&', '&amp;', $dv->getURI() ), $dv );
 354+ return new SMWExpData( $res );
 355+ break;
 356+ case SMWDataValue::TYPE_TIME:
 357+ $lit = new SMWExpLiteral( $dv->getXMLSchemaDate(), $dv, 'http://www.w3.org/2001/XMLSchema#dateTime' );
 358+ return new SMWExpData( $lit );
 359+ break;
 360+ case SMWDataValue::TYPE_GEO:
 361+ /// TODO
 362+ break;
 363+ case SMWDataValue::TYPE_CONT:
 364+ /// TODO
 365+ break;
 366+ case SMWDataValue::TYPE_PAGE:
 367+ if ( $dv->getNamespace() == NS_MEDIA ) { // special handling for linking media files directly (object only)
 368+ $file = wfFindFile( $dv->getTitle() );
 369+ if ( $file !== false ) {
 370+ return new SMWExpData( new SMWExpResource( $file->getFullURL(), $this ) );
 371+ } else { // Medialink to non-existing file :-/
 372+ return null;
 373+ }
 374+ } else {
 375+ return new SMWExpData( SMWExporter::getResourceElement( $dv ) );
 376+ }
 377+ break;
 378+ case SMWDataValue::TYPE_CONCEPT:
 379+ /// TODO
 380+ break;
 381+ case SMWDataValue::TYPE_PROP:
 382+ return new SMWExpData( SMWExporter::getResourceElement( $dv->getWikiPageValue() ) );
 383+ break;
 384+ }
 385+ }
 386+
331387 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValue.php
@@ -48,29 +48,6 @@
4949 */
5050 abstract class SMWDataValue {
5151
52 - /// Primitive type for numbers as implemented by SMWNumberValue
53 - const TYPE_NUMBER = 1;
54 - /// Primitive type for plain strings as implemented by SMWImportValue, SMWStringValue, SMWTypeListValue, SMW_ErrorValue
55 - const TYPE_STRING = 2;
56 - /// Primitive type Blob (long string) implemented by SMWStringValue
57 - const TYPE_BLOB = 3;
58 - /// Primitive type Boolean as implemented by SMWBoolValue
59 - const TYPE_BOOL = 4;
60 - /// Primitive type URI as implemented by SMWURIValue
61 - const TYPE_URI = 5;
62 - /// Primitive type Time as implemented by SMWTimeValue
63 - const TYPE_TIME = 6;
64 - /// Primitive type Geographic coordinate as implemented
65 - const TYPE_GEO = 7;
66 - /// Primitive type Container as implemented by SMWContainerValue
67 - const TYPE_CONT = 8;
68 - /// Primitive type for pages as implemented by SMWPageValue
69 - const TYPE_PAGE = 9;
70 - /// Primitive type Concept as implemented by SMWConceptValue
71 - const TYPE_CONCEPT = 10;
72 - /// Primitive type representing a property implemented by SMWPropertyValue
73 - const TYPE_PROP = 11;
74 -
7552 /**
7653 * Associated data item. This is the reference to the immutable object
7754 * that represents the current data content. All other data stored here
@@ -100,7 +77,7 @@
10178 * True if a value was set.
10279 * @var boolean
10380 */
104 - protected $m_isset = false;
 81+ private $m_isset;
10582
10683 /**
10784 * The type id for this value object.
@@ -176,11 +153,10 @@
177154 public function setUserValue( $value, $caption = false ) {
178155 wfProfileIn( 'SMWDataValue::setUserValue (SMW)' );
179156
180 - $this->m_dataitem = null;
 157+ unset( $this->m_dataitem );
181158 $this->mErrors = array(); // clear errors
182159 $this->mHasErrors = false;
183160 $this->m_infolinks = array(); // clear links
184 - $this->m_isset = false;
185161 $this->mHasSearchLink = false;
186162 $this->mHasServiceLinks = false;
187163 $this->m_stubvalues = false;
@@ -193,7 +169,6 @@
194170 // Note: \x07 was used in MediaWiki 1.11.0, \x7f is used now
195171 if ( ( strpos( $value, "\x7f" ) === false ) && ( strpos( $value, "\x07" ) === false ) ) {
196172 $this->parseUserValue( $value ); // may set caption if not set yet, depending on datavalue
197 - $this->m_isset = true;
198173 } else {
199174 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
200175 $this->addError( wfMsgForContent( 'smw_parseerror' ) );
@@ -219,6 +194,7 @@
220195 * @param array $args
221196 */
222197 public function setDBkeys( array $args ) {
 198+ throw new Exception( "setDBkeys() must no longer be called." );
223199 $this->mErrors = array(); // clear errors
224200 $this->mHasErrors = false;
225201 $this->m_infolinks = array(); // clear links
@@ -226,7 +202,6 @@
227203 $this->mHasServiceLinks = false;
228204 $this->m_caption = false;
229205 $this->m_stubvalues = $args;
230 - $this->m_isset = true;
231206 }
232207
233208 /**
@@ -237,24 +212,24 @@
238213 * It takes only very little effort if unstubbing is not needed.
239214 */
240215 protected function unstub() {
241 - if ( $this->m_stubvalues !== false ) {
242 - wfProfileIn( 'SMWDataValue::unstub-' . $this->m_typeid . ' (SMW)' );
243 -
244 - $args = $this->m_stubvalues;
245 - $this->m_stubvalues = false; // Careful to avoid recursive unstubbing.
246 - $this->parseDBkeys( $args );
247 -
248 - wfProfileOut( 'SMWDataValue::unstub-' . $this->m_typeid . ' (SMW)' );
249 - }
 216+// if ( $this->m_stubvalues !== false ) {
 217+// wfProfileIn( 'SMWDataValue::unstub-' . $this->m_typeid . ' (SMW)' );
 218+//
 219+// $args = $this->m_stubvalues;
 220+// $this->m_stubvalues = false; // Careful to avoid recursive unstubbing.
 221+// $this->parseDBkeys( $args );
 222+//
 223+// wfProfileOut( 'SMWDataValue::unstub-' . $this->m_typeid . ' (SMW)' );
 224+// }
250225 }
251226
252227 /**
253228 * Specify the property to which this value refers. Used to generate search links and
254229 * to find custom settings that relate to the property.
255230 *
256 - * @param SMWPropertyValue $property
 231+ * @param SMWDIProperty $property
257232 */
258 - public function setProperty( SMWPropertyValue $property ) {
 233+ public function setProperty( SMWDIProperty $property ) {
259234 $this->m_property = $property;
260235 }
261236
@@ -299,7 +274,7 @@
300275 }
301276
302277 array_unshift( $args, '' ); // add a 0 element as placeholder
303 - $servicelinks = smwfGetStore()->getPropertyValues( $this->m_property->getWikiPageValue(), SMWPropertyValue::makeProperty( '_SERV' ) );
 278+ $servicelinks = smwfGetStore()->getPropertyValues( $this->m_property->getWikiPageValue(), new SMWDIProperty( '_SERV' ) );
304279
305280 foreach ( $servicelinks as $dv ) {
306281 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
@@ -453,13 +428,39 @@
454429 /**
455430 * Get the actual data contained in this object or null if the data is
456431 * not defined (due to errors or due to not being set at all).
 432+ * @note Most implementations ensure that a data item is always set,
 433+ * even if errors occurred, to avoid additional checks for not
 434+ * accessing null. Hence, one must not assume that a non-null return
 435+ * value here implies that isValid() returns true.
 436+ *
457437 * @return SMWDataItem
458438 */
459439 public function getDataItem() {
460 - return $this->m_dataitem;
 440+ if ( $this->isValid() ) {
 441+ return $this->m_dataitem;
 442+ } else {
 443+ return new SMWDIError( $this->mErrors );
 444+ }
461445 }
462446
463447 /**
 448+ * Set the actual data contained in this object. The method returns
 449+ * true if this was successful (requiring the type of the dataitem
 450+ * to match the data value). If false is returned, the data value is
 451+ * left unchanged (the data item was rejected).
 452+ *
 453+ * @note Even if this function returns true, the data value object
 454+ * might become invalid if the content of the data item caused errors
 455+ * in spite of it being of the right basic type. False is only returned
 456+ * if the data item is fundamentally incompatible with the data value.
 457+ *
 458+ * @param $dataitem SMWDataItem
 459+ * @return boolean
 460+ * @bug This method must get some wrapper to reset basic values of this class. Currently, things like error messages are kept.
 461+ */
 462+ abstract public function setDataItem( SMWDataItem $dataItem );
 463+
 464+ /**
464465 * Return an array of values that characterize the given datavalue
465466 * completely, and that are sufficient to reproduce a value of identical
466467 * content using the function setDBkeys(). The value array must use number
@@ -760,7 +761,7 @@
761762 */
762763 public function isValid() {
763764 $this->unstub();
764 - return ( ( !$this->mHasErrors ) && $this->m_isset );
 765+ return ( ( !$this->mHasErrors ) && isset( $this->m_dataitem ) );
765766 }
766767
767768 /**
@@ -801,36 +802,36 @@
802803 * Creates an error if the value is illegal.
803804 */
804805 protected function checkAllowedValues() {
805 - if ( ( $this->m_property === null ) || ( $this->m_property->getWikiPageValue() === null ) ) {
806 - return; // no property known
 806+ if ( ( $this->m_property === null ) || ( $this->m_property->getDiWikiPage() === null ) || ( !isset( $this->m_dataitem ) ) ) {
 807+ return; // no property known, or no data to check
807808 }
808809
809810 $allowedvalues = smwfGetStore()->getPropertyValues(
810 - $this->m_property->getWikiPageValue(),
811 - SMWPropertyValue::makeProperty( '_PVAL' )
 811+ $this->m_property->getDiWikiPage(),
 812+ new SMWDIProperty( '_PVAL' )
812813 );
813814
814815 if ( count( $allowedvalues ) == 0 ) {
815816 return;
816817 }
817818
818 - $hash = $this->getHash();
819 - $value = SMWDataValueFactory::newTypeIDValue( $this->getTypeID() );
 819+ $hash = $this->m_dataitem->getHash();
 820+ $testdv = SMWDataValueFactory::newTypeIDValue( $this->getTypeID() );
820821 $accept = false;
821822 $valuestring = '';
 823+ foreach ( $allowedvalues as $di ) {
 824+ if ( $di->getDIType() === SMWDataItem::TYPE_STRING ) {
 825+ $testdv->setUserValue( $di->getString() );
822826
823 - foreach ( $allowedvalues as $stringvalue ) {
824 - $value->setUserValue( $stringvalue->getWikiValue() );
825 -
826 - if ( $hash === $value->getHash() ) {
827 - $accept = true;
828 - break;
829 - } else {
830 - if ( $valuestring != '' ) {
831 - $valuestring .= ', ';
 827+ if ( $hash === $testdv->getDataItem()->getHash() ) {
 828+ $accept = true;
 829+ break;
 830+ } else {
 831+ if ( $valuestring != '' ) {
 832+ $valuestring .= ', ';
 833+ }
 834+ $valuestring .= $di->getString();
832835 }
833 -
834 - $valuestring .= $value->getShortWikiText();
835836 }
836837 }
837838
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryPrinter.php
@@ -196,11 +196,12 @@
197197 *
198198 * @param string $result
199199 * @param SMWQueryResult $results
200 - * @param $outputmode
 200+ * @param integer $outputmode
201201 *
202202 * @return string
203203 */
204204 protected function handleNonFileResult( $result, SMWQueryResult $results, $outputmode ) {
 205+ global $wgParser;
205206 $result .= $this->getErrorString( $results ); // append errors
206207
207208 if ( ( !$this->isHTML ) && ( $this->hasTemplates ) ) { // preprocess embedded templates if needed
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php
@@ -37,7 +37,7 @@
3838 // Process redirects, if any (it seems that there is indeed no more direct way of getting this info from MW)
3939 $rt = Title::newFromRedirect( $text );
4040 if ( $rt !== null ) {
41 - $p = SMWPropertyValue::makeProperty( '_REDI' );
 41+ $p = new SMWDIProperty( '_REDI' );
4242 $dv = SMWDataValueFactory::newPropertyObjectValue( $p, $rt->getPrefixedText() );
4343
4444 if ( $smwgStoreAnnotations ) {
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Import.php
@@ -114,23 +114,38 @@
115115 }
116116
117117 protected function parseDBkeys( $args ) {
118 - $parts = explode( ' ', $args[0], 3 );
119 - if ( count( $parts ) != 3 ) {
 118+ try {
 119+ $dataItem = new SMWDIString( $args[0] );
 120+ $this->setDataItem( $dataItem );
 121+ } catch ( SMWStringLengthException $e ) {
120122 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
121 - $this->addError( wfMsgForContent( 'smw_parseerror' ) );
122 - } else {
123 - $this->m_namespace = $parts[0];
124 - $this->m_section = $parts[1];
125 - $this->m_uri = $parts[2];
126 - try {
127 - $this->m_dataitem = new SMWDIString( $args[0] );
128 - } catch ( SMWStringLengthException $e ) {
 123+ $this->addError( wfMsgForContent( 'smw_maxstring', '"' . $args[0] . '"' ) );
 124+ $this->m_dataitem = new SMWDIString( '' );
 125+ }
 126+ }
 127+
 128+ /**
 129+ * @see SMWDataValue::setDataItem()
 130+ * @param $dataitem SMWDataItem
 131+ * @return boolean
 132+ */
 133+ public function setDataItem( SMWDataItem $dataItem ) {
 134+ if ( $dataItem->getDIType() == SMWDataItem::TYPE_STRING ) {
 135+ $this->m_dataitem = $dataItem;
 136+ $parts = explode( ' ', $dataItem->getString(), 3 );
 137+ if ( count( $parts ) != 3 ) {
129138 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
130 - $this->addError( wfMsgForContent( 'smw_maxstring', '"' . $args[0] . '"' ) );
131 - $this->m_dataitem = new SMWDIString( '' );
 139+ $this->addError( wfMsgForContent( 'smw_parseerror' ) );
 140+ } else {
 141+ $this->m_namespace = $parts[0];
 142+ $this->m_section = $parts[1];
 143+ $this->m_uri = $parts[2];
 144+ $this->m_qname = $this->m_namespace . ':' . $this->m_section;
 145+ $this->m_caption = "[" . $this->m_uri . " " . $this->m_qname . "] (" . $this->m_name . ")";
132146 }
133 - $this->m_qname = $this->m_namespace . ':' . $this->m_section;
134 - $this->m_caption = "[" . $this->m_uri . " " . $this->m_qname . "] (" . $this->m_name . ")";
 147+ return true;
 148+ } else {
 149+ return false;
135150 }
136151 }
137152
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Linear.php
@@ -118,22 +118,24 @@
119119 $this->m_unitfactors = array();
120120 $this->m_mainunit = false;
121121
122 - $typepage = SMWWikiPageValue::makePage( $this->m_typeid, SMW_NS_TYPE );
123 - if ( !$typepage->isValid() ) {
 122+ try {
 123+ $typeDiWikiPage = new SMWDIWikiPage( $this->m_typeid, SMW_NS_TYPE, '' );
 124+ } catch ( SMWDataItemException $e ) {
124125 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
125126 $this->addError( wfMsgForContent( 'smw_unknowntype', SMWDataValueFactory::findTypeLabel( $this->getTypeID() ) ) );
126127 return;
127128 }
128 - $factors = smwfGetStore()->getPropertyValues( $typepage, SMWPropertyValue::makeProperty( '_CONV' ) );
 129+ $factors = smwfGetStore()->getPropertyValues( $typeDiWikiPage, new SMWDIProperty( '_CONV' ) );
129130 if ( count( $factors ) == 0 ) { // no custom type
130131 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
131132 $this->addError( wfMsgForContent( 'smw_unknowntype', SMWDataValueFactory::findTypeLabel( $this->getTypeID() ) ) );
132133 return;
133134 }
134135 $number = $unit = '';
135 - foreach ( $factors as $dv ) {
136 - if ( SMWNumberValue::parseNumberValue( $dv->getWikiValue(), $number, $unit ) != 0 ) {
137 - continue; // ignore problematic conversions
 136+ foreach ( $factors as $di ) {
 137+ if ( ( $di->getDIType() !== SMWDataItem::TYPE_STRING ) ||
 138+ ( SMWNumberValue::parseNumberValue( $di->getString(), $number, $unit ) != 0 ) ) {
 139+ continue; // ignore corrupted data and bogus inputs
138140 }
139141 $unit_aliases = preg_split( '/\s*,\s*/u', $unit );
140142 $first = true;
@@ -170,11 +172,15 @@
171173 if ( $this->m_displayunits !== false ) return; // do the below only once
172174 $this->initConversionData(); // needed to normalise unit strings
173175 $this->m_displayunits = array();
174 - if ( ( $this->m_property === null ) || ( $this->m_property->getWikiPageValue() === null ) ) return;
175 - $values = smwfGetStore()->getPropertyValues( $this->m_property->getWikiPageValue(), SMWPropertyValue::makeProperty( '_UNIT' ) );
 176+ if ( ( $this->m_property === null ) || ( $this->m_property->getDIWikiPage() === null ) ) {
 177+ return;
 178+ }
 179+ $dataItems = smwfGetStore()->getPropertyValues( $this->m_property->getDIWikiPage(), new SMWDIProperty( '_UNIT' ) );
176180 $units = array();
177 - foreach ( $values as $value ) { // Join all if many annotations exist. Discouraged (random order) but possible.
178 - $units = $units + preg_split( '/\s*,\s*/u', $value->getWikiValue() );
 181+ foreach ( $dataItems as $di ) { // Join all if many annotations exist. Discouraged (random order) but possible.
 182+ if ( $di->getDIType() === SMWDataItem::TYPE_STRING ) {
 183+ $units = $units + preg_split( '/\s*,\s*/u', $di->getString() );
 184+ }
179185 }
180186 foreach ( $units as $unit ) {
181187 $unit = SMWNumberValue::normalizeUnit( $unit );
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_TypeList.php
@@ -41,6 +41,26 @@
4242 }
4343
4444 /**
 45+ * @see SMWDataValue::setDataItem()
 46+ * @param $dataitem SMWDataItem
 47+ * @return boolean
 48+ */
 49+ public function setDataItem( SMWDataItem $dataItem ) {
 50+ if ( $dataItem->getDIType() == SMWDataItem::TYPE_STRING ) {
 51+ $this->m_dataitem = $dataItem;
 52+ $this->m_typevalues = array();
 53+ $ids = explode( ';', $dataItem->getString() );
 54+ foreach ( $ids as $id ) {
 55+ $this->m_typevalues[] = SMWDataValueFactory::newTypeIDValue( '__typ', SMWDataValueFactory::findTypeLabel( $id ) );
 56+ }
 57+ $this->m_caption = false;
 58+ return true;
 59+ } else {
 60+ return false;
 61+ }
 62+ }
 63+
 64+ /**
4565 * The special feature of this implementation of getDBkeys is that it uses
4666 * internal type ids to obtain a short internal value for the type. Note
4767 * that this also given language independence but that this is of little
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php
@@ -51,14 +51,14 @@
5252 if ( $querymode ) {
5353 $subdescriptions[] = new SMWRecordFieldDescription( $i, new SMWValueDescription( $dv, $comparator ) );
5454 } else {
55 - $property = SMWPropertyValue::makeProperty( '_' . ( $i + 1 ) );
 55+ $property = new SMWDIProperty( '_' . ( $i + 1 ) );
5656 $this->m_data->addPropertyObjectValue( $property, $dv );
5757 }
5858 $vi++;
5959 $empty = false;
6060 } elseif ( ( count( $values ) - $vi ) == ( count( $types ) - $i ) ) {
6161 // too many errors: keep this one to have enough slots left
62 - $this->m_data->addPropertyObjectValue( SMWPropertyValue::makeProperty( '_' . ( $i + 1 ) ), $dv );
 62+ $this->m_data->addPropertyObjectValue( new SMWDIProperty( '_' . ( $i + 1 ) ), $dv );
6363 $this->addError( $dv->getErrors() );
6464 $vi++;
6565 }
@@ -84,7 +84,7 @@
8585 if ( count( $args ) > 0 ) {
8686 foreach ( reset( $args ) as $value ) {
8787 if ( is_array( $value ) && ( count( $value ) == 2 ) ) {
88 - $property = SMWPropertyValue::makeProperty( reset( $value ) );
 88+ $property = new SMWDIProperty( reset( $value ) );
8989 $pnum = intval( substr( reset( $value ), 1 ) ); // try to find the number of this property
9090 if ( array_key_exists( $pnum - 1, $types ) ) {
9191 $dv = SMWDataValueFactory::newTypeObjectValue( $types[$pnum - 1] );
@@ -138,7 +138,7 @@
139139 * @todo This is not a full reset yet (the case that property is changed after a value
140140 * was set does not occur in the normal flow of things, hence this has low priority).
141141 */
142 - public function setProperty( SMWPropertyValue $property ) {
 142+ public function setProperty( SMWDIProperty $property ) {
143143 parent::setProperty( $property );
144144 $this->m_typevalues = null;
145145 }
@@ -204,7 +204,7 @@
205205 if ( ( $this->m_property === null ) || ( $this->m_property->getWikiPageValue() === null ) ) {
206206 $this->m_typevalues = array(); // no property known -> no types
207207 } else { // query for type values
208 - $typelist = smwfGetStore()->getPropertyValues( $this->m_property->getWikiPageValue(), SMWPropertyValue::makeProperty( '_LIST' ) );
 208+ $typelist = smwfGetStore()->getPropertyValues( $this->m_property->getWikiPageValue(), new SMWDIProperty( '_LIST' ) );
209209 if ( count( $typelist ) == 1 ) {
210210 $this->m_typevalues = reset( $typelist )->getTypeValues();
211211 } else { ///TODO internalionalize
@@ -228,7 +228,7 @@
229229 } elseif ( $i > 1 ) {
230230 $result .= ( $type == 4 ) ? '; ':", ";
231231 }
232 - $property = SMWPropertyValue::makeProperty( '_' . ( $i + 1 ) );
 232+ $property = new SMWDIProperty( '_' . ( $i + 1 ) );
233233 $propertyvalues = $this->m_data->getPropertyValues( $property ); // combining this with next line violates PHP strict standards
234234 $dv = reset( $propertyvalues );
235235 $result .= ( $dv !== false ) ? $this->makeValueOutputText( $type, $dv, $linker ): '?';
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Property.php
@@ -87,9 +87,10 @@
8888 * in any case.
8989 */
9090 static public function makeProperty( $propertyid ) {
91 - $property = new SMWPropertyValue( '__pro' );
92 - $property->setDBkeys( array( $propertyid ) );
93 - return $property;
 91+ $diProperty = new SMWDIProperty( $propertyid );
 92+ $dvProperty = new SMWPropertyValue( '__pro' );
 93+ $dvProperty->setDataItem( $diProperty );
 94+ return $dvProperty;
9495 }
9596
9697 /**
@@ -136,24 +137,37 @@
137138 * internal property id accordingly.
138139 */
139140 protected function parseDBkeys( $args ) {
140 - $this->mPropTypeValue = null;
141 - $this->mPropTypeId = '';
142 - unset( $this->m_wikipage );
143 -
144141 try {
145 - $this->m_dataitem = new SMWDIProperty( $args[0], false, $this->m_typeid );
 142+ $dataItem = new SMWDIProperty( $args[0], false, $this->m_typeid );
146143 } catch ( SMWDataItemException $e ) {
147144 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
148145 $this->addError( wfMsgForContent( 'smw_parseerror' ) ); // very rare to get an error here, don't bother with detailed reporting
149 - $this->m_dataitem = new SMWDIProperty( 'ERROR', false, $this->m_typeid ); // just to have something
 146+ $dataItem = new SMWDIProperty( 'ERROR', false, $this->m_typeid ); // just to have something
150147 }
 148+ $this->setDataItem( $dataItem );
 149+ }
151150
152 - $this->m_caption = false;
 151+ /**
 152+ * @see SMWDataValue::setDataItem()
 153+ * @param $dataitem SMWDataItem
 154+ * @return boolean
 155+ */
 156+ public function setDataItem( SMWDataItem $dataItem ) {
 157+ if ( $dataItem->getDIType() == SMWDataItem::TYPE_PROPERTY ) {
 158+ $this->m_dataitem = $dataItem;
 159+ $this->mPropTypeValue = null;
 160+ $this->mPropTypeId = '';
 161+ unset( $this->m_wikipage );
 162+ $this->m_caption = false;
 163+ return true;
 164+ } else {
 165+ return false;
 166+ }
153167 }
154168
155169 public function setCaption( $caption ) {
156170 parent::setCaption( $caption );
157 - if ( $this->m_wikipage instanceof SMWDataValue ) { // pass caption to embedded datavalue (used for printout)
 171+ if ( $this->getWikiPageValue() instanceof SMWDataValue ) { // pass caption to embedded datavalue (used for printout)
158172 $this->m_wikipage->setCaption( $caption );
159173 }
160174 }
@@ -179,11 +193,9 @@
180194 public function getWikiPageValue() {
181195 $this->unstub();
182196 if ( !isset( $this->m_wikipage ) ) {
183 - $label = $this->m_dataitem->getLabel();
184 - if ( $label != '' ) {
185 - $this->m_wikipage = SMWDataValueFactory::newTypeIDValue( '_wpp' );
186 - $this->m_wikipage->setDBkeys( array( str_replace( ' ', '_', $label ), SMW_NS_PROPERTY, '', '' ) );
187 - $this->m_wikipage->setCaption( $this->m_caption );
 197+ $diWikiPage = $this->m_dataitem->getDiWikiPage();
 198+ if ( $diWikiPage !== null ) {
 199+ $this->m_wikipage = SMWDataValueFactory::newDataItemValue( $diWikiPage, $this->m_caption );
188200 $this->m_wikipage->setOutputFormat( $this->m_outformat );
189201 $this->addError( $this->m_wikipage->getErrors() );
190202 } else { // should rarely happen ($value is only changed if the input $value really was a label for a predefined prop)
@@ -200,7 +212,7 @@
201213 */
202214 public function isVisible() {
203215 $this->unstub();
204 - return ( $this->getWikiPageValue() !== null );
 216+ return ( $this->m_dataitem->isUserDefined() ) || ( $this->m_dataitem->getLabel() != '' );
205217 }
206218
207219 public function getShortWikiText( $linked = null ) {
@@ -263,7 +275,7 @@
264276 $result->setDBkeys( array( '__err' ) );
265277 $result->addError( $this->getErrors() );
266278 } elseif ( $this->m_dataitem->isUserDefined() ) { // normal property
267 - $typearray = smwfGetStore()->getPropertyValues( $this->getWikiPageValue(), SMWPropertyValue::makeProperty( '_TYPE' ) );
 279+ $typearray = smwfGetStore()->getPropertyValues( $this->getWikiPageValue(), new SMWDIProperty( '_TYPE' ) );
268280 if ( count( $typearray ) == 1 ) { // unique type given
269281 $result = current( $typearray );
270282 } elseif ( count( $typearray ) == 0 ) { // no type given
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Number.php
@@ -118,13 +118,28 @@
119119 }
120120
121121 protected function parseDBkeys( $args ) {
122 - $this->m_dataitem = SMWDINumber::doUnserialize( $args[0], $this->m_typeid );
123 - $this->m_caption = false;
124 - $this->m_unitin = false;
125 - $this->makeUserValue();
126 - $this->m_unitvalues = false;
 122+ $dataItem = SMWDINumber::doUnserialize( $args[0], $this->m_typeid );
 123+ $this->setDataItem( $dataItem );
127124 }
128125
 126+ /**
 127+ * @see SMWDataValue::setDataItem()
 128+ * @param $dataitem SMWDataItem
 129+ * @return boolean
 130+ */
 131+ public function setDataItem( SMWDataItem $dataItem ) {
 132+ if ( $dataItem->getDIType() == SMWDataItem::TYPE_NUMBER ) {
 133+ $this->m_dataitem = $dataItem;
 134+ $this->m_caption = false;
 135+ $this->m_unitin = false;
 136+ $this->makeUserValue();
 137+ $this->m_unitvalues = false;
 138+ return true;
 139+ } else {
 140+ return false;
 141+ }
 142+ }
 143+
129144 public function setOutputFormat( $formatstring ) {
130145 if ( $formatstring != $this->m_outformat ) {
131146 $this->m_outformat = $formatstring;
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Error.php
@@ -15,16 +15,20 @@
1616 */
1717 class SMWErrorValue extends SMWDataValue {
1818
19 - public function __construct( $errormsg = '', $uservalue = '', $caption = false ) {
20 - $this->setUserValue( $uservalue, $caption );
21 - if ( $errormsg != '' ) $this->addError( $errormsg );
 19+ public function __construct( $typeid, $errormsg = '', $uservalue = '', $caption = false ) {
 20+ parent::__construct( $typeid );
 21+ $this->m_caption = ( $caption !== false ) ? $caption : $uservalue;
 22+ if ( $errormsg != '' ) {
 23+ $this->addError( $errormsg );
 24+ }
2225 }
2326
2427 protected function parseUserValue( $value ) {
2528 if ( $this->m_caption === false ) {
2629 $this->m_caption = $value;
2730 }
28 - $this->m_dataitem = new SMWDIBlob( $value );
 31+ smwfLoadExtensionMessages( 'SemanticMediaWiki' );
 32+ $this->addError( wfMsgForContent( 'smw_parseerror' ) );
2933 }
3034
3135 protected function parseDBkeys( $args ) {
@@ -36,6 +40,21 @@
3741 // irrelevant.
3842 }
3943
 44+ /**
 45+ * @see SMWDataValue::setDataItem()
 46+ * @param $dataitem SMWDataItem
 47+ * @return boolean
 48+ */
 49+ public function setDataItem( SMWDataItem $dataItem ) {
 50+ if ( $dataItem->getDIType() == SMWDataItem::TYPE_ERROR ) {
 51+ $this->addError( $dataItem->getErrors() );
 52+ $this->m_caption = $this->getErrorText();
 53+ return true;
 54+ } else {
 55+ return false;
 56+ }
 57+ }
 58+
4059 public function getShortWikiText( $linked = null ) {
4160 $this->unstub();
4261 return $this->m_caption;
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Bool.php
@@ -44,7 +44,7 @@
4545 } else {
4646 $this->addError( wfMsgForContent( 'smw_noboolean', $value ) );
4747 }
48 - $this->m_dataitem = new SMWDIBool( $boolvalue, $this->m_typeid );
 48+ $this->m_dataitem = new SMWDIBoolean( $boolvalue, $this->m_typeid );
4949 }
5050
5151 protected function parseDBkeys( $args ) {
@@ -52,6 +52,21 @@
5353 $this->m_caption = $this->getStandardCaption( true ); // use default for this language
5454 }
5555
 56+ /**
 57+ * @see SMWDataValue::setDataItem()
 58+ * @param $dataitem SMWDataItem
 59+ * @return boolean
 60+ */
 61+ public function setDataItem( SMWDataItem $dataItem ) {
 62+ if ( $dataItem->getDIType() == SMWDataItem::TYPE_BOOLEAN ) {
 63+ $this->m_dataitem = $dataItem;
 64+ $this->m_caption = $this->getStandardCaption( true ); // use default for this language
 65+ return true;
 66+ } else {
 67+ return false;
 68+ }
 69+ }
 70+
5671 public function setOutputFormat( $formatstring ) {
5772 if ( $formatstring == $this->m_outformat ) return;
5873 unset( $this->m_truecaption );
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Concept.php
@@ -28,6 +28,21 @@
2929 $this->m_dataitem = new SMWDIConcept( $args[0], smwfXMLContentEncode( $args[1] ), $args[2], $args[3], $args[4], $this->m_typeid );
3030 }
3131
 32+ /**
 33+ * @see SMWDataValue::setDataItem()
 34+ * @param $dataitem SMWDataItem
 35+ * @return boolean
 36+ */
 37+ public function setDataItem( SMWDataItem $dataItem ) {
 38+ if ( $dataItem->getDIType() == SMWDataItem::TYPE_CONCEPT ) {
 39+ $this->m_dataitem = $dataItem;
 40+ $this->m_caption = $dataItem->getConceptQuery(); // probably useless
 41+ return true;
 42+ } else {
 43+ return false;
 44+ }
 45+ }
 46+
3247 protected function clear() {
3348 $this->m_dataitem = new SMWDIConcept( '', '', 0, -1, -1, $this->m_typeid );
3449 }
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Time.php
@@ -159,7 +159,7 @@
160160 if ( ( $era === false ) && ( $hours === false ) && ( $timeoffset == 0 ) ) {
161161 try {
162162 $jd = floatval( reset( $datecomponents ) );
163 - if ( $calendarmodel == 'MJD' ) $jd += SMWTimeValue::MJD_EPOCH;
 163+ if ( $calendarmodel == 'MJD' ) $jd += self::MJD_EPOCH;
164164 $this->m_dataitem = SMWDITime::newFromJD( $jd, SMWDITime::CM_GREGORIAN, SMWDITime::PREC_YMDT, $this->m_typeid );
165165 } catch ( SMWDataItemException $e ) {
166166 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
@@ -231,18 +231,18 @@
232232 $calendarmodel = $match;
233233 } elseif ( ( $ampm === false ) && ( ( strtolower( $match ) == 'am' ) || ( strtolower( $match ) == 'pm' ) ) ) {
234234 $ampm = strtolower( $match );
235 - } elseif ( ( $hours === false ) && ( $this->parseTimeString( $match, $hours, $minutes, $seconds, $timeoffset ) ) ) {
 235+ } elseif ( ( $hours === false ) && ( self::parseTimeString( $match, $hours, $minutes, $seconds, $timeoffset ) ) ) {
236236 // nothing to do
237237 } elseif ( ( $hours === true ) && ( $timezoneoffset === false ) &&
238 - ( array_key_exists( $match, SMWTimeValue::$m_tz ) ) ) {
 238+ ( array_key_exists( $match, self::$m_tz ) ) ) {
239239 // only accept timezone if time has already been set
240 - $timezoneoffset = SMWTimeValue::$m_tz[ $match ];
 240+ $timezoneoffset = self::$m_tz[ $match ];
241241 } elseif ( ( $prevmatchwasnumber ) && ( $hours === false ) && ( $timezoneoffset === false ) &&
242 - ( array_key_exists( $match, SMWTimeValue::$m_miltz ) ) &&
243 - ( $this->parseMilTimeString( end( $datecomponents ), $hours, $minutes, $seconds ) ) ) {
 242+ ( array_key_exists( $match, self::$m_miltz ) ) &&
 243+ ( self::parseMilTimeString( end( $datecomponents ), $hours, $minutes, $seconds ) ) ) {
244244 // military timezone notation is found after a number -> re-interpret the number as military time
245245 array_pop( $datecomponents );
246 - $timezoneoffset = SMWTimeValue::$m_miltz[ $match ];
 246+ $timezoneoffset = self::$m_miltz[ $match ];
247247 } elseif ( ( $prevmatchwasdate || ( count( $datecomponents ) == 0 ) ) &&
248248 $this->parseMonthString( $match, $monthname ) ) {
249249 $datecomponents[] = $monthname;
@@ -284,6 +284,8 @@
285285 * If successful, the function sets the provided call-by-ref values to
286286 * the respective numbers and returns true. Otherwise, it returns
287287 * false and does not set any values.
 288+ * @note This method is only temporarily public for enabling SMWCompatibilityHelpers. Do not use it directly in your code.
 289+ *
288290 * @param $string string input time representation, e.g. "13:45:23-3:30"
289291 * @param $hours integer between 0 and 24
290292 * @param $minutes integer between 0 and 59
@@ -291,7 +293,7 @@
292294 * @param $timeoffset double for time offset (e.g. 3.5), or false if not given
293295 * @return boolean stating if the parsing succeeded
294296 */
295 - protected static function parseTimeString( $string, &$hours, &$minutes, &$seconds, &$timeoffset ) {
 297+ public static function parseTimeString( $string, &$hours, &$minutes, &$seconds, &$timeoffset ) {
296298 if ( !preg_match( "/^[T]?([0-2]?[0-9]):([0-5][0-9])(:[0-5][0-9])?(([+\-][0-2]?[0-9])(:(30|00))?)?$/u", $string, $match ) ) {
297299 return false;
298300 } else {
@@ -365,12 +367,12 @@
366368 if ( $monthnum !== false ) {
367369 $monthnum -= 1;
368370 } else {
369 - $monthnum = array_search( $string, SMWTimeValue::$m_months ); // check English names
 371+ $monthnum = array_search( $string, self::$m_months ); // check English names
370372 }
371373 if ( $monthnum !== false ) {
372 - $monthname = SMWTimeValue::$m_monthsshort[ $monthnum ];
 374+ $monthname = self::$m_monthsshort[ $monthnum ];
373375 return true;
374 - } elseif ( array_search( $string, SMWTimeValue::$m_monthsshort ) !== false ) {
 376+ } elseif ( array_search( $string, self::$m_monthsshort ) !== false ) {
375377 $monthname = $string;
376378 return true;
377379 } else {
@@ -432,7 +434,7 @@
433435 foreach ( $dateformats[count( $propercomponents ) - 1] as $formatvector ) {
434436 if ( !( ~$datevector & $formatvector ) ) { // check if $formatvector => $datevector ("the input supports the format")
435437 $i = 0;
436 - foreach ( SMWTimeValue::$m_formats[$formatvector] as $fieldname ) {
 438+ foreach ( self::$m_formats[$formatvector] as $fieldname ) {
437439 $date[$fieldname] = $propercomponents[$i];
438440 $i += 1;
439441 }
@@ -487,7 +489,7 @@
488490 // Having more than years or specifying a calendar model does
489491 // not make sense for prehistoric dates, and our calendar
490492 // conversion would not be reliable if JD numbers get too huge:
491 - if ( ( $date['y'] <= SMWTimeValue::PREHISTORY ) &&
 493+ if ( ( $date['y'] <= self::PREHISTORY ) &&
492494 ( ( $this->m_dataitem->getPrecision() > SMWDITime::PREC_Y ) || ( $calendarmodel !== false ) ) ) {
493495 $this->addError( wfMsgForContent( 'smw_nodatetime', $this->m_wikivalue ) );
494496 return false;
@@ -536,7 +538,7 @@
537539 return 0;
538540 }
539541 } else {
540 - $monthnum = array_search( $component, SMWTimeValue::$m_monthsshort );
 542+ $monthnum = array_search( $component, self::$m_monthsshort );
541543 if ( $monthnum !== false ) {
542544 $numvalue = $monthnum + 1;
543545 return SMW_MONTH;
@@ -568,7 +570,7 @@
569571 ( ( $year == 1582 ) && ( $month > 10 ) ) ||
570572 ( ( $year == 1582 ) && ( $month == 10 ) && ( $day > 4 ) ) ) {
571573 return SMWDITime::CM_GREGORIAN;
572 - } elseif ( $year > SMWTimeValue::PREHISTORY ) {
 574+ } elseif ( $year > self::PREHISTORY ) {
573575 return SMWDITime::CM_JULIAN;
574576 } else {
575577 // proleptic Julian years at some point deviate from the count of complete revolutions of the earth around the sun
@@ -583,9 +585,9 @@
584586 $timedate = explode( 'T', $args[0], 2 );
585587 if ( ( count( $args ) == 2 ) && ( count( $timedate ) == 2 ) ) {
586588 $date = reset( $timedate );
587 - $hours = $minutes = $seconds = $timeoffset = false;
 589+ $year = $month = $day = $hours = $minutes = $seconds = $timeoffset = false;
588590 if ( ( end( $timedate ) == '' ) ||
589 - ( $this->parseTimeString( end( $timedate ), $hours, $minutes, $seconds, $timeoffset ) == true ) ) {
 591+ ( self::parseTimeString( end( $timedate ), $hours, $minutes, $seconds, $timeoffset ) == true ) ) {
590592 $d = explode( '/', $date, 3 );
591593 if ( count( $d ) == 3 ) {
592594 list( $year, $month, $day ) = $d;
@@ -609,6 +611,21 @@
610612 $this->m_dataitem = new SMWDITime( SMWDITime::CM_GREGORIAN, 32202 ); // always default to something
611613 }
612614
 615+ /**
 616+ * @see SMWDataValue::setDataItem()
 617+ * @param $dataitem SMWDataItem
 618+ * @return boolean
 619+ */
 620+ public function setDataItem( SMWDataItem $dataItem ) {
 621+ if ( $dataItem->getDIType() == SMWDataItem::TYPE_TIME ) {
 622+ $this->m_dataitem = $dataItem;
 623+ $this->m_caption = $this->m_wikivalue = false;
 624+ return true;
 625+ } else {
 626+ return false;
 627+ }
 628+ }
 629+
613630 public function getShortWikiText( $linked = NULL ) {
614631 return ( $this->m_caption !== false ) ? $this->m_caption : $this->getPreferredCaption();
615632 }
@@ -770,7 +787,7 @@
771788 $result .= str_pad( $this->getYear() + 1, 4, "0", STR_PAD_LEFT ) .
772789 '-' . str_pad( $monthnum, 2, "0", STR_PAD_LEFT );
773790 if ( !$mindefault && ( $this->m_dataitem->getPrecision() < SMWDITime::PREC_YMD ) ) {
774 - $maxday = SMWTimeValue::getDayNumberForMonth( $monthnum, $this->getYear(), SMWDITime::CM_GREGORIAN );
 791+ $maxday = self::getDayNumberForMonth( $monthnum, $this->getYear(), SMWDITime::CM_GREGORIAN );
775792 $result .= '-' . str_pad( $this->getDay( SMWDITime::CM_GREGORIAN, $maxday ), 2, "0", STR_PAD_LEFT );
776793 } else {
777794 $result .= '-' . str_pad( $this->getDay(), 2, "0", STR_PAD_LEFT );
@@ -791,7 +808,7 @@
792809 * @return SMWDITime
793810 */
794811 protected function getDataForCalendarModel( $calendarmodel ) {
795 - if ( $this->m_dataitem->getYear() <= SMWTimeValue::PREHISTORY ) {
 812+ if ( $this->m_dataitem->getYear() <= self::PREHISTORY ) {
796813 return ( $this->m_dataitem->getCalendarModel() == $calendarmodel ) ? $this->m_dataitem : null;
797814 } elseif ( $calendarmodel == SMWDITime::CM_GREGORIAN ) {
798815 if ( $this->m_dataitem_greg === null ) {
@@ -843,9 +860,9 @@
844861 if ( ( strtoupper( $this->m_outformat ) == 'ISO' ) || ( $this->m_outformat == '-' ) ) {
845862 return $this->getISO8601Date();
846863 } else {
847 - if ( $this->m_dataitem->getYear() <= SMWTimeValue::PREHISTORY ) {
 864+ if ( $this->m_dataitem->getYear() <= self::PREHISTORY ) {
848865 return $this->getCaptionFromDataitem( $this->m_dataitem ); // should be Gregorian, but don't bother here
849 - } elseif ( $this->m_dataitem->getJD() < SMWTimeValue::J1582 ) {
 866+ } elseif ( $this->m_dataitem->getJD() < self::J1582 ) {
850867 return $this->getCaptionFromDataitem( $this->getDataForCalendarModel( SMWDITime::CM_JULIAN ) );
851868 } else {
852869 return $this->getCaptionFromDataitem( $this->getDataForCalendarModel( SMWDITime::CM_GREGORIAN ) );
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_URI.php
@@ -65,7 +65,7 @@
6666 $scheme = $hierpart = $query = $fragment = '';
6767 if ( $value == '' ) { // do not accept empty strings
6868 $this->addError( wfMsgForContent( 'smw_emptystring' ) );
69 - $this->m_dataitem = new SMWDIURI( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value
 69+ $this->m_dataitem = new SMWDIUri( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value
7070 return;
7171 }
7272
@@ -83,7 +83,7 @@
8484 $uri = trim( $uri );
8585 if ( $uri == mb_substr( $value, 0, mb_strlen( $uri ) ) ) { // disallowed URI!
8686 $this->addError( wfMsgForContent( 'smw_baduri', $value ) );
87 - $this->m_dataitem = new SMWDIURI( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value
 87+ $this->m_dataitem = new SMWDIUri( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value
8888 return;
8989 }
9090 }
@@ -145,10 +145,10 @@
146146
147147 // Now create the URI data item:
148148 try {
149 - $this->m_dataitem = new SMWDIURI( $scheme, $hierpart, $query, $fragment, $this->m_typeid);
 149+ $this->m_dataitem = new SMWDIUri( $scheme, $hierpart, $query, $fragment, $this->m_typeid);
150150 } catch ( SMWDataItemException $e ) {
151151 $this->addError( wfMsgForContent( 'smw_baduri', $this->m_wikitext ) );
152 - $this->m_dataitem = new SMWDIURI( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value
 152+ $this->m_dataitem = new SMWDIUri( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value
153153 }
154154 }
155155
@@ -164,22 +164,35 @@
165165
166166 protected function parseDBkeys( $args ) {
167167 try {
168 - $this->m_dataitem = SMWDIURI::doUnserialize( $args[0], $this->m_typeid);
 168+ $dataItem = SMWDIUri::doUnserialize( $args[0], $this->m_typeid);
 169+ $this->setDataItem( $dataItem );
169170 } catch ( SMWDataItemException $e ) {
170171 $this->addError( wfMsgForContent( 'smw_baduri', $this->m_wikitext ) );
171 - $this->m_dataitem = new SMWDIURI( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value
 172+ $this->m_dataitem = new SMWDIUri( 'http', '//example.com', '', '', $this->m_typeid ); // define data item to have some value
172173 return;
173174 }
 175+ }
174176
175 - if ( $this->m_mode == SMW_URI_MODE_EMAIL ) {
176 - $this->m_wikitext = substr( $this->m_wikitext, 7 );
177 - } elseif ( $this->m_mode == SMW_URI_MODE_TEL ) {
178 - $this->m_wikitext = substr( $this->m_wikitext, 4 );
179 - $this->m_wikitext = $this->m_caption;
 177+ /**
 178+ * @see SMWDataValue::setDataItem()
 179+ * @param $dataitem SMWDataItem
 180+ * @return boolean
 181+ */
 182+ public function setDataItem( SMWDataItem $dataItem ) {
 183+ if ( $dataItem->getDIType() == SMWDataItem::TYPE_URI ) {
 184+ $this->m_dataitem = $dataItem;
 185+ if ( $this->m_mode == SMW_URI_MODE_EMAIL ) {
 186+ $this->m_wikitext = substr( $dataItem->getURI(), 7 );
 187+ } elseif ( $this->m_mode == SMW_URI_MODE_TEL ) {
 188+ $this->m_wikitext = substr( $dataItem->getURI(), 4 );
 189+ } else {
 190+ $this->m_wikitext = $dataItem->getURI();
 191+ }
 192+ $this->m_caption = $this->m_wikitext;
 193+ return true;
180194 } else {
181 - $this->m_wikitext = $this->m_dataitem->getURI();
 195+ return false;
182196 }
183 - $this->m_caption = $this->m_wikitext;
184197 }
185198
186199 public function getShortWikiText( $linked = null ) {
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_WikiPage.php
@@ -88,22 +88,26 @@
8989 *
9090 * @return SMWWikiPageValue
9191 */
92 - static public function makePage( $title, $namespace, $sortkey = '', $interwiki = '' ) {
93 - $page = new SMWWikiPageValue( '_wpg' );
94 - $page->setDBkeys( array( $title, $namespace, $interwiki, $sortkey ) );
95 - return $page;
 92+ static public function makePage( $dbkey, $namespace, $sortkey = '', $interwiki = '' ) {
 93+ $diWikiPage = new SMWDIWikiPage( $dbkey, $namespace, $interwiki );
 94+ $dvWikiPage = new SMWWikiPageValue( '_wpg' );
 95+ $dvWikiPage->setDataItem( $diWikiPage );
 96+ return $dvWikiPage;
9697 }
9798
9899 /**
99100 * Static function for creating a new wikipage object from a
100101 * MediaWiki Title object.
 102+ * @todo Evaluate whether we really want this function. It might be obsolete due to recent changes.
101103 *
102104 * @return SMWWikiPageValue
103105 */
104 - static public function makePageFromTitle( $titleobject ) {
105 - $page = new SMWWikiPageValue( '_wpg' );
106 - $page->setTitle( $titleobject );
107 - return $page;
 106+ static public function makePageFromTitle( Title $title ) {
 107+ $dvWikiPage = new SMWWikiPageValue( '_wpg' );
 108+ $diWikiPage = new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki() );
 109+ $dvWikiPage->setDataItem( $diWikiPage );
 110+ $dvWikiPage->m_title = $title;
 111+ return $dvWikiPage;
108112 }
109113
110114 public function __construct( $typeid ) {
@@ -166,16 +170,31 @@
167171 $this->addError( wfMsgForContent( 'smw_notitle', $this->getPrefixedText() ) );
168172 $this->m_dataitem = new SMWDIWikiPage( 'ERROR', NS_MAIN, '', $this->m_typeid );
169173 } else {
170 - $this->m_dataitem = new SMWDIWikiPage( $args[0], floatval( $args[1] ), $args[2], $this->m_typeid );
171 - $this->m_textform = str_replace( '_', ' ', $this->m_dataitem->getDBkey() );
 174+ $dataItem = new SMWDIWikiPage( $args[0], floatval( $args[1] ), $args[2], $this->m_typeid );
 175+ $this->setDataItem( $dataItem );
 176+ }
 177+ }
 178+
 179+ /**
 180+ * @see SMWDataValue::setDataItem()
 181+ * @param $dataitem SMWDataItem
 182+ * @return boolean
 183+ */
 184+ public function setDataItem( SMWDataItem $dataItem ) {
 185+ if ( $dataItem->getDIType() == SMWDataItem::TYPE_WIKIPAGE ) {
 186+ $this->m_dataitem = $dataItem;
 187+ $this->m_textform = str_replace( '_', ' ', $dataItem->getDBkey() );
172188 $this->m_id = -1;
173189 $this->m_title = null;
174190 $this->m_sortkey = $this->m_fragment = $this->m_prefixedtext = '';
175191 $this->m_caption = false;
176 - if ( ( $this->m_fixNamespace != NS_MAIN ) && ( $this->m_fixNamespace != $this->m_dataitem->getNamespace() ) ) {
 192+ if ( ( $this->m_fixNamespace != NS_MAIN ) && ( $this->m_fixNamespace != $dataItem->getNamespace() ) ) {
177193 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
178194 $this->addError( wfMsgForContent( 'smw_notitle', $this->getPrefixedText() ) );
179195 }
 196+ return true;
 197+ } else {
 198+ return false;
180199 }
181200 }
182201
@@ -398,9 +417,11 @@
399418
400419 /**
401420 * Init this data value object based on a given Title object.
 421+ * @deprecated Use setDataItem(); it's easy to create an SMWDIWikiPage from a Title, will vanish before SMW 1.7
402422 */
403423 public function setTitle( $title ) {
404 - $this->setDBkeys( array( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki(), '' ) );
 424+ $diWikiPage = new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki() );
 425+ $this->setDataItem( $diWikiPage );
405426 $this->m_title = $title;
406427 }
407428
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Types.php
@@ -34,6 +34,21 @@
3535 $this->m_isalias = false;
3636 }
3737
 38+ /**
 39+ * @see SMWDataValue::setDataItem()
 40+ * @param $dataitem SMWDataItem
 41+ * @return boolean
 42+ */
 43+ public function setDataItem( SMWDataItem $dataItem ) {
 44+ if ( parent::setDataItem( $dataItem ) ) {
 45+ $this->m_reallabel = $this->m_textform;
 46+ $this->m_isalias = false;
 47+ return true;
 48+ } else {
 49+ return false;
 50+ }
 51+ }
 52+
3853 public function getLongWikiText( $linked = null ) {
3954 $this->unstub();
4055 if ( ( $linked === null ) || ( $linked === false ) ) {
Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_String.php
@@ -40,6 +40,26 @@
4141 $this->m_caption = $this->m_dataitem->getString(); // this is our output text
4242 }
4343
 44+ /**
 45+ * @see SMWDataValue::setDataItem()
 46+ * @param $dataitem SMWDataItem
 47+ * @return boolean
 48+ */
 49+ public function setDataItem( SMWDataItem $dataItem ) {
 50+ $diType = ( ( $this->m_typeid == '_txt' ) || ( $this->m_typeid == '_cod' ) ) ? SMWDataItem::TYPE_BLOB : SMWDataItem::TYPE_STRING;
 51+ if ( $dataItem->getDIType() == $diType ) {
 52+ $this->m_dataitem = $dataItem;
 53+ if ( $this->m_typeid == '_cod' ) {
 54+ $this->m_caption = $this->getCodeDisplay( $this->m_dataitem->getString() );
 55+ } else {
 56+ $this->m_caption = $this->m_dataitem->getString();
 57+ }
 58+ return true;
 59+ } else {
 60+ return false;
 61+ }
 62+ }
 63+
4464 public function getShortWikiText( $linked = null ) {
4565 $this->unstub();
4666 return $this->m_caption;
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_JSONlink.php
@@ -94,7 +94,7 @@
9595 }
9696 if ( $rowsubject !== false ) { // stuff in the page URI and some category data
9797 $valuestack[] = '"uri" : "' . $wgServer . $wgScriptPath . '/index.php?title=' . $rowsubject->getPrefixedText() . '"';
98 - $page_cats = smwfGetStore()->getPropertyValues( $rowsubject, SMWPropertyValue::makeProperty( '_INST' ) ); // TODO: set limit to 1 here
 98+ $page_cats = smwfGetStore()->getPropertyValues( $rowsubject, new SMWDIProperty( '_INST' ) ); // TODO: set limit to 1 here
9999 if ( count( $page_cats ) > 0 ) {
100100 $valuestack[] = '"type" : "' . reset($page_cats)->getShortHTMLText() . '"';
101101 }
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_Table.php
@@ -53,19 +53,20 @@
5454 $result .= ">";
5555
5656 $first = true;
57 - while ( ( $object = $field->getNextObject() ) !== false ) {
 57+ while ( ( $dv = $field->getNextDataValue() ) !== false ) {
5858 if ( $first ) {
59 - if ( $object->isNumeric() ) { // additional hidden sortkey for numeric entries
60 - $result .= '<span class="smwsortkey">' . $object->getValueKey() . '</span>';
 59+ $sortkey = $dv->getDataItem()->getSortKey();
 60+ if ( is_numeric( $sortkey ) ) { // additional hidden sortkey for numeric entries
 61+ $result .= '<span class="smwsortkey">' . $sortkey . '</span>';
6162 }
6263 $first = false;
6364 } else {
6465 $result .= '<br />';
6566 }
6667 // use shorter "LongText" for wikipage
67 - $result .= ( ( $object->getTypeID() == '_wpg' ) || ( $object->getTypeID() == '__sin' ) ) ?
68 - $object->getLongText( $outputmode, $this->getLinker( $firstcol ) ):
69 - $object->getShortText( $outputmode, $this->getLinker( $firstcol ) );
 68+ $result .= ( ( $dv->getTypeID() == '_wpg' ) || ( $dv->getTypeID() == '__sin' ) ) ?
 69+ $dv->getLongText( $outputmode, $this->getLinker( $firstcol ) ) :
 70+ $dv->getShortText( $outputmode, $this->getLinker( $firstcol ) );
7071 }
7172 $result .= "</td>\n";
7273 $firstcol = false;
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_RDF.php
@@ -58,7 +58,7 @@
5959 $property = $printreq->getData();
6060 break;
6161 case SMWPrintRequest::PRINT_CATS:
62 - $property = SMWPropertyValue::makeProperty( '_TYPE' );
 62+ $property = new SMWDIProperty( '_TYPE' );
6363 break;
6464 case SMWPrintRequest::PRINT_CCAT:
6565 // not serialised right now
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QueryParser.php
@@ -315,7 +315,7 @@
316316 return null; ///TODO: read some more chunks and try to finish [[ ]]
317317 }
318318
319 - $typeid = $property->getPropertyTypeID();
 319+ $typeid = $property->getDataItem()->findPropertyTypeID();
320320 $inverse = $property->isInverse();
321321 $prevname = $name;
322322 $properties[] = $property;
@@ -377,7 +377,7 @@
378378 }
379379 } ///NOTE: at this point, we normally already read one more chunk behind the value
380380
381 - $dv = SMWDataValueFactory::newPropertyObjectValue( $property );
 381+ $dv = SMWDataValueFactory::newPropertyObjectValue( $property->getDataItem() );
382382 $vd = $dv->getQueryDescription( $value );
383383 $innerdesc = $this->addDescription( $innerdesc, $vd, false );
384384 $this->m_errors = $this->m_errors + $dv->getErrors();
@@ -395,7 +395,7 @@
396396 $properties = array_reverse( $properties );
397397
398398 foreach ( $properties as $property ) {
399 - $innerdesc = new SMWSomeProperty( $property, $innerdesc );
 399+ $innerdesc = new SMWSomeProperty( $property->getDataItem(), $innerdesc );
400400 }
401401
402402 $result = $innerdesc;
Index: trunk/extensions/SemanticMediaWiki/includes/parserhooks/SMW_Concept.php
@@ -28,7 +28,7 @@
2929 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
3030
3131 $title = $parser->getTitle();
32 - $pconc = SMWPropertyValue::makeProperty( '_CONC' );
 32+ $pconc = new SMWDIProperty( '_CONC' );
3333
3434 if ( $title->getNamespace() != SMW_NS_CONCEPT ) {
3535 $result = smwfEncodeMessages( array( wfMsgForContent( 'smw_no_concept_namespace' ) ) );
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Factbox.php
@@ -36,47 +36,49 @@
3737 return '';
3838 }
3939 break;
40 - // case SMW_FACTBOX_SHOWN: // just show ...
 40+ // case SMW_FACTBOX_SHOWN: // just show ...
4141 }
4242
4343 // actually build the Factbox text:
4444 $text = '';
4545 if ( wfRunHooks( 'smwShowFactbox', array( &$text, $semdata ) ) ) {
4646 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
 47+ $subjectDv = SMWDataValueFactory::newDataItemValue( $semdata->getSubject() );
4748 SMWOutputs::requireHeadItem( SMW_HEADER_STYLE );
4849 $rdflink = SMWInfolink::newInternalLink(
4950 wfMsgForContent( 'smw_viewasrdf' ),
5051 $wgContLang->getNsText( NS_SPECIAL ) . ':ExportRDF/' .
51 - $semdata->getSubject()->getWikiValue(),
 52+ $subjectDv->getWikiValue(),
5253 'rdflink'
5354 );
5455
5556 $browselink = SMWInfolink::newBrowsingLink(
56 - $semdata->getSubject()->getText(),
57 - $semdata->getSubject()->getWikiValue(),
 57+ $subjectDv->getText(),
 58+ $subjectDv->getWikiValue(),
5859 'swmfactboxheadbrowse'
5960 );
6061 $text .= '<div class="smwfact">' .
6162 '<span class="smwfactboxhead">' . wfMsgForContent( 'smw_factbox_head', $browselink->getWikiText() ) . '</span>' .
6263 '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' .
6364 '<table class="smwfacttable">' . "\n";
64 - foreach ( $semdata->getProperties() as $property ) {
65 - if ( !$property->isShown() ) { // showing this is not desired, hide
 65+ foreach ( $semdata->getProperties() as $propertyDi ) {
 66+ $propertyDv = SMWDataValueFactory::newDataItemValue( $propertyDi );
 67+ if ( !$propertyDi->isShown() ) { // showing this is not desired, hide
6668 continue;
67 - } elseif ( $property->isUserDefined() ) { // user defined property
68 - $property->setCaption( preg_replace( '/[ ]/u', '&#160;', $property->getWikiValue(), 2 ) );
 69+ } elseif ( $propertyDi->isUserDefined() ) { // user defined property
 70+ $propertyDv->setCaption( preg_replace( '/[ ]/u', '&#160;', $propertyDv->getWikiValue(), 2 ) );
6971 /// NOTE: the preg_replace is a slight hack to ensure that the left column does not get too narrow
70 - $text .= '<tr><td class="smwpropname">' . $property->getLongWikiText( true ) . '</td><td class="smwprops">';
71 - } elseif ( $property->isVisible() ) { // predefined property
72 - $text .= '<tr><td class="smwspecname">' . $property->getLongWikiText( true ) . '</td><td class="smwspecs">';
 72+ $text .= '<tr><td class="smwpropname">' . $propertyDv->getLongWikiText( true ) . '</td><td class="smwprops">';
 73+ } elseif ( $propertyDv->isVisible() ) { // predefined property
 74+ $text .= '<tr><td class="smwspecname">' . $propertyDv->getLongWikiText( true ) . '</td><td class="smwspecs">';
7375 } else { // predefined, internal property
7476 continue;
7577 }
7678
77 - $propvalues = $semdata->getPropertyValues( $property );
 79+ $propvalues = $semdata->getPropertyValues( $propertyDi );
7880 $l = count( $propvalues );
7981 $i = 0;
80 - foreach ( $propvalues as $propvalue ) {
 82+ foreach ( $propvalues as $di ) {
8183 if ( $i != 0 ) {
8284 if ( $i > $l - 2 ) {
8385 $text .= wfMsgForContent( 'smw_finallistconjunct' ) . ' ';
@@ -85,7 +87,8 @@
8688 }
8789 }
8890 $i += 1;
89 - $text .= $propvalue->getLongWikiText( true ) . $propvalue->getInfolinkText( SMW_OUTPUT_WIKI );
 91+ $dv = SMWDataValueFactory::newDataItemValue( $di );
 92+ $text .= $dv->getLongWikiText( true ) . $dv->getInfolinkText( SMW_OUTPUT_WIKI );
9093 }
9194 $text .= '</td></tr>';
9295 }
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_OrderedListPage.php
@@ -159,7 +159,7 @@
160160 $first = $this->from;
161161
162162 if ( $ac > $this->limit ) {
163 - $last = $this->articles[$ac - 1]->getSortkey();
 163+ $last = SMWCompatibilityHelpers::getSortKey( $this->articles[$ac - 1] );
164164 } else {
165165 $last = '';
166166 }
@@ -199,21 +199,22 @@
200200 }
201201
202202 /**
203 - * Like Article's getTitle(), but returning a suitable SMWWikiPageValue
 203+ * Like Article's getTitle(), but returning a suitable SMWDIWikiPage.
204204 *
205 - * @return SMWWikiPageValue
 205+ * @return SMWDIWikiPage
206206 */
207 - protected function getDataValue() {
208 - return SMWWikiPageValue::makePageFromTitle( $this->getTitle() );
 207+ protected function getDataItem() {
 208+ $title = $this->getTitle();
 209+ return new SMWDIWikiPage( $title->getDBKey(), $title->getNamespace(), $title->getInterwiki() );
209210 }
210211
211212 /**
212 - * Format a list of SMWWikipageValues chunked by letter in a three-column
 213+ * Format a list of SMWDIWikiPage objects chunked by letter in a three-column
213214 * list, ordered vertically.
214215 *
215 - * @param integer $start
216 - * @param integer $end
217 - * @param array $elements
 216+ * @param $start integer
 217+ * @param $end integer
 218+ * @param $elements of SMWDIWikiPage
218219 *
219220 * @return string
220221 */
@@ -237,6 +238,7 @@
238239
239240 // output all articles
240241 for ( $index = $startChunk ; $index < $endChunk && $index < $end; $index++ ) {
 242+ $elementDv = SMWDataValueFactory::newDataItemValue( $elements[$index] );
241243 // check for change of starting letter or begining of chunk
242244 $start_char = $wgContLang->convert( $wgContLang->firstChar( $elements[$index]->getSortkey() ) );
243245
@@ -258,7 +260,7 @@
259261 $prev_start_char = $start_char;
260262 }
261263
262 - $r .= "<li>" . $elements[$index]->getLongHTMLText( $this->getSkin() ) . "</li>\n";
 264+ $r .= "<li>" . $elementDv->getLongHTMLText( $this->getSkin() ) . "</li>\n";
263265 }
264266
265267 if ( !$atColumnTop ) {
@@ -288,9 +290,11 @@
289291 $start_char = $wgContLang->convert( $wgContLang->firstChar( $elements[$start]->getSortkey() ) );
290292 $prev_start_char = $start_char;
291293 $r = '<h3>' . htmlspecialchars( $start_char ) . "</h3>\n";
292 - $r .= '<ul><li>' . $elements[$start]->getLongHTMLText( $this->getSkin() ) . '</li>';
 294+ $elementStartDv = SMWDataValueFactory::newDataItemValue( $elements[$start] );
 295+ $r .= '<ul><li>' . $elementStartDv->getLongHTMLText( $this->getSkin() ) . '</li>';
293296
294297 for ( $index = $start + 1; $index < $end; $index++ ) {
 298+ $elementDv = SMWDataValueFactory::newDataItemValue( $elements[$index] );
295299 $start_char = $wgContLang->convert( $wgContLang->firstChar( $elements[$index]->getSortkey() ) );
296300
297301 if ( $start_char != $prev_start_char ) {
@@ -298,7 +302,7 @@
299303 $prev_start_char = $start_char;
300304 }
301305
302 - $r .= '<li>' . $elements[$index]->getLongHTMLText( $this->getSkin() ) . '</li>';
 306+ $r .= '<li>' . $elementDv->getLongHTMLText( $this->getSkin() ) . '</li>';
303307 }
304308
305309 $r .= '</ul>';
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_TypePage.php
@@ -42,14 +42,14 @@
4343 $options->boundary = $this->from;
4444 $options->ascending = true;
4545 $options->include_boundary = true;
46 - $this->articles = $store->getPropertySubjects( SMWPropertyValue::makeProperty( '_TYPE' ), $typevalue, $options );
 46+ $this->articles = $store->getPropertySubjects( new SMWDIProperty( '_TYPE' ), $typevalue->getDataItem(), $options );
4747 } elseif ( $this->until != '' ) {
4848 $options->boundary = $this->until;
4949 $options->ascending = false;
5050 $options->include_boundary = false;
51 - $this->articles = array_reverse( $store->getPropertySubjects( SMWPropertyValue::makeProperty( '_TYPE' ), $typevalue, $options ) );
 51+ $this->articles = array_reverse( $store->getPropertySubjects( new SMWDIProperty( '_TYPE' ), $typevalue->getDataItem(), $options ) );
5252 } else {
53 - $this->articles = $store->getPropertySubjects( SMWPropertyValue::makeProperty( '_TYPE' ), $typevalue, $options );
 53+ $this->articles = $store->getPropertySubjects( new SMWDIProperty( '_TYPE' ), $typevalue->getDataItem(), $options );
5454 }
5555 } else {
5656 $this->articles = array();
Index: trunk/extensions/SemanticMediaWiki/includes/articlepages/SMW_PropertyPage.php
@@ -18,15 +18,13 @@
1919 private $mProperty; // property object
2020
2121 /**
22 - * Use small $limit (property pages might become large)
 22+ * @see SMWOrderedListPage::initParameters()
 23+ * @note We use a smaller limit here; property pages might become large.
2324 */
2425 protected function initParameters() {
25 - global $smwgContLang, $smwgPropertyPagingLimit;
26 -
 26+ global $smwgPropertyPagingLimit;
2727 $this->limit = $smwgPropertyPagingLimit;
28 - $this->mProperty = SMWPropertyValue::makeProperty( $this->mTitle->getDBkey() );
29 - $this->mProperty->setInverse( false );
30 -
 28+ $this->mProperty = new SMWDIProperty( $this->mTitle->getDBkey(), false );
3129 return true;
3230 }
3331
@@ -72,7 +70,7 @@
7371 $s_options = new SMWRequestOptions();
7472 $s_options->sort = true;
7573 $s_options->ascending = true;
76 - $this->subproperties = $store->getPropertySubjects( SMWPropertyValue::makeProperty( '_SUBP' ), $this->getDataValue(), $s_options );
 74+ $this->subproperties = $store->getPropertySubjects( new SMWDIProperty( '_SUBP' ), $this->getDataItem(), $s_options );
7775 }
7876
7977 /**
@@ -144,7 +142,9 @@
145143 $prev_start_char = 'None';
146144
147145 for ( $index = $start; $index < $ac; $index++ ) {
148 - $start_char = $wgContLang->convert( $wgContLang->firstChar( $this->articles[$index]->getSortkey() ) );
 146+ $diWikiPage = $this->articles[$index];
 147+ $dvWikiPage = SMWDataValueFactory::newDataItemValue( $diWikiPage );
 148+ $start_char = $wgContLang->convert( $wgContLang->firstChar( SMWCompatibilityHelpers::getSortKey( $diWikiPage ) ) );
149149
150150 // Header for index letters
151151 if ( $start_char != $prev_start_char ) {
@@ -153,31 +153,31 @@
154154 }
155155
156156 // Property name
157 - $searchlink = SMWInfolink::newBrowsingLink( '+', $this->articles[$index]->getShortHTMLText() );
158 - $r .= '<tr><td class="smwpropname">' . $this->articles[$index]->getLongHTMLText( $this->getSkin() ) .
 157+ $searchlink = SMWInfolink::newBrowsingLink( '+', $dvWikiPage->getShortHTMLText() );
 158+ $r .= '<tr><td class="smwpropname">' . $dvWikiPage->getLongHTMLText( $this->getSkin() ) .
159159 '&#160;' . $searchlink->getHTML( $this->getSkin() ) . '</td><td class="smwprops">';
160160
161161 // Property values
162162 $ropts = new SMWRequestOptions();
163163 $ropts->limit = $smwgMaxPropertyValues + 1;
164 - $values = $store->getPropertyValues( $this->articles[$index], $this->mProperty, $ropts );
 164+ $values = $store->getPropertyValues( $diWikiPage, $this->mProperty, $ropts );
165165 $i = 0;
166166
167 - foreach ( $values as $value ) {
 167+ foreach ( $values as $di ) {
168168 if ( $i != 0 ) {
169169 $r .= ', ';
170170 }
171 -
172171 $i++;
173 -
 172+
174173 if ( $i < $smwgMaxPropertyValues + 1 ) {
175 - $r .= $value->getLongHTMLText( $this->getSkin() ) . $value->getInfolinkText( SMW_OUTPUT_HTML, $this->getSkin() );
 174+ $dv = SMWDataValueFactory::newDataItemValue( $di );
 175+ $r .= $dv->getLongHTMLText( $this->getSkin() ) . $dv->getInfolinkText( SMW_OUTPUT_HTML, $this->getSkin() );
176176 } else {
177 - $searchlink = SMWInfolink::newInversePropertySearchLink( '…', $this->articles[$index]->getWikiValue(), $this->mTitle->getText() );
 177+ $searchlink = SMWInfolink::newInversePropertySearchLink( '…', $dvWikiPage->getWikiValue(), $this->mTitle->getText() );
178178 $r .= $searchlink->getHTML( $this->getSkin() );
179179 }
180180 }
181 -
 181+
182182 $r .= "</td></tr>\n";
183183 }
184184
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SetupLight.php
@@ -104,15 +104,16 @@
105105 $wgAutoloadClasses['SMWDataItem'] = $diDir . 'SMW_DataItem.php';
106106 $wgAutoloadClasses['SMWDataItemException'] = $diDir . 'SMW_DataItem.php';
107107 $wgAutoloadClasses['SMWDIProperty'] = $diDir . 'SMW_DI_Property.php';
108 -// $wgAutoloadClasses['SMWDIBool'] = $diDir . 'SMW_DI_Bool.php';
 108+// $wgAutoloadClasses['SMWDIBoolean'] = $diDir . 'SMW_DI_Bool.php';
109109 $wgAutoloadClasses['SMWDINumber'] = $diDir . 'SMW_DI_Number.php';
110110 $wgAutoloadClasses['SMWDIBlob'] = $diDir . 'SMW_DI_Blob.php';
111111 $wgAutoloadClasses['SMWDIString'] = $diDir . 'SMW_DI_String.php';
112112 $wgAutoloadClasses['SMWStringLengthException'] = $diDir . 'SMW_DI_String.php';
113 - $wgAutoloadClasses['SMWDIURI'] = $diDir . 'SMW_DI_URI.php';
 113+ $wgAutoloadClasses['SMWDIUri'] = $diDir . 'SMW_DI_URI.php';
114114 $wgAutoloadClasses['SMWDIWikiPage'] = $diDir . 'SMW_DI_WikiPage.php';
115115 $wgAutoloadClasses['SMWDITime'] = $diDir . 'SMW_DI_Time.php';
116116 // $wgAutoloadClasses['SMWDIConcept'] = $diDir . 'SMW_DI_Concept.php';
 117+ $wgAutoloadClasses['SMWDIError'] = $diDir . 'SMW_DI_Error.php';
117118
118119 // Datavalues
119120 $dvDir = $smwgIP . 'includes/datavalues/';
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Description.php
@@ -285,7 +285,7 @@
286286
287287 protected $m_concept;
288288
289 - public function __construct( Title $concept ) {
 289+ public function __construct( SMWDIWikiPage $concept ) {
290290 $this->m_concept = $concept;
291291 }
292292
@@ -738,7 +738,7 @@
739739 protected $m_description;
740740 protected $m_property;
741741
742 - public function __construct( SMWPropertyValue $property, SMWDescription $description ) {
 742+ public function __construct( SMWDIProperty $property, SMWDescription $description ) {
743743 $this->m_property = $property;
744744 $this->m_description = $description;
745745 }
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_QueryResult.php
@@ -28,8 +28,8 @@
2929 class SMWQueryResult {
3030
3131 /**
32 - * Array of SMWWikiPageValue objects that are the basis for this result
33 - * @var Array of SMWWikiPageValue
 32+ * Array of SMWDIWikiPage objects that are the basis for this result
 33+ * @var Array of SMWDIWikiPage
3434 */
3535 protected $mResults;
3636
@@ -66,7 +66,7 @@
6767 *
6868 * @param array of SMWPrintRequest $printRequests
6969 * @param SMWQuery $query
70 - * @param array of SMWWikiPageValue $results
 70+ * @param array of SMWDIWikiPage $results
7171 * @param SMWStore $store
7272 * @param boolean $furtherRes
7373 */
@@ -110,10 +110,10 @@
111111 }
112112
113113 /**
114 - * Return an array of SMWWikiPageValue objects that make up the
 114+ * Return an array of SMWDIWikiPage objects that make up the
115115 * results stored in this object.
116116 *
117 - * @return array of SMWWikiPageValue
 117+ * @return array of SMWDIWikiPage
118118 */
119119 public function getResults() {
120120 return $this->mResults;
@@ -220,7 +220,7 @@
221221
222222 /**
223223 * Container for the contents of a single result field of a query result,
224 - * i.e. basically an array of SMWDataValues with some additional parameters.
 224+ * i.e. basically an array of SMWDataItems with some additional parameters.
225225 * The content of the array is fetched on demand only.
226226 * @ingroup SMWQuery
227227 */
@@ -231,7 +231,7 @@
232232 protected $mPrintRequest;
233233
234234 /**
235 - * @var SMWWikiPageValue
 235+ * @var SMWDIWikiPage
236236 */
237237 protected $mResult;
238238
@@ -241,7 +241,7 @@
242242 protected $mStore;
243243
244244 /**
245 - * @var array of SMWDataValue or false
 245+ * @var array of SMWDataItem or false
246246 */
247247 protected $mContent;
248248
@@ -251,11 +251,11 @@
252252 /**
253253 * Constructor.
254254 *
255 - * @param SMWWikiPageValue $resultPage
 255+ * @param SMWDIWikiPage $resultPage
256256 * @param SMWPrintRequest $printRequest
257257 * @param SMWStore $store
258258 */
259 - public function __construct( SMWWikiPageValue $resultPage, SMWPrintRequest $printRequest, SMWStore $store ) {
 259+ public function __construct( SMWDIWikiPage $resultPage, SMWPrintRequest $printRequest, SMWStore $store ) {
260260 $this->mResult = $resultPage;
261261 $this->mPrintRequest = $printRequest;
262262 $this->mStore = $store;
@@ -263,21 +263,21 @@
264264 }
265265
266266 /**
267 - * Returns the SMWWikiPageValue object to which this SMWResultArray refers.
 267+ * Returns the SMWDIWikiPage object to which this SMWResultArray refers.
268268 * If you only care for those objects, consider using SMWQueryResult::getResults()
269269 * directly.
270270 *
271 - * @return SMWWikiPageValue
 271+ * @return SMWDIWikiPage
272272 */
273273 public function getResultSubject() {
274274 return $this->mResult;
275275 }
276276
277277 /**
278 - * Returns an array of SMWDataValue objects that contain the results of
 278+ * Returns an array of SMWDataItem objects that contain the results of
279279 * the given print request for the given result object.
280280 *
281 - * @return array of SMWDataValue or false
 281+ * @return array of SMWDataItem or false
282282 */
283283 public function getContent() {
284284 $this->loadContent();
@@ -295,37 +295,62 @@
296296 }
297297
298298 /**
299 - * Return the next SMWDataValue object or false if no further object exists.
 299+ * Compatibility alias for getNextDatItem().
 300+ * @deprecated Call getNextDataValue() or getNextDataItem() directly as needed. Method will vanish before SMW 1.7.
 301+ */
 302+ public function getNextObject() {
 303+ return $this->getNextDataValue();
 304+ }
 305+
 306+ /**
 307+ * Return the next SMWDataItem object or false if no further object exists.
300308 *
301 - * @return SMWDataValue
 309+ * @return SMWDataItem or false
302310 */
303 - public function getNextObject() {
 311+ public function getNextDataItem() {
304312 $this->loadContent();
305 -
306313 $result = current( $this->mContent );
307314 next( $this->mContent );
308 -
309315 return $result;
310316 }
311317
 318+
312319 /**
313 - * Return the main text representation of the next SMWDataValue object
 320+ * Return an SMWDataValue object for the next SMWDataItem object or
 321+ * false if no further object exists.
 322+ *
 323+ * @return SMWDataValue or false
 324+ */
 325+ public function getNextDataValue() {
 326+ $di = $this->getNextDataItem();
 327+ if ( $di === false ) {
 328+ return false;
 329+ }
 330+ $dv = SMWDataValueFactory::newDataItemValue( $di );
 331+ if ( $this->mPrintRequest->getOutputFormat() ) {
 332+ $dv->setOutputFormat( $this->mPrintRequest->getOutputFormat() );
 333+ }
 334+ return $dv;
 335+ }
 336+
 337+ /**
 338+ * Return the main text representation of the next SMWDataItem object
314339 * in the specified format, or false if no further object exists.
315340 *
316341 * The parameter $linker controls linking of title values and should
317 - * be some Linker object (or NULL for no linking). At some stage its
318 - * interpretation should be part of the generalised SMWDataValue.
 342+ * be some Linker object (or NULL for no linking).
319343 *
320 - * @param $outputMode
321 - * @param $linker
 344+ * @param integer $outputMode
 345+ * @param mixed $linker
322346 */
323347 public function getNextText( $outputMode, $linker = null ) {
324 - $object = $this->getNextObject();
325 -
326 - if ( $object instanceof SMWDataValue ) { // Print data values.
327 - return ( ( $object->getTypeID() == '_wpg' ) || ( $object->getTypeID() == '__sin' ) ) ? // Prefer "long" text for page-values.
328 - $object->getLongText( $outputMode, $linker ) :
329 - $object->getShortText( $outputMode, $linker );
 348+ $dv = $this->getNextDataValue();
 349+ if ( $dv !== false ) { // Print data values.
 350+ if ( ( $dv->getTypeID() == '_wpg' ) || ( $dv->getTypeID() == '__sin' ) ) { // Prefer "long" text for page-values.
 351+ return $dv->getLongText( $outputMode, $linker );
 352+ } else {
 353+ return $dv->getShortText( $outputMode, $linker );
 354+ }
330355 } else {
331356 return false;
332357 }
@@ -342,30 +367,24 @@
343368
344369 switch ( $this->mPrintRequest->getMode() ) {
345370 case SMWPrintRequest::PRINT_THIS: // NOTE: The limit is ignored here.
346 - if ( $this->mPrintRequest->getOutputFormat() ) {
347 - $res = clone $this->mResult;
348 - $res->setOutputFormat( $this->mPrintRequest->getOutputFormat() );
349 - } else {
350 - $res = $this->mResult;
351 - }
352 -
353 - $this->mContent = array( $res );
 371+ $this->mContent = array( $this->mResult );
354372 break;
355373 case SMWPrintRequest::PRINT_CATS:
356374 // Always recompute cache here to ensure output format is respected.
357 - self::$catCache = $this->mStore->getPropertyValues( $this->mResult, SMWPropertyValue::makeProperty( '_INST' ), $this->getRequestOptions( false ), $this->mPrintRequest->getOutputFormat() );
 375+ self::$catCache = $this->mStore->getPropertyValues( $this->mResult, new SMWDIProperty( '_INST' ), $this->getRequestOptions( false ) );
358376 self::$catCacheObj = $this->mResult->getHash();
359377
360378 $limit = $this->mPrintRequest->getParameter( 'limit' );
361379 $this->mContent = ( $limit === false ) ? ( self::$catCache ) : array_slice( self::$catCache, 0, $limit );
362380 break;
363381 case SMWPrintRequest::PRINT_PROP:
364 - $this->mContent = $this->mStore->getPropertyValues( $this->mResult, $this->mPrintRequest->getData(), $this->getRequestOptions(), $this->mPrintRequest->getOutputFormat() );
365 -
 382+ $this->mContent = $this->mStore->getPropertyValues( $this->mResult, $this->mPrintRequest->getData()->getDataItem(), $this->getRequestOptions() );
 383+
366384 // Print one component of a multi-valued string.
367385 // Known limitation: the printrequest still is of type _rec, so if printers check
368386 // for this then they will not recognize that it returns some more concrete type.
369 - if ( ( $this->mPrintRequest->getTypeID() == '_rec' ) && ( $this->mPrintRequest->getParameter( 'index' ) !== false ) ) {
 387+ if ( ( $this->mPrintRequest->getTypeID() == '_rec' ) &&
 388+ ( $this->mPrintRequest->getParameter( 'index' ) !== false ) ) {
370389 $pos = $this->mPrintRequest->getParameter( 'index' ) - 1;
371390 $newcontent = array();
372391
@@ -381,24 +400,20 @@
382401 break;
383402 case SMWPrintRequest::PRINT_CCAT: ///NOTE: The limit is ignored here.
384403 if ( self::$catCacheObj != $this->mResult->getHash() ) {
385 - self::$catCache = $this->mStore->getPropertyValues( $this->mResult, SMWPropertyValue::makeProperty( '_INST' ) );
 404+ self::$catCache = $this->mStore->getPropertyValues( $this->mResult, new SMWDIProperty( '_INST' ) );
386405 self::$catCacheObj = $this->mResult->getHash();
387406 }
388 -
 407+
389408 $found = '0';
390409 $prkey = $this->mPrintRequest->getData()->getDBkey();
391 -
 410+
392411 foreach ( self::$catCache as $cat ) {
393412 if ( $cat->getDBkey() == $prkey ) {
394413 $found = '1';
395414 break;
396415 }
397416 }
398 -
399 - $dv = SMWDataValueFactory::newTypeIDValue( '_boo' );
400 - $dv->setOutputFormat( $this->mPrintRequest->getOutputFormat() );
401 - $dv->setDBkeys( array( $found ) );
402 - $this->mContent = array( $dv );
 417+ $this->mContent = array( new SMWDIBoolean( $found ) );
403418 break;
404419 default: $this->mContent = array(); // Unknown print request.
405420 }
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStoreLight.php
@@ -100,7 +100,7 @@
101101 return $this->m_semdata[$sid];
102102 }
103103
104 - public function getPropertyValues( $subject, SMWPropertyValue $property, $requestoptions = null, $outputformat = '' ) {
 104+ public function getPropertyValues( $subject, SMWDIProperty $property, $requestoptions = null, $outputformat = '' ) {
105105 wfProfileIn( "SMWSQLStoreLight::getPropertyValues (SMW)" );
106106 if ( $property->isInverse() ) { // inverses are working differently
107107 $noninverse = clone $property;
@@ -136,7 +136,7 @@
137137 return $result;
138138 }
139139
140 - public function getPropertySubjects( SMWPropertyValue $property, $value, $requestoptions = null ) {
 140+ public function getPropertySubjects( SMWDIProperty $property, $value, $requestoptions = null ) {
141141 wfProfileIn( "SMWSQLStoreLight::getPropertySubjects (SMW)" );
142142 if ( $property->isInverse() ) { // inverses are working differently
143143 $noninverse = clone $property;
@@ -170,7 +170,7 @@
171171 return $result;
172172 }
173173
174 - public function getAllPropertySubjects( SMWPropertyValue $property, $requestoptions = null ) {
 174+ public function getAllPropertySubjects( SMWDIProperty $property, $requestoptions = null ) {
175175 wfProfileIn( "SMWSQLStoreLight::getAllPropertySubjects (SMW)" );
176176 $result = $this->getPropertySubjects( $property, null, $requestoptions );
177177 wfProfileOut( "SMWSQLStoreLight::getAllPropertySubjects (SMW)" );
@@ -202,7 +202,7 @@
203203 'pageid=' . $db->addQuotes($sid) . $this->getSQLConditions( $suboptions, 'propname', 'propname' ),
204204 'SMW::getProperties', $this->getSQLOptions( $suboptions, 'propname' ) );
205205 while ( $row = $db->fetchObject( $res ) ) {
206 - $result[] = SMWPropertyValue::makeProperty( $row->propname );
 206+ $result[] = new SMWDIProperty( $row->propname );
207207 }
208208 $db->freeResult( $res );
209209 }
@@ -242,7 +242,7 @@
243243 $where . $this->getSQLConditions( $suboptions, 'propname', 'propname' ),
244244 'SMW::getInProperties', $this->getSQLOptions( $suboptions, 'propname' ) );
245245 while ( $row = $db->fetchObject( $res ) ) {
246 - $result[] = SMWPropertyValue::makeProperty( $row->propname );
 246+ $result[] = new SMWDIProperty( $row->propname );
247247 }
248248 $db->freeResult( $res );
249249 }
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_PrintRequest.php
@@ -135,13 +135,15 @@
136136 /**
137137 * If this print request refers to some property, return the type id of this property.
138138 * Otherwise return FALSE.
 139+ *
 140+ * @todo It is unclear why the actual code returns '_wpg' as a default given this documentation.
139141 *
140142 * @return string
141143 */
142144 public function getTypeID() {
143145 if ( $this->m_typeid === false ) {
144146 if ( $this->m_mode == SMWPrintRequest::PRINT_PROP ) {
145 - $this->m_typeid = $this->m_data->getPropertyTypeID();
 147+ $this->m_typeid = $this->m_data->getDataItem()->findPropertyTypeID();
146148 } else {
147149 $this->m_typeid = '_wpg'; // return objects might be titles, but anyway
148150 }
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php
@@ -101,9 +101,9 @@
102102 return $this->m_errors;
103103 }
104104
105 - $values = $this->m_store->getPropertyValues( $concept, SMWPropertyValue::makeProperty( '_CONC' ) );// two lines due to "strict standards" warning
106 - $dv = end( $values );
107 - $desctxt = ( $dv !== false ) ? $dv->getWikiValue() : false;
 105+ $values = $this->m_store->getPropertyValues( $concept, new SMWDIProperty( '_CONC' ) );// two lines due to "strict standards" warning
 106+ $di = end( $values );
 107+ $desctxt = ( $di !== false ) ? $di->getConceptQuery() : false;
108108 $this->m_errors = array();
109109
110110 if ( $desctxt ) { // concept found
@@ -408,7 +408,7 @@
409409
410410 while ( ( $count < $query->getLimit() ) && ( $row = $this->m_dbs->fetchObject( $res ) ) ) {
411411 $count++;
412 - $v = SMWWikiPageValue::makePage( $row->t, $row->ns, $row->sortkey );
 412+ $v = new SMWDIWikiPage( $row->t, $row->ns, $row->iw );
413413 $qr[] = $v;
414414 $this->m_store->cacheSMWPageID( $row->id, $row->t, $row->ns, $row->iw );
415415 }
@@ -587,14 +587,14 @@
588588 * to check for this and discard the query in this case.
589589 * @todo Check if hierarchy queries work as expected.
590590 */
591 - protected function compilePropertyCondition( SMWSQLStore2Query $query, $property, SMWDescription $valuedesc ) {
 591+ protected function compilePropertyCondition( SMWSQLStore2Query $query, SMWDIProperty $property, SMWDescription $valuedesc ) {
592592 $tableid = SMWSQLStore2::findPropertyTableID( $property );
593593
594594 if ( $tableid == '' ) { // probably a type-polymorphic property
595595 $typeid = $valuedesc->getTypeID();
596596 $tableid = SMWSQLStore2::findTypeTableID( $typeid );
597597 } else { // normal property
598 - $typeid = $property->getPropertyTypeID();
 598+ $typeid = $property->findPropertyTypeID();
599599 }
600600
601601 if ( $tableid == '' ) { // Still no table to query? Give up.
@@ -611,7 +611,7 @@
612612 }
613613
614614 list( $sig, $valueindex, $labelindex ) = SMWSQLStore2::getTypeSignature( $typeid );
615 - $sortkey = $property->getDBkey(); // TODO: strictly speaking, the DB key is not what we want here, since sortkey is based on a "wiki value"
 615+ $sortkey = $property->getKey(); // TODO: strictly speaking, the DB key is not what we want here, since sortkey is based on a "wiki value"
616616
617617 // *** Basic settings: table, joinfield, and objectfields ***//
618618 $query->jointable = $proptable->name;
@@ -634,7 +634,7 @@
635635 if ( $proptable->fixedproperty == false ) {
636636 $pid = $this->m_store->getSMWPropertyID( $property );
637637
638 - if ( !$property->getPropertyID() || ( $property->getPropertyTypeID() != '__err' ) ) {
 638+ if ( $property->isUserDefined() || ( $property->findPropertyTypeID() != '__err' ) ) {
639639 // also make property hierarchy (may or may not be executed later on)
640640 // exclude type-polymorphic properties _1, _2, ... (2nd check above suffices, but 1st is faster to check)
641641 // we could also exclude other cases here, if desired
@@ -1076,7 +1076,7 @@
10771077 $sortprop = SMWPropertyValue::makeUserProperty( $propkey );
10781078
10791079 if ( $sortprop->isValid() ) {
1080 - $extraproperties[] = new SMWSomeProperty( $sortprop, new SMWThingDescription() );
 1080+ $extraproperties[] = new SMWSomeProperty( $sortprop->getDataItem(), new SMWThingDescription() );
10811081 }
10821082 }
10831083 }
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php
@@ -77,10 +77,9 @@
7878
7979 /**
8080 * Should the result be ordered? The employed order is defined
81 - * by the type of result that are requested: Title objects and
82 - * strings are ordered alphabetically, whereas SMWDataValue
83 - * objects can provide different custom orders if they are scalar.
84 - * Usually, the order should be fairly "natural".
 81+ * by the type of result that are requested: wiki pages and strings
 82+ * are ordered alphabetically, whereas other data is ordered
 83+ * numerically. Usually, the order should be fairly "natural".
8584 */
8685 public $sort = false;
8786
@@ -155,47 +154,45 @@
156155 * than requested when a filter is used. Filtering just ensures that
157156 * only necessary requests are made, i.e. it improves performance.
158157 */
159 - public abstract function getSemanticData( $subject, $filter = false );
 158+ public abstract function getSemanticData( SMWDIWikiPage $subject, $filter = false );
160159
161160 /**
162161 * Get an array of all property values stored for the given subject and property. The result
163 - * is an array of SMWDataValue objects. The provided outputformat is a string identifier that
164 - * may be used by the datavalues to modify their output behaviour, e.g. when interpreted as a
165 - * desired unit to convert the output to.
 162+ * is an array of SMWDataItem objects.
166163 *
167164 * If called with $subject == NULL, all values for the given property are returned.
168165 */
169 - public abstract function getPropertyValues( $subject, SMWPropertyValue $property, $requestoptions = null, $outputformat = '' );
 166+ public abstract function getPropertyValues( $subject, SMWDIProperty $property, $requestoptions = null );
170167
171168 /**
172169 * Get an array of all subjects that have the given value for the given property. The
173 - * result is an array of SMWWikiPageValue objects. If NULL is given as a value, all subjects having
 170+ * result is an array of SMWDIWikiPage objects. If NULL is given as a value, all subjects having
174171 * that property are returned.
175172 */
176 - public abstract function getPropertySubjects( SMWPropertyValue $property, $value, $requestoptions = null );
 173+ public abstract function getPropertySubjects( SMWDIProperty $property, $value, $requestoptions = null );
177174
178175 /**
179176 * Get an array of all subjects that have some value for the given property. The
180 - * result is an array of SMWWikiPageValue objects.
 177+ * result is an array of SMWDIWikiPage objects.
181178 */
182 - public abstract function getAllPropertySubjects( SMWPropertyValue $property, $requestoptions = null );
 179+ public abstract function getAllPropertySubjects( SMWDIProperty $property, $requestoptions = null );
183180
184181 /**
185182 * Get an array of all properties for which the given subject has some value. The result is an
186 - * array of SMWPropertyValue objects.
 183+ * array of SMWDIProperty objects.
187184 *
188 - * @param $subject Title or SMWWikiPageValue denoting the subject
 185+ * @param $subject SMWDIWikiPage denoting the subject
189186 * @param $requestoptions SMWRequestOptions optionally defining further options
190187 */
191 - public abstract function getProperties( $subject, $requestoptions = null );
 188+ public abstract function getProperties( SMWDIWikiPage $subject, $requestoptions = null );
192189
193190 /**
194191 * Get an array of all properties for which there is some subject that relates to the given value.
195 - * The result is an array of SMWWikiPageValue objects.
 192+ * The result is an array of SMWDIWikiPage objects.
196193 * @note In some stores, this function might be implemented partially so that only values of type Page
197194 * (_wpg) are supported.
198195 */
199 - public abstract function getInProperties( SMWDataValue $object, $requestoptions = null );
 196+ public abstract function getInProperties( SMWDataItem $object, $requestoptions = null );
200197
201198 ///// Writing methods /////
202199
@@ -215,31 +212,33 @@
216213 public abstract function doDataUpdate( SMWSemanticData $data );
217214
218215 /**
219 - * Update the semantic data stored for some individual. The data is given
220 - * as a SMWSemanticData object, which contains all semantic data for one particular
221 - * subject.
 216+ * Update the semantic data stored for some individual. The data is
 217+ * given as a SMWSemanticData object, which contains all semantic data
 218+ * for one particular subject.
 219+ *
 220+ * @param $data SMWSemanticData
222221 */
223222 public function updateData( SMWSemanticData $data ) {
224223 wfRunHooks( 'SMWStore::updateDataBefore', array( $this, $data ) );
225 -
 224+
226225 $this->doDataUpdate( $data );
227 -
 226+
228227 // Invalidate the page, so data stored on it gets displayed immeditaely in queries.
229228 global $smwgAutoRefreshSubject, $wgDBtype;
230229 if ( $smwgAutoRefreshSubject && !wfReadOnly() ) {
231 - $title = $data->getSubject()->getTitle();
 230+ $title = Title::makeTitle( $data->getSubject()->getNamespace(), $data->getSubject()->getDBkey() );
232231 $dbw = wfGetDB( DB_MASTER );
233 -
 232+
234233 $dbw->update(
235234 'page',
236235 array( 'page_touched' => $dbw->timestamp( time() + 9001 ) ),
237236 $title->pageCond(),
238237 __METHOD__
239238 );
240 -
 239+
241240 HTMLFileCache::clearFileCache( $title );
242241 }
243 -
 242+
244243 wfRunHooks( 'SMWStore::updateDataAfter', array( $this, $data ) );
245244 }
246245
@@ -247,7 +246,7 @@
248247 * Clear all semantic data specified for some page.
249248 */
250249 public function clearData( Title $subject ) {
251 - $emptydata = new SMWSemanticData( SMWWikiPageValue::makePageFromTitle( $subject ) );
 250+ $emptydata = new SMWSemanticData( new SMWDIWikiPage( $subject->getDbKey(), $subject->getNamespace(), $subject->getInterwiki() ) );
252251 $this->updateData( $emptydata );
253252 }
254253
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_TestStore.php
@@ -67,7 +67,7 @@
6868 }
6969 }
7070
71 - function getPropertyValues( $subject, SMWPropertyValue $property, $requestoptions = null, $outputformat = '' ) {
 71+ function getPropertyValues( $subject, SMWDIProperty $property, $requestoptions = null, $outputformat = '' ) {
7272 $type = $this->getSpecialValues( $property, SMW_SP_HAS_TYPE );
7373 $type = $type[0];
7474 $valarray = array();
@@ -98,14 +98,14 @@
9999 return $result;
100100 }
101101
102 - function getPropertySubjects( SMWPropertyValue $property, $value, $requestoptions = null ) {
 102+ function getPropertySubjects( SMWDIProperty $property, $value, $requestoptions = null ) {
103103 if ( !$value->isValid() ) {
104104 return array();
105105 }
106106 return $this->getTestTitles( $requestoptions );
107107 }
108108
109 - function getAllPropertySubjects( SMWPropertyValue $property, $requestoptions = null ) {
 109+ function getAllPropertySubjects( SMWDIProperty $property, $requestoptions = null ) {
110110 return $this->getTestTitles( $requestoptions );
111111 }
112112
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
@@ -145,35 +145,24 @@
146146
147147 ///// Reading methods /////
148148
149 - public function getSemanticData( $subject, $filter = false ) {
 149+ public function getSemanticData( SMWDIWikiPage $subject, $filter = false ) {
150150 wfProfileIn( "SMWSQLStore2::getSemanticData (SMW)" );
151151
152152 // Do not clear the cache when called recursively.
153153 self::$in_getSemanticData++;
154154
155155 // *** Find out if this subject exists ***//
156 - if ( $subject instanceof Title ) { ///TODO: can this still occur?
157 - $sid = $this->getSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki() );
158 - $svalue = SMWWikiPageValue::makePageFromTitle( $subject );
159 - } elseif ( $subject instanceof SMWWikiPageValue ) {
160 - $sid = $subject->isValid() ?
161 - $this->getSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki() ):
162 - 0;
163 - $svalue = $subject;
164 - } else {
165 - $sid = 0;
166 - }
167 -
 156+ $sid = $this->getSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki() );
168157 if ( $sid == 0 ) { // no data, safe our time
169158 /// NOTE: we consider redirects for getting $sid, so $sid == 0 also means "no redirects"
170159 self::$in_getSemanticData--;
171160 wfProfileOut( "SMWSQLStore2::getSemanticData (SMW)" );
172 - return isset( $svalue ) ? ( new SMWSemanticData( $svalue ) ):null;
 161+ return new SMWSemanticData( $subject );
173162 }
174163
175164 // *** Prepare the cache ***//
176165 if ( !array_key_exists( $sid, $this->m_semdata ) ) { // new cache entry
177 - $this->m_semdata[$sid] = new SMWSemanticData( $svalue, false );
 166+ $this->m_semdata[$sid] = new SMWSemanticData( $subject, false );
178167 $this->m_sdstate[$sid] = array();
179168 }
180169
@@ -197,7 +186,7 @@
198187 if ( !$relevant ) continue;
199188 }
200189
201 - $data = $this->fetchSemanticData( $sid, $svalue, $proptable );
 190+ $data = $this->fetchSemanticData( $sid, $subject, $proptable );
202191
203192 foreach ( $data as $d ) {
204193 $this->m_semdata[$sid]->addPropertyStubValue( reset( $d ), end( $d ) );
@@ -216,35 +205,21 @@
217206 /**
218207 * @see SMWStore::getPropertyValues
219208 *
220 - * @param $subject
221 - * @param SMWPropertyValue $property
 209+ * @param SMWDataItem $subject
 210+ * @param SMWDIProperty $property
222211 * @param SMWRequestOptions $requestoptions
223 - * @param string $outputformat
224212 *
225 - * @return array
 213+ * @return array of SMWDataItem
226214 */
227 - public function getPropertyValues( $subject, SMWPropertyValue $property, $requestoptions = null, $outputformat = '' ) {
 215+ public function getPropertyValues( $subject, SMWDIProperty $property, $requestoptions = null ) {
228216 wfProfileIn( "SMWSQLStore2::getPropertyValues (SMW)" );
229217
230218 if ( $property->isInverse() ) { // inverses are working differently
231 - $noninverse = clone $property;
232 - $noninverse->setInverse( false );
 219+ $noninverse = new SMWDIProperty( $property->getKey(), false, $property->findPropertyTypeID() );
233220 $result = $this->getPropertySubjects( $noninverse, $subject, $requestoptions );
234 - } elseif ( $subject !== null ) { // subject given, use semantic data cache:
235 - $sd = $this->getSemanticData( $subject, array( $property->getPropertyTypeID() ) );
 221+ } elseif ( $subject !== null ) { // subject given, use semantic data cache
 222+ $sd = $this->getSemanticData( $subject, array( $property->findPropertyTypeID() ) );
236223 $result = $this->applyRequestOptions( $sd->getPropertyValues( $property ), $requestoptions );
237 -
238 - if ( $outputformat != '' ) { // reformat cached values
239 - $newres = array();
240 -
241 - foreach ( $result as $dv ) {
242 - $ndv = clone $dv;
243 - $ndv->setOutputFormat( $outputformat );
244 - $newres[] = $ndv;
245 - }
246 -
247 - $result = $newres;
248 - }
249224 } else { // no subject given, get all values for the given property
250225 $pid = $this->getSMWPropertyID( $property );
251226 $tableid = self::findPropertyTableID( $property );
@@ -259,10 +234,12 @@
260235 $result = array();
261236
262237 foreach ( $data as $dbkeys ) {
263 - $dv = SMWDataValueFactory::newPropertyObjectValue( $property );
264 - if ( $outputformat != '' ) $dv->setOutputFormat( $outputformat );
265 - $dv->setDBkeys( $dbkeys );
266 - $result[] = $dv;
 238+ try {
 239+ $result[] = SMWDataValueFactory::newTypeIdItem( $property->findPropertyTypeID(), $dbkeys );
 240+ } catch ( SMWDataItemException $e ) {
 241+ // maybe some type assignment changed since the data was stored;
 242+ // don't worry, but we can ony drop the data here
 243+ }
267244 }
268245 }
269246
@@ -280,7 +257,7 @@
281258 * In case (1), the first two parameters are taken to refer to a subject; in case (2) they
282259 * are taken to refer to a property. In any case, the retrieval is limited to the specified
283260 * $proptable. The parameters are an internal $id (of a subject or property), and an $object
284 - * (being an SMWPageValue or SMWPropertyValue). Moreover, when filtering by property, it is
 261+ * (being an SMWDIWikiPage or SMWDIProperty). Moreover, when filtering by property, it is
285262 * assumed that the given $proptable belongs to the property: if it is a table with fixed
286263 * property, it will not be checked that this is the same property as the one that was given
287264 * in $object.
@@ -297,8 +274,8 @@
298275 * @todo Maybe share DB handler; asking for it seems to take quite some time and we do not want
299276 * to change it in one call.
300277 *
301 - * @param $id
302 - * @param $object
 278+ * @param integer $id
 279+ * @param SMWDataItem $object
303280 * @param SMWSQLStore2Table $proptable
304281 * @param boolean $issubject
305282 * @param SMWRequestOptions $requestoptions
@@ -438,13 +415,13 @@
439416 /**
440417 * @see SMWStore::getPropertySubjects
441418 *
442 - * @param SMWPropertyValue $property
443 - * @param $value
 419+ * @param SMWDiProperty $property
 420+ * @param mixed $value SMWDataItem or null
444421 * @param SMWRequestOptions $requestoptions
445422 *
446 - * @return array
 423+ * @return array of SMWDIWikiPage
447424 */
448 - public function getPropertySubjects( SMWPropertyValue $property, $value, $requestoptions = null ) {
 425+ public function getPropertySubjects( SMWDiProperty $property, $value, $requestoptions = null ) {
449426 /// TODO: should we share code with #ask query computation here? Just use queries?
450427 wfProfileIn( "SMWSQLStore2::getPropertySubjects (SMW)" );
451428
@@ -467,7 +444,7 @@
468445 $tableid = self::findTypeTableID( $value->getTypeID() );
469446 }
470447
471 - if ( ( $pid == 0 ) || ( $tableid == '' ) || ( ( $value !== null ) && ( !$value->isValid() ) ) ) {
 448+ if ( ( $pid == 0 ) || ( $tableid == '' ) ) {
472449 wfProfileOut( "SMWSQLStoreLight::getPropertySubjects (SMW)" );
473450 return array();
474451 }
@@ -498,7 +475,11 @@
499476 $this->getSQLOptions( $requestoptions, 'smw_sortkey' ) );
500477
501478 while ( $row = $db->fetchObject( $res ) ) {
502 - $result[] = SMWWikiPageValue::makePage( $row->title, $row->namespace, $row->smw_sortkey );
 479+ try {
 480+ $result[] = new SMWDIWikiPage( $row->title, $row->namespace, '' );
 481+ } catch ( SMWDataItemException $e ) {
 482+ // silently drop data, should be extremely rare and will usually fix itself at next edit
 483+ }
503484 }
504485
505486 $db->freeResult( $res );
@@ -518,16 +499,16 @@
519500 * @todo Maybe do something about redirects. The old code was
520501 * $oid = $this->getSMWPageID($value->getDBkey(),$value->getNamespace(),$value->getInterwiki(),false);
521502 *
522 - * @param $from
523 - * @param $where
524 - * @param $proptable
525 - * @param $value
526 - * @param $tableindex
 503+ * @param string $from
 504+ * @param string $where
 505+ * @param SMWSQLStore2Table $proptable
 506+ * @param SMWDataItem $value
 507+ * @param integer $tableindex
527508 */
528509 protected function prepareValueQuery( &$from, &$where, $proptable, $value, $tableindex = 1 ) {
529510 $db = wfGetDB( DB_SLAVE );
530511
531 - if ( $value instanceof SMWContainerValue ) { // recursive handling of containers
 512+ if ( $value instanceof SMWDIContainer ) { // recursive handling of containers
532513 $joinfield = "t$tableindex." . reset( array_keys( $proptable->objectfields ) ); // this must be a type 'p' object
533514 $proptables = self::getPropertyTables();
534515
@@ -559,7 +540,7 @@
560541 }
561542 }
562543 } elseif ( $value !== null ) { // add conditions for given value
563 - $dbkeys = $value->getDBkeys();
 544+ $dbkeys = SMWCompatibilityHelpers::getDBkeysFromDataItem( $value );
564545 $i = 0;
565546
566547 foreach ( $proptable->objectfields as $fieldname => $typeid ) {
@@ -581,12 +562,12 @@
582563 /**
583564 * @see SMWStore::getAllPropertySubjects
584565 *
585 - * @param SMWPropertyValue $property
 566+ * @param SMWDIProperty $property
586567 * @param SMWRequestOptions $requestoptions
587568 *
588 - * @return array
 569+ * @return array of SMWDIWikiPage
589570 */
590 - public function getAllPropertySubjects( SMWPropertyValue $property, $requestoptions = null ) {
 571+ public function getAllPropertySubjects( SMWDIProperty $property, $requestoptions = null ) {
591572 wfProfileIn( "SMWSQLStore2::getAllPropertySubjects (SMW)" );
592573 $result = $this->getPropertySubjects( $property, null, $requestoptions );
593574 wfProfileOut( "SMWSQLStore2::getAllPropertySubjects (SMW)" );
@@ -596,13 +577,11 @@
597578
598579 /**
599580 * @see SMWStore::getProperties
600 - *
601 - * TODO: Restrict this function to SMWWikiPageValue subjects.
602581 *
603 - * @param $subject
 582+ * @param SMWDIWikiPage $subject
604583 * @param SMWRequestOptions $requestoptions
605584 */
606 - public function getProperties( $subject, $requestoptions = null ) {
 585+ public function getProperties( SMWDIWikiPage $subject, $requestoptions = null ) {
607586 wfProfileIn( "SMWSQLStore2::getProperties (SMW)" );
608587 $sid = $this->getSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki() );
609588
@@ -640,13 +619,13 @@
641620 'SMW::getProperties', $this->getSQLOptions( $suboptions, 'smw_sortkey' ) );
642621
643622 while ( $row = $db->fetchObject( $res ) ) {
644 - $result[] = SMWPropertyValue::makeProperty( $row->smw_title );
 623+ $result[] = new SMWDIProperty( $row->smw_title );
645624 }
646625 } else { // just check if subject occurs in table
647626 $res = $db->select( $from, '*', $where, 'SMW::getProperties', array( 'LIMIT' => 1 ) );
648627
649628 if ( $db->numRows( $res ) > 0 ) {
650 - $result[] = SMWPropertyValue::makeProperty( $proptable->fixedproperty );
 629+ $result[] = new SMWDIProperty( $proptable->fixedproperty );
651630 }
652631 }
653632
@@ -672,12 +651,12 @@
673652 * can be confused. This is a minor issue now since no code is known to use
674653 * this function in cases where this occurs.
675654 *
676 - * @param SMWDataValue $value
 655+ * @param SMWDataItem $value
677656 * @param SMWRequestOptions $requestoptions
678657 *
679658 * @return array of SMWWikiPageValue
680659 */
681 - public function getInProperties( SMWDataValue $value, $requestoptions = null ) {
 660+ public function getInProperties( SMWDataItem $value, $requestoptions = null ) {
682661 wfProfileIn( "SMWSQLStore2::getInProperties (SMW)" );
683662
684663 $db = wfGetDB( DB_SLAVE );
@@ -706,7 +685,7 @@
707686 'SMW::getInProperties', $this->getSQLOptions( $suboptions, 'smw_sortkey' ) );
708687
709688 while ( $row = $db->fetchObject( $res ) ) {
710 - $result[] = SMWPropertyValue::makeProperty( $row->smw_title );
 689+ $result[] = new SMWDIProperty( $row->smw_title );
711690 }
712691 } else {
713692 $from = $db->tableName( $proptable->name ) . " AS t1";
@@ -714,7 +693,7 @@
715694 $res = $db->select( $from, '*', $where, 'SMW::getProperties', array( 'LIMIT' => 1 ) );
716695
717696 if ( $db->numRows( $res ) > 0 ) {
718 - $result[] = SMWPropertyValue::makeProperty( $proptable->fixedproperty );
 697+ $result[] = new SMWDIProperty( $proptable->fixedproperty );
719698 }
720699 }
721700 $db->freeResult( $res );
@@ -766,7 +745,7 @@
767746
768747 $subject = $data->getSubject();
769748 $this->deleteSemanticData( $subject );
770 - $redirects = $data->getPropertyValues( SMWPropertyValue::makeProperty( '_REDI' ) );
 749+ $redirects = $data->getPropertyValues( new SMWDIProperty( '_REDI' ) );
771750
772751 if ( count( $redirects ) > 0 ) {
773752 $redirect = end( $redirects ); // at most one redirect per page
@@ -862,8 +841,8 @@
863842
864843 $proptable = $proptables[$tableid];
865844
866 - foreach ( $data->getPropertyValues( $property ) as $dv ) {
867 - if ( !$dv->isValid() || ( $tableid == 'smw_redi2' ) ) continue;
 845+ foreach ( $data->getPropertyValues( $property ) as $di ) {
 846+ if ( $tableid == 'smw_redi2' ) continue;
868847
869848 // errors are already recorded separately, no need to store them here;
870849 // redirects were treated above
@@ -874,13 +853,13 @@
875854 $uvals['p_id'] = $this->makeSMWPropertyID( $property );
876855 }
877856
878 - if ( $dv instanceof SMWContainerValue ) { // process subobjects recursively
879 - $bnode = $this->prepareDBUpdates( $updates, $dv->getData(), $pageid );
 857+ if ( $di instanceof SMWDIContainer ) { // process subobjects recursively
 858+ $bnode = $this->prepareDBUpdates( $updates, $di->getData(), $pageid );
880859 // Note: tables for container objects MUST have objectfields == array(<somename> => 'p')
881860 reset( $proptable->objectfields );
882861 $uvals[key( $proptable->objectfields )] = $bnode;
883862 } else {
884 - $dbkeys = $dv->getDBkeys();
 863+ $dbkeys = SMWCompatibilityHelpers::getDBkeysFromDataItem( $di );
885864 reset( $dbkeys );
886865
887866 foreach ( $proptable->objectfields as $fieldname => $typeid ) {
@@ -1040,7 +1019,7 @@
10411020 $result = array();
10421021
10431022 while ( $row = $db->fetchObject( $res ) ) {
1044 - $result[] = array( SMWPropertyValue::makeProperty( $row->smw_title ), $row->count );
 1023+ $result[] = array( new SMWDIProperty( $row->smw_title ), $row->count );
10451024 }
10461025
10471026 $db->freeResult( $res );
@@ -1120,7 +1099,7 @@
11211100 $result = array();
11221101
11231102 while ( $row = $db->fetchObject( $res ) ) {
1124 - $result[] = SMWPropertyValue::makeProperty( $row->title );
 1103+ $result[] = new SMWDIProperty( $row->title );
11251104 }
11261105
11271106 $db->freeResult( $res );
@@ -1162,7 +1141,7 @@
11631142 'SMW::getWantedPropertiesSpecial', $options );
11641143
11651144 while ( $row = $db->fetchObject( $res ) ) {
1166 - $result[] = array( SMWPropertyValue::makeProperty( $row->smw_title ), $row->count );
 1145+ $result[] = array( new SMWDIProperty( $row->smw_title ), $row->count );
11671146 }
11681147 }
11691148
@@ -1179,7 +1158,7 @@
11801159 $proptables = self::getPropertyTables();
11811160
11821161 // count number of declared properties by counting "has type" annotations
1183 - $typeprop = SMWPropertyValue::makeProperty( '_TYPE' );
 1162+ $typeprop = new SMWDIProperty( '_TYPE' );
11841163 $typetable = $proptables[self::findPropertyTableID( $typeprop )];
11851164 $res = $db->select( $typetable->name, 'COUNT(s_id) AS count', array( 'p_id' => $this->getSMWPropertyID( $typeprop ) ), 'SMW::getStatistics' );
11861165 $row = $db->fetchObject( $res );
@@ -1403,13 +1382,13 @@
14041383 $this->reportProgress( " ... writing entries for internal properties.", $verbose );
14051384
14061385 foreach ( self::$special_ids as $prop => $id ) {
1407 - $p = SMWPropertyValue::makeProperty( $prop );
 1386+ $p = new SMWDIProperty( $prop );
14081387 $db->replace( 'smw_ids', array( 'smw_id' ), array(
14091388 'smw_id' => $id,
1410 - 'smw_title' => $p->getDBkey(),
 1389+ 'smw_title' => $p->getKey(),
14111390 'smw_namespace' => SMW_NS_PROPERTY,
14121391 'smw_iw' => $this->getPropertyInterwiki( $p ),
1413 - 'smw_sortkey' => $p->getDBkey()
 1392+ 'smw_sortkey' => $p->getKey()
14141393 ), 'SMW::setup'
14151394 );
14161395 }
@@ -1710,7 +1689,7 @@
17111690
17121691 foreach ( $data as $item ) {
17131692 $ok = true; // keep datavalue only if this remains true
1714 - $keys = $item->getDBkeys();
 1693+ $keys = SMWCompatibilityHelpers::getDBkeysFromDataItem( $item );
17151694 $value = array_key_exists( $valueIndex, $keys ) ? $keys[$valueIndex] : '';
17161695 $label = array_key_exists( $labelIndex, $keys ) ? $keys[$labelIndex] : '';
17171696
@@ -1865,7 +1844,7 @@
18661845 * Retrieve the id of the property table that is to be used for storing
18671846 * values for the given property object.
18681847 */
1869 - public static function findPropertyTableID( $property ) {
 1848+ public static function findPropertyTableID( SMWDIProperty $property ) {
18701849 if ( self::$fixed_prop_tables === null ) { // Build lookup array once.
18711850 self::$fixed_prop_tables = array();
18721851
@@ -1876,17 +1855,16 @@
18771856 }
18781857 }
18791858
1880 - $propertykey = ( $property->isUserDefined() ) ? $property->getDBkey() : $property->getPropertyId();
1881 -
 1859+ $propertykey = $property->getKey();
18821860 if ( array_key_exists( $propertykey, self::$fixed_prop_tables ) ) {
1883 - $signature = self::getTypeSignature( $property->getPropertyTypeID() );
 1861+ $signature = self::getTypeSignature( $property->findPropertyTypeID() );
18841862
18851863 if ( self::tableFitsSignature( SMWSQLStore2::$fixed_prop_tables[$propertykey], $signature ) ) {
18861864 return self::$fixed_prop_tables[$propertykey];
18871865 }
18881866 } // else: Don't check for non-fitting entries in $fixed_prop_tables: not really important.
18891867
1890 - return self::findTypeTableID( $property->getPropertyTypeID() );
 1868+ return self::findTypeTableID( $property->findPropertyTypeID() );
18911869 }
18921870
18931871 /**
@@ -2038,11 +2016,11 @@
20392017 * predefined properties from the ids for the current pages (which may,
20402018 * e.g. be moved, while the predefined object is not movable).
20412019 */
2042 - protected function getPropertyInterwiki( SMWPropertyValue $property ) {
 2020+ protected function getPropertyInterwiki( SMWDIProperty $property ) {
20432021 if ( $property->isUserDefined() ) {
20442022 return '';
20452023 } else {
2046 - return $property->isVisible() ? SMW_SQL2_SMWPREDEFIW : SMW_SQL2_SMWINTDEFIW;
 2024+ return ( $property->getLabel() != '' ) ? SMW_SQL2_SMWPREDEFIW : SMW_SQL2_SMWINTDEFIW;
20472025 }
20482026 }
20492027
@@ -2050,11 +2028,11 @@
20512029 * This function does the same as getSMWPageID() but takes into account
20522030 * that properties might be predefined.
20532031 */
2054 - public function getSMWPropertyID( SMWPropertyValue $property ) {
2055 - if ( ( !$property->isUserDefined() ) && ( array_key_exists( $property->getPropertyID(), self::$special_ids ) ) ) {
2056 - return self::$special_ids[$property->getPropertyID()]; // very important property with fixed id
 2032+ public function getSMWPropertyID( SMWDIProperty $property ) {
 2033+ if ( ( !$property->isUserDefined() ) && ( array_key_exists( $property->getKey(), self::$special_ids ) ) ) {
 2034+ return self::$special_ids[$property->getKey()]; // very important property with fixed id
20572035 } else {
2058 - return $this->getSMWPageID( $property->getDBkey(), SMW_NS_PROPERTY, $this->getPropertyInterwiki( $property ), true );
 2036+ return $this->getSMWPageID( $property->getKey(), SMW_NS_PROPERTY, $this->getPropertyInterwiki( $property ), true );
20592037 }
20602038 }
20612039
@@ -2062,11 +2040,11 @@
20632041 * This function does the same as makeSMWPageID() but takes into account
20642042 * that properties might be predefined.
20652043 */
2066 - protected function makeSMWPropertyID( SMWPropertyValue $property ) {
2067 - if ( ( !$property->isUserDefined() ) && ( array_key_exists( $property->getPropertyID(), self::$special_ids ) ) ) {
2068 - return self::$special_ids[$property->getPropertyID()]; // very important property with fixed id
 2044+ protected function makeSMWPropertyID( SMWDIProperty $property ) {
 2045+ if ( ( !$property->isUserDefined() ) && ( array_key_exists( $property->getKey(), self::$special_ids ) ) ) {
 2046+ return self::$special_ids[$property->getKey()]; // very important property with fixed id
20692047 } else {
2070 - return $this->makeSMWPageID( $property->getDBkey(), SMW_NS_PROPERTY, $this->getPropertyInterwiki( $property ), true );
 2048+ return $this->makeSMWPageID( $property->getKey(), SMW_NS_PROPERTY, $this->getPropertyInterwiki( $property ), true );
20712049 }
20722050 }
20732051
@@ -2270,12 +2248,12 @@
22712249 }
22722250
22732251 /**
2274 - * Delete all semantic data stored for the given subject. Used for update
2275 - * purposes.
 2252+ * Delete all semantic data stored for the given subject. Used for
 2253+ * update purposes.
22762254 *
2277 - * @param SMWWikiPageValue $subject
 2255+ * @param $subject SMWDIWikiPage the data of which is deleted
22782256 */
2279 - protected function deleteSemanticData( SMWWikiPageValue $subject ) {
 2257+ protected function deleteSemanticData( SMWDIWikiPage $subject ) {
22802258 $db = wfGetDB( DB_MASTER );
22812259
22822260 $fname = 'SMW::deleteSemanticData';
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Compatibility_Helpers.php
@@ -0,0 +1,159 @@
 2+<?php
 3+/**
 4+ * This file contains the SMWCompatibilityHelper class.
 5+ * @note This file and its contents will vanish before SMW 1.7. Please modify your code to not require these helpers.
 6+ *
 7+ * @author Markus Krötzsch
 8+ *
 9+ * @file
 10+ * @ingroup SMW
 11+ */
 12+
 13+/**
 14+ * Helper class to collect various static functions that provide some
 15+ * interfaces used in SMW 1.6 that are no longer available in SMW 1.7.
 16+ * In particular, this relates to the new data model based on data items
 17+ * instead of data value classes with DB key arrays and singatures.
 18+ *
 19+ * @note This class will vanish before SMW 1.7. Please change your code to not require the old interfaces at all.
 20+ *
 21+ * @ingroup SMW
 22+ */
 23+class SMWCompatibilityHelpers {
 24+
 25+ /**
 26+ * Method to create a dataitem from a type ID and array of DB keys.
 27+ * Throws SMWDataItemException if problems occur, to get our callers
 28+ * used to it.
 29+ *
 30+ * @param $typeid id string for the given type
 31+ * @param $dbkeys array of mixed
 32+ *
 33+ * @return SMWDataItem
 34+ */
 35+ static public function dataItemFromDBKeys( $typeid, $dbkeys ) {
 36+ switch ( SMWDataValueFactory::getDataItemId( $typeid ) ) {
 37+ case SMWDataItem::TYPE_ERROR:
 38+ break;
 39+ case SMWDataItem::TYPE_NUMBER:
 40+ return SMWDINumber::doUnserialize( $dbkeys[0], $typeid );
 41+ case SMWDataItem::TYPE_STRING:
 42+ return new SMWDIString( $dbkeys[0], $typeid );
 43+ case SMWDataItem::TYPE_BLOB:
 44+ return new SMWDIBlob( $dbkeys[0], $typeid );
 45+ case SMWDataItem::TYPE_BOOLEAN:
 46+ return new SMWDIBoolean( ( $dbkeys[0] == '1' ), $typeid );
 47+ case SMWDataItem::TYPE_URI:
 48+ return SMWDIUri::doUnserialize( $dbkeys[0], $typeid);
 49+ case SMWDataItem::TYPE_TIME:
 50+ $timedate = explode( 'T', $dbkeys[0], 2 );
 51+ if ( ( count( $dbkeys ) == 2 ) && ( count( $timedate ) == 2 ) ) {
 52+ $date = reset( $timedate );
 53+ $year = $month = $day = $hours = $minutes = $seconds = $timeoffset = false;
 54+ if ( ( end( $timedate ) == '' ) ||
 55+ ( SMWTimeValue::parseTimeString( end( $timedate ), $hours, $minutes, $seconds, $timeoffset ) == true ) ) {
 56+ $d = explode( '/', $date, 3 );
 57+ if ( count( $d ) == 3 ) {
 58+ list( $year, $month, $day ) = $d;
 59+ } elseif ( count( $d ) == 2 ) {
 60+ list( $year, $month ) = $d;
 61+ } elseif ( count( $d ) == 1 ) {
 62+ list( $year ) = $d;
 63+ }
 64+ $calendarmodel = SMWDITime::CM_GREGORIAN;
 65+ return new SMWDITime( $calendarmodel, $year, $month, $day, $hours, $minutes, $seconds, $typeid );
 66+ }
 67+ }
 68+ break;
 69+ case SMWDataItem::TYPE_GEO:
 70+ break;
 71+ case SMWDataItem::TYPE_CONTAINER:
 72+ break;
 73+ case SMWDataItem::TYPE_WIKIPAGE:
 74+ if ( $typeid == '__typ' ) { // DBkeys for types values are special (used to be a SMWSimpleWikiPageValue)
 75+ $pagedbkey = str_replace( ' ', '_', SMWDataValueFactory::findTypeLabel( $dbkeys[0] ) );
 76+ return new SMWDIWikiPage( $pagedbkey, SMW_NS_TYPE, '', $typeid );
 77+ } elseif ( count( $dbkeys ) >= 3 ) {
 78+ return new SMWDIWikiPage( $dbkeys[0], floatval( $dbkeys[1] ), $dbkeys[2], $typeid );
 79+ }
 80+ break;
 81+ case SMWDataItem::TYPE_CONCEPT:
 82+ if ( count( $dbkeys ) >= 5 ) {
 83+ new SMWDIConcept( $dbkeys[0], smwfXMLContentEncode( $dbkeys[1] ), $dbkeys[2], $dbkeys[3], $dbkeys[4], $typeid );
 84+ }
 85+ break;
 86+ case SMWDataItem::TYPE_PROPERTY:
 87+ return new SMWDIProperty( $dbkeys[0], false, $typeid );
 88+ case SMWDataItem::TYPE_NOTYPE:
 89+ if ( ( $typeid != '' ) && ( $typeid{0} != '_' ) ) { // linear conversion type
 90+ return SMWDINumber::doUnserialize( $dbkeys[0], $typeid );
 91+ }
 92+ }
 93+ throw new SMWDataItemException( 'Failed to create data item from DB keys.' );
 94+ }
 95+
 96+ /**
 97+ * Compatibility function for computing the old getDBkeys() array for the new SMW data items.
 98+ */
 99+ public static function getDBkeysFromDataItem( SMWDataItem $dataItem ) {
 100+ switch ( $dataItem->getTypeId() ) {
 101+ case '_txt': case '_cod': case '_str': case '__sps': case '__tls': case '__imp':
 102+ if ( $dataItem->getDIType() !== SMWDataItem::TYPE_STRING ) break;
 103+ return array( $dataItem->getString() );
 104+ case '_ema': case '_uri': case '_anu': case '_tel': case '__spu':
 105+ if ( $dataItem->getDIType() !== SMWDataItem::TYPE_URI ) break;
 106+ return array( $dataItem->getSerialization() );
 107+ case '_wpg': case '_wpp': case '_wpc': case '_wpf': case '__sup':
 108+ case '__suc': case '__spf': case '__sin': case '__red':
 109+ if ( $dataItem->getDIType() !== SMWDataItem::TYPE_WIKIPAGE ) break;
 110+ return array( $dataItem->getDBkey(), $dataItem->getNamespace(), $dataItem->getInterwiki(), $dataItem->getDBkey() );
 111+ case '_num': case '_tem': case '__lin':
 112+ if ( $dataItem->getDIType() !== SMWDataItem::TYPE_NUMBER ) break;
 113+ return array( $dataItem->getSerialization(), floatval( $dataItem->getNumber() ) );
 114+ case '_dat':
 115+ if ( $dataItem->getDIType() !== SMWDataItem::TYPE_TIME ) break;
 116+ $xsdvalue = $dataItem->getYear() . "/" .
 117+ ( ( $dataItem->getPrecision() >= SMWDITime::PREC_YM ) ? $dataItem->getMonth() : '' ) . "/" .
 118+ ( ( $dataItem->getPrecision() >= SMWDITime::PREC_YMD ) ? $dataItem->getDay() : '' ) . "T";
 119+ if ( $dataItem->getPrecision() == SMWDITime::PREC_YMDT ) {
 120+ $xsdvalue .= sprintf( "%02d", $dataItem->getHour() ) . ':' .
 121+ sprintf( "%02d", $dataItem->getMinute()) . ':' .
 122+ sprintf( "%02d", $dataItem->getSecond() );
 123+ }
 124+ return array( $xsdvalue, $dataItem->getSortKey() );
 125+ case '_boo':
 126+ if ( $dataItem->getDIType() !== SMWDataItem::TYPE_BOOLEAN ) break;
 127+ return $dataItem->getBoolean() ? array( '1', 1 ) : array( '0', 0 );
 128+ case '_rec':
 129+ if ( $dataItem->getDIType() !== SMWDataItem::TYPE_CONTAINER ) break;
 130+ return array( false );
 131+ case '__typ':
 132+ if ( $dataItem->getDIType() !== SMWDataItem::TYPE_WIKIPAGE ) break;
 133+ return array( SMWDataValueFactory::findTypeID( str_replace( '_', ' ', $dataItem->getDBkey() ) ) );
 134+ case '__con':
 135+ if ( $dataItem->getDIType() !== SMWDataItem::TYPE_CONCEPT ) break;
 136+ array( $dataItem->getConceptQuery(), $dataItem->getDocumentation(), $dataItem->getQueryFeatures(), $dataItem->getSize(), $dataItem->getDepth() );
 137+ case '__err':
 138+ return array( false );
 139+ case '__pro':
 140+ if ( $dataItem->getDIType() !== SMWDataItem::TYPE_PROPERTY ) break;
 141+ return array( $dataItem->getKey() );
 142+ default:
 143+ $typeid = $dataItem->getTypeId();
 144+ if ( ( $typeid != '' ) && ( $typeid{0} != '_' ) &&
 145+ ( $dataItem->getDIType() == SMWDataItem::TYPE_NUMBER ) ) { // linear conversion type
 146+ return array( $dataItem->getSerialization(), floatval( $dataItem->getNumber() ) );
 147+ }
 148+ }
 149+ return array( false );
 150+ }
 151+
 152+ /**
 153+ * Find the sortkey for a SMWDIWikiPage.
 154+ * @bug Not correct. Only an intermediate solution.
 155+ */
 156+ public static function getSortKey( SMWDIWikiPage $wikiPage ) {
 157+ return str_replace( '_', ' ', $wikiPage->getDBkey() );
 158+ }
 159+
 160+}
\ No newline at end of file
Property changes on: trunk/extensions/SemanticMediaWiki/includes/SMW_Compatibility_Helpers.php
___________________________________________________________________
Added: svn:eol-style
1161 + native
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php
@@ -1,8 +1,7 @@
22 <?php
33 /**
4 - * The class in this file manages (special) mProperties that are
5 - * associated with a certain subject (article). It is used as a
6 - * container for chunks of subject-centred data.
 4+ * The class in this file provides a container for chunks of subject-centred
 5+ * data.
76 *
87 * @file
98 * @ingroup SMW
@@ -13,45 +12,54 @@
1413
1514 /**
1615 * Class for representing chunks of semantic data for one given
17 - * article (subject), similar what is typically displayed in the factbox.
 16+ * article (subject), similar what is typically displayed in the Factbox.
1817 * This is a light-weight data container.
 18+ *
 19+ * By its very design, the container is unable to hold inverse properties.
 20+ * For one thing, it would not be possible to identify them with mere keys.
 21+ * Since SMW cannot annotate pages with inverses, this is not a limitation.
1922 *
2023 * @ingroup SMW
2124 */
2225 class SMWSemanticData {
2326
2427 /**
25 - * States whether this is a stub object. Stubbing might happen on serialisation to save DB space.
 28+ * Cache for the localized version of the namespace prefix "Property:".
2629 *
27 - * @var boolean
 30+ * @var string
2831 */
29 - public $stubObject = true;
 32+ static protected $mPropertyPrefix = '';
3033
3134 /**
32 - * Cache for the local version of "Property:"
 35+ * States whether this is a stub object. Stubbing might happen on
 36+ * serialisation to save DB space.
3337 *
34 - * @var mixed
 38+ * @todo Check why this is public and document this here. Or fix it.
 39+ *
 40+ * @var boolean
3541 */
36 - static protected $mPropertyPrefix = false;
 42+ public $stubObject;
3743
3844 /**
39 - * Text keys and arrays of datavalue objects.
 45+ * Array mapping property keys (string) to arrays of SMWDataItem
 46+ * objects.
4047 *
4148 * @var array
4249 */
43 - protected $mPropVals = array();
 50+ protected $mPropVals;
4451
4552 /**
46 - * Text keys and title objects.
 53+ * Array mapping property keys (string) to SMWDIProperty objects.
4754 *
4855 * @var array
4956 */
50 - protected $mProperties = array();
 57+ protected $mProperties;
5158
5259 /**
53 - * Stub property data that is not part of $propvals and $mProperties yet. Entries use
54 - * property DB keys as keys. The value is an array of DBkey-arrays that define individual
55 - * datavalues. The stubs will be set up when first accessed.
 60+ * Stub property data that is not part of $mPropVals and $mProperties
 61+ * yet. Entries use property keys as keys. The value is an array of
 62+ * DBkey-arrays that define individual datavalues. The stubs will be
 63+ * set up when first accessed.
5664 *
5765 * @var array
5866 */
@@ -65,39 +73,47 @@
6674 protected $mHasVisibleProps = false;
6775
6876 /**
69 - * States whether the container holds any displayable special mProperties (some are internal only without a display name).
 77+ * States whether the container holds any displayable predefined
 78+ * $mProperties (as opposed to predefined properties without a display
 79+ * label). For some settings we need this to decide if a Factbox is
 80+ * displayed.
7081 *
7182 * @var boolean
7283 */
7384 protected $mHasVisibleSpecs = false;
7485
7586 /**
76 - * States whether repeated values should be avoided. Not needing duplicte elimination
77 - * (e.g. when loading from store) can save much time, since objects can remain stubs until someone
78 - * really acesses their value.
 87+ * States whether repeated values should be avoided. Not needing
 88+ * duplicate elimination (e.g. when loading from store) can save much
 89+ * time, since objects can remain stubs until someone really acesses
 90+ * their value.
 91+ *
 92+ * @note This setting is merely for optimization. The SMW data model
 93+ * never cares about the multiplicity of identical data assignments.
7994 *
8095 * @var boolean
8196 */
8297 protected $mNoDuplicates;
8398
8499 /**
85 - * SMWWikiPageValue object that is the subject of this container.
86 - * Subjects that are NULL are used to represent "internal objects" only.
 100+ * SMWDIWikiPage object that is the subject of this container.
 101+ * Subjects that are null are used to represent "internal objects"
 102+ * only.
87103 *
88 - * @var SMWWikiPageValue
 104+ * @var SMWDIWikiPage
89105 */
90106 protected $mSubject;
91107
92108 /**
93109 * Constructor.
94110 *
95 - * @param SMWWikiPageValue $subject
96 - * @param boolean $noDuplicates
 111+ * @param $subject SMWDIWikiPage to which this data refers
 112+ * @param $noDuplicates boolean stating if duplicate data should be avoided
97113 */
98 - public function __construct( $subject, $noDuplicates = true ) {
 114+ public function __construct( SMWDIWikiPage $subject, $noDuplicates = true ) {
 115+ $this->clear();
99116 $this->mSubject = $subject;
100117 $this->mNoDuplicates = $noDuplicates;
101 - $this->stubObject = false;
102118 }
103119
104120 /**
@@ -118,7 +134,7 @@
119135 /**
120136 * Return subject to which the stored semantic annotation refer to.
121137 *
122 - * @return SMWWikiPageValue subject
 138+ * @return SMWDIWikiPage subject
123139 */
124140 public function getSubject() {
125141 return $this->mSubject;
@@ -126,6 +142,8 @@
127143
128144 /**
129145 * Get the array of all properties that have stored values.
 146+ *
 147+ * @return array of SMWDIProperty objects
130148 */
131149 public function getProperties() {
132150 $this->unstubProperties();
@@ -137,40 +155,45 @@
138156 /**
139157 * Get the array of all stored values for some property.
140158 *
141 - * @param SMWPropertyValue $property
142 - *
143 - * @return array
 159+ * @param $property SMWDIProperty
 160+ * @return array of SMWDataItem
144161 */
145 - public function getPropertyValues( SMWPropertyValue $property ) {
146 - if ( array_key_exists( $property->getDBkey(), $this->mStubPropVals ) ) {
147 - // Unstub those entries completely.
148 - $this->unstubProperty( $property->getDBkey(), $property );
 162+ public function getPropertyValues( SMWDIProperty $property ) {
 163+ if ( $property->isInverse() ) { // we never have any data for inverses
 164+ return array();
 165+ }
149166
150 - foreach ( $this->mStubPropVals[$property->getDBkey()] as $dbkeys ) {
151 - $dv = SMWDataValueFactory::newPropertyObjectValue( $property );
152 - $dv->setDBkeys( $dbkeys );
 167+ if ( array_key_exists( $property->getKey(), $this->mStubPropVals ) ) {
 168+ $this->unstubProperty( $property->getKey(), $property );
153169
154 - if ( $this->mNoDuplicates ) {
155 - $this->mPropVals[$property->getDBkey()][$dv->getHash()] = $dv;
156 - } else {
157 - $this->mPropVals[$property->getDBkey()][] = $dv;
 170+ foreach ( $this->mStubPropVals[$property->getKey()] as $dbkeys ) {
 171+ try {
 172+ $di = SMWCompatibilityHelpers::dataItemFromDBKeys( $property->findPropertyTypeID(), $dbkeys );
 173+ if ( $this->mNoDuplicates ) {
 174+ $this->mPropVals[$property->getKey()][$di->getHash()] = $di;
 175+ } else {
 176+ $this->mPropVals[$property->getKey()][] = $di;
 177+ }
 178+ } catch ( SMWDataItemException $e ) {
 179+ // ignore data
158180 }
159181 }
160182
161 - unset( $this->mStubPropVals[$property->getDBkey()] );
 183+ unset( $this->mStubPropVals[$property->getKey()] );
162184 }
163185
164 - if ( array_key_exists( $property->getDBkey(), $this->mPropVals ) ) {
165 - return $this->mPropVals[$property->getDBkey()];
 186+ if ( array_key_exists( $property->getKey(), $this->mPropVals ) ) {
 187+ return $this->mPropVals[$property->getKey()];
166188 } else {
167189 return array();
168190 }
169191 }
170192
171193 /**
172 - * Generate a hash value to simplify the comparison of this data container with other
173 - * containers. The hash uses PHP's md5 implementation, which is among the fastest hash
174 - * algorithms that PHP offers.
 194+ * Generate a hash value to simplify the comparison of this data
 195+ * container with other containers. The hash uses PHP's md5
 196+ * implementation, which is among the fastest hash algorithms that
 197+ * PHP offers.
175198 *
176199 * @return string
177200 */
@@ -178,14 +201,14 @@
179202 $ctx = hash_init( 'md5' );
180203
181204 if ( $this->mSubject !== null ) { // here and below, use "_#_" to separate values; really not much care needed here
182 - hash_update( $ctx, '_#_' . $this->mSubject->getHash() );
 205+ hash_update( $ctx, '_#_' . $this->mSubject->getSerialisation() );
183206 }
184207
185208 foreach ( $this->getProperties() as $property ) {
186 - hash_update( $ctx, '_#_' . $property->getHash() . '##' );
 209+ hash_update( $ctx, '_#_' . $property->getKey() . '##' );
187210
188211 foreach ( $this->getPropertyValues( $property ) as $dv ) {
189 - hash_update( $ctx, '_#_' . $dv->getHash() );
 212+ hash_update( $ctx, '_#_' . $dv->getSerialisation() );
190213 }
191214 }
192215
@@ -195,8 +218,9 @@
196219 /**
197220 * Return true if there are any visible properties.
198221 *
199 - * @note While called "visible" this check actually refers to the function
200 - * SMWPropertyValue::isShown(). The name is kept for compatibility.
 222+ * @note While called "visible" this check actually refers to the
 223+ * function SMWDIProperty::isShown(). The name is kept for
 224+ * compatibility.
201225 *
202226 * @return boolean
203227 */
@@ -209,8 +233,9 @@
210234 * Return true if there are any special properties that can
211235 * be displayed.
212236 *
213 - * @note While called "visible" this check actually refers to the function
214 - * SMWPropertyValue::isShown(). The name is kept for compatibility.
 237+ * @note While called "visible" this check actually refers to the
 238+ * function SMWDIProperty::isShown(). The name is kept for
 239+ * compatibility.
215240 *
216241 * @return boolean
217242 */
@@ -220,30 +245,30 @@
221246 }
222247
223248 /**
224 - * Store a value for a property identified by its title object. Duplicate
225 - * value entries are usually ignored.
 249+ * Store a value for a property identified by its SMWDataItem object.
226250 *
227 - * @note Attention: there is no check whether the type of the given datavalue agrees
228 - * with what SMWDataValueFactory is producing (based on predefined property records and
229 - * the current DB content). Always use SMWDataValueFactory to produce fitting values!
 251+ * @note There is no check whether the type of the given data item
 252+ * agrees with the type of the property. Since property types can
 253+ * change, all parts of SMW are prepared to handle mismatched data item
 254+ * types anyway.
230255 *
231 - * @param SMWPropertyValue $property
232 - * @param SMWDataValue $value
 256+ * @param $property SMWDIProperty
 257+ * @param $dataItem SMWDataItem
233258 */
234 - public function addPropertyObjectValue( SMWPropertyValue $property, SMWDataValue $value ) {
235 - if ( !$property->isValid() ) {
236 - return; // nothing we can do
 259+ public function addPropertyObjectValue( SMWDIProperty $property, SMWDataItem $dataItem ) {
 260+ if ( $property->isInverse() ) { // inverse properties cannot be used for annotation
 261+ return;
237262 }
238263
239 - if ( !array_key_exists( $property->getDBkey(), $this->mPropVals ) ) {
240 - $this->mPropVals[$property->getDBkey()] = array();
241 - $this->mProperties[$property->getDBkey()] = $property;
 264+ if ( !array_key_exists( $property->getKey(), $this->mPropVals ) ) {
 265+ $this->mPropVals[$property->getKey()] = array();
 266+ $this->mProperties[$property->getKey()] = $property;
242267 }
243268
244269 if ( $this->mNoDuplicates ) {
245 - $this->mPropVals[$property->getDBkey()][$value->getHash()] = $value;
 270+ $this->mPropVals[$property->getKey()][$dataItem->getHash()] = $dataItem;
246271 } else {
247 - $this->mPropVals[$property->getDBkey()][] = $value;
 272+ $this->mPropVals[$property->getKey()][] = $dataItem;
248273 }
249274
250275 if ( !$property->isUserDefined() ) {
@@ -257,31 +282,33 @@
258283 }
259284
260285 /**
261 - * Store a value for a given property identified by its text label (without
262 - * namespace prefix). Duplicate value entries are usually ignored.
 286+ * Store a value for a given property identified by its text label
 287+ * (without namespace prefix).
263288 *
264 - * @param string $propertyName
265 - * @param SMWDataValue $value
 289+ * @param $propertyName string
 290+ * @param $dataItem SMWDataItem
266291 */
267 - public function addPropertyValue( $propertyName, SMWDataValue $value ) {
268 - $propertykey = smwfNormalTitleDBKey( $propertyName );
 292+ public function addPropertyValue( $propertyName, SMWDataItem $dataItem ) {
 293+ $propertyKey = smwfNormalTitleDBKey( $propertyName );
269294
270 - if ( array_key_exists( $propertykey, $this->mProperties ) ) {
271 - $property = $this->mProperties[$propertykey];
 295+ if ( array_key_exists( $propertyKey, $this->mProperties ) ) {
 296+ $property = $this->mProperties[$propertyKey];
272297 } else {
273 - if ( self::$mPropertyPrefix == false ) {
 298+ if ( SMWSemanticData::$mPropertyPrefix == '' ) {
274299 global $wgContLang;
275 - self::$mPropertyPrefix = $wgContLang->getNsText( SMW_NS_PROPERTY ) . ':';
 300+ SMWSemanticData::$mPropertyPrefix = $wgContLang->getNsText( SMW_NS_PROPERTY ) . ':';
276301 } // explicitly use prefix to cope with things like [[Property:User:Stupid::somevalue]]
277302
278 - $property = SMWPropertyValue::makeUserProperty( self::$mPropertyPrefix . $propertyName );
 303+ $propertyDV = SMWPropertyValue::makeUserProperty( SMWSemanticData::$mPropertyPrefix . $propertyName );
279304
280 - if ( !$property->isValid() ) { // error, maybe illegal title text
 305+ if ( !$propertyDV->isValid() ) { // error, maybe illegal title text
281306 return;
282307 }
 308+
 309+ $property = $propertyDV->getDataItem();
283310 }
284311
285 - $this->addPropertyObjectValue( $property, $value );
 312+ $this->addPropertyObjectValue( $property, $dataItem );
286313 }
287314
288315 /**
@@ -290,12 +317,12 @@
291318 * the added value that will be used to initialize the value if needed at some point.
292319 */
293320 public function addPropertyStubValue( $propertyKey, $valueKeys ) {
294 - // Catch built-in mProperties, since their internal key is not what is used as a key elsewhere in SMWSemanticData.
295 - if ( $propertyKey { 0 } == '_' ) {
296 - $property = SMWPropertyValue::makeProperty( $propertyKey );
297 - $propertyKey = $property->getDBkey();
298 - $this->unstubProperty( $propertyKey, $property );
299 - }
 321+ // Catch built-in properties, since their internal key is not what is used as a key elsewhere in SMWSemanticData.
 322+// if ( $propertyKey { 0 } == '_' ) {
 323+// $property = new SMWDIProperty( $propertyKey );
 324+// $propertyKey = $property->getKey();
 325+// $this->unstubProperty( $propertyKey, $property );
 326+// }
300327
301328 $this->mStubPropVals[$propertyKey][] = $valueKeys;
302329 }
@@ -309,14 +336,16 @@
310337 $this->mStubPropVals = array();
311338 $this->mHasVisibleProps = false;
312339 $this->mHasVisibleSpecs = false;
 340+ $this->stubObject = false;
313341 }
314342
315343 /**
316 - * Process all mProperties that have been added as stubs. Associated data may remain in stub form.
 344+ * Process all mProperties that have been added as stubs.
 345+ * Associated data may remain in stub form.
317346 */
318347 protected function unstubProperties() {
319 - foreach ( $this->mStubPropVals as $pname => $values ) { // unstub property values only, the value lists are still kept as stubs
320 - $this->unstubProperty( $pname );
 348+ foreach ( $this->mStubPropVals as $pkey => $values ) { // unstub property values only, the value lists are still kept as stubs
 349+ $this->unstubProperty( $pkey );
321350 }
322351 }
323352
@@ -325,19 +354,21 @@
326355 * for that property might be provided, so we do not need to make a new one. It is not
327356 * checked if the object matches the property name.
328357 *
329 - * @param string $propertyName
330 - * @param $propertyObject
 358+ * @param $propertyKey string
 359+ * @param SMWDIProperty $diProperty
331360 */
332 - protected function unstubProperty( $propertyName, $propertyObject = null ) {
333 - if ( !array_key_exists( $propertyName, $this->mProperties ) ) {
334 - if ( $propertyObject === null ) {
335 - $propertyObject = SMWPropertyValue::makeProperty( $propertyName );
 361+ protected function unstubProperty( $propertyKey, $diProperty = null ) {
 362+ if ( !array_key_exists( $propertyKey, $this->mProperties ) ) {
 363+ if ( $diProperty === null ) {
 364+ //$propertyDV = SMWPropertyValue::makeProperty( $propertyKey );
 365+ //$diProperty = $propertyDV->getDataItem();
 366+ $diProperty = new SMWDIProperty( $propertyKey, false );
336367 }
337368
338 - $this->mProperties[$propertyName] = $propertyObject;
 369+ $this->mProperties[$propertyKey] = $diProperty;
339370
340 - if ( !$propertyObject->isUserDefined() ) {
341 - if ( $propertyObject->isShown() ) {
 371+ if ( !$diProperty->isUserDefined() ) {
 372+ if ( $diProperty->isShown() ) {
342373 $this->mHasVisibleSpecs = true;
343374 $this->mHasVisibleProps = true;
344375 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php
@@ -43,11 +43,26 @@
4444 /**
4545 * Array of class names for creating new SMWDataValue, indexed by type id.
4646 *
47 - * @var array of SMWDataValue
 47+ * @var array of string
4848 */
4949 static private $mTypeClasses;
5050
5151 /**
 52+ * Array of data item classes, indexed by type id.
 53+ *
 54+ * @note This is only used for transition. Data items will not be created directly by SMWDataValueFactory in the future.
 55+ * @var array of string
 56+ */
 57+ static private $mTypeDiClasses;
 58+
 59+ /**
 60+ * Array of data item classes, indexed by type id.
 61+ *
 62+ * @var array of integer
 63+ */
 64+ static private $mTypeDataItemIds;
 65+
 66+ /**
5267 * Create an SMWDataValue object that can hold values for the type that the
5368 * given SMWTypesValue object specifies. If no $value is given, an empty
5469 * container is created, the value of which can be set later on.
@@ -55,7 +70,7 @@
5671 * @param SMWTypesValue $typevalue Represents the type of the object
5772 * @param mixed $value user value string, or false if unknown
5873 * @param mixed $caption user-defined caption or false if none given
59 - * @param $property SMWPropertyValue property object for which this value was made, or NULL
 74+ * @param SMWDIProperty $property property object for which this value was made, or null
6075 */
6176 static public function newTypeObjectValue( SMWTypesValue $typeValue, $value = false, $caption = false, $property = null ) {
6277 if ( !$typeValue->isValid() ) { // just return the error, pass it through
@@ -73,13 +88,13 @@
7489 * is created, the value of which can be set later on.
7590 *
7691 * @param $typeid id string for the given type
77 - * @param mixed $value user value string, or false if unknown
78 - * @param mixed $caption user-defined caption or false if none given
79 - * @param SMWPropertyValue $property Property object for which this value was made, or NULL
 92+ * @param $value mixed user value string, or false if unknown
 93+ * @param $caption mixed user-defined caption, or false if none given
 94+ * @param $property SMWDIProperty property object for which this value is made, or NULL
8095 *
8196 * @return SMWDataValue
8297 */
83 - static public function newTypeIDValue( $typeid, $value = false, $caption = false, $property = null ) {
 98+ static public function newTypeIdValue( $typeid, $value = false, $caption = false, $property = null ) {
8499 self::initDatatypes();
85100
86101 if ( array_key_exists( $typeid, self::$mTypeClasses ) ) { // direct response for basic types
@@ -88,7 +103,7 @@
89104 $result = new self::$mTypeClasses['__lin']( $typeid );
90105 } else { // type really unknown
91106 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
92 - return new SMWErrorValue( wfMsgForContent( 'smw_unknowntype', $typeid ), $value, $caption );
 107+ return new SMWErrorValue( $typeid, wfMsgForContent( 'smw_unknowntype', $typeid ), $value, $caption );
93108 }
94109
95110 if ( $property !== null ) {
@@ -102,21 +117,57 @@
103118 }
104119
105120 /**
106 - * Create a value for the given property, provided as an SMWPropertyValue
 121+ * Create a value for a data item.
 122+ *
 123+ * @param SMWDataItem $typeid id string for the given type
 124+ * @param mixed $caption user-defined caption, or false if none given
 125+ * @param SMWDIProperty $property property object for which this value is made, or NULL
 126+ *
 127+ * @return SMWDataValue
 128+ */
 129+ static public function newDataItemValue( SMWDataItem $dataItem, $caption = false, $property = null ) {
 130+ $result = self::newTypeIdValue( $dataItem->getTypeID(), false, $caption, $property );
 131+ $result->setDataItem( $dataItem );
 132+ if ( $caption !== false ) {
 133+ $result->setCaption( $caption );
 134+ }
 135+ return $result;
 136+ }
 137+
 138+
 139+ /**
 140+ * Get the preferred data item ID for a given type. The ID defines the
 141+ * appropriate data item class for processing data of this type. See
 142+ * SMWDataItem for possible values.
 143+ *
 144+ * @param $typeid id string for the given type
 145+ * @return integer data item ID
 146+ */
 147+ static public function getDataItemId( $typeid ) {
 148+ self::initDatatypes();
 149+ if ( array_key_exists( $typeid, self::$mTypeDataItemIds ) ) {
 150+ return self::$mTypeDataItemIds[$typeid];
 151+ } else {
 152+ return SMWDataItem::TYPE_NOTYPE;
 153+ }
 154+ }
 155+
 156+ /**
 157+ * Create a value for the given property, provided as an SMWDIProperty
107158 * object. If no value is given, an empty container is created, the value
108159 * of which can be set later on.
109160 *
110 - * @param SMWPropertyValue $property
111 - * @param mixed $value
112 - * @param mixed $caption
 161+ * @param $property SMWDIProperty
 162+ * @param $value mixed
 163+ * @param $caption mixed
113164 *
114165 * @return SMWDataValue
115166 */
116 - static public function newPropertyObjectValue( SMWPropertyValue $property, $value = false, $caption = false ) {
 167+ static public function newPropertyObjectValue( SMWDIProperty $property, $value = false, $caption = false ) {
117168 if ( $property->isInverse() ) {
118169 return self::newTypeIdValue( '_wpg', $value, $caption, $property );
119170 } else {
120 - return self::newTypeIDValue( $property->getPropertyTypeID(), $value, $caption, $property );
 171+ return self::newTypeIdValue( $property->findPropertyTypeID(), $value, $caption, $property );
121172 }
122173 }
123174
@@ -172,6 +223,74 @@
173224 '__pro' => 'SMWPropertyValue', // Property type (possibly predefined, no always based on a page)
174225 );
175226
 227+ self::$mTypeDiClasses = array(
 228+ '_txt' => 'SMWDIBlob', // Text type
 229+ '_cod' => 'SMWDIBlob', // Code type
 230+ '_str' => 'SMWDIString', // String type
 231+ '_ema' => 'SMWDIUri', // Email type
 232+ '_uri' => 'SMWDIUri', // URL/URI type
 233+ '_anu' => 'SMWDIUri', // Annotation URI type
 234+ '_tel' => 'SMWDIUri', // Phone number (URI) type
 235+ '_wpg' => 'SMWDIWikiPage', // Page type
 236+ '_wpp' => 'SMWDIWikiPage', // Property page type TODO: make available to user space
 237+ '_wpc' => 'SMWDIWikiPage', // Category page type TODO: make available to user space
 238+ '_wpf' => 'SMWDIWikiPage', // Form page type for Semantic Forms
 239+ '_num' => 'SMWDINumber', // Number type
 240+ '_tem' => 'SMWDINumber', // Temperature type
 241+ '_dat' => 'SMWDITime', // Time type
 242+ '_boo' => 'SMWDIBoolean', // Boolean type
 243+ '_rec' => 'SMWDIContainer', // Value list type (replacing former nary properties)
 244+ // Special types are not avaialble directly for users (and have no local language name):
 245+ '__typ' => 'SMWDIWikiPage', // Special type page type
 246+ '__tls' => 'SMWDIString', // Special type list for decalring _rec properties
 247+ '__con' => 'SMWDIConcept', // Special concept page type
 248+ '__sps' => 'SMWDIString', // Special string type
 249+ '__spu' => 'SMWDIUri', // Special uri type
 250+ '__sup' => 'SMWDIWikiPage', // Special subproperty type
 251+ '__suc' => 'SMWDIWikiPage', // Special subcategory type
 252+ '__spf' => 'SMWDIWikiPage', // Special Form page type for Semantic Forms
 253+ '__sin' => 'SMWDIWikiPage', // Special instance of type
 254+ '__red' => 'SMWDIWikiPage', // Special redirect type
 255+ '__lin' => 'SMWDINumber', // Special linear unit conversion type
 256+ '__err' => 'SMWDIString', // Special error type
 257+ '__imp' => 'SMWDIString', // Special import vocabulary type
 258+ '__pro' => 'SMWDIProperty', // Property type (possibly predefined, no always based on a page)
 259+ );
 260+
 261+ self::$mTypeDataItemIds = array(
 262+ '_txt' => SMWDataItem::TYPE_BLOB, // Text type
 263+ '_cod' => SMWDataItem::TYPE_BLOB, // Code type
 264+ '_str' => SMWDataItem::TYPE_STRING, // String type
 265+ '_ema' => SMWDataItem::TYPE_URI, // Email type
 266+ '_uri' => SMWDataItem::TYPE_URI, // URL/URI type
 267+ '_anu' => SMWDataItem::TYPE_URI, // Annotation URI type
 268+ '_tel' => SMWDataItem::TYPE_URI, // Phone number (URI) type
 269+ '_wpg' => SMWDataItem::TYPE_WIKIPAGE, // Page type
 270+ '_wpp' => SMWDataItem::TYPE_WIKIPAGE, // Property page type TODO: make available to user space
 271+ '_wpc' => SMWDataItem::TYPE_WIKIPAGE, // Category page type TODO: make available to user space
 272+ '_wpf' => SMWDataItem::TYPE_WIKIPAGE, // Form page type for Semantic Forms
 273+ '_num' => SMWDataItem::TYPE_NUMBER, // Number type
 274+ '_tem' => SMWDataItem::TYPE_NUMBER, // Temperature type
 275+ '_dat' => SMWDataItem::TYPE_TIME, // Time type
 276+ '_boo' => SMWDataItem::TYPE_BOOLEAN, // Boolean type
 277+ '_rec' => SMWDataItem::TYPE_CONTAINER, // Value list type (replacing former nary properties)
 278+ // Special types are not avaialble directly for users (and have no local language name):
 279+ '__typ' => SMWDataItem::TYPE_WIKIPAGE, // Special type page type
 280+ '__tls' => SMWDataItem::TYPE_STRING, // Special type list for decalring _rec properties
 281+ '__con' => SMWDataItem::TYPE_CONCEPT, // Special concept page type
 282+ '__sps' => SMWDataItem::TYPE_STRING, // Special string type
 283+ '__spu' => SMWDataItem::TYPE_URI, // Special uri type
 284+ '__sup' => SMWDataItem::TYPE_WIKIPAGE, // Special subproperty type
 285+ '__suc' => SMWDataItem::TYPE_WIKIPAGE, // Special subcategory type
 286+ '__spf' => SMWDataItem::TYPE_WIKIPAGE, // Special Form page type for Semantic Forms
 287+ '__sin' => SMWDataItem::TYPE_WIKIPAGE, // Special instance of type
 288+ '__red' => SMWDataItem::TYPE_WIKIPAGE, // Special redirect type
 289+ '__lin' => SMWDataItem::TYPE_NUMBER, // Special linear unit conversion type
 290+ '__err' => SMWDataItem::TYPE_STRING, // Special error type
 291+ '__imp' => SMWDataItem::TYPE_STRING, // Special import vocabulary type
 292+ '__pro' => SMWDataItem::TYPE_PROPERTY, // Property type (possibly predefined, no always based on a page)
 293+ );
 294+
176295 wfRunHooks( 'smwInitDatatypes' );
177296 }
178297
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Number.php
@@ -34,6 +34,10 @@
3535 return $this->m_number;
3636 }
3737
 38+ public function getSortKey() {
 39+ return $this->m_number;
 40+ }
 41+
3842 public function getSerialization() {
3943 return strval( $this->m_number );
4044 }
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Error.php
@@ -0,0 +1,53 @@
 2+<?php
 3+/**
 4+ * @file
 5+ * @ingroup SMWDataItems
 6+ */
 7+
 8+/**
 9+ * This class implements error list data items. These data items are used to
 10+ * pass around lists of error messages within the application. They are not
 11+ * meant to be stored or exported, but they can be useful to a user.
 12+ *
 13+ * @author Markus Krötzsch
 14+ * @ingroup SMWDataItems
 15+ */
 16+class SMWDIError extends SMWDataItem {
 17+
 18+ /**
 19+ * List of error messages. Should always be safe for HTML.
 20+ * @var array of strings
 21+ */
 22+ protected $m_errors;
 23+
 24+ public function __construct( $errors, $typeid = '__err' ) {
 25+ parent::__construct( $typeid );
 26+ $this->m_errors = $errors;
 27+ }
 28+
 29+ public function getDIType() {
 30+ return SMWDataItem::TYPE_ERROR;
 31+ }
 32+
 33+ public function getErrors() {
 34+ return $this->m_errors;
 35+ }
 36+
 37+ public function getSortKey() {
 38+ return 'error';
 39+ }
 40+
 41+ public function getSerialization() {
 42+ return serialize( $this->m_errors );
 43+ }
 44+
 45+ /**
 46+ * Create a data item from the provided serialization string and type
 47+ * ID.
 48+ * @return SMWDIError
 49+ */
 50+ public static function doUnserialize( $serialization, $typeid ) {
 51+ return new SMWDIError( unserialize( $serialization ), $typeid );
 52+ }
 53+
 54+}
Property changes on: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Error.php
___________________________________________________________________
Added: svn:eol-style
155 + native
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Bool.php
@@ -10,7 +10,7 @@
1111 * @author Markus Krötzsch
1212 * @ingroup SMWDataItems
1313 */
14 -class SMWDIBool extends SMWDataItem {
 14+class SMWDIBoolean extends SMWDataItem {
1515
1616 /**
1717 * Internal value.
@@ -24,7 +24,7 @@
2525 }
2626
2727 public function getDIType() {
28 - return SMWDataItem::TYPE_BOOL;
 28+ return SMWDataItem::TYPE_BOOLEAN;
2929 }
3030
3131 public function getBoolean() {
@@ -35,16 +35,20 @@
3636 return $this->m_boolean ? 't' : 'f';
3737 }
3838
 39+ public function getSortKey() {
 40+ return $this->m_boolean ? 1 : 0;
 41+ }
 42+
3943 /**
4044 * Create a data item from the provided serialization string and type
4145 * ID.
42 - * @return SMWDIBool
 46+ * @return SMWDIBoolean
4347 */
4448 public static function doUnserialize( $serialization, $typeid ) {
4549 if ( $serialization == 't' ) {
46 - return new SMWDIBool( true, $typeid );
 50+ return new SMWDIBoolean( true, $typeid );
4751 } elseif ( $serialization == 'f' ) {
48 - return new SMWDIBool( true, $typeid );
 52+ return new SMWDIBoolean( true, $typeid );
4953 } else {
5054 throw new SMWDataItemException( "Boolean data item unserialised from illegal value '$serialization'" );
5155 }
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Concept.php
@@ -82,6 +82,10 @@
8383 return $this->m_depth;
8484 }
8585
 86+ public function getSortKey() {
 87+ return $this->m_docu;
 88+ }
 89+
8690 public function getSerialization() {
8791 return serialize( $this );
8892 }
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DataItem.php
@@ -42,28 +42,32 @@
4343 */
4444 abstract class SMWDataItem {
4545
 46+ /// Data item ID that can be used to indicate that no data item class is appropriate
 47+ const TYPE_NOTYPE = 0;
4648 /// Data item ID for SMWDINumber
47 - const TYPE_NUMBER = 1;
 49+ const TYPE_NUMBER = 1;
4850 /// Data item ID for SMWDIString
49 - const TYPE_STRING = 2;
 51+ const TYPE_STRING = 2;
5052 /// Data item ID for SMWDIBlob
51 - const TYPE_BLOB = 3;
52 - /// Data item ID for SMWDIBool
53 - const TYPE_BOOL = 4;
54 - /// Data item ID for SMWDIURI
55 - const TYPE_URI = 5;
 53+ const TYPE_BLOB = 3;
 54+ /// Data item ID for SMWDIBoolean
 55+ const TYPE_BOOLEAN = 4;
 56+ /// Data item ID for SMWDIUri
 57+ const TYPE_URI = 5;
5658 /// Data item ID for SMWDITimePoint
57 - const TYPE_TIME = 6;
 59+ const TYPE_TIME = 6;
5860 /// Data item ID for SMWDIGeoCoords
59 - const TYPE_GEO = 7;
 61+ const TYPE_GEO = 7;
6062 /// Data item ID for SMWDIContainer
61 - const TYPE_CONT = 8;
 63+ const TYPE_CONTAINER = 8;
6264 /// Data item ID for SMWDIWikiPage
63 - const TYPE_WIKIPAGE = 9;
 65+ const TYPE_WIKIPAGE = 9;
6466 /// Data item ID for SMWDIConcept
65 - const TYPE_CONCEPT = 10;
 67+ const TYPE_CONCEPT = 10;
6668 /// Data item ID for SMWDIProperty
67 - const TYPE_PROP = 11;
 69+ const TYPE_PROPERTY = 11;
 70+ /// Data item ID for SMWDIError
 71+ const TYPE_ERROR = 12;
6872
6973 /**
7074 * The SMW type ID that governs the handling of this data item.
@@ -99,14 +103,35 @@
100104 }
101105
102106 /**
 107+ * Return a value that can be used for sorting data of this type.
 108+ * If the data is of a numerical type, the sorting must be done in
 109+ * numerical order. If the data is a string, the data must be sorted
 110+ * alphabetically.
 111+ *
 112+ * @return float or string
 113+ */
 114+ abstract public function getSortKey();
 115+
 116+ /**
103117 * Get a UTF-8 encoded string serialization of this data item.
104118 * The serialisation should be concise and need not be pretty, but it
105 - * must allow unserialization. For this purpose
 119+ * must allow unserialization. Each subclass of SMWDataItem implements
 120+ * a static method doUnserialize() for this purpose.
106121 * @return string
107122 */
108123 abstract public function getSerialization();
109124
110125 /**
 126+ * Get a hash string for this data item. Might be overwritten in
 127+ * subclasses to obtain shorter or more efficient hashes.
 128+ *
 129+ * @return string
 130+ */
 131+ public function getHash() {
 132+ return $this->getSerialization();
 133+ }
 134+
 135+ /**
111136 * Create a data item from the provided serialization string and type
112137 * ID. This static method really needs to be re-implemented by each
113138 * data item class. It is given here only for reference. Note that PHP
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Blob.php
@@ -31,6 +31,10 @@
3232 return $this->m_string;
3333 }
3434
 35+ public function getSortKey() {
 36+ return $this->m_string;
 37+ }
 38+
3539 public function getSerialization() {
3640 return $this->m_string;
3741 }
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Time.php
@@ -110,16 +110,16 @@
111111 }
112112 parent::__construct( $typeid );
113113 $this->m_model = $calendarmodel;
114 - $this->m_year = $year;
115 - $this->m_month = $month !== false ? $month : 1;
116 - $this->m_day = $day !== false ? $day : 1;
117 - $this->m_hours = $hour !== false ? $hour : 0;
118 - $this->m_minutes = $minute !== false ? $minute : 0;
119 - $this->m_seconds = $second !== false ? $second : 0;
 114+ $this->m_year = intval( $year );
 115+ $this->m_month = $month != false ? intval( $month ) : 1;
 116+ $this->m_day = $day != false ? intval( $day ) : 1;
 117+ $this->m_hours = $hour !== false ? intval( $hour ) : 0;
 118+ $this->m_minutes = $minute !== false ? intval( $minute ) : 0;
 119+ $this->m_seconds = $second !== false ? intval( $second ) : 0;
120120 if ( ( $this->m_hours < 0 ) || ( $this->m_hours > 23 ) ||
121121 ( $this->m_minutes < 0 ) || ( $this->m_minutes > 59 ) ||
122122 ( $this->m_seconds < 0 ) || ( $this->m_seconds > 59 ) ||
123 - ( $this->m_month < 0 ) || ( $this->m_month > 12 ) ) {
 123+ ( $this->m_month < 1 ) || ( $this->m_month > 12 ) ) {
124124 throw new SMWDataItemException( "Part of the date is out of bounds." );
125125 }
126126 if ( $this->m_day > SMWDITime::getDayNumberForMonth( $this->m_month, $this->m_year, $this->m_model ) ) {
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_URI.php
@@ -10,7 +10,7 @@
1111 * @author Markus Krötzsch
1212 * @ingroup SMWDataItems
1313 */
14 -class SMWDIURI extends SMWDataItem {
 14+class SMWDIUri extends SMWDataItem {
1515
1616 /**
1717 * URI scheme such as "html" or "mailto".
@@ -87,6 +87,10 @@
8888 return $this->m_fragment;
8989 }
9090
 91+ public function getSortKey() {
 92+ return $this->getURI();
 93+ }
 94+
9195 public function getSerialization() {
9296 return $this->getURI();
9397 }
@@ -94,7 +98,7 @@
9599 /**
96100 * Create a data item from the provided serialization string and type
97101 * ID.
98 - * @return SMWDIURI
 102+ * @return SMWDIUri
99103 */
100104 public static function doUnserialize( $serialization, $typeid ) {
101105 $parts = explode( ':', $serialization, 2 ); // try to split "schema:rest"
@@ -114,7 +118,7 @@
115119 $hierpart = $parts[0];
116120 $fragment = ( count( $parts ) == 2 ) ? $parts[1] : '';
117121 }
118 - return new SMWDIURI( $scheme, $hierpart, $query, $fragment, $typeid );
 122+ return new SMWDIUri( $scheme, $hierpart, $query, $fragment, $typeid );
119123 }
120124
121125 }
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_WikiPage.php
@@ -62,6 +62,15 @@
6363 return $this->m_interwiki;
6464 }
6565
 66+ /**
 67+ * Get the sortkey of the wiki page data item. Note that this is not
 68+ * the sortkey that might have been set for the corresponding wiki
 69+ * page.
 70+ */
 71+ public function getSortKey() {
 72+ return $this->m_dbkey;
 73+ }
 74+
6675 public function getSerialization() {
6776 return strval( $this->m_dbkey . '#' . strval( $this->m_namespace ) . '#' . $this->m_interwiki );
6877 }
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_Property.php
@@ -53,6 +53,11 @@
5454 * @var boolean
5555 */
5656 protected $m_inverse;
 57+ /**
 58+ * Cache for property type ID.
 59+ * @var string
 60+ */
 61+ protected $m_proptypeid;
5762
5863 /**
5964 * Initialise a property. This constructor checks that keys of
@@ -81,7 +86,7 @@
8287 }
8388
8489 public function getDIType() {
85 - return SMWDataItem::TYPE_PROP;
 90+ return SMWDataItem::TYPE_PROPERTY;
8691 }
8792
8893 public function getKey() {
@@ -92,6 +97,10 @@
9398 return $this->m_inverse;
9499 }
95100
 101+ public function getSortKey() {
 102+ return $this->m_key;
 103+ }
 104+
96105 /**
97106 * Specifies whether values of this property should be shown in the
98107 * Factbox. A property may wish to prevent this if either
@@ -141,6 +150,26 @@
142151 }
143152
144153 /**
 154+ * Get an object of type SMWDIWikiPage that represents the page which
 155+ * relates to this property, or null if no such page exists. The latter
 156+ * can happen for special properties without user-readable label, and
 157+ * for inverse properties.
 158+ */
 159+ public function getDiWikiPage() {
 160+ if ( $this->m_inverse ) return null;
 161+ if ( $this->isUserDefined() ) {
 162+ $dbkey = $this->m_key;
 163+ } else {
 164+ $dbkey = str_replace( ' ', '_', $this->getLabel() );
 165+ }
 166+ try {
 167+ return new SMWDIWikiPage( $dbkey, SMW_NS_PROPERTY, '', '_wpp' );
 168+ } catch ( SMWDataItemException $e ) {
 169+ return null;
 170+ }
 171+ }
 172+
 173+ /**
145174 * Get the type ID of a predefined property, or '' if the property
146175 * is not predefined.
147176 * The function is guaranteed to return a type ID if isUserDefined()
@@ -155,6 +184,35 @@
156185 }
157186 }
158187
 188+ /**
 189+ * Find the property's type ID, either by looking up its predefined ID
 190+ * (if any) or by retrieving the relevant information from the store.
 191+ * If no type is stored for a user defined property, the global default
 192+ * type will be used.
 193+ *
 194+ * @return string type ID
 195+ */
 196+ public function findPropertyTypeID() {
 197+ global $smwgPDefaultType;
 198+ if ( !isset( $this->m_proptypeid ) ) {
 199+ if ( $this->isUserDefined() ) { // normal property
 200+ $diWikiPage = new SMWDIWikiPage( $this->getKey(), SMW_NS_PROPERTY, '' );
 201+ $typearray = smwfGetStore()->getPropertyValues( $diWikiPage, new SMWDIProperty( '_TYPE' ) );
 202+ if ( count( $typearray ) >= 1 ) { // some types given, pick one (hopefully unique)
 203+ $typeString = reset( $typearray );
 204+ $this->m_proptypeid = ( $typeString instanceOf SMWDIWikiPage ) ?
 205+ SMWDataValueFactory::findTypeID( $typeString->getDBKey() ) : '__err';
 206+ } elseif ( count( $typearray ) == 0 ) { // no type given
 207+ $this->m_proptypeid = $smwgPDefaultType;
 208+ }
 209+ } else { // pre-defined property
 210+ $this->m_proptypeid = $this->getPredefinedPropertyTypeID();
 211+ }
 212+ }
 213+ return $this->m_proptypeid;
 214+ }
 215+
 216+
159217 public function getSerialization() {
160218 return ( $this->m_inverse ? '-' : '' ) . $this->m_key ;
161219 }
Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Setup.php
@@ -109,6 +109,7 @@
110110 $wgAutoloadClasses['SMWDataValueFactory'] = $smwgIP . 'includes/SMW_DataValueFactory.php';
111111 $wgAutoloadClasses['SMWDataValue'] = $smwgIP . 'includes/SMW_DataValue.php';
112112 $wgAutoloadClasses['SMWQueryLanguage'] = $smwgIP . 'includes/SMW_QueryLanguage.php';
 113+ $wgAutoloadClasses['SMWCompatibilityHelpers'] = $smwgIP . 'includes/SMW_Compatibility_Helpers.php';
113114
114115 // Article pages
115116 $apDir = $smwgIP . 'includes/articlepages/';
@@ -135,15 +136,16 @@
136137 $wgAutoloadClasses['SMWDataItem'] = $diDir . 'SMW_DataItem.php';
137138 $wgAutoloadClasses['SMWDataItemException'] = $diDir . 'SMW_DataItem.php';
138139 $wgAutoloadClasses['SMWDIProperty'] = $diDir . 'SMW_DI_Property.php';
139 - $wgAutoloadClasses['SMWDIBool'] = $diDir . 'SMW_DI_Bool.php';
 140+ $wgAutoloadClasses['SMWDIBoolean'] = $diDir . 'SMW_DI_Bool.php';
140141 $wgAutoloadClasses['SMWDINumber'] = $diDir . 'SMW_DI_Number.php';
141142 $wgAutoloadClasses['SMWDIBlob'] = $diDir . 'SMW_DI_Blob.php';
142143 $wgAutoloadClasses['SMWDIString'] = $diDir . 'SMW_DI_String.php';
143144 $wgAutoloadClasses['SMWStringLengthException'] = $diDir . 'SMW_DI_String.php';
144 - $wgAutoloadClasses['SMWDIURI'] = $diDir . 'SMW_DI_URI.php';
 145+ $wgAutoloadClasses['SMWDIUri'] = $diDir . 'SMW_DI_URI.php';
145146 $wgAutoloadClasses['SMWDIWikiPage'] = $diDir . 'SMW_DI_WikiPage.php';
146147 $wgAutoloadClasses['SMWDITime'] = $diDir . 'SMW_DI_Time.php';
147148 $wgAutoloadClasses['SMWDIConcept'] = $diDir . 'SMW_DI_Concept.php';
 149+ $wgAutoloadClasses['SMWDIError'] = $diDir . 'SMW_DI_Error.php';
148150
149151 // Datavalues
150152 $dvDir = $smwgIP . 'includes/datavalues/';

Status & tagging log