Exemplo n.º 1
0
	/**
	 * Encode an array of parameters, formatted as $name => $value, to a parameter
	 * string that can be used for linking. If $forTitle is true (default), then the
	 * parameters are encoded for use in a MediaWiki page title (useful for making
	 * internal links to parameterised special pages), otherwise the parameters are
	 * encoded HTTP GET style. The parameter name "x" is used to collect parameters
	 * that do not have any string keys in GET, and hence "x" should never be used
	 * as a parameter name.
	 *
	 * The function SMWInfolink::decodeParameters() can be used to undo this encoding.
	 * It is strongly recommended to not create any code that depends on the concrete
	 * way of how parameters are encoded within this function, and to always use the
	 * respective encoding/decoding methods instead.
	 *
	 * @param array $params
	 * @param boolean $forTitle
	 */
	static public function encodeParameters( array $params, $forTitle = true ) {
		$result = '';

		if ( $forTitle ) {
			foreach ( $params as $name => $value ) {
				if ( is_string( $name ) && ( $name !== '' ) ) {
					$value = $name . '=' . $value;
				}
				// Escape certain problematic values. Use SMW-escape
				// (like URLencode but - instead of % to prevent double encoding by later MW actions)
				//
				/// : SMW's parameter separator, must not occur within params
				// - : used in SMW-encoding strings, needs escaping too
				// [ ] < > &lt; &gt; '' |: problematic in MW titles
				// & : sometimes problematic in MW titles ([[&amp;]] is OK, [[&test]] is OK, [[&test;]] is not OK)
				//     (Note: '&' in strings obtained during parsing already has &entities; replaced by
				//      UTF8 anyway)
				// ' ': are equivalent with '_' in MW titles, but are not equivalent in certain parameter values
				// "\n": real breaks not possible in [[...]]
				// "#": has special meaning in URLs, triggers additional MW escapes (using . for %)
				// '%': must be escaped to prevent any impact of double decoding when replacing -
				//      by % before urldecode
				// '?': if not escaped, strange effects were observed on some sites (printout and other
				//      parameters ignored without obvious cause); SMW-escaping is always save to do -- it just
				//      make URLs less readable
				//
				$value = str_replace(
					array( '-', '#', "\n", ' ', '/', '[', ']', '<', '>', '&lt;', '&gt;', '&amp;', '\'\'', '|', '&', '%', '?' ),
					array( '-2D', '-23', '-0A', '-20', '-2F', '-5B', '-5D', '-3C', '-3E', '-3C', '-3E', '-26', '-27-27', '-7C', '-26', '-25', '-3F' ),
					$value
				);

				if ( $result !== '' ) {
					$result .= '/';
				}

				$result .= $value;
			}
		} else { // Note: this requires to have HTTP compatible parameter names (ASCII)
			$q = array(); // collect unlabelled query parameters here

			foreach ( $params as $name => $value ) {
				if ( is_string( $name ) && ( $name !== '' ) ) {
					$value = $name . '=' . rawurlencode( $value );

					if ( $result !== '' ) {
						$result .= '&';
					}

					$result .= $value;
				} else {
					$q[] = $value;
				}
			}
			if ( count( $q ) > 0 ) { // prepend encoding for unlabelled parameters
				if ( $result !== '' ) {
					$result = '&' . $result;
				}
				$result = 'x=' . rawurlencode( SMWInfolink::encodeParameters( $q, true ) ) . $result;
			}
		}

		return $result;
	}
