function __construct($args)
 {
     global $sparqlEndpointConfiguration;
     //query string is first argument
     $query_string = array_shift($args);
     // prepend prefixes to query
     $query_string = SparqlUtil::createPrefixes() . $query_string;
     // get the rest of the function arguments
     $tmp = array();
     foreach ($args as $arg) {
         if (!is_object($arg)) {
             preg_match('/^(\\w+)\\s*=\\s*(.+)$/is', $arg, $match) ? $tmp[$match[1]] = $match[2] : ($args[] = $arg);
         }
     }
     // add query string to the parameters
     $tmp[$sparqlEndpointConfiguration["query_parameter"]] = $query_string;
     if (isset($tmp["format"])) {
         $this->format = $tmp["format"];
     } else {
         $this->format = SparqlOutputFormat::$DEFAULT_FORMAT;
     }
     $this->parameters = $tmp;
 }
 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;
     }
 }