Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php |
— | — | @@ -70,11 +70,12 @@ |
71 | 71 | * @param mixed $typesvalueforproperty either an SMWTypesValue or null |
72 | 72 | */ |
73 | 73 | static public function makeExportDataForSubject( SMWDIWikiPage $subject, $typesvalueforproperty = null ) { |
74 | | - $result = $subject->getExportData(); |
| 74 | + $result = self::getDataItemExpData( $subject ); |
| 75 | + $subj_title = Title::makeTitle( $subject->getNamespace(), $subject->getDBkey() ); |
75 | 76 | switch ( $subject->getNamespace() ) { |
76 | 77 | case NS_CATEGORY: case SMW_NS_CONCEPT: |
77 | 78 | $maintype_pe = SMWExporter::getSpecialElement( 'owl', 'Class' ); |
78 | | - $label = $subject->getText(); |
| 79 | + $label = $subj_title->getText(); |
79 | 80 | break; |
80 | 81 | case SMW_NS_PROPERTY: |
81 | 82 | if ( $typesvalueforproperty == null ) { |
— | — | @@ -82,14 +83,13 @@ |
83 | 84 | $typesvalueforproperty = end( $types ); |
84 | 85 | } |
85 | 86 | $maintype_pe = SMWExporter::getSpecialElement( 'owl', SMWExporter::getOWLPropertyType( $typesvalueforproperty ) ); |
86 | | - $label = $subject->getText(); |
| 87 | + $label = $subj_title->getText(); |
87 | 88 | break; |
88 | 89 | default: |
89 | | - $label = $subject->getWikiValue(); |
| 90 | + $label = $subj_title->getPrefixedText(); |
90 | 91 | $maintype_pe = SMWExporter::getSpecialElement( 'swivt', 'Subject' ); |
91 | 92 | } |
92 | 93 | $ed = new SMWExpData( new SMWExpLiteral( $label ) ); |
93 | | - $subj_title = $subject->getTitle(); |
94 | 94 | $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'rdfs', 'label' ), $ed ); |
95 | 95 | $ed = new SMWExpData( new SMWExpResource( '&wikiurl;' . $subj_title->getPrefixedURL() ) ); |
96 | 96 | $result->addPropertyObjectValue( SMWExporter::getSpecialElement( 'swivt', 'page' ), $ed ); |
— | — | @@ -106,21 +106,21 @@ |
107 | 107 | * specified property data itme. This method is called when |
108 | 108 | * constructing export data structures from SMWSemanticData objects. |
109 | 109 | * |
110 | | - * @param SMWDIProperty $property |
111 | | - * @param array $values of SMWDataValue objects for the given property |
112 | | - * @param SMWExpData $data to add the data to |
| 110 | + * @param $property SMWDIProperty |
| 111 | + * @param $dataItems array of SMWDataItem objects for the given property |
| 112 | + * @param $data SMWExpData to add the data to |
113 | 113 | */ |
114 | | - static public function addPropertyValues(SMWDIProperty $property, $values, SMWExpData &$data) { |
| 114 | + static public function addPropertyValues( SMWDIProperty $property, $dataItems, SMWExpData &$expData ) { |
115 | 115 | if ( $property->isUserDefined() ) { |
116 | 116 | $pe = SMWExporter::getResourceElement( $property ); |
117 | | - foreach ( $values as $dv ) { |
118 | | - $ed = $dv->getExportData(); |
| 117 | + foreach ( $dataItems as $dataItem ) { |
| 118 | + $ed = self::getDataItemExpData( $dataItem ); |
119 | 119 | if ( $ed !== null ) { |
120 | | - $data->addPropertyObjectValue( $pe, $ed ); |
| 120 | + $expData->addPropertyObjectValue( $pe, $ed ); |
121 | 121 | } |
122 | 122 | } |
123 | 123 | } else { // pre-defined property, only exported if known |
124 | | - $subject = $data->getSubject()->getDatavalue(); |
| 124 | + $subject = $expData->getSubject()->getDatavalue(); |
125 | 125 | if ( $subject == null ) return; // subject datavalue (wikipage) required for treating special properties properly |
126 | 126 | switch ( $subject->getNamespace() ) { |
127 | 127 | case NS_CATEGORY: case SMW_NS_CONCEPT: |
— | — | @@ -140,7 +140,7 @@ |
141 | 141 | } |
142 | 142 | $pe = null; |
143 | 143 | $cat_only = false; // basic namespace checking for equivalent categories |
144 | | - switch ( $property->getPropertyID() ) { |
| 144 | + switch ( $property->getKey() ) { |
145 | 145 | ///TODO: distinguish instanceof and subclassof in the _INST case |
146 | 146 | case '_INST': $pe = $category_pe; break; |
147 | 147 | case '_CONC': $pe = $equality_pe; break; |
— | — | @@ -159,25 +159,25 @@ |
160 | 160 | break; |
161 | 161 | } |
162 | 162 | if ( $pe === null ) return; // unknown special property, not exported |
163 | | - foreach ( $values as $dv ) { |
| 163 | + foreach ( $dataItems as $dataItem ) { |
164 | 164 | if ( $cat_only ) { |
165 | | - if ( !( $dv instanceof SMWDIWikiPage ) || ( $dv->getNamespace() != NS_CATEGORY ) ) { |
| 165 | + if ( !( $dataItem instanceof SMWDIWikiPage ) || ( $dataItem->getNamespace() != NS_CATEGORY ) ) { |
166 | 166 | continue; |
167 | 167 | } |
168 | 168 | } |
169 | | - $ed = $dv->getExportData(); |
| 169 | + $ed = self::getDataItemExpData( $dataItem ); |
170 | 170 | if ( $ed !== null ) { |
171 | | - if ( ( $property->getPropertyID() == '_CONC' ) && ( $ed->getSubject()->getName() == '' ) ) { |
| 171 | + if ( ( $property->getKey() == '_CONC' ) && ( $ed->getSubject()->getName() == '' ) ) { |
172 | 172 | // equivalent to anonymous class -> simplify description |
173 | 173 | foreach ( $ed->getProperties() as $subp ) { |
174 | 174 | if ( $subp->getName() != SMWExporter::getSpecialElement( 'rdf', 'type' )->getName() ) { |
175 | 175 | foreach ( $ed->getValues( $subp ) as $subval ) { |
176 | | - $data->addPropertyObjectValue( $subp, $subval ); |
| 176 | + $expData->addPropertyObjectValue( $subp, $subval ); |
177 | 177 | } |
178 | 178 | } |
179 | 179 | } |
180 | 180 | } else { |
181 | | - $data->addPropertyObjectValue( $pe, $ed ); |
| 181 | + $expData->addPropertyObjectValue( $pe, $ed ); |
182 | 182 | } |
183 | 183 | } |
184 | 184 | } |
— | — | @@ -186,45 +186,47 @@ |
187 | 187 | |
188 | 188 | /** |
189 | 189 | * Create an SMWExpElement for some internal resource, given by an |
190 | | - * SMWDIWikiPage or SMWDIProperty object. Returns null on error. |
| 190 | + * SMWDIWikiPage or SMWDIProperty object. |
191 | 191 | * This is the one place in the code where URIs of wiki pages and |
192 | 192 | * properties are defined. |
193 | 193 | * |
194 | | - * @param mixed SMWDIWikiPage or SMWDIProperty |
195 | | - * @return SMWExpResource or null |
| 194 | + * @param $resource SMWDataItem must be SMWDIWikiPage or SMWDIProperty |
| 195 | + * @return SMWExpResource |
196 | 196 | */ |
197 | 197 | static public function getResourceElement( SMWDataItem $resource ) { |
| 198 | + global $wgContLang; |
198 | 199 | if ( $resource instanceof SMWDIWikiPage ) { |
199 | | - $dv = $resource; |
| 200 | + $diWikiPage = $resource; |
200 | 201 | } elseif ( $resource instanceof SMWDIProperty ) { |
201 | | - $dv = $resource->getWikiPageValue(); |
| 202 | + $diWikiPage = $resource->getDiWikiPage(); |
| 203 | + if ( $diWikiPage === null ) { /// TODO Maybe treat special properties here, too |
| 204 | + return null; |
| 205 | + } |
202 | 206 | } else { |
203 | | - return null; |
| 207 | + throw new InvalidArgumentException( 'SMWExporter::getResourceElement() expects an object of type SMWDIWikiPage or SMWDIProperty' ); |
204 | 208 | } |
205 | | - $idvs = smwfGetStore()->getPropertyValues( $dv, new SMWDIProperty( '_IMPO' ) ); |
206 | | - if ( count( $idvs ) > 0 ) { |
207 | | - $namespace = current( $idvs )->getNS(); |
208 | | - $namespaceid = current( $idvs )->getNSID(); |
209 | | - $localname = current( $idvs )->getLocalName(); |
| 209 | + $importDis = smwfGetStore()->getPropertyValues( $diWikiPage, new SMWDIProperty( '_IMPO' ) ); |
| 210 | + if ( count( $importDis ) > 0 ) { |
| 211 | + $namespace = current( $importDis )->getNS(); |
| 212 | + $namespaceid = current( $importDis )->getNSID(); |
| 213 | + $localname = current( $importDis )->getLocalName(); |
210 | 214 | } else { |
211 | 215 | $localname = ''; |
212 | | - if ( $dv->getNamespace() == SMW_NS_PROPERTY ) { |
| 216 | + if ( $diWikiPage->getNamespace() == SMW_NS_PROPERTY ) { |
213 | 217 | $namespace = '&property;'; |
214 | 218 | $namespaceid = 'property'; |
215 | | - $localname = SMWExporter::encodeURI( rawurlencode( $dv->getDBkey() ) ); |
216 | | - if ( in_array( $localname[0], array( '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ) ) ) { |
217 | | - $namespace = '&wiki;'; |
218 | | - $namespaceid = 'wiki'; |
219 | | - $localname = SMWExporter::encodeURI( wfUrlencode( str_replace( ' ', '_', $dv->getPrefixedText() ) ) ); |
220 | | - } |
221 | | - } else { // no QName needed, do not attempt to make one |
222 | | - $namespace = false; |
223 | | - $namespaceid = false; |
224 | | - $localname = '&wiki;' . SMWExporter::encodeURI( wfUrlencode( str_replace( ' ', '_', $dv->getPrefixedText() ) ) ); |
| 219 | + $localname = SMWExporter::encodeURI( rawurlencode( $diWikiPage->getDBkey() ) ); |
225 | 220 | } |
| 221 | + if ( ( $localname == '' ) || |
| 222 | + ( in_array( $localname[0], array( '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ) ) ) ) { |
| 223 | + $namespace = '&wiki;'; |
| 224 | + $namespaceid = 'wiki'; |
| 225 | + $nsText = str_replace( ' ', '_', $wgContLang->getNSText( $diWikiPage->getNamespace() ) ); |
| 226 | + $localname = SMWExporter::encodeURI( wfUrlencode( $nsText . ':' . $diWikiPage->getDBkey() ) ); |
| 227 | + } |
226 | 228 | } |
227 | 229 | |
228 | | - return new SMWExpResource( $localname, $dv, $namespace, $namespaceid ); |
| 230 | + return new SMWExpResource( $localname, $diWikiPage, $namespace, $namespaceid ); |
229 | 231 | } |
230 | 232 | |
231 | 233 | /** |
— | — | @@ -326,59 +328,84 @@ |
327 | 329 | |
328 | 330 | /** |
329 | 331 | * Create an SWMExpData container that encodes the data of the given |
330 | | - * datavalue object. |
| 332 | + * dataitem object. |
331 | 333 | * |
332 | | - * @param SMWDataValue $dv the datavalue to encode |
| 334 | + * @param $dataItem SMWDataItem |
| 335 | + * @return SMWExpData |
333 | 336 | */ |
334 | | - static public function getDVExpData( SMWDataValue $dv ) { |
335 | | - if ( !$dv->isValid() ) return null; |
336 | | - |
337 | | - switch ( $dv->getBaseType() ) { |
338 | | - case SMWDataValue::TYPE_NUMBER: |
339 | | - $lit = new SMWExpLiteral( $dv->getNumber(), $dv, 'http://www.w3.org/2001/XMLSchema#double' ); |
| 337 | + static public function getDataItemExpData( SMWDataItem $dataItem ) { |
| 338 | + switch ( $dataItem->getDIType() ) { |
| 339 | + case SMWDataItem::TYPE_NUMBER: |
| 340 | + $lit = new SMWExpLiteral( $dataItem->getNumber(), $dataItem, 'http://www.w3.org/2001/XMLSchema#double' ); |
340 | 341 | return new SMWExpData( $lit ); |
341 | 342 | 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' ); |
| 343 | + case SMWDataItem::TYPE_STRING: case SMWDataItem::TYPE_BLOB: |
| 344 | + $lit = new SMWExpLiteral( smwfHTMLtoUTF8( $dataItem->getString() ), $dataItem, 'http://www.w3.org/2001/XMLSchema#string' ); |
344 | 345 | return new SMWExpData( $lit ); |
345 | 346 | 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' ); |
| 347 | + case SMWDataItem::TYPE_BOOLEAN: |
| 348 | + $xsdvalue = $dataItem->getBoolean() ? 'true' : 'false'; |
| 349 | + $lit = new SMWExpLiteral( $xsdvalue, $dataItem, 'http://www.w3.org/2001/XMLSchema#boolean' ); |
349 | 350 | return new SMWExpData( $lit ); |
350 | 351 | break; |
351 | | - case SMWDataValue::TYPE_URI: |
| 352 | + case SMWDataItem::TYPE_URI: |
352 | 353 | /// TODO This escaping seems very odd. The serialisation should handle such things. |
353 | | - $res = new SMWExpResource( str_replace( '&', '&', $dv->getURI() ), $dv ); |
| 354 | + $res = new SMWExpResource( str_replace( '&', '&', $dataItem->getURI() ), $dataItem ); |
354 | 355 | return new SMWExpData( $res ); |
355 | 356 | break; |
356 | | - case SMWDataValue::TYPE_TIME: |
357 | | - $lit = new SMWExpLiteral( $dv->getXMLSchemaDate(), $dv, 'http://www.w3.org/2001/XMLSchema#dateTime' ); |
| 357 | + case SMWDataItem::TYPE_TIME: |
| 358 | + $gregorianTime = $dataItem->getForCalendarModel( SMWDITime::CM_GREGORIAN ); |
| 359 | + if ( $gregorianTime->getYear() > 0 ) { |
| 360 | + $xsdvalue = str_pad( $gregorianTime->getYear(), 4, "0", STR_PAD_LEFT ); |
| 361 | + } else { |
| 362 | + $xsdvalue = '-' . str_pad( 1 - $gregorianTime->getYear(), 4, "0", STR_PAD_LEFT ); |
| 363 | + } |
| 364 | + $xsdtype = 'http://www.w3.org/2001/XMLSchema#gYear'; |
| 365 | + if ( $gregorianTime->getPrecision() >= SMWDITime::PREC_YM ) { |
| 366 | + $xsdtype = 'http://www.w3.org/2001/XMLSchema#gYearMonth'; |
| 367 | + $xsdvalue .= '-' . str_pad( $gregorianTime->getMonth(), 2, "0", STR_PAD_LEFT ); |
| 368 | + if ( $gregorianTime->getPrecision() >= SMWDITime::PREC_YMD ) { |
| 369 | + $xsdtype = 'http://www.w3.org/2001/XMLSchema#date'; |
| 370 | + $xsdvalue .= '-' . str_pad( $gregorianTime->getDay(), 2, "0", STR_PAD_LEFT ); |
| 371 | + if ( $gregorianTime->getPrecision() == SMWDITime::PREC_YMDT ) { |
| 372 | + $xsdtype = 'http://www.w3.org/2001/XMLSchema#dateTime'; |
| 373 | + $xsdvalue .= 'T' . |
| 374 | + sprintf( "%02d", $gregorianTime->getHour() ) . ':' . |
| 375 | + sprintf( "%02d", $gregorianTime->getMinute()) . ':' . |
| 376 | + sprintf( "%02d", $gregorianTime->getSecond() ); |
| 377 | + } |
| 378 | + } |
| 379 | + } |
| 380 | + $xsdvalue .= 'Z'; |
| 381 | + $lit = new SMWExpLiteral( $xsdvalue, $gregorianTime, $xsdtype ); |
358 | 382 | return new SMWExpData( $lit ); |
359 | 383 | break; |
360 | | - case SMWDataValue::TYPE_GEO: |
| 384 | + case SMWDataItem::TYPE_GEO: |
361 | 385 | /// TODO |
| 386 | + return null; |
362 | 387 | break; |
363 | | - case SMWDataValue::TYPE_CONT: |
| 388 | + case SMWDataItem::TYPE_CONTAINER: |
364 | 389 | /// TODO |
| 390 | + return null; |
365 | 391 | 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() ); |
| 392 | + case SMWDataItem::TYPE_WIKIPAGE: |
| 393 | + if ( $dataItem->getNamespace() == NS_MEDIA ) { // special handling for linking media files directly (object only) |
| 394 | + $title = Title::makeTitle( $dataItem->getNamespace(), $dataItem->getDBkey() ) ; |
| 395 | + $file = wfFindFile( $title ); |
369 | 396 | if ( $file !== false ) { |
370 | 397 | return new SMWExpData( new SMWExpResource( $file->getFullURL() ) ); |
371 | 398 | } else { // Medialink to non-existing file :-/ |
372 | | - return null; |
| 399 | + return new SMWExpData( SMWExporter::getResourceElement( $dataItem ) ); |
373 | 400 | } |
374 | 401 | } else { |
375 | | - return new SMWExpData( SMWExporter::getResourceElement( $dv ) ); |
| 402 | + return new SMWExpData( SMWExporter::getResourceElement( $dataItem ) ); |
376 | 403 | } |
377 | 404 | break; |
378 | | - case SMWDataValue::TYPE_CONCEPT: |
| 405 | + case SMWDataItem::TYPE_CONCEPT: |
379 | 406 | /// TODO |
380 | 407 | break; |
381 | | - case SMWDataValue::TYPE_PROP: |
382 | | - return new SMWExpData( SMWExporter::getResourceElement( $dv->getWikiPageValue() ) ); |
| 408 | + case SMWDataItem::TYPE_PROPERTY: |
| 409 | + return new SMWExpData( SMWExporter::getResourceElement( $dataItem->getDiWikiPage() ) ); |
383 | 410 | break; |
384 | 411 | } |
385 | 412 | } |