Exemplo n.º 2
0
 /**
  * TODO: document
  */
 protected function makeHTMLResult()
 {
     global $wgOut;
     // TODO: hold into account $smwgAutocompleteInSpecialAsk
     $wgOut->addModules('ext.smw.ask');
     $result = '';
     $result_mime = false;
     // output in MW Special page as usual
     // build parameter strings for URLs, based on current settings
     $urlArgs['q'] = $this->m_querystring;
     $tmp_parray = array();
     foreach ($this->m_params as $key => $value) {
         if (!in_array($key, array('sort', 'order', 'limit', 'offset', 'title'))) {
             $tmp_parray[$key] = $value;
         }
     }
     $urlArgs['p'] = SMWInfolink::encodeParameters($tmp_parray);
     $printoutstring = '';
     /**
      * @var SMWPrintRequest $printout
      */
     foreach ($this->m_printouts as $printout) {
         $printoutstring .= $printout->getSerialisation() . "\n";
     }
     if ($printoutstring !== '') {
         $urlArgs['po'] = $printoutstring;
     }
     if (array_key_exists('sort', $this->m_params)) {
         $urlArgs['sort'] = $this->m_params['sort'];
     }
     if (array_key_exists('order', $this->m_params)) {
         $urlArgs['order'] = $this->m_params['order'];
     }
     if ($this->m_querystring !== '') {
         // FIXME: this is a hack
         SMWQueryProcessor::addThisPrintout($this->m_printouts, $this->m_params);
         $params = SMWQueryProcessor::getProcessedParams($this->m_params, $this->m_printouts);
         $this->m_params['format'] = $params['format']->getValue();
         $this->params = $params;
         $queryobj = SMWQueryProcessor::createQuery($this->m_querystring, $params, SMWQueryProcessor::SPECIAL_PAGE, $this->m_params['format'], $this->m_printouts);
         /**
          * @var SMWQueryResult $res
          */
         // Determine query results
         $res = $params['source']->getValue()->getQueryResult($queryobj);
         // Try to be smart for rss/ical if no description/title is given and we have a concept query:
         if ($this->m_params['format'] == 'rss') {
             $desckey = 'rssdescription';
             $titlekey = 'rsstitle';
         } elseif ($this->m_params['format'] == 'icalendar') {
             $desckey = 'icalendardescription';
             $titlekey = 'icalendartitle';
         } else {
             $desckey = false;
         }
         if ($desckey && $queryobj->getDescription() instanceof SMWConceptDescription && (!isset($this->m_params[$desckey]) || !isset($this->m_params[$titlekey]))) {
             $concept = $queryobj->getDescription()->getConcept();
             if (!isset($this->m_params[$titlekey])) {
                 $this->m_params[$titlekey] = $concept->getText();
             }
             if (!isset($this->m_params[$desckey])) {
                 // / @bug The current SMWStore will never return SMWConceptValue (an SMWDataValue) here; it might return SMWDIConcept (an SMWDataItem)
                 $dv = end(smwfGetStore()->getPropertyValues(SMWWikiPageValue::makePageFromTitle($concept), new SMWDIProperty('_CONC')));
                 if ($dv instanceof SMWConceptValue) {
                     $this->m_params[$desckey] = $dv->getDocu();
                 }
             }
         }
         $printer = SMWQueryProcessor::getResultPrinter($this->m_params['format'], SMWQueryProcessor::SPECIAL_PAGE);
         global $wgRequest;
         $hidequery = $wgRequest->getVal('eq') == 'no';
         if (!$printer->isExportFormat()) {
             if ($res->getCount() > 0) {
                 if ($this->m_editquery) {
                     $urlArgs['eq'] = 'yes';
                 } elseif ($hidequery) {
                     $urlArgs['eq'] = 'no';
                 }
                 $navigation = $this->getNavigationBar($res, $urlArgs);
                 $result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n";
                 $query_result = $printer->getResult($res, $params, SMW_OUTPUT_HTML);
                 if (is_array($query_result)) {
                     $result .= $query_result[0];
                 } else {
                     $result .= $query_result;
                 }
                 $result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n";
             } else {
                 $result = '<div style="text-align: center;">' . wfMessage('smw_result_noresults')->escaped() . '</div>';
             }
         }
     }
     if (isset($printer) && $printer->isExportFormat()) {
         $wgOut->disable();
         /**
          * @var SMWIExportPrinter $printer
          */
         $printer->outputAsFile($res, $params);
     } else {
         if ($this->m_querystring) {
             $wgOut->setHTMLtitle($this->m_querystring);
         } else {
             $wgOut->setHTMLtitle(wfMessage('ask')->text());
         }
         $urlArgs['offset'] = $this->m_params['offset'];
         $urlArgs['limit'] = $this->m_params['limit'];
         $result = $this->getInputForm($printoutstring, wfArrayToCGI($urlArgs)) . $result;
         $wgOut->addHTML($result);
     }
 }
 private function encodePrefixedDBkey()
 {
     return Infolink::encodeParameters(array($this->skinTemplate->getSkin()->getTitle()->getPrefixedDBkey()), true);
 }
