Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php |
— | — | @@ -45,11 +45,14 @@ |
46 | 46 | * Create exportable data from a given semantic data record. |
47 | 47 | * |
48 | 48 | * @param $semdata SMWSemanticData |
| 49 | + * @param $subject mixed SMWDIWikiPage to use as subject, or null to use the one from $semdata |
49 | 50 | * @return SMWExpData |
50 | 51 | */ |
51 | | - static public function makeExportData( SMWSemanticData $semdata ) { |
| 52 | + static public function makeExportData( SMWSemanticData $semdata, $subject = null ) { |
52 | 53 | self::initBaseURIs(); |
53 | | - $subject = $semdata->getSubject(); |
| 54 | + if ( is_null( $subject ) ) { |
| 55 | + $subject = $semdata->getSubject(); |
| 56 | + } |
54 | 57 | if ( $subject->getNamespace() == SMW_NS_PROPERTY ) { |
55 | 58 | $types = $semdata->getPropertyValues( new SMWDIProperty( '_TYPE' ) ); |
56 | 59 | } else { |
— | — | @@ -57,7 +60,7 @@ |
58 | 61 | } |
59 | 62 | $result = self::makeExportDataForSubject( $subject, end( $types ) ); |
60 | 63 | foreach ( $semdata->getProperties() as $property ) { |
61 | | - self::addPropertyValues( $property, $semdata->getPropertyValues( $property ), $result ); |
| 64 | + self::addPropertyValues( $property, $semdata->getPropertyValues( $property ), $result, $subject ); |
62 | 65 | } |
63 | 66 | return $result; |
64 | 67 | } |
— | — | @@ -76,51 +79,58 @@ |
77 | 80 | * @param $addStubData boolean to indicate if additional data should be added to make a stub entry for this page |
78 | 81 | * @return SMWExpData |
79 | 82 | */ |
80 | | - static public function makeExportDataForSubject( SMWDIWikiPage $diWikiPage, $typesvalueforproperty = null, $addStubData = false ) { |
| 83 | + static public function makeExportDataForSubject( SMWDIWikiPage $diWikiPage, $typesvalueforproperty = null, $addStubData = false ) { |
81 | 84 | global $wgContLang; |
82 | | - $wikiPageExpElement = self::getDataItemExpElement( $diWikiPage ); |
| 85 | + $wikiPageExpElement = self::getDataItemExpElement( $diWikiPage, $diWikiPage ); |
83 | 86 | $result = new SMWExpData( $wikiPageExpElement ); |
84 | 87 | |
85 | | - $pageTitle = str_replace( '_', ' ', $diWikiPage->getDBkey() ); |
86 | | - if ( $diWikiPage->getNamespace() !== 0 ) { |
87 | | - $prefixedSubjectTitle = $wgContLang->getNsText( $diWikiPage->getNamespace()) . ":" . $pageTitle; |
| 88 | + if ( $diWikiPage->getSubobjectName() != '' ) { |
| 89 | + $result->addPropertyObjectValue( self::getSpecialNsResource( 'rdf', 'type' ), self::getSpecialNsResource( 'swivt', 'Subject' ) ); |
| 90 | + $masterPage = new SMWDIWikiPage( $diWikiPage->getDBkey(), $diWikiPage->getNamespace(), $diWikiPage->getInterwiki() ); |
| 91 | + $masterExpElement = self::getDataItemExpElement( $masterPage, $masterPage ); |
| 92 | + $result->addPropertyObjectValue( self::getSpecialNsResource( 'swivt', 'masterPage' ), $masterExpElement ); |
88 | 93 | } else { |
89 | | - $prefixedSubjectTitle = $pageTitle; |
90 | | - } |
91 | | - $prefixedSubjectUrl = wfUrlencode( str_replace( ' ', '_', $prefixedSubjectTitle ) ); |
| 94 | + $pageTitle = str_replace( '_', ' ', $diWikiPage->getDBkey() ); |
| 95 | + if ( $diWikiPage->getNamespace() !== 0 ) { |
| 96 | + $prefixedSubjectTitle = $wgContLang->getNsText( $diWikiPage->getNamespace()) . ":" . $pageTitle; |
| 97 | + } else { |
| 98 | + $prefixedSubjectTitle = $pageTitle; |
| 99 | + } |
| 100 | + $prefixedSubjectUrl = wfUrlencode( str_replace( ' ', '_', $prefixedSubjectTitle ) ); |
92 | 101 | |
93 | | - switch ( $diWikiPage->getNamespace() ) { |
94 | | - case NS_CATEGORY: case SMW_NS_CONCEPT: |
95 | | - $maintype_pe = self::getSpecialNsResource( 'owl', 'Class' ); |
96 | | - $label = $pageTitle; |
97 | | - break; |
98 | | - case SMW_NS_PROPERTY: |
99 | | - if ( $typesvalueforproperty == null ) { |
100 | | - $types = smwfGetStore()->getPropertyValues( $diWikiPage, new SMWDIProperty( '_TYPE' ) ); |
101 | | - $typesvalueforproperty = end( $types ); |
102 | | - } |
103 | | - $maintype_pe = self::getSpecialNsResource( 'owl', self::getOWLPropertyType( $typesvalueforproperty ) ); |
104 | | - $label = $pageTitle; |
105 | | - break; |
106 | | - default: |
107 | | - $label = $prefixedSubjectTitle; |
108 | | - $maintype_pe = self::getSpecialNsResource( 'swivt', 'Subject' ); |
109 | | - } |
| 102 | + switch ( $diWikiPage->getNamespace() ) { |
| 103 | + case NS_CATEGORY: case SMW_NS_CONCEPT: |
| 104 | + $maintype_pe = self::getSpecialNsResource( 'owl', 'Class' ); |
| 105 | + $label = $pageTitle; |
| 106 | + break; |
| 107 | + case SMW_NS_PROPERTY: |
| 108 | + if ( $typesvalueforproperty == null ) { |
| 109 | + $types = smwfGetStore()->getPropertyValues( $diWikiPage, new SMWDIProperty( '_TYPE' ) ); |
| 110 | + $typesvalueforproperty = end( $types ); |
| 111 | + } |
| 112 | + $maintype_pe = self::getSpecialNsResource( 'owl', self::getOWLPropertyType( $typesvalueforproperty ) ); |
| 113 | + $label = $pageTitle; |
| 114 | + break; |
| 115 | + default: |
| 116 | + $label = $prefixedSubjectTitle; |
| 117 | + $maintype_pe = self::getSpecialNsResource( 'swivt', 'Subject' ); |
| 118 | + } |
110 | 119 | |
111 | | - $result->addPropertyObjectValue( self::getSpecialNsResource( 'rdf', 'type' ), $maintype_pe ); |
| 120 | + $result->addPropertyObjectValue( self::getSpecialNsResource( 'rdf', 'type' ), $maintype_pe ); |
112 | 121 | |
113 | | - if ( !$wikiPageExpElement->isBlankNode() ) { |
114 | | - $ed = new SMWExpLiteral( $label ); |
115 | | - $result->addPropertyObjectValue( self::getSpecialNsResource( 'rdfs', 'label' ), $ed ); |
116 | | - $ed = new SMWExpResource( self::getNamespaceUri( 'wikiurl' ) . $prefixedSubjectUrl ); |
117 | | - $result->addPropertyObjectValue( self::getSpecialNsResource( 'swivt', 'page' ), $ed ); |
118 | | - $ed = new SMWExpResource( self::$m_exporturl . '/' . $prefixedSubjectUrl ); |
119 | | - $result->addPropertyObjectValue( self::getSpecialNsResource( 'rdfs', 'isDefinedBy' ), $ed ); |
120 | | - $ed = new SMWExpLiteral( $diWikiPage->getNamespace(), 'http://www.w3.org/2001/XMLSchema#integer' ); |
121 | | - $result->addPropertyObjectValue( self::getSpecialNsResource( 'swivt', 'wikiNamespace' ), $ed ); |
122 | | - if ( $addStubData ) { |
123 | | - $defaultSortkey = new SMWExpLiteral( str_replace( '_', ' ', $diWikiPage->getDBkey() ) ); |
124 | | - $result->addPropertyObjectValue( self::getSpecialPropertyResource( '_SKEY' ), $defaultSortkey ); |
| 122 | + if ( !$wikiPageExpElement->isBlankNode() ) { |
| 123 | + $ed = new SMWExpLiteral( $label ); |
| 124 | + $result->addPropertyObjectValue( self::getSpecialNsResource( 'rdfs', 'label' ), $ed ); |
| 125 | + $ed = new SMWExpResource( self::getNamespaceUri( 'wikiurl' ) . $prefixedSubjectUrl ); |
| 126 | + $result->addPropertyObjectValue( self::getSpecialNsResource( 'swivt', 'page' ), $ed ); |
| 127 | + $ed = new SMWExpResource( self::$m_exporturl . '/' . $prefixedSubjectUrl ); |
| 128 | + $result->addPropertyObjectValue( self::getSpecialNsResource( 'rdfs', 'isDefinedBy' ), $ed ); |
| 129 | + $ed = new SMWExpLiteral( $diWikiPage->getNamespace(), 'http://www.w3.org/2001/XMLSchema#integer' ); |
| 130 | + $result->addPropertyObjectValue( self::getSpecialNsResource( 'swivt', 'wikiNamespace' ), $ed ); |
| 131 | + if ( $addStubData ) { |
| 132 | + $defaultSortkey = new SMWExpLiteral( str_replace( '_', ' ', $diWikiPage->getDBkey() ) ); |
| 133 | + $result->addPropertyObjectValue( self::getSpecialPropertyResource( '_SKEY' ), $defaultSortkey ); |
| 134 | + } |
125 | 135 | } |
126 | 136 | } |
127 | 137 | |
— | — | @@ -135,13 +145,14 @@ |
136 | 146 | * @param $property SMWDIProperty |
137 | 147 | * @param $dataItems array of SMWDataItem objects for the given property |
138 | 148 | * @param $data SMWExpData to add the data to |
| 149 | + * @param $masterPage SMWDIWikiPage to which the data belongs; needed for internal object URIs |
139 | 150 | */ |
140 | | - static public function addPropertyValues( SMWDIProperty $property, array $dataItems, SMWExpData &$expData ) { |
| 151 | + static public function addPropertyValues( SMWDIProperty $property, array $dataItems, SMWExpData &$expData, SMWDIWikiPage $masterPage ) { |
141 | 152 | if ( $property->isUserDefined() ) { |
142 | 153 | $pe = self::getResourceElementForProperty( $property ); |
143 | 154 | $peHelper = self::getResourceElementForProperty( $property, true ); |
144 | 155 | foreach ( $dataItems as $dataItem ) { |
145 | | - $ed = self::getDataItemExpElement( $dataItem ); |
| 156 | + $ed = self::getDataItemExpElement( $dataItem, $masterPage ); |
146 | 157 | if ( $ed !== null ) { |
147 | 158 | $expData->addPropertyObjectValue( $pe, $ed ); |
148 | 159 | } |
— | — | @@ -175,7 +186,7 @@ |
176 | 187 | ( $dataItem->getNamespace() != $diSubject->getNamespace() ) ) ) { |
177 | 188 | continue; |
178 | 189 | } |
179 | | - $ed = self::getDataItemExpElement( $dataItem ); |
| 190 | + $ed = self::getDataItemExpElement( $dataItem, $masterPage ); |
180 | 191 | if ( $ed !== null ) { |
181 | 192 | if ( ( $property->getKey() == '_CONC' ) && ( $ed->getSubject()->getUri() == '' ) ) { |
182 | 193 | // equivalent to anonymous class -> simplify description |
— | — | @@ -231,7 +242,7 @@ |
232 | 243 | * occuring in MW titles). |
233 | 244 | * |
234 | 245 | * @param $diWikiPage SMWDIWikiPage or SMWDIProperty |
235 | | - * @param $modifier string, using only Latin letters |
| 246 | + * @param $modifier string, using only Latin letters and numbers |
236 | 247 | * @return SMWExpResource |
237 | 248 | */ |
238 | 249 | static public function getResourceElementForWikiPage( SMWDIWikiPage $diWikiPage, $modifier = '' ) { |
— | — | @@ -245,6 +256,10 @@ |
246 | 257 | } // else: Medialink to non-existing file :-/ fall through |
247 | 258 | } |
248 | 259 | |
| 260 | + if ( $diWikiPage->getSubobjectName() != '' ) { |
| 261 | + $modifier = $diWikiPage->getSubobjectName(); |
| 262 | + } |
| 263 | + |
249 | 264 | if ( $modifier == '' ) { |
250 | 265 | $importProperty = new SMWDIProperty( '_IMPO' ); |
251 | 266 | $importDis = smwfGetStore()->getPropertyValues( $diWikiPage, $importProperty ); |
— | — | @@ -273,7 +288,7 @@ |
274 | 289 | $namespace = self::getNamespaceUri( 'wiki' ); |
275 | 290 | $namespaceId = 'wiki'; |
276 | 291 | if ( $diWikiPage->getNamespace() !== 0 ) { |
277 | | - $localName = str_replace( ' ', '_', $wgContLang->getNSText( $diWikiPage->getNamespace() ) ) . ":" . $diWikiPage->getDBkey(); |
| 292 | + $localName = str_replace( ' ', '_', $wgContLang->getNSText( $diWikiPage->getNamespace() ) ) . ':' . $diWikiPage->getDBkey(); |
278 | 293 | } else { |
279 | 294 | $localName = $diWikiPage->getDBkey(); |
280 | 295 | } |
— | — | @@ -304,9 +319,18 @@ |
305 | 320 | if ( strpos( $uri, $wikiNamespace ) === 0 ) { |
306 | 321 | $localName = substr( $uri, strlen( $wikiNamespace ) ); |
307 | 322 | $dbKey = urldecode( self::decodeURI( $localName ) ); |
| 323 | + |
| 324 | + $parts = explode( '-23', $dbKey, 2 ); |
| 325 | + if ( count( $parts ) == 2 ) { |
| 326 | + $dbkey = $parts[0]; |
| 327 | + $subobjectname = $parts[1]; |
| 328 | + } else { |
| 329 | + $subobjectname = ''; |
| 330 | + } |
| 331 | + |
308 | 332 | $parts = explode( ':', $dbKey, 2 ); |
309 | 333 | if ( count( $parts ) == 1 ) { |
310 | | - $dataItem = new SMWDIWikiPage( $dbKey, NS_MAIN, '' ); |
| 334 | + $dataItem = new SMWDIWikiPage( $dbKey, NS_MAIN, '', $subobjectname ); |
311 | 335 | } else { |
312 | 336 | // try the by far most common cases directly before using Title |
313 | 337 | $namespaceName = str_replace( '_', ' ', $parts[0] ); |
— | — | @@ -318,11 +342,11 @@ |
319 | 343 | } |
320 | 344 | } |
321 | 345 | if ( $namespaceId != -1 ) { |
322 | | - $dataItem = new SMWDIWikiPage( $parts[1], $namespaceId, '' ); |
| 346 | + $dataItem = new SMWDIWikiPage( $parts[1], $namespaceId, '', $subobjectname ); |
323 | 347 | } else { |
324 | 348 | $title = Title::newFromDBkey( $dbKey ); |
325 | 349 | if ( $title !== null ) { |
326 | | - $dataItem = SMWDIWikiPage::newFromTitle( $title ); |
| 350 | + $dataItem = new SMWDIWikiPage( $title->getDBkey(), $title->getNamespace(), $title->getInterwiki(), $subobjectname ); |
327 | 351 | } |
328 | 352 | } |
329 | 353 | } |
— | — | @@ -513,9 +537,10 @@ |
514 | 538 | * SMWExporter::getSpecialPropertyResource(). |
515 | 539 | * |
516 | 540 | * @param $dataItem SMWDataItem |
| 541 | + * @param $masterPage mixed SMWDIWikiPage to which the data belongs (needed for internal object URIs); or NULL if deemed irrelevant |
517 | 542 | * @return SMWExpElement |
518 | 543 | */ |
519 | | - static public function getDataItemExpElement( SMWDataItem $dataItem ) { |
| 544 | + static public function getDataItemExpElement( SMWDataItem $dataItem, $masterPage ) { |
520 | 545 | switch ( $dataItem->getDIType() ) { |
521 | 546 | case SMWDataItem::TYPE_NUMBER: |
522 | 547 | $lit = new SMWExpLiteral( $dataItem->getNumber(), 'http://www.w3.org/2001/XMLSchema#double', $dataItem ); |
— | — | @@ -560,7 +585,7 @@ |
561 | 586 | /// TODO |
562 | 587 | return null; |
563 | 588 | case SMWDataItem::TYPE_CONTAINER: |
564 | | - return self::makeExportData( $dataItem->getSemanticData() ); |
| 589 | + return self::makeExportData( $dataItem->getSemanticData(), $dataItem->getSubjectPage( $masterPage ) ); |
565 | 590 | case SMWDataItem::TYPE_WIKIPAGE: |
566 | 591 | return self::getResourceElementForWikiPage( $dataItem ); |
567 | 592 | case SMWDataItem::TYPE_CONCEPT: |
Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_RDF.php |
— | — | @@ -49,7 +49,8 @@ |
50 | 50 | $serializer->startSerialization(); |
51 | 51 | $serializer->serializeExpData( SMWExporter::getOntologyExpData( '' ) ); |
52 | 52 | while ( $row = $res->getNext() ) { |
53 | | - $data = SMWExporter::makeExportDataForSubject( reset( $row )->getResultSubject() ); |
| 53 | + $subjectDi = reset( $row )->getResultSubject(); |
| 54 | + $data = SMWExporter::makeExportDataForSubject( $subjectDi ); |
54 | 55 | foreach ( $row as $resultarray ) { |
55 | 56 | $printreq = $resultarray->getPrintRequest(); |
56 | 57 | $property = null; |
— | — | @@ -68,7 +69,7 @@ |
69 | 70 | break; |
70 | 71 | } |
71 | 72 | if ( $property !== null ) { |
72 | | - SMWExporter::addPropertyValues( $property, $resultarray->getContent() , $data ); |
| 73 | + SMWExporter::addPropertyValues( $property, $resultarray->getContent() , $data, $subjectDi ); |
73 | 74 | } |
74 | 75 | } |
75 | 76 | $serializer->serializeExpData( $data ); |
Index: trunk/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabase.php |
— | — | @@ -201,7 +201,7 @@ |
202 | 202 | * |
203 | 203 | * @param $vars mixed array or string, field name(s) to be retrieved, can be '*' |
204 | 204 | * @param $where string WHERE part of the query, without surrounding { } |
205 | | - * @param $options array (associative) of options, e.g. array('LIMIT' => '10') |
| 205 | + * @param $options array (associative) of options, e.g. array( 'LIMIT' => '10' ) |
206 | 206 | * @param $extraNamespaces array (associative) of namespaceId => namespaceUri |
207 | 207 | * @return SMWSparqlResultWrapper |
208 | 208 | */ |
— | — | @@ -318,6 +318,26 @@ |
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
| 322 | + * Convenience method for deleting all triples that have a subject that |
| 323 | + * occurs in a triple with the given property and object. This is used |
| 324 | + * in SMW to delete subobjects with all their data. Some RDF stores fail |
| 325 | + * on complex delete queries, hence a wrapper function is provided to |
| 326 | + * allow more pedestrian implementations. |
| 327 | + * |
| 328 | + * The function declares the standard namespaces wiki, swivt, rdf, owl, |
| 329 | + * rdfs, property, xsd, so these do not have to be included in |
| 330 | + * $extraNamespaces. |
| 331 | + * |
| 332 | + * @param $propertyName string Turtle name of marking property |
| 333 | + * @param $objectName string Turtle name of marking object/value |
| 334 | + * @param $extraNamespaces array (associative) of namespaceId => namespaceUri |
| 335 | + * @return boolean stating whether the operations succeeded |
| 336 | + */ |
| 337 | + public function deleteContentByValue( $propertyName, $objectName, $extraNamespaces = array() ) { |
| 338 | + return smwfGetSparqlDatabase()->delete( "?s ?p ?o", "?s $propertyName $objectName . ?s ?p ?o" ); |
| 339 | + } |
| 340 | + |
| 341 | + /** |
322 | 342 | * INSERT DELETE wrapper. |
323 | 343 | * The function declares the standard namespaces wiki, swivt, rdf, owl, |
324 | 344 | * rdfs, property, xsd, so these do not have to be included in |
Index: trunk/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabase4Store.php |
— | — | @@ -60,6 +60,28 @@ |
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
| 64 | + * Complex SPARQL Update delete operations are not supported in 4Store |
| 65 | + * as of v1.1.3, hence this implementation uses a less efficient method |
| 66 | + * for accomplishing this. |
| 67 | + * |
| 68 | + * @param $propertyName string Turtle name of marking property |
| 69 | + * @param $objectName string Turtle name of marking object/value |
| 70 | + * @param $extraNamespaces array (associative) of namespaceId => namespaceUri |
| 71 | + * @return boolean stating whether the operations succeeded |
| 72 | + */ |
| 73 | + public function deleteContentByValue( $propertyName, $objectName, $extraNamespaces = array() ) { |
| 74 | + $affectedObjects = $this->select( '*', "?s $propertyName $objectName", array(), $extraNamespaces ); |
| 75 | + $success = ( $affectedObjects->getErrorCode() == SMWSparqlResultWrapper::ERROR_NOERROR ); |
| 76 | + foreach ( $affectedObjects as $expElements ) { |
| 77 | + if ( count( $expElements ) > 0 ) { |
| 78 | + $turtleName = SMWTurtleSerializer::getTurtleNameForExpElement( reset( $expElements ) ); |
| 79 | + $success = $this->delete( "$turtleName ?p ?o", "$turtleName ?p ?o", $extraNamespaces ) && $success; |
| 80 | + } |
| 81 | + } |
| 82 | + return $success; |
| 83 | + } |
| 84 | + |
| 85 | + /** |
64 | 86 | * Execute a HTTP-based SPARQL POST request according to |
65 | 87 | * http://www.w3.org/2009/sparql/docs/http-rdf-update/. |
66 | 88 | * The method throws exceptions based on |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SparqlStoreQueryEngine.php |
— | — | @@ -811,7 +811,7 @@ |
812 | 812 | } elseif ( $comparator == '=' ) { |
813 | 813 | $expElement = SMWExporter::getDataItemHelperExpElement( $dataItem ); |
814 | 814 | if ( $expElement === null ) { |
815 | | - $expElement = SMWExporter::getDataItemExpElement( $dataItem ); |
| 815 | + $expElement = SMWExporter::getDataItemExpElement( $dataItem, null ); |
816 | 816 | } |
817 | 817 | $result = new SMWSparqlSingletonCondition( $expElement ); |
818 | 818 | $this->addOrderByDataForProperty( $result, $joinVariable, $orderByProperty, $dataItem->getDIType() ); |
— | — | @@ -831,11 +831,11 @@ |
832 | 832 | $orderByVariable = $result->orderByVariable; |
833 | 833 | |
834 | 834 | if ( $dataItem instanceof SMWDIWikiPage ) { |
835 | | - $expElement = SMWExporter::getDataItemExpElement( $dataItem->getSortKeyDataItem() ); |
| 835 | + $expElement = SMWExporter::getDataItemExpElement( $dataItem->getSortKeyDataItem(), null ); |
836 | 836 | } else { |
837 | 837 | $expElement = SMWExporter::getDataItemHelperExpElement( $dataItem ); |
838 | 838 | if ( $expElement === null ) { |
839 | | - $expElement = SMWExporter::getDataItemExpElement( $dataItem ); |
| 839 | + $expElement = SMWExporter::getDataItemExpElement( $dataItem, null ); |
840 | 840 | } |
841 | 841 | } |
842 | 842 | |
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SparqlStore.php |
— | — | @@ -24,16 +24,17 @@ |
25 | 25 | |
26 | 26 | public function deleteSubject( Title $subject ) { |
27 | 27 | $dataItem = SMWDIWikiPage::newFromTitle( $subject ); |
28 | | - $expResource = SMWExporter::getDataItemExpElement( $dataItem ); |
| 28 | + $expResource = SMWExporter::getDataItemExpElement( $dataItem, $dataItem ); |
29 | 29 | $this->deleteSparqlData( $expResource ); |
30 | 30 | parent::deleteSubject( $subject ); |
31 | 31 | } |
32 | 32 | |
| 33 | + /// @todo Change master page entries as well |
33 | 34 | public function changeTitle( Title $oldtitle, Title $newtitle, $pageid, $redirid = 0 ) { |
34 | 35 | $oldWikiPage = SMWDIWikiPage::newFromTitle( $oldtitle ); |
35 | 36 | $newWikiPage = SMWDIWikiPage::newFromTitle( $newtitle ); |
36 | | - $oldExpResource = SMWExporter::getDataItemExpElement( $oldWikiPage ); |
37 | | - $newExpResource = SMWExporter::getDataItemExpElement( $newWikiPage ); |
| 37 | + $oldExpResource = SMWExporter::getDataItemExpElement( $oldWikiPage, $oldWikiPage ); |
| 38 | + $newExpResource = SMWExporter::getDataItemExpElement( $newWikiPage, $newWikiPage ); |
38 | 39 | $namespaces = array( $oldExpResource->getNamespaceId() => $oldExpResource->getNamespace() ); |
39 | 40 | $namespaces[$newExpResource->getNamespaceId()] = $newExpResource->getNamespace(); |
40 | 41 | $oldUri = SMWTurtleSerializer::getTurtleNameForExpElement( $oldExpResource ); |
— | — | @@ -62,7 +63,7 @@ |
63 | 64 | $expDataArray = $this->prepareUpdateExpData( $data ); |
64 | 65 | |
65 | 66 | if ( count( $expDataArray ) > 0 ) { |
66 | | - $subjectResource = SMWExporter::getDataItemExpElement( $data->getSubject() ); |
| 67 | + $subjectResource = SMWExporter::getDataItemExpElement( $data->getSubject(), $data->getSubject() ); |
67 | 68 | $this->deleteSparqlData( $subjectResource ); |
68 | 69 | |
69 | 70 | $turtleSerializer = new SMWTurtleSerializer( true ); |
— | — | @@ -95,7 +96,7 @@ |
96 | 97 | protected function prepareUpdateExpData( SMWSemanticData $data ) { |
97 | 98 | $expData = SMWExporter::makeExportData( $data ); |
98 | 99 | $result = array(); |
99 | | - $newExpData = $this->expandUpdateExpData( $expData, $expData->getSubject(), $result, false ); |
| 100 | + $newExpData = $this->expandUpdateExpData( $expData, $result, false ); |
100 | 101 | array_unshift( $result, $newExpData ); |
101 | 102 | return $result; |
102 | 103 | } |
— | — | @@ -110,15 +111,14 @@ |
111 | 112 | * This auxiliary data is collected in a call-by-ref array. |
112 | 113 | * |
113 | 114 | * @param $expElement SMWExpElement object containing the update data |
114 | | - * @param $masterExpElement SMWExpResource to which encountered blank nodes will be associated |
115 | 115 | * @param $auxiliaryExpData array of SMWExpData |
116 | 116 | * @return SMWExpElement |
117 | 117 | */ |
118 | | - protected function expandUpdateExpElement( SMWExpElement $expElement, SMWExpResource $masterExpElement, array &$auxiliaryExpData ) { |
| 118 | + protected function expandUpdateExpElement( SMWExpElement $expElement, array &$auxiliaryExpData ) { |
119 | 119 | if ( $expElement instanceof SMWExpResource ) { |
120 | | - $elementTarget = $this->expandUpdateExpResource( $expElement, $masterExpElement, $auxiliaryExpData ); |
| 120 | + $elementTarget = $this->expandUpdateExpResource( $expElement, $auxiliaryExpData ); |
121 | 121 | } elseif ( $expElement instanceof SMWExpData ) { |
122 | | - $elementTarget = $this->expandUpdateExpData( $expElement, $masterExpElement, $auxiliaryExpData, true ); |
| 122 | + $elementTarget = $this->expandUpdateExpData( $expElement, $auxiliaryExpData, true ); |
123 | 123 | } else { |
124 | 124 | $elementTarget = $expElement; |
125 | 125 | } |
— | — | @@ -136,11 +136,10 @@ |
137 | 137 | * This auxiliary data is collected in a call-by-ref array. |
138 | 138 | * |
139 | 139 | * @param $expResource SMWExpResource object containing the update data |
140 | | - * @param $masterExpElement SMWExpResource to which encountered blank nodes will be associated |
141 | 140 | * @param $auxiliaryExpData array of SMWExpData |
142 | 141 | * @return SMWExpElement |
143 | 142 | */ |
144 | | - protected function expandUpdateExpResource( SMWExpResource $expResource, SMWExpResource $masterExpElement, array &$auxiliaryExpData ) { |
| 143 | + protected function expandUpdateExpResource( SMWExpResource $expResource, array &$auxiliaryExpData ) { |
145 | 144 | $exists = true; |
146 | 145 | if ( $expResource instanceof SMWExpNsResource ) { |
147 | 146 | $elementTarget = $this->getSparqlRedirectTarget( $expResource, $exists ); |
— | — | @@ -148,12 +147,7 @@ |
149 | 148 | $elementTarget = $expResource; |
150 | 149 | } |
151 | 150 | |
152 | | - if ( $elementTarget->isBlankNode() ) { |
153 | | - $auxExpData = new SMWExpData( $elementTarget ); |
154 | | - $masterResourceProperty = SMWExporter::getSpecialNsResource( 'swivt', 'masterResource' ); |
155 | | - $auxExpData->addPropertyObjectValue( $masterResourceProperty, $masterExpElement ); |
156 | | - $elementTarget = $auxExpData; |
157 | | - } elseif ( !$exists && ( $elementTarget->getDataItem() instanceof SMWDIWikiPage ) ) { |
| 151 | + if ( !$exists && ( $elementTarget->getDataItem() instanceof SMWDIWikiPage ) ) { |
158 | 152 | $diWikiPage = $elementTarget->getDataItem(); |
159 | 153 | $hash = $diWikiPage->getHash(); |
160 | 154 | if ( !array_key_exists( $hash, $auxiliaryExpData ) ) { |
— | — | @@ -173,15 +167,14 @@ |
174 | 168 | * This auxiliary data is collected in a call-by-ref array. |
175 | 169 | * |
176 | 170 | * @param $expData SMWExpData object containing the update data |
177 | | - * @param $masterExpElement SMWExpResource to which encountered blank nodes will be associated |
178 | 171 | * @param $auxiliaryExpData array of SMWExpData |
179 | 172 | * @param $expandSubject boolean controls if redirects/auxiliary data should also be sought for subject |
180 | 173 | * @return SMWExpData |
181 | 174 | */ |
182 | | - protected function expandUpdateExpData( SMWExpData $expData, SMWExpResource $masterExpElement, array &$auxiliaryExpData, $expandSubject ) { |
| 175 | + protected function expandUpdateExpData( SMWExpData $expData, array &$auxiliaryExpData, $expandSubject ) { |
183 | 176 | $subjectExpResource = $expData->getSubject(); |
184 | 177 | if ( $expandSubject ) { |
185 | | - $expandedExpElement = $this->expandUpdateExpElement( $subjectExpResource, $masterExpElement, $auxiliaryExpData ); |
| 178 | + $expandedExpElement = $this->expandUpdateExpElement( $subjectExpResource, $auxiliaryExpData ); |
186 | 179 | if ( $expandedExpElement instanceof SMWExpData ) { |
187 | 180 | $newExpData = $expandedExpElement; |
188 | 181 | } else { // instanceof SMWExpResource |
— | — | @@ -192,9 +185,9 @@ |
193 | 186 | } |
194 | 187 | |
195 | 188 | foreach ( $expData->getProperties() as $propertyResource ) { |
196 | | - $propertyTarget = $this->expandUpdateExpElement( $propertyResource, $masterExpElement, $auxiliaryExpData ); |
| 189 | + $propertyTarget = $this->expandUpdateExpElement( $propertyResource, $auxiliaryExpData ); |
197 | 190 | foreach ( $expData->getValues( $propertyResource ) as $expElement ) { |
198 | | - $elementTarget = $this->expandUpdateExpElement( $expElement, $masterExpElement, $auxiliaryExpData ); |
| 191 | + $elementTarget = $this->expandUpdateExpElement( $expElement, $auxiliaryExpData ); |
199 | 192 | $newExpData->addPropertyObjectValue( $propertyTarget, $elementTarget ); |
200 | 193 | } |
201 | 194 | } |
— | — | @@ -210,13 +203,17 @@ |
211 | 204 | * |
212 | 205 | * @param $expNsResource string URI to check |
213 | 206 | * @param $exists boolean that is set to true if $expNsResource is in the |
214 | | - * store; always false for blank nodes |
| 207 | + * store; always false for blank nodes; always true for subobjects |
215 | 208 | * @return SMWExpNsResource |
216 | 209 | */ |
217 | 210 | protected function getSparqlRedirectTarget( SMWExpNsResource $expNsResource, &$exists ) { |
218 | 211 | if ( $expNsResource->isBlankNode() ) { |
219 | 212 | $exists = false; |
220 | 213 | return $expNsResource; |
| 214 | + } elseif ( ( $expNsResource->getDataItem() instanceof SMWDIWikiPage ) && |
| 215 | + $expNsResource->getDataItem()->getSubobjectName() != '' ) { |
| 216 | + $exists = true; |
| 217 | + return $expNsResource; |
221 | 218 | } |
222 | 219 | |
223 | 220 | $resourceUri = SMWTurtleSerializer::getTurtleNameForExpElement( $expNsResource ); |
— | — | @@ -224,7 +221,7 @@ |
225 | 222 | $skeyUri = SMWTurtleSerializer::getTurtleNameForExpElement( SMWExporter::getSpecialPropertyResource( '_SKEY' ) ); |
226 | 223 | |
227 | 224 | $sparqlResult = smwfGetSparqlDatabase()->select( '*', |
228 | | - "$resourceUri $skeyUri ?s OPTIONAL { $resourceUri $skeyUri ?s }", |
| 225 | + "$resourceUri $skeyUri ?s OPTIONAL { $resourceUri $rediUri ?r }", |
229 | 226 | array( 'LIMIT' => 1 ), |
230 | 227 | array( $expNsResource->getNamespaceId() => $expNsResource->getNamespace() ) ); |
231 | 228 | |
— | — | @@ -253,10 +250,19 @@ |
254 | 251 | * given resource. |
255 | 252 | * |
256 | 253 | * @param $expResource SMWExpResource |
| 254 | + * @return boolean success |
257 | 255 | */ |
258 | 256 | protected function deleteSparqlData( SMWExpResource $expResource ) { |
259 | 257 | $resourceUri = SMWTurtleSerializer::getTurtleNameForExpElement( $expResource ); |
260 | | - smwfGetSparqlDatabase()->delete( "$resourceUri ?p ?o", "$resourceUri ?p ?o" ); |
| 258 | + $masterPageProperty = SMWExporter::getSpecialNsResource( 'swivt', 'masterPage' ); |
| 259 | + $masterPagePropertyUri = SMWTurtleSerializer::getTurtleNameForExpElement( $masterPageProperty ); |
| 260 | + |
| 261 | + $success = smwfGetSparqlDatabase()->deleteContentByValue( $masterPagePropertyUri, $resourceUri ); |
| 262 | + if ( $success ) { |
| 263 | + return smwfGetSparqlDatabase()->delete( "$resourceUri ?p ?o", "$resourceUri ?p ?o" ); |
| 264 | + } else { |
| 265 | + return false; |
| 266 | + } |
261 | 267 | } |
262 | 268 | |
263 | 269 | |
— | — | @@ -284,5 +290,10 @@ |
285 | 291 | } |
286 | 292 | } |
287 | 293 | |
| 294 | + public function drop( $verbose = true ) { |
| 295 | + parent::drop( $verbose ); |
| 296 | + smwfGetSparqlDatabase()->delete( "?s ?p ?o", "?s ?p ?o" ); |
| 297 | + } |
| 298 | + |
288 | 299 | } |
289 | 300 | |