From a6727bcf73ef39493fc017503c8674cd02a56b89 Mon Sep 17 00:00:00 2001 From: Samuel Lampa Date: Thu, 17 Aug 2017 19:50:34 +0200 Subject: [PATCH] Fix default Content-type header for CONSTRUCT queries (Only RDF/XML so far) --- classes/RDFIO_SpecialPage.php | 4 ++-- specials/SpecialSPARQLEndpoint.php | 36 +++++++++++++++--------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/classes/RDFIO_SpecialPage.php b/classes/RDFIO_SpecialPage.php index d6d741f..a9a0e0c 100644 --- a/classes/RDFIO_SpecialPage.php +++ b/classes/RDFIO_SpecialPage.php @@ -42,9 +42,9 @@ private function setHeadersForOutputType( $outputType ) { $contentTypeMap = array( 'sparqlresult' => 'application/sparql-results+xml', - 'rdfxml' => 'application/xml', + 'rdfxml' => 'application/rdf+xml', 'json' => 'application/json', - 'turtle' => 'text/html', + 'turtle' => 'text/turtle', 'htmltab' => '', // Not applicable 'tsv' => 'text/html' ); diff --git a/specials/SpecialSPARQLEndpoint.php b/specials/SpecialSPARQLEndpoint.php index 6cf1375..6dda630 100644 --- a/specials/SpecialSPARQLEndpoint.php +++ b/specials/SpecialSPARQLEndpoint.php @@ -87,7 +87,7 @@ private function executeReadOnlyQuery( $options ) { } if ( $options->queryType == 'select' ) { - if ( $options->outputType == 'rdfxml' ) { + if ( in_array( $options->outputType, array( 'rdfxml' ) ) ) { $this->errorMsg( wfMessage( 'rdfio-error-invalid-output-for-select' )->parse() ); $this->printHTMLForm( $options ); return; @@ -108,26 +108,25 @@ private function executeReadOnlyQuery( $options ) { } if ( $options->queryType == 'construct' ) { - if ( $options->outputType == 'rdfxml' ) { - // Here the results should be RDF/XML triples, - // not just plain XML SPARQL result set - $tripleindex = $outputArr['result']; - - $arc2 = new ARC2_Class( array(), $this ); - $triples = $arc2->toTriples( $tripleindex ); + if ( $options->outputType !== 'turtle' ) { + // Falling back on using RDF/XML as default + $options->outputType = 'rdfxml'; + } - if ( $options->outputEquivUris ) { - $triples = $this->storewrapper->toEquivUrisInTriples( $triples ); - } + // Here the results should be RDF/XML triples, + // not just plain XML SPARQL result set + $tripleindex = $outputArr['result']; - $this->prepareCreatingDownloadableFile( $options ); - // Using echo instead of $wgOut->addHTML() here, since output format is not HTML - echo $this->triplesToRDFXML( $triples ); - return; + $arc2 = new ARC2_Class( array(), $this ); + $triples = $arc2->toTriples( $tripleindex ); + if ( $options->outputEquivUris ) { + $triples = $this->storewrapper->toEquivUrisInTriples( $triples ); } - $this->errorMsg( wfMessage( 'rdfio-error-invalid-output-for-construct' )->parse() ); - $this->printHTMLForm( $options ); + + $this->prepareCreatingDownloadableFile( $options ); + // Using echo instead of $wgOut->addHTML() here, since output format is not HTML + echo $this->triplesToRDFXML( $triples ); return; } } @@ -434,6 +433,7 @@ private function getHTMLForm( $query = '' ) { $chkFilterVocab = $wRequest->getBool( 'filtervocab', false ) == 1 ? ' checked="true" ' : ''; $selOutputHTML = $wRequest->getText( 'output', '' ) == 'htmltab' ? ' selected="selected" ' : ''; $selOutputRDFXML = $wRequest->getText( 'output', '' ) == 'rdfxml' ? ' selected="selected" ' : ''; + //$selOutputTurtle = $wRequest->getText( 'output', '' ) == 'turtle' ? ' selected="selected" ' : ''; // Make the HTML format selected by default if ( $selOutputRDFXML == '' ) { @@ -472,10 +472,10 @@ private function getHTMLForm( $query = '' ) { - +