Exemplo n.º 4
0
 protected function makeHTMLResult()
 {
     global $wgOut;
     $result = '';
     $result_mime = false;
     // output in MW Special page as usual
     // build parameter strings for URLs, based on current settings
     $urltail = '&q=' . urlencode($this->m_querystring);
     $tmp_parray = array();
     foreach ($this->m_params as $key => $value) {
         if (!in_array($key, array('sort', 'order', 'limit', 'offset', 'title'))) {
             $tmp_parray[$key] = $value;
         }
     }
     $urltail .= '&p=' . urlencode(SMWInfolink::encodeParameters($tmp_parray));
     $printoutstring = '';
     foreach ($this->m_printouts as $printout) {
         $printoutstring .= $printout->getSerialisation() . "\n";
     }
     if ('' != $printoutstring) {
         $urltail .= '&po=' . urlencode($printoutstring);
     }
     if ('' != $this->m_params['sort']) {
         $urltail .= '&sort=' . $this->m_params['sort'];
     }
     if ('' != $this->m_params['order']) {
         $urltail .= '&order=' . $this->m_params['order'];
     }
     if ($this->m_querystring != '') {
         $queryobj = SMWQueryProcessor::createQuery($this->m_querystring, $this->m_params, false, '', $this->m_printouts);
         $queryobj->querymode = SMWQuery::MODE_INSTANCES;
         ///TODO: Somewhat hacky (just as the query mode computation in SMWQueryProcessor::createQuery!)
         $res = smwfGetStore()->getQueryResult($queryobj);
         $printer = SMWQueryProcessor::getResultPrinter($this->m_params['format'], false, $res);
         $result_mime = $printer->getMimeType($res);
         if ($result_mime == false) {
             $navigation = $this->getNavigationBar($res, $urltail);
             $result = '<div style="text-align: center;">' . $navigation;
             $result .= '</div>' . $printer->getResult($res, $this->m_params, SMW_OUTPUT_HTML);
             $result .= '<div style="text-align: center;">' . $navigation . '</div>';
         } else {
             // make a stand-alone file
             $result = $printer->getResult($res, $this->m_params, SMW_OUTPUT_FILE);
         }
     }
     if ($result_mime == false) {
         if ($this->m_querystring) {
             $wgOut->setHTMLtitle($this->m_querystring);
         } else {
             $wgOut->setHTMLtitle(wfMsg('ask'));
         }
         $result = $this->getInputForm($printoutstring, 'offset=' . $this->m_params['offset'] . '&limit=' . $this->m_params['limit'] . $urltail) . $result;
         $wgOut->addHTML($result);
     } else {
         $wgOut->disable();
         header("Content-type: {$result_mime}; charset=UTF-8");
         print $result;
     }
 }
