r66972 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66971‎ | r66972 | r66973 >
Date:16:42, 27 May 2010
Author:mkroetzsch
Status:deferred
Tags:
Comment:
no longer needed to have schema references in the OWL/RDF export; importing the relevant schema is enough even for pedantic processors
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/Export/SMW_SpecialOWLExport.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/Export/SMW_SpecialOWLExport.php
@@ -1,10 +1,10 @@
22 <?php
33
44 /**
5 - * File holding the SMWSpecialOWLExport class for the Special:ExportRDF page.
 5+ * File holding the SMWSpecialOWLExport class for the Special:ExportRDF page.
66 *
77 * @file SMW_SpecialOWLExport.php
8 - *
 8+ *
99 * @ingroup SMWSpecialPage
1010 * @ingroup SpecialPage
1111 *
@@ -19,35 +19,35 @@
2020 * This special page for MediaWiki implements an OWL-export of semantic data,
2121 * gathered both from the annotations in articles, and from metadata already
2222 * present in the database.
23 - *
 23+ *
2424 * @ingroup SMWSpecialPage
2525 * @ingroup SpecialPage
26 - *
 26+ *
2727 * @author Markus Krötzsch
2828 */
2929 class SMWSpecialOWLExport extends SpecialPage {
30 -
 30+
3131 public function __construct() {
3232 parent::__construct( 'ExportRDF' );
3333 }
3434
3535 public function execute( $page = '' ) {
3636 global $wgOut, $wgRequest, $wgUser, $smwgAllowRecursiveExport, $smwgExportBacklinks, $smwgExportAll;
37 -
 37+
3838 $wgOut->setPageTitle( wfMsg( 'exportrdf' ) );
39 -
 39+
4040 $recursive = 0; // default, no recursion
4141 $backlinks = $smwgExportBacklinks; // default
42 -
 42+
4343 // check whether we already know what to export //
44 -
 44+
4545 if ( $page == '' ) { // try to get GET parameter; simple way of calling the export
4646 $page = $wgRequest->getVal( 'page' );
4747 } else {
4848 // this is needed since MediaWiki 1.8, but it is wrong for 1.7
4949 $page = rawurldecode( $page );
5050 }
51 -
 51+
5252 if ( $page == '' ) { // try to get POST list; some settings are only available via POST
5353 $pageblob = $wgRequest->getText( 'pages' );
5454 if ( '' != $pageblob ) {
@@ -56,11 +56,11 @@
5757 } else {
5858 $pages = array( $page );
5959 }
60 -
 60+
6161 if ( isset( $pages ) ) { // export to RDF
6262 $wgOut->disable();
6363 ob_start();
64 -
 64+
6565 // Only use rdf+xml mimetype if explicitly requested
6666 // TODO: should the see also links in the exported RDF then have this parameter as well?
6767 if ( $wgRequest->getVal( 'xmlmime' ) == 'rdf' ) {
@@ -68,11 +68,11 @@
6969 } else {
7070 header( "Content-type: application/xml; charset=UTF-8" );
7171 }
72 -
 72+
7373 if ( $wgRequest->getText( 'postform' ) == 1 ) {
7474 $postform = true; // effect: assume "no" from missing parameters generated by checkboxes
7575 } else $postform = false;
76 -
 76+
7777 $rec = $wgRequest->getText( 'recursive' );
7878 if ( $rec == '' ) $rec = $wgRequest->getVal( 'recursive' );
7979 if ( ( $rec == '1' ) && ( $smwgAllowRecursiveExport || $wgUser->isAllowed( 'delete' ) ) ) {
@@ -87,7 +87,7 @@
8888 }
8989 $date = $wgRequest->getText( 'date' );
9090 if ( $date == '' ) $date = $wgRequest->getVal( 'date' );
91 -
 91+
9292 $exp = new OWLExport();
9393 if ( $date != '' ) $exp->setDate( $date );
9494 $exp->printPages( $pages, $recursive, $backlinks );
@@ -112,9 +112,9 @@
113113 }
114114 }
115115 }
116 -
 116+
117117 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
118 -
 118+
119119 // nothing exported yet; show user interface:
120120 $html = '<form name="tripleSearch" action="" method="POST">' . "\n" .
121121 '<p>' . wfMsg( 'smw_exportrdf_docu' ) . "</p>\n" .
@@ -131,9 +131,9 @@
132132 $html .= '<input type="text" name="date" value="' . date( DATE_W3C, mktime( 0, 0, 0, 1, 1, 2000 ) ) . '" id="date">&nbsp;<label for="ea">' . wfMsg( 'smw_exportrdf_lastdate' ) . '</label></input><br />' . "\n";
133133 }
134134 $html .= "<br /><input type=\"submit\" value=\"" . wfMsg( 'smw_exportrdf_submit' ) . "\"/>\n</form>";
135 - $wgOut->addHTML( $html );
136 - }
137 -
 135+ $wgOut->addHTML( $html );
 136+ }
 137+
