public function getEndpointRequestUrlForType($type)
 {
     global $sparqlEndpointConfiguration, $smwgDefaultStore;
     // store endpoint parameters
     $endpoint_parameters = array();
     $endpoint_parameters[$sparqlEndpointConfiguration["query_parameter"]] = $this->parameters[$sparqlEndpointConfiguration["query_parameter"]];
     $endpoint_parameters[$sparqlEndpointConfiguration["output_type_parameter"]] = $type;
     // build endpoint request url
     if ($smwgDefaultStore == "SesameStore") {
         // FIXME: for Sesame the use of a proxy does not seem to work, using
         // direct endpoint for now instead (Jeen).
         $srvc_url = $sparqlEndpointConfiguration["service_url"];
     } else {
         // pipe everything thorugh the proxy
         // TODO: performance test - maybe better to go for the original endpoint instead of proxy,
         // but also possible to do some caching via proxy and query rewriting, user control etc...much better
         $srvc_url = SpecialPage::getTitleFor("SparqlExtension")->getFullURL();
     }
     $endpoint_request_url = SparqlUtil::build_restful_url($srvc_url, $endpoint_parameters);
     return $endpoint_request_url;
 }
 function execute($par)
 {
     global $wgRequest, $wgOut, $sparqlEndpointConfiguration;
     $request = $wgRequest->getValues();
     if (is_null($wgRequest->getVal("query"))) {
         // if no query provided - show the form page
         $url = $this->getTitle()->getLinkUrl();
         $formHTML = "<form action=\"" . $url . "\" method=\"get\">" . "<textarea name=\"query\" rows=\"40\">" . SparqlUtil::createPrefixes() . "select * where {\n" . "?x ?y ?z .\n" . "} limit 10" . "</textarea>" . "<div><select name=\"" . $sparqlEndpointConfiguration["output_type_parameter"] . "\">" . "<option value=\"" . SparqlExtension::$XML_TYPE . "\">XML</option>" . "<option value=\"" . SparqlExtension::$JSON_TYPE . "\">JSON</option>" . "<option value=\"" . SparqlExtension::$TEXT_TYPE . "\" selected=\"true\">TEXT</option>" . "<option value=\"" . SparqlExtension::$CSV_TYPE . "\">CSV</option>" . "<option value=\"" . SparqlExtension::$TSV_TYPE . "\">TSV</option>" . "<option value=\"" . SparqlExtension::$GDS_TYPE . "\">GOOGLE-VIS</option>" . "<option value=\"" . SparqlExtension::$SR_TYPE . "\">SEMANTIC REPORT</option>" . "</select><input type=\"submit\" value=\"Get Results\" /></form></div>";
         $this->setHeaders();
         $wgOut->addHTML($formHTML);
     } else {
         $sparql_url = $sparqlEndpointConfiguration["service_url"];
         $response = "";
         $header = "";
         $output = isset($request["output"]) ? $request["output"] : "xml";
         switch (strtolower($output)) {
             case "xml":
                 $url = SparqlUtil::build_restful_url($sparql_url, $request);
                 $opts = array('http' => array('method' => 'GET', 'header' => 'Accept: application/sparql-results+xml, application/rdf+xml, application/xml'));
                 $context = stream_context_create($opts);
                 $response = file_get_contents($url, false, $context);
                 $header = "Content-type: application/xml; charset=utf-8";
                 break;
             case "gds":
                 $url = SparqlUtil::build_restful_url($sparql_url, $request);
                 $inputparams = array();
                 if (isset($request["tqx"])) {
                     $inputparams["tqx"] = $request["tqx"];
                 }
                 $response = $this->xslt_transform($url, SparqlExtension::$GDS_XSL_URL, $inputparams);
                 $header = "Content-type: application/x-javascript; charset=utf-8";
                 break;
             case "json":
                 $url = SparqlUtil::build_restful_url($sparql_url, $request);
                 $opts = array('http' => array('method' => 'GET', 'header' => 'Accept: application/sparql-results+json, application/rdf+json, application/json'));
                 $context = stream_context_create($opts);
                 $response = file_get_contents($url, false, $context);
                 $header = "Content-type: application/json; charset=utf-8";
                 break;
             case "text":
                 $url = SparqlUtil::build_restful_url($sparql_url, $request);
                 $opts = array('http' => array('method' => 'GET', 'header' => 'Accept: text/plain, text/*, */*'));
                 $context = stream_context_create($opts);
                 $response = file_get_contents($url, false, $context);
                 $header = "Content-type: text/plain; charset=utf-8";
                 break;
             case "csv":
                 $url = SparqlUtil::build_restful_url($sparql_url, $request);
                 $opts = array('http' => array('method' => 'GET', 'header' => 'Accept: text/csv, text/*, */*'));
                 $context = stream_context_create($opts);
                 $response = file_get_contents($url, false, $context);
                 $header = "Content-type: text/csv; charset=utf-8";
                 break;
             case "tsv":
                 $url = SparqlUtil::build_restful_url($sparql_url, $request);
                 $opts = array('http' => array('method' => 'GET', 'header' => 'Accept: text/tsv, text/*, */*'));
                 $context = stream_context_create($opts);
                 $response = file_get_contents($url, false, $context);
                 $header = "Content-type: text/tsv; charset=utf-8";
                 break;
             case "semantic-reports":
                 $request["endpoint"] = $sparql_url;
                 $request["view"] = "create";
                 $url = SparqlUtil::build_restful_url("http://semanticreports.com/reports/", $request);
                 //$response = file_get_contents($url);
                 $header = "Location: " . $url;
                 break;
             default:
                 $url = SparqlUtil::build_restful_url($sparql_url, $request);
                 $opts = array('http' => array('method' => 'GET', 'header' => 'Accept: application/sparql-results+xml, application/rdf+xml, application/xml'));
                 $context = stream_context_create($opts);
                 $response = file_get_contents($url, false, $context);
                 $header = "Content-type: application/xml; charset=utf-8";
                 break;
         }
         $wgOut->disable();
         header($header);
         print $response;
     }
 }