Exemplo n.º 5
0
 /**
  * TODO: document
  */
 protected function makeHTMLResult()
 {
     global $wgOut;
     // TODO: hold into account $smwgAutocompleteInSpecialAsk
     $result = '';
     $res = null;
     $htmlContentBuilder = new HtmlContentBuilder();
     // build parameter strings for URLs, based on current settings
     $urlArgs['q'] = $this->m_querystring;
     $tmp_parray = array();
     foreach ($this->m_params as $key => $value) {
         if (!in_array($key, array('sort', 'order', 'limit', 'offset', 'title'))) {
             $tmp_parray[$key] = $value;
         }
     }
     $urlArgs['p'] = SMWInfolink::encodeParameters($tmp_parray);
     $printoutstring = '';
     $duration = 0;
     $navigation = '';
     $queryobj = null;
     /**
      * @var PrintRequest $printout
      */
     foreach ($this->m_printouts as $printout) {
         $printoutstring .= $printout->getSerialisation(true) . "\n";
     }
     if ($printoutstring !== '') {
         $urlArgs['po'] = $printoutstring;
     }
     if (array_key_exists('sort', $this->m_params)) {
         $urlArgs['sort'] = $this->m_params['sort'];
     }
     if (array_key_exists('order', $this->m_params)) {
         $urlArgs['order'] = $this->m_params['order'];
     }
     if ($this->getRequest()->getCheck('bTitle')) {
         $urlArgs['bTitle'] = $this->getRequest()->getVal('bTitle');
         $urlArgs['bMsg'] = $this->getRequest()->getVal('bMsg');
     }
     if ($this->m_querystring !== '') {
         // FIXME: this is a hack
         SMWQueryProcessor::addThisPrintout($this->m_printouts, $this->m_params);
         $params = SMWQueryProcessor::getProcessedParams($this->m_params, $this->m_printouts);
         $this->m_params['format'] = $params['format']->getValue();
         $this->params = $params;
         $queryobj = SMWQueryProcessor::createQuery($this->m_querystring, $params, SMWQueryProcessor::SPECIAL_PAGE, $this->m_params['format'], $this->m_printouts);
         /**
          * @var SMWQueryResult $res
          */
         // Determine query results
         $duration = microtime(true);
         $res = $this->getStoreFromParams($params)->getQueryResult($queryobj);
         $duration = number_format(microtime(true) - $duration, 4, '.', '');
         // Try to be smart for rss/ical if no description/title is given and we have a concept query:
         if ($this->m_params['format'] == 'rss') {
             $desckey = 'rssdescription';
             $titlekey = 'rsstitle';
         } elseif ($this->m_params['format'] == 'icalendar') {
             $desckey = 'icalendardescription';
             $titlekey = 'icalendartitle';
         } else {
             $desckey = false;
         }
         if ($desckey && $queryobj->getDescription() instanceof SMWConceptDescription && (!isset($this->m_params[$desckey]) || !isset($this->m_params[$titlekey]))) {
             $concept = $queryobj->getDescription()->getConcept();
             if (!isset($this->m_params[$titlekey])) {
                 $this->m_params[$titlekey] = $concept->getText();
             }
             if (!isset($this->m_params[$desckey])) {
                 // / @bug The current SMWStore will never return SMWConceptValue (an SMWDataValue) here; it might return SMWDIConcept (an SMWDataItem)
                 $dv = end(\SMW\StoreFactory::getStore()->getPropertyValues(SMWWikiPageValue::makePageFromTitle($concept), new SMW\DIProperty('_CONC')));
                 if ($dv instanceof SMWConceptValue) {
                     $this->m_params[$desckey] = $dv->getDocu();
                 }
             }
         }
         $printer = SMWQueryProcessor::getResultPrinter($this->m_params['format'], SMWQueryProcessor::SPECIAL_PAGE);
         $printer->setShowErrors(false);
         global $wgRequest;
         $hidequery = $wgRequest->getVal('eq') == 'no';
         if (!$printer->isExportFormat()) {
             if ($res->getCount() > 0) {
                 if ($this->m_editquery) {
                     $urlArgs['eq'] = 'yes';
                 } elseif ($hidequery) {
                     $urlArgs['eq'] = 'no';
                 }
                 $navigation = $this->getNavigationBar($res, $urlArgs);
                 $query_result = $printer->getResult($res, $params, SMW_OUTPUT_HTML);
                 if (is_array($query_result)) {
                     $result .= $query_result[0];
                 } else {
                     $result .= $query_result;
                 }
             } else {
                 $result = Html::element('div', array('class' => 'smw-callout smw-callout-info'), wfMessage('smw_result_noresults')->escaped());
             }
         }
     }
     // FileExport will override the header and cause issues during the unit
     // test when fetching the output stream therefore use the plain output
     if (defined('MW_PHPUNIT_TEST') && isset($printer) && $printer->isExportFormat()) {
         $result = $printer->getResult($res, $params, SMW_OUTPUT_FILE);
         $printer = null;
     }
     if (isset($printer) && $printer->isExportFormat()) {
         $wgOut->disable();
         /**
          * @var SMWIExportPrinter $printer
          */
         $printer->outputAsFile($res, $params);
     } else {
         if ($this->m_querystring) {
             $this->getOutput()->setHTMLtitle($this->m_querystring);
         } else {
             $this->getOutput()->setHTMLtitle(wfMessage('ask')->text());
         }
         $urlArgs['offset'] = $this->m_params['offset'];
         $urlArgs['limit'] = $this->m_params['limit'];
         $isFromCache = $res !== null ? $res->isFromCache() : false;
         $result = $this->getInputForm($printoutstring, wfArrayToCGI($urlArgs), $navigation, $duration, $isFromCache) . $htmlContentBuilder->getFormattedErrorString($queryobj) . $result;
         $this->getOutput()->addHTML($result);
     }
 }
	/**
	 * TODO: document
	 */
	protected function makeHTMLResult() {
		global $wgOut, $smwgAutocompleteInSpecialAsk;

		$delete_msg = wfMsg( 'delete' );

		// Javascript code for the dynamic parts of the page
		$javascript_text = <<<END
<script type="text/javascript">
function updateOtherOptions(strURL) {
	jQuery.ajax({ url: strURL, context: document.body, success: function(data){
		jQuery("#other_options").html(data);
	}});
}

// code for handling adding and removing the "sort" inputs
var num_elements = {$this->m_num_sort_values};

function addInstance(starter_div_id, main_div_id) {
	var starter_div = document.getElementById(starter_div_id);
	var main_div = document.getElementById(main_div_id);

	//Create the new instance
	var new_div = starter_div.cloneNode(true);
	var div_id = 'sort_div_' + num_elements;
	new_div.className = 'multipleTemplate';
	new_div.id = div_id;
	new_div.style.display = 'block';

	var children = new_div.getElementsByTagName('*');
	var x;
	for (x = 0; x < children.length; x++) {
		if (children[x].name)
			children[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']');
	}

	//Create 'delete' link
	var remove_button = document.createElement('span');
	remove_button.innerHTML = '[<a href="javascript:removeInstance(\'sort_div_' + num_elements + '\')">{$delete_msg}</a>]';
	new_div.appendChild(remove_button);

	//Add the new instance
	main_div.appendChild(new_div);
	num_elements++;
}

function removeInstance(div_id) {
	var olddiv = document.getElementById(div_id);
	var parent = olddiv.parentNode;
	parent.removeChild(olddiv);
}
</script>

END;

		$wgOut->addScript( $javascript_text );

		if ( $smwgAutocompleteInSpecialAsk ) {
			self::addAutocompletionJavascriptAndCSS();
		}

		$result = '';
		$result_mime = false; // output in MW Special page as usual

		// build parameter strings for URLs, based on current settings
		$urlArgs['q'] = $this->m_querystring;

		$tmp_parray = array();
		foreach ( $this->m_params as $key => $value ) {
			if ( !in_array( $key, array( 'sort', 'order', 'limit', 'offset', 'title' ) ) ) {
				$tmp_parray[$key] = $value;
			}
		}

		$urlArgs['p'] = SMWInfolink::encodeParameters( $tmp_parray );
		$printoutstring = '';

		foreach ( $this->m_printouts as /* SMWPrintRequest */ $printout ) {
			$printoutstring .= $printout->getSerialisation() . "\n";
		}

		if ( $printoutstring !== '' ) $urlArgs['po'] = $printoutstring;
		if ( array_key_exists( 'sort', $this->m_params ) )  $urlArgs['sort'] = $this->m_params['sort'];
		if ( array_key_exists( 'order', $this->m_params ) ) $urlArgs['order'] = $this->m_params['order'];

		if ( $this->m_querystring !== '' ) {
			// FIXME: this is a hack
			SMWQueryProcessor::addThisPrintout( $this->m_printouts, $this->m_params );
			$params = SMWQueryProcessor::getProcessedParams( $this->m_params, $this->m_printouts );
			$this->m_params['format'] = $params['format'];

			$queryobj = SMWQueryProcessor::createQuery(
				$this->m_querystring,
				$params,
				SMWQueryProcessor::SPECIAL_PAGE ,
				$this->m_params['format'],
				$this->m_printouts
			);

			$res = smwfGetStore()->getQueryResult( $queryobj );

			// Try to be smart for rss/ical if no description/title is given and we have a concept query:
			if ( $this->m_params['format'] == 'rss' ) {
				$desckey = 'rssdescription';
				$titlekey = 'rsstitle';
			} elseif ( $this->m_params['format'] == 'icalendar' ) {
				$desckey = 'icalendardescription';
				$titlekey = 'icalendartitle';
			} else { $desckey = false; }

			if ( ( $desckey ) && ( $queryobj->getDescription() instanceof SMWConceptDescription ) &&
			     ( !isset( $this->m_params[$desckey] ) || !isset( $this->m_params[$titlekey] ) ) ) {
				$concept = $queryobj->getDescription()->getConcept();

				if ( !isset( $this->m_params[$titlekey] ) ) {
					$this->m_params[$titlekey] = $concept->getText();
				}

				if ( !isset( $this->m_params[$desckey] ) ) {
					// / @bug The current SMWStore will never return SMWConceptValue (an SMWDataValue) here; it might return SMWDIConcept (an SMWDataItem)
					$dv = end( smwfGetStore()->getPropertyValues( SMWWikiPageValue::makePageFromTitle( $concept ), new SMWDIProperty( '_CONC' ) ) );
					if ( $dv instanceof SMWConceptValue ) {
						$this->m_params[$desckey] = $dv->getDocu();
					}
				}
			}

			$printer = SMWQueryProcessor::getResultPrinter( $this->m_params['format'], SMWQueryProcessor::SPECIAL_PAGE );
			$result_mime = $printer->getMimeType( $res );

			global $wgRequest;

			$hidequery = $wgRequest->getVal( 'eq' ) == 'no';

			// if it's an export format (like CSV, JSON, etc.),
			// don't actually export the data if 'eq' is set to
			// either 'yes' or 'no' in the query string - just
			// show the link instead
			if ( $this->m_editquery || $hidequery ) $result_mime = false;

			if ( $result_mime == false ) {
				if ( $res->getCount() > 0 ) {
					if ( $this->m_editquery ) {
						$urlArgs['eq'] = 'yes';
					}
					elseif ( $hidequery ) {
						$urlArgs['eq'] = 'no';
					}

					$navigation = $this->getNavigationBar( $res, $urlArgs );
					$result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n";
					$query_result = $printer->getResult( $res, $params, SMW_OUTPUT_HTML );

					if ( is_array( $query_result ) ) {
						$result .= $query_result[0];
					} else {
						$result .= $query_result;
					}

					$result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n";
				} else {
					$result = '<div style="text-align: center;">' . wfMsgHtml( 'smw_result_noresults' ) . '</div>';
				}
			} else { // make a stand-alone file
				$result = $printer->getResult( $res, $params, SMW_OUTPUT_FILE );
				$result_name = $printer->getFileName( $res ); // only fetch that after initialising the parameters
			}
		}

		if ( $result_mime == false ) {
			if ( $this->m_querystring ) {
				$wgOut->setHTMLtitle( $this->m_querystring );
			} else {
				$wgOut->setHTMLtitle( wfMsg( 'ask' ) );
			}

			$urlArgs['offset'] = $this->m_params['offset'];
			$urlArgs['limit'] = $this->m_params['limit'];

			$result = $this->getInputForm(
				$printoutstring,
				wfArrayToCGI( $urlArgs )
			) . $result;

			$wgOut->addHTML( $result );
		} else {
			$wgOut->disable();

			header( "Content-type: $result_mime; charset=UTF-8" );

			if ( $result_name !== false ) {
				header( "content-disposition: attachment; filename=$result_name" );
			}

			echo $result;
		}
	}
