Skip to content

Commit 060c63d

Browse files
committed
By default, set correct content type headers for SPARQL (XML) resultset
1 parent 4338de2 commit 060c63d

2 files changed

Lines changed: 27 additions & 23 deletions

File tree

classes/RDFIO_SpecialPage.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,27 @@ private function setHeadersForOutputType( $outputType ) {
4141
$wRequest = $this->getRequest();
4242

4343
$contentTypeMap = array(
44-
'xml' => 'application/xml',
45-
'rdfxml' => 'application/xml',
46-
'json' => 'application/json',
47-
'turtle' => 'text/html',
48-
'htmltab' => '', // Not applicable
49-
'tsv' => 'text/html'
44+
'sparqlresult' => 'application/sparql-results+xml',
45+
'rdfxml' => 'application/xml',
46+
'json' => 'application/json',
47+
'turtle' => 'text/html',
48+
'htmltab' => '', // Not applicable
49+
'tsv' => 'text/html'
5050
);
5151

5252
$extensionMap = array(
53-
'xml' => '.xml',
54-
'rdfxml' => '_rdf.xml',
55-
'json' => '.json',
56-
'turtle' => '.ttl',
57-
'htmltab' => '', // Not applicable
58-
'tsv' => '.tsv'
53+
'sparqlresult' => '.xml',
54+
'rdfxml' => '_rdf.xml',
55+
'json' => '.json',
56+
'turtle' => '.ttl',
57+
'htmltab' => '', // Not applicable
58+
'tsv' => '.tsv'
5959
);
6060

6161
if ( $outputType != 'htmltab' ) { // For HTML table we are taking care of the output earlier
6262
$wRequest->response()->header( 'Content-type: ' . $contentTypeMap[$outputType] . '; charset=utf-8' );
6363

64-
$fileName = urlencode('sparql_output_' . wfTimestampNow() . $extensionMap[$outputType] );
64+
$fileName = urlencode('sparql_result_' . wfTimestampNow() . $extensionMap[$outputType] );
6565
$wRequest->response()->header( 'Content-disposition: attachment;filename=' . $fileName );
6666
}
6767
}

specials/SpecialSPARQLEndpoint.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,23 @@ private function executeReadOnlyQuery( $options ) {
8787
}
8888

8989
if ( $options->queryType == 'select' ) {
90-
if ( $options->outputType == 'htmltab' ) {
91-
$resultHtml = $this->sparqlResultToHTML( $outputArr );
90+
if ( $options->outputType == 'rdfxml' ) {
91+
$this->errorMsg( wfMessage( 'rdfio-error-invalid-output-for-select' )->parse() );
9292
$this->printHTMLForm( $options );
93-
$wikiOut->addHTML( $resultHtml );
9493
return;
9594
}
9695

97-
if ( $options->outputType == 'xml' ) {
98-
$this->prepareCreatingDownloadableFile( $options );
99-
// Using echo instead of $wgOut->addHTML() here, since output format is not HTML
100-
echo $this->sparqlendpoint->getSPARQLXMLSelectResultDoc( $outputArr );
96+
if ( $options->outputType == 'htmltab' ) {
97+
$resultHtml = $this->sparqlResultToHTML( $outputArr );
98+
$this->printHTMLForm( $options );
99+
$wikiOut->addHTML( $resultHtml );
101100
return;
102101
}
103102

104-
$this->errorMsg( );
105-
$this->printHTMLForm( $options );
103+
// Default option: Return SPARQL result document
104+
$this->prepareCreatingDownloadableFile( $options );
105+
// Using echo instead of $wgOut->addHTML() here, since output format is not HTML
106+
echo $this->sparqlendpoint->getSPARQLXMLSelectResultDoc( $outputArr );
106107
return;
107108
}
108109

@@ -160,6 +161,9 @@ private function buildOptionsObj( $request, $queryByEquivURIs, $outputEquivURIs
160161
$seOptions->queryByEquivUris = isset( $queryByEquivURIs ) ? $queryByEquivURIs : $request->getBool( 'equivuri_q' );
161162
$seOptions->outputEquivUris = isset( $outputEquivURIs ) ? $outputEquivURIs : $request->getBool( 'equivuri_o' );
162163
$seOptions->outputType = $request->getText( 'output' );
164+
if ( $seOptions->outputType === '' ) {
165+
$seOptions->outputType = 'sparqlresult'; // Default according to https://www.w3.org/TR/sparql11-protocol
166+
}
163167

164168
if ( $seOptions->query != '' ) {
165169
$result = $this->extractQueryInfosAndType( $seOptions->query );
@@ -470,7 +474,7 @@ private function getHTMLForm( $query = '' ) {
470474
<!-- <option value="php_ser" >Serialized PHP</option> -->
471475
<!-- <option value="turtle" >Turtle</option> -->
472476
<option value="htmltab" ' . $selOutputHTML . '>HTML</option>
473-
<option value="xml" >XML Resultset</option>
477+
<option value="sparqlresult" >SPARQL Resultset (XML)</option>
474478
<option value="rdfxml" ' . $selOutputRDFXML . '>RDF/XML</option>
475479
<!-- <option value="infos" >Query Structure</option> -->
476480
<!-- <option value="tsv" >TSV</option> -->

0 commit comments

Comments
 (0)