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 |
1 | 106 | + native |
Index: trunk/extensions/SemanticMediaWiki/languages/SMW_Messages.php |
— | — | @@ -44,6 +44,8 @@ |
45 | 45 | 'smw_csv_link' => 'CSV', |
46 | 46 | // Link to JSON feeds |
47 | 47 | 'smw_json_link' => 'JSON', |
| 48 | + // Link to RDF feeds |
| 49 | + 'smw_rdf_link' => 'RDF', |
48 | 50 | |
49 | 51 | // Names for result formats: |
50 | 52 | 'smw_printername_auto' => 'Automatic', |
— | — | @@ -59,6 +61,7 @@ |
60 | 62 | 'smw_printername_table' => 'Table', |
61 | 63 | 'smw_printername_broadtable' => 'Broad table', |
62 | 64 | 'smw_printername_template' => 'Template', |
| 65 | + 'smw_printername_rdf' => 'RDF export', |
63 | 66 | |
64 | 67 | // Messages for query parameter descriptions |
65 | 68 | 'smw_paramdesc_limit' => 'The maximum number of results to return', |
— | — | @@ -79,6 +82,7 @@ |
80 | 83 | 'smw_paramdesc_embedonly' => 'Display no headings', |
81 | 84 | 'smw_paramdesc_rsstitle' => 'The text to be used as the title of the feed', |
82 | 85 | 'smw_paramdesc_rssdescription' => 'The text to be used as the description of the feed', |
| 86 | + 'smw_paramdesc_rdfsyntax' => 'The RDF syntax to be used', |
83 | 87 | |
84 | 88 | // Messages and strings for inline queries |
85 | 89 | 'smw_iq_disabled' => "Semantic queries have been disabled for this wiki.", |
Index: trunk/extensions/SemanticMediaWiki/SMW_Settings.php |
— | — | @@ -295,7 +295,8 @@ |
296 | 296 | 'debug' => 'SMWListResultPrinter', |
297 | 297 | 'rss' => 'SMWRSSResultPrinter', |
298 | 298 | 'csv' => 'SMWCsvResultPrinter', |
299 | | - 'json' => 'SMWJSONResultPrinter' |
| 299 | + 'json' => 'SMWJSONResultPrinter', |
| 300 | + 'rdf' => 'SMWRDFResultPrinter' |
300 | 301 | ); |
301 | 302 | ## |
302 | 303 | |