138138 }
139139
140140 /**
@@ -203,12 +203,6 @@
204204 private $global_namespaces;
205205
206206 /**
207 - * Array of references to the SWIVT schema. Will be added at the end of the
208 - * export.
209 - */
210 - private $schema_refs;
211 -
212 - /**
213207 * Unprinted XML is composed from the strings $pre_ns_buffer and $post_ns_buffer.
214208 * The split between the two is such that one can append additional namespace
215209 * declarations to $pre_ns_buffer so that they affect all current elements. The
@@ -242,7 +236,6 @@
243237 public function __construct() {
244238 $this->element_queue = array();
245239 $this->element_done = array();
246 - $this->schema_refs = array();
247240 $this->date = '';
248241 }
249242
@@ -594,24 +587,13 @@
595588 "\t\t<owl:imports rdf:resource=\"http://semantic-mediawiki.org/swivt/1.0\" />\n" .
596589 "\t</owl:Ontology>\n" .
597590 "\t<!-- exported page data -->\n";
598 - $this->addSchemaRef( "page", "owl:AnnotationProperty" );
599 - $this->addSchemaRef( "creationDate", "owl:AnnotationProperty" );
600 - $this->addSchemaRef( "Subject", "owl:Class" );
601591 }
602592
603593 /**
604 - * Prints the footer. Prints also all open schema-references.
605 - * No schema-references can be added after printing the footer.
 594+ * Prints the footer.
606595 */
607596 protected function printFooter() {
608 - $this->post_ns_buffer .= "\t<!-- References to the SWiVT Ontology, see http://semantic-mediawiki.org/swivt/ -->\n";
609 - foreach ( $this->schema_refs as $name => $type ) {
610 - $this->post_ns_buffer .=
611 - "\t<$type rdf:about=\"&swivt;$name\">\n" .
612 - "\t\t<rdfs:isDefinedBy rdf:resource=\"http://semantic-mediawiki.org/swivt/1.0\"/>\n" .
613 - "\t</$type>\n";
614 - }
615 - $this->post_ns_buffer .= "\t<!-- Created by Semantic MediaWiki, http://semantic-mediawiki.org -->\n";
 597+ $this->post_ns_buffer .= "\t<!-- Created by Semantic MediaWiki, http://semantic-mediawiki.org/ -->\n";
616598 $this->post_ns_buffer .= '</rdf:RDF>';
617599 }
618600
@@ -769,16 +751,16 @@
770752
771753 print $this->pre_ns_buffer;
772754 $this->pre_ns_buffer = '';
773 -
 755+
774756 foreach ( $this->extra_namespaces as $nsshort => $nsuri ) {
775757 if ( $this->first_flush ) {
776758 $this->global_namespaces[$nsshort] = true;
777759 print "\n\t";
778760 } else print ' ';
779 -
 761+
780762 print "xmlns:$nsshort=\"$nsuri\"";
781763 }
782 -
 764+
783765 $this->extra_namespaces = array();
784766 print $this->post_ns_buffer;
785767 $this->post_ns_buffer = '';
@@ -802,21 +784,6 @@
803785 }
804786
805787 /**
806 - * Adds a reference to the SWIVT schema. This will make sure that at the end of the page,
807 - * all required schema references will be defined and point to the appropriate ontology.
808 - *
809 - * @param $name The fragmend identifier of the entity to be referenced. The SWIVT namespace
810 - * is added.
811 - * @param $type The type of the referenced identifier, i.e. is it an annotation property, an
812 - * object property, a class, etc. Should be given as a QName (i.e. in the form "owl:Class",
813 - * etc.)
814 - */
815 - public function addSchemaRef( $name, $type ) {
816 - if ( !array_key_exists( $name, $this->schema_refs ) )
817 - $this->schema_refs[$name] = $type;
818 - }
819 -
820 - /**
821788 * Add a given SMWExpResource to the export queue if needed.
822789 */
823790 public function queueElement( $element ) {

Status & tagging log