Exemplo n.º 7
0
    protected function makeHTMLResult()
    {
        $this->checkIfThisIsAWSCALL();
        global $wgOut, $smwgAutocompleteInSpecialAsk;
        $delete_msg = wfMsg('delete');
        // Javascript code for the dynamic parts of the page
        $javascript_text = <<<END
<script type="text/javascript">       
jQuery.noConflict();
function xmlhttpPost(strURL) {
\tjQuery.ajax({ url: strURL, data: getquerystring(), context: document.body, success: function(data){
\t\tdocument.getElementById("other_options").innerHTML = data;
\t}});   
}
function getquerystring() {
\tvar format_selector = document.getElementById('formatSelector');
\treturn format_selector.value;
}

// code for handling adding and removing the "sort" inputs
var num_elements = {$this->m_num_sort_values};

function addInstance(starter_div_id, main_div_id) {
\tvar starter_div = document.getElementById(starter_div_id);
\tvar main_div = document.getElementById(main_div_id);

\t//Create the new instance
\tvar new_div = starter_div.cloneNode(true);
\tvar div_id = 'sort_div_' + num_elements;
\tnew_div.className = 'multipleTemplate';
\tnew_div.id = div_id;
\tnew_div.style.display = 'block';

\tvar children = new_div.getElementsByTagName('*');
\tvar x;
\tfor (x = 0; x < children.length; x++) {
\t\tif (children[x].name)
\t\t\tchildren[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']');
\t}

\t//Create 'delete' link
\tvar remove_button = document.createElement('span');
\tremove_button.innerHTML = '[<a href="javascript:removeInstance(\\'sort_div_' + num_elements + '\\')">{$delete_msg}</a>]';
\tnew_div.appendChild(remove_button);

\t//Add the new instance
\tmain_div.appendChild(new_div);
\tnum_elements++;
}

function removeInstance(div_id) {
\tvar olddiv = document.getElementById(div_id);
\tvar parent = olddiv.parentNode;
\tparent.removeChild(olddiv);
}
</script>

END;
        $wgOut->addScript($javascript_text);
        if ($smwgAutocompleteInSpecialAsk) {
            self::addAutocompletionJavascriptAndCSS();
        }
        $result = '';
        $result_mime = false;
        // output in MW Special page as usual
        // build parameter strings for URLs, based on current settings
        $urltail = '&q=' . urlencode($this->m_querystring);
        $tmp_parray = array();
        foreach ($this->m_params as $key => $value) {
            if (!in_array($key, array('sort', 'order', 'limit', 'offset', 'title'))) {
                $tmp_parray[$key] = $value;
            }
        }
        $urltail .= '&p=' . urlencode(SMWInfolink::encodeParameters($tmp_parray));
        $printoutstring = '';
        foreach ($this->m_printouts as $printout) {
            $printoutstring .= $printout->getSerialisation() . "\n";
        }
        if ($printoutstring != '') {
            $urltail .= '&po=' . urlencode($printoutstring);
        }
        if (array_key_exists('sort', $this->m_params)) {
            $urltail .= '&sort=' . $this->m_params['sort'];
        }
        if (array_key_exists('order', $this->m_params)) {
            $urltail .= '&order=' . $this->m_params['order'];
        }
        if ($this->m_querystring != '') {
            $queryobj = SMWQueryProcessor::createQuery($this->m_querystring, $this->m_params, SMWQueryProcessor::SPECIAL_PAGE, $this->m_params['format'], $this->m_printouts);
            $queryobj->params = $this->m_params;
            $store = $this->getStore();
            $res = $store->getQueryResult($queryobj);
            // try to be smart for rss/ical if no description/title is given and we have a concept query:
            if ($this->m_params['format'] == 'rss') {
                $desckey = 'rssdescription';
                $titlekey = 'rsstitle';
            } elseif ($this->m_params['format'] == 'icalendar') {
                $desckey = 'icalendardescription';
                $titlekey = 'icalendartitle';
            } else {
                $desckey = false;
            }
            if ($desckey && $queryobj->getDescription() instanceof SMWConceptDescription && (!isset($this->m_params[$desckey]) || !isset($this->m_params[$titlekey]))) {
                $concept = $queryobj->getDescription()->getConcept();
                if (!isset($this->m_params[$titlekey])) {
                    $this->m_params[$titlekey] = $concept->getText();
                }
                if (!isset($this->m_params[$desckey])) {
                    $dv = end(smwfGetStore()->getPropertyValues(SMWWikiPageValue::makePageFromTitle($concept), SMWPropertyValue::makeProperty('_CONC')));
                    if ($dv instanceof SMWConceptValue) {
                        $this->m_params[$desckey] = $dv->getDocu();
                    }
                }
            }
            $printer = SMWQueryProcessor::getResultPrinter($this->m_params['format'], SMWQueryProcessor::SPECIAL_PAGE);
            $result_mime = $printer->getMimeType($res);
            global $wgRequest;
            $hidequery = $wgRequest->getVal('eq') == 'no';
            // if it's an export format (like CSV, JSON, etc.),
            // don't actually export the data if 'eq' is set to
            // either 'yes' or 'no' in the query string - just
            // show the link instead
            if ($this->m_editquery || $hidequery) {
                $result_mime = false;
            }
            if ($result_mime == false) {
                if ($res->getCount() > 0) {
                    if ($this->m_editquery) {
                        $urltail .= '&eq=yes';
                    }
                    if ($hidequery) {
                        $urltail .= '&eq=no';
                    }
                    $navigation = $this->getNavigationBar($res, $urltail);
                    $result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n";
                    $query_result = $printer->getResult($res, $this->m_params, SMW_OUTPUT_HTML);
                    if (is_array($query_result)) {
                        $result .= $query_result[0];
                    } else {
                        $result .= $query_result;
                    }
                    $result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n";
                } else {
                    $result = '<div style="text-align: center;">' . wfMsg('smw_result_noresults') . '</div>';
                }
            } else {
                // make a stand-alone file
                $result = $printer->getResult($res, $this->m_params, SMW_OUTPUT_FILE);
                $result_name = $printer->getFileName($res);
                // only fetch that after initialising the parameters
            }
        }
        if ($result_mime == false) {
            if ($this->m_querystring) {
                $wgOut->setHTMLtitle($this->m_querystring);
            } else {
                $wgOut->setHTMLtitle(wfMsg('ask'));
            }
            $result = $this->getInputForm($printoutstring, 'offset=' . $this->m_params['offset'] . '&limit=' . $this->m_params['limit'] . $urltail) . $result;
            $result = $this->postProcessHTML($result);
            $wgOut->addHTML($result);
        } else {
            $wgOut->disable();
            header("Content-type: {$result_mime}; charset=UTF-8");
            if ($result_name !== false) {
                header("content-disposition: attachment; filename={$result_name}");
            }
            print $result;
        }
    }