r79734 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79733‎ | r79734 | r79735 >
Date:17:19, 6 January 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
new query format "rdf" that allows query results to be exported as RDF using the new modular serialization code
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/SMW_Settings.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_RDF.php (added) (history)
  • /trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_RDF.php
@@ -0,0 +1,104 @@
 2+<?php
 3+/**
 4+ * RDF export for SMW Queries
 5+ * @file
 6+ * @ingroup SMWQuery
 7+ */
 8+
 9+/**
 10+ * Printer class for generating RDF output
 11+ * @author Markus Krötzsch
 12+ * @ingroup SMWQuery
 13+ */
 14+class SMWRDFResultPrinter extends SMWResultPrinter {
 15+
 16+ /**
 17+ * The syntax to be used for export. May be 'rdfxml' or 'turtle'.
 18+ */
 19+ protected $syntax;
 20+
 21+ protected function readParameters( $params, $outputmode ) {
 22+ SMWResultPrinter::readParameters( $params, $outputmode );
 23+ if ( array_key_exists( 'syntax', $params ) ) {
 24+ $this->syntax = $params['syntax'];
 25+ } else {
 26+ $this->syntax = 'rdfxml';
 27+ }
 28+ }
 29+
 30+ public function getMimeType( $res ) {
 31+ return $this->syntax == 'turtle' ? 'application/x-turtle' : 'application/xml';
 32+ }
 33+
 34+ public function getFileName( $res ) {
 35+ return $this->syntax == 'turtle' ? 'result.ttl' : 'result.rdf';
 36+ }
 37+
 38+ public function getQueryMode( $context ) {
 39+ return ( $context == SMWQueryProcessor::SPECIAL_PAGE ) ? SMWQuery::MODE_INSTANCES : SMWQuery::MODE_NONE;
 40+ }
 41+
 42+ public function getName() {
 43+ smwfLoadExtensionMessages( 'SemanticMediaWiki' );
 44+ return wfMsg( 'smw_printername_rdf' );
 45+ }
 46+
 47+ protected function getResultText( $res, $outputmode ) {
 48+ if ( $outputmode == SMW_OUTPUT_FILE ) { // make RDF file
 49+ $serializer = $this->syntax == 'turtle' ? new SMWTurtleSerializer() : new SMWRDFXMLSerializer();
 50+ $serializer->startSerialization();
 51+ $serializer->serializeExpData( SMWExporter::getOntologyExpData( '' ) );
 52+ while ( $row = $res->getNext() ) {
 53+ $data = SMWExporter::makeExportDataForSubject( reset( $row )->getResultSubject() );
 54+ foreach ( $row as $resultarray ) {
 55+ $printreq = $resultarray->getPrintRequest();
 56+ $property = null;
 57+ switch ( $printreq->getMode() ) {
 58+ case SMWPrintRequest::PRINT_PROP:
 59+ $property = $printreq->getData();
 60+ break;
 61+ case SMWPrintRequest::PRINT_CATS:
 62+ $property = SMWPropertyValue::makeProperty( '_TYPE' );
 63+ break;
 64+ case SMWPrintRequest::PRINT_CCAT:
 65+ // not serialised right now
 66+ break;
 67+ case SMWPrintRequest::PRINT_THIS:
 68+ // ignored here (object is always included in export)
 69+ break;
 70+ }
 71+ if ( $property !== null ) {
 72+ SMWExporter::addPropertyValues( $property, $resultarray->getContent() , $data );
 73+ }
 74+ }
 75+ $serializer->serializeExpData( $data );
 76+ }
 77+ $serializer->finishSerialization();
 78+ return $serializer->flushContent();
 79+ } else { // just make link to feed
 80+ if ( $this->getSearchLabel( $outputmode ) ) {
 81+ $label = $this->getSearchLabel( $outputmode );
 82+ } else {
 83+ smwfLoadExtensionMessages( 'SemanticMediaWiki' );
 84+ $label = wfMsgForContent( 'smw_rdf_link' );
 85+ }
 86+
 87+ $link = $res->getQueryLink( $label );
 88+ $link->setParameter( 'rdf', 'format' );
 89+ $link->setParameter( $this->syntax, 'syntax' );
 90+ if ( array_key_exists( 'limit', $this->m_params ) ) {
 91+ $link->setParameter( $this->m_params['limit'], 'limit' );
 92+ } else { // use a reasonable default limit
 93+ $link->setParameter( 100, 'limit' );
 94+ }
 95+ $this->isHTML = ( $outputmode == SMW_OUTPUT_HTML ); // yes, our code can be viewed as HTML if requested, no more parsing needed
 96+ return $link->getText( $outputmode, $this->mLinker );
 97+ }
 98+ }
 99+
 100+ public function getParameters() {
 101+ $syntaxparam = array( 'name' => 'syntax', 'type' => 'enumeration', 'description' => wfMsg( 'smw_paramdesc_rdfsyntax' ), 'values' =>array( 'rdfxml', 'turtle' ) );
 102+ return array_merge( parent::exportFormatParameters(), array( $syntaxparam ) );
 103+ }
 104+
 105+}
Property changes on: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_RDF.php
___________________________________________________________________
Added: svn:eol-style
1106 + native
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php
@@ -44,6 +44,8 @@
4545 'smw_csv_link' => 'CSV',
4646 // Link to JSON feeds
4747 'smw_json_link' => 'JSON',
 48+ // Link to RDF feeds
 49+ 'smw_rdf_link' => 'RDF',
4850
4951 // Names for result formats:
5052 'smw_printername_auto' => 'Automatic',
@@ -59,6 +61,7 @@
6062 'smw_printername_table' => 'Table',
6163 'smw_printername_broadtable' => 'Broad table',
6264 'smw_printername_template' => 'Template',
 65+ 'smw_printername_rdf' => 'RDF export',
6366
6467 // Messages for query parameter descriptions
6568 'smw_paramdesc_limit' => 'The maximum number of results to return',
@@ -79,6 +82,7 @@
8083 'smw_paramdesc_embedonly' => 'Display no headings',
8184 'smw_paramdesc_rsstitle' => 'The text to be used as the title of the feed',
8285 'smw_paramdesc_rssdescription' => 'The text to be used as the description of the feed',
 86+ 'smw_paramdesc_rdfsyntax' => 'The RDF syntax to be used',
8387
8488 // Messages and strings for inline queries
8589 'smw_iq_disabled' => "Semantic queries have been disabled for this wiki.",
Index: trunk/extensions/SemanticMediaWiki/SMW_Settings.php
@@ -295,7 +295,8 @@
296296 'debug' => 'SMWListResultPrinter',
297297 'rss' => 'SMWRSSResultPrinter',
298298 'csv' => 'SMWCsvResultPrinter',
299 - 'json' => 'SMWJSONResultPrinter'
 299+ 'json' => 'SMWJSONResultPrinter',
 300+ 'rdf' => 'SMWRDFResultPrinter'
300301 );
301302 ##
302303

Follow-up revisions

RevisionCommit summaryAuthorDate
r79757Follow-up r79734: Make new message optional for Translatewiki because it is i...raymond21:09, 6 January 2011

Status & tagging log