r88882 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88881‎ | r88882 | r88883 >
Date:08:10, 26 May 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
enable basic RDF eport for arbitrary special properties;
escape URIs in RDF/XML serialization, not in Export
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/export/SMW_Serializer_RDFXML.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Serializer_RDFXML.php
@@ -180,8 +180,7 @@
181181 if ( $expLiteral->getDatatype() != '' ) {
182182 $this->post_ns_buffer .= ' rdf:datatype="' . $expLiteral->getDatatype() . '"';
183183 }
184 - $this->post_ns_buffer .= '>' .
185 - str_replace( array( '&', '>', '<' ), array( '&amp;', '&gt;', '&lt;' ), $expLiteral->getLexicalForm() ) .
 184+ $this->post_ns_buffer .= '>' . $this->makeAttributeValueString( $expLiteral->getLexicalForm() ) .
186185 '</' . $expResourceProperty->getQName() . ">\n";
187186 }
188187
@@ -197,10 +196,12 @@
198197 protected function serializeExpResource( SMWExpNsResource $expResourceProperty, SMWExpResource $expResource, $indent, $isClassTypeProp ) {
199198 $this->post_ns_buffer .= $indent . '<' . $expResourceProperty->getQName();
200199 if ( !$expResource->isBlankNode() ) {
201 - if ( ( $expResource instanceof SMWExpNsResource ) && ( $expResource->getNamespaceID() == 'wiki' ) ) { // very common case, reduce bandwidth
 200+ if ( ( $expResource instanceof SMWExpNsResource ) && ( $expResource->getNamespaceID() == 'wiki' ) ) {
 201+ // very common case, reduce bandwidth
202202 $this->post_ns_buffer .= ' rdf:resource="&wiki;' . $expResource->getLocalName() . '"';
203203 } else {
204 - $this->post_ns_buffer .= ' rdf:resource="' . $expResource->getUri() . '"';
 204+ $uriValue = $this->makeAttributeValueString( $expResource->getUri() );
 205+ $this->post_ns_buffer .= ' rdf:resource="' . $uriValue . '"';
205206 }
206207 }
207208 $this->post_ns_buffer .= "/>\n";
@@ -237,10 +238,22 @@
238239 * Escape a string in the special form that is required for values in
239240 * DTD entity declarations in XML. Namely, this require the percent sign
240241 * to be replaced.
241 - * @param string $string to be escaped
 242+ *
 243+ * @param $string string to be escaped
 244+ * @return string
242245 */
243246 protected function makeValueEntityString( $string ) {
244247 return "'" . str_replace( '%','&#37;',$string ) . "'";
245248 }
246249
 250+ /**
 251+ * Escape a string as required for using it in XML attribute values.
 252+ *
 253+ * @param $string string to be escaped
 254+ * @return string
 255+ */
 256+ protected function makeAttributeValueString( $string ) {
 257+ return str_replace( array( '&', '>', '<' ), array( '&amp;', '&gt;', '&lt;' ), $string );
 258+ }
 259+
247260 }
Index: trunk/extensions/SemanticMediaWiki/includes/export/SMW_Exporter.php
@@ -313,7 +313,7 @@
314314 }
315315 }
316316 }
317 - }
 317+ } // else: not in wiki namespace -- TODO: this could be an imported URI
318318 } else {
319319 // TODO (currently not needed, but will be useful for displaying external SPARQL results)
320320 }
@@ -358,7 +358,7 @@
359359 return self::getSpecialNsResource( 'rdf', 'type' );
360360 case '_SUBC':
361361 return self::getSpecialNsResource( 'rdfs', 'subClassOf' );
362 - case '_CONC': // we actually simplify this below, but need a non-null value now
 362+ case '_CONC':
363363 return self::getSpecialNsResource( 'owl', 'equivalentClass' );
364364 case '_URI':
365365 if ( $forNamespace == NS_CATEGORY || $forNamespace == SMW_NS_CONCEPT ) {
@@ -380,9 +380,10 @@
381381 return self::getSpecialNsResource( 'swivt', 'wikiPageModificationDate' );
382382 case '_SKEY':
383383 return self::getSpecialNsResource( 'swivt', 'wikiPageSortKey' );
384 - case '_TYPE': /// TODO: property type currently not exported
385 - return null;
386 - default: return null;
 384+ case '_TYPE':
 385+ return self::getSpecialNsResource( 'swivt', 'type' );
 386+ default:
 387+ return self::getSpecialNsResource( 'swivt', 'specialProperty' . $propertyKey );
387388 }
388389 }
389390
@@ -514,8 +515,7 @@
515516 $lit = new SMWExpLiteral( $xsdvalue, 'http://www.w3.org/2001/XMLSchema#boolean', $dataItem );
516517 return $lit;
517518 case SMWDataItem::TYPE_URI:
518 - /// TODO This escaping seems very odd. The serialisation should handle such things.
519 - $res = new SMWExpResource( str_replace( '&', '&amp;', $dataItem->getURI() ), $dataItem );
 519+ $res = new SMWExpResource( $dataItem->getURI(), $dataItem );
520520 return $res;
521521 case SMWDataItem::TYPE_TIME:
522522 $gregorianTime = $dataItem->getForCalendarModel( SMWDITime::CM_GREGORIAN );

Status & tagging log