00001 <?php
00002
00018 class SMWAskPage extends SpecialPage {
00019
00020 protected $m_querystring = '';
00021 protected $m_params = array();
00022 protected $m_printouts = array();
00023 protected $m_editquery = false;
00024
00028 public function __construct() {
00029 parent::__construct( 'Ask' );
00030 }
00031
00037 public function execute( $p ) {
00038 global $wgOut, $wgRequest, $smwgQEnabled;
00039
00040 $this->setHeaders();
00041 wfProfileIn( 'doSpecialAsk (SMW)' );
00042
00043 if ( !$smwgQEnabled ) {
00044 $wgOut->addHTML( '<br />' . wfMsg( 'smw_iq_disabled' ) );
00045 } else {
00046 if ( $wgRequest->getCheck( 'showformatoptions' ) ) {
00047
00048 $format = $wgRequest->getVal( 'showformatoptions' );
00049 $params = $wgRequest->getArray( 'params' );
00050 $wgOut->disable();
00051 echo $this->showFormatOptions( $format, $params );
00052 } else {
00053 $this->extractQueryParameters( $p );
00054 $this->makeHTMLResult();
00055 }
00056 }
00057
00058 SMWOutputs::commitToOutputPage( $wgOut );
00059 wfProfileOut( 'doSpecialAsk (SMW)' );
00060 }
00061
00069 protected function extractQueryParameters( $p ) {
00070 global $wgRequest, $smwgQMaxInlineLimit;
00071
00072
00073 if ( $wgRequest->getCheck( 'q' ) ) {
00074 $query_val = $wgRequest->getVal( 'p' );
00075
00076 if ( !empty( $query_val ) )
00077
00078 $rawparams = SMWInfolink::decodeParameters( $query_val, false );
00079 else {
00080 $query_values = $wgRequest->getArray( 'p' );
00081
00082 if ( is_array( $query_values ) ) {
00083 foreach ( $query_values as $key => $val ) {
00084 if ( empty( $val ) ) unset( $query_values[$key] );
00085 }
00086 }
00087
00088
00089 $rawparams = SMWInfolink::decodeParameters( $query_values, false );
00090 }
00091 } else {
00092 $rawparams = SMWInfolink::decodeParameters( $p, true );
00093 }
00094
00095
00096 $this->m_querystring = $wgRequest->getText( 'q' );
00097 if ( $this->m_querystring !== '' ) {
00098 $rawparams[] = $this->m_querystring;
00099 }
00100
00101
00102 $paramstring = $wgRequest->getText( 'po' );
00103
00104 if ( $paramstring !== '' ) {
00105 $ps = explode( "\n", $paramstring );
00106
00107 foreach ( $ps as $param ) {
00108 $param = trim( $param );
00109
00110 if ( ( $param !== '' ) && ( $param { 0 } != '?' ) ) {
00111 $param = '?' . $param;
00112 }
00113
00114 $rawparams[] = $param;
00115 }
00116 }
00117
00118
00119 SMWQueryProcessor::processFunctionParams( $rawparams, $this->m_querystring, $this->m_params, $this->m_printouts );
00120
00121
00122 if ( !array_key_exists( 'format', $this->m_params ) ) {
00123 $this->m_params['format'] = 'broadtable';
00124 }
00125
00126 if ( !array_key_exists( 'order', $this->m_params ) ) {
00127 $order_values = $wgRequest->getArray( 'order' );
00128
00129 if ( is_array( $order_values ) ) {
00130 $this->m_params['order'] = '';
00131
00132 foreach ( $order_values as $order_value ) {
00133 if ( $order_value === '' ) $order_value = 'ASC';
00134 $this->m_params['order'] .= ( $this->m_params['order'] !== '' ? ',' : '' ) . $order_value;
00135 }
00136 }
00137 }
00138
00139 $this->m_num_sort_values = 0;
00140
00141 if ( !array_key_exists( 'sort', $this->m_params ) ) {
00142 $sort_values = $wgRequest->getArray( 'sort' );
00143 if ( is_array( $sort_values ) ) {
00144 $this->m_params['sort'] = implode( ',', $sort_values );
00145 $this->m_num_sort_values = count( $sort_values );
00146 }
00147 }
00148
00149 if ( !array_key_exists( 'offset', $this->m_params ) ) {
00150 $this->m_params['offset'] = $wgRequest->getVal( 'offset' );
00151 if ( $this->m_params['offset'] === '' ) $this->m_params['offset'] = 0;
00152 }
00153
00154 if ( !array_key_exists( 'limit', $this->m_params ) ) {
00155 $this->m_params['limit'] = $wgRequest->getVal( 'limit' );
00156
00157 if ( $this->m_params['limit'] === '' ) {
00158 $this->m_params['limit'] = ( $this->m_params['format'] == 'rss' ) ? 10 : 20;
00159 }
00160 }
00161
00162 $this->m_params['limit'] = min( $this->m_params['limit'], $smwgQMaxInlineLimit );
00163
00164 $this->m_editquery = ( $wgRequest->getVal( 'eq' ) == 'yes' ) || ( $this->m_querystring === '' );
00165 }
00166
00173 protected static function addAutocompletionJavascriptAndCSS() {
00174 global $wgOut, $smwgScriptPath, $smwgJQueryIncluded, $smwgJQueryUIIncluded;
00175
00176
00177 $wgOut->addExtensionStyle( "$smwgScriptPath/skins/jquery-ui/base/jquery.ui.all.css" );
00178
00179 $scripts = array();
00180
00181 if ( !$smwgJQueryIncluded ) {
00182 $realFunction = array( $wgOut, 'includeJQuery' );
00183 if ( is_callable( $realFunction ) ) {
00184 $wgOut->includeJQuery();
00185 } else {
00186 $scripts[] = "$smwgScriptPath/libs/jquery-1.4.2.min.js";
00187 }
00188
00189 $smwgJQueryIncluded = true;
00190 }
00191
00192 if ( !$smwgJQueryUIIncluded ) {
00193 $scripts[] = "$smwgScriptPath/libs/jquery-ui/jquery.ui.core.min.js";
00194 $scripts[] = "$smwgScriptPath/libs/jquery-ui/jquery.ui.widget.min.js";
00195 $scripts[] = "$smwgScriptPath/libs/jquery-ui/jquery.ui.position.min.js";
00196 $scripts[] = "$smwgScriptPath/libs/jquery-ui/jquery.ui.autocomplete.min.js";
00197 $smwgJQueryUIIncluded = true;
00198 }
00199
00200 foreach ( $scripts as $js ) {
00201 $wgOut->addScriptFile( $js );
00202 }
00203
00204 $javascript_autocomplete_text = <<<END
00205 <script type="text/javascript">
00206 function split(val) {
00207 return val.split('\\n');
00208 }
00209 function extractLast(term) {
00210 return split(term).pop();
00211 }
00212 function escapeQuestion(term){
00213 if (term.substring(0, 1) == "?") {
00214 return term.substring(1);
00215 } else {
00216 return term;
00217 }
00218 }
00219
00220
00221 jQuery.ui.autocomplete.prototype._renderItem = function( ul, item) {
00222 var term_without_q = escapeQuestion(extractLast(this.term));
00223 var re = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term_without_q.replace("/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi", "\\$1") + ")(?![^<>]*>)(?![^&;]+;)", "gi");
00224 var loc = item.label.search(re);
00225 if (loc >= 0) {
00226 var t = item.label.substr(0, loc) + '<strong>' + item.label.substr(loc, term_without_q.length) + '</strong>' + item.label.substr(loc + term_without_q.length);
00227 } else {
00228 var t = item.label;
00229 }
00230 jQuery( "<li></li>" )
00231 .data( "item.autocomplete", item )
00232 .append( " <a>" + t + "</a>" )
00233 .appendTo( ul );
00234 };
00235
00237 jQuery.extend( jQuery.ui.autocomplete, {
00238 filter: function(array, term) {
00239 var matcher = new RegExp("\\\b" + jQuery.ui.autocomplete.escapeRegex(term), "i" );
00240 return jQuery.grep( array, function(value) {
00241 return matcher.test( value.label || value.value || value );
00242 });
00243 }
00244 });
00245
00246 jQuery(document).ready(function(){
00247 jQuery("#add_property").autocomplete({
00248 minLength: 2,
00249 source: function(request, response) {
00250 request.term=request.term.substr(request.term.lastIndexOf("\\n")+1);
00251 url=wgScriptPath+'/api.php?action=opensearch&limit=10&namespace='+wgNamespaceIds['property']+'&format=jsonfm&search=';
00252
00253 jQuery.getJSON(url+request.term, function(data){
00254
00255 for(i=0;i<data[1].length;i++) data[1][i]="?"+data[1][i].substr(data[1][i].indexOf(':')+1);
00256 response(jQuery.ui.autocomplete.filter(data[1], escapeQuestion(extractLast(request.term))));
00257 });
00258 },
00259 focus: function() {
00260
00261 return false;
00262 },
00263 select: function(event, ui) {
00264 var terms = split( this.value );
00265
00266 terms.pop();
00267
00268 terms.push( ui.item.value );
00269
00270 terms.push("");
00271 this.value = terms.join("\\n");
00272 return false;
00273 }
00274 });
00275 });
00276 </script>
00277
00278 END;
00279
00280 $wgOut->addScript( $javascript_autocomplete_text );
00281 }
00282
00286 protected function makeHTMLResult() {
00287 global $wgOut, $smwgAutocompleteInSpecialAsk;
00288
00289 $delete_msg = wfMsg( 'delete' );
00290
00291
00292 $javascript_text = <<<END
00293 <script type="text/javascript">
00294 function updateOtherOptions(strURL) {
00295 jQuery.ajax({ url: strURL, context: document.body, success: function(data){
00296 jQuery("#other_options").html(data);
00297 }});
00298 }
00299
00300
00301 var num_elements = {$this->m_num_sort_values};
00302
00303 function addInstance(starter_div_id, main_div_id) {
00304 var starter_div = document.getElementById(starter_div_id);
00305 var main_div = document.getElementById(main_div_id);
00306
00307
00308 var new_div = starter_div.cloneNode(true);
00309 var div_id = 'sort_div_' + num_elements;
00310 new_div.className = 'multipleTemplate';
00311 new_div.id = div_id;
00312 new_div.style.display = 'block';
00313
00314 var children = new_div.getElementsByTagName('*');
00315 var x;
00316 for (x = 0; x < children.length; x++) {
00317 if (children[x].name)
00318 children[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']');
00319 }
00320
00321
00322 var remove_button = document.createElement('span');
00323 remove_button.innerHTML = '[<a href="javascript:removeInstance(\'sort_div_' + num_elements + '\')">{$delete_msg}</a>]';
00324 new_div.appendChild(remove_button);
00325
00326 //Add the new instance
00327 main_div.appendChild(new_div);
00328 num_elements++;
00329 }
00330
00331 function removeInstance(div_id) {
00332 var olddiv = document.getElementById(div_id);
00333 var parent = olddiv.parentNode;
00334 parent.removeChild(olddiv);
00335 }
00336 </script>
00337
00338 END;
00339
00340 $wgOut->addScript( $javascript_text );
00341
00342 if ( $smwgAutocompleteInSpecialAsk ) {
00343 self::addAutocompletionJavascriptAndCSS();
00344 }
00345
00346 $result = '';
00347 $result_mime = false; // output in MW Special page as usual
00348
00349 // build parameter strings for URLs, based on current settings
00350 $urlArgs['q'] = $this->m_querystring;
00351
00352 $tmp_parray = array();
00353 foreach ( $this->m_params as $key => $value ) {
00354 if ( !in_array( $key, array( 'sort', 'order', 'limit', 'offset', 'title' ) ) ) {
00355 $tmp_parray[$key] = $value;
00356 }
00357 }
00358
00359 $urlArgs['p'] = SMWInfolink::encodeParameters( $tmp_parray );
00360 $printoutstring = '';
00361
00362 foreach ( $this->m_printouts as /* SMWPrintRequest */ $printout ) {
00363 $printoutstring .= $printout->getSerialisation() . "\n";
00364 }
00365
00366 if ( $printoutstring !== '' ) $urlArgs['po'] = $printoutstring;
00367 if ( array_key_exists( 'sort', $this->m_params ) ) $urlArgs['sort'] = $this->m_params['sort'];
00368 if ( array_key_exists( 'order', $this->m_params ) ) $urlArgs['order'] = $this->m_params['order'];
00369
00370 if ( $this->m_querystring !== '' ) {
00371 // FIXME: this is a hack
00372 SMWQueryProcessor::addThisPrintout( $this->m_printouts, $this->m_params );
00373 $params = SMWQueryProcessor::getProcessedParams( $this->m_params, $this->m_printouts );
00374 $this->m_params['format'] = $params['format'];
00375
00376 $queryobj = SMWQueryProcessor::createQuery(
00377 $this->m_querystring,
00378 $params,
00379 SMWQueryProcessor::SPECIAL_PAGE ,
00380 $this->m_params['format'],
00381 $this->m_printouts
00382 );
00383
00384 $res = smwfGetStore()->getQueryResult( $queryobj );
00385
00386 // Try to be smart for rss/ical if no description/title is given and we have a concept query:
00387 if ( $this->m_params['format'] == 'rss' ) {
00388 $desckey = 'rssdescription';
00389 $titlekey = 'rsstitle';
00390 } elseif ( $this->m_params['format'] == 'icalendar' ) {
00391 $desckey = 'icalendardescription';
00392 $titlekey = 'icalendartitle';
00393 } else { $desckey = false; }
00394
00395 if ( ( $desckey ) && ( $queryobj->getDescription() instanceof SMWConceptDescription ) &&
00396 ( !isset( $this->m_params[$desckey] ) || !isset( $this->m_params[$titlekey] ) ) ) {
00397 $concept = $queryobj->getDescription()->getConcept();
00398
00399 if ( !isset( $this->m_params[$titlekey] ) ) {
00400 $this->m_params[$titlekey] = $concept->getText();
00401 }
00402
00403 if ( !isset( $this->m_params[$desckey] ) ) {
00404 // / @bug The current SMWStore will never return SMWConceptValue (an SMWDataValue) here; it might return SMWDIConcept (an SMWDataItem)
00405 $dv = end( smwfGetStore()->getPropertyValues( SMWWikiPageValue::makePageFromTitle( $concept ), new SMWDIProperty( '_CONC' ) ) );
00406 if ( $dv instanceof SMWConceptValue ) {
00407 $this->m_params[$desckey] = $dv->getDocu();
00408 }
00409 }
00410 }
00411
00412 $printer = SMWQueryProcessor::getResultPrinter( $this->m_params['format'], SMWQueryProcessor::SPECIAL_PAGE );
00413 $result_mime = $printer->getMimeType( $res );
00414
00415 global $wgRequest;
00416
00417 $hidequery = $wgRequest->getVal( 'eq' ) == 'no';
00418
00419 // if it's an export format (like CSV, JSON, etc.),
00420 // don't actually export the data if 'eq' is set to
00421 // either 'yes' or 'no' in the query string - just
00422 // show the link instead
00423 if ( $this->m_editquery || $hidequery ) $result_mime = false;
00424
00425 if ( $result_mime == false ) {
00426 if ( $res->getCount() > 0 ) {
00427 if ( $this->m_editquery ) {
00428 $urlArgs['eq'] = 'yes';
00429 }
00430 elseif ( $hidequery ) {
00431 $urlArgs['eq'] = 'no';
00432 }
00433
00434 $navigation = $this->getNavigationBar( $res, $urlArgs );
00435 $result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n";
00436 $query_result = $printer->getResult( $res, $params, SMW_OUTPUT_HTML );
00437
00438 if ( is_array( $query_result ) ) {
00439 $result .= $query_result[0];
00440 } else {
00441 $result .= $query_result;
00442 }
00443
00444 $result .= '<div style="text-align: center;">' . "\n" . $navigation . "\n</div>\n";
00445 } else {
00446 $result = '<div style="text-align: center;">' . wfMsgHtml( 'smw_result_noresults' ) . '</div>';
00447 }
00448 } else { // make a stand-alone file
00449 $result = $printer->getResult( $res, $params, SMW_OUTPUT_FILE );
00450 $result_name = $printer->getFileName( $res ); // only fetch that after initialising the parameters
00451 }
00452 }
00453
00454 if ( $result_mime == false ) {
00455 if ( $this->m_querystring ) {
00456 $wgOut->setHTMLtitle( $this->m_querystring );
00457 } else {
00458 $wgOut->setHTMLtitle( wfMsg( 'ask' ) );
00459 }
00460
00461 $urlArgs['offset'] = $this->m_params['offset'];
00462 $urlArgs['limit'] = $this->m_params['limit'];
00463
00464 $result = $this->getInputForm(
00465 $printoutstring,
00466 wfArrayToCGI( $urlArgs )
00467 ) . $result;
00468
00469 $wgOut->addHTML( $result );
00470 } else {
00471 $wgOut->disable();
00472
00473 header( "Content-type: $result_mime; charset=UTF-8" );
00474
00475 if ( $result_name !== false ) {
00476 header( "content-disposition: attachment; filename=$result_name" );
00477 }
00478
00479 echo $result;
00480 }
00481 }
00482
00491 protected function getInputForm( $printoutstring, $urltail ) {
00492 global $smwgQSortingSupport, $smwgResultFormats, $wgScript;
00493
00494 $result = '';
00495
00496 if ( $this->m_editquery ) {
00497 $result .= Html::openElement( 'form',
00498 array( 'action' => $wgScript, 'name' => 'ask', 'method' => 'get' ) );
00499 $result .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBKey() );
00500
00501 // Table for main query and printouts.
00502 $result .= '<table style="width: 100%;"><tr><th>' . wfMsg( 'smw_ask_queryhead' ) . "</th>\n<th>" . wfMsg( 'smw_ask_printhead' ) . "<br />\n" .
00503 '<span style="font-weight: normal;">' . wfMsg( 'smw_ask_printdesc' ) . '</span>' . "</th></tr>\n" .
00504 '<tr><td style="padding-right: 7px;"><textarea name="q" cols="20" rows="6">' . htmlspecialchars( $this->m_querystring ) . "</textarea></td>\n" .
00505 '<td style="padding-left: 7px;"><textarea id = "add_property" name="po" cols="20" rows="6">' . htmlspecialchars( $printoutstring ) . '</textarea></td></tr></table>' . "\n";
00506 // @TODO
00507 // sorting inputs
00508 if ( $smwgQSortingSupport ) {
00509 if ( ! array_key_exists( 'sort', $this->m_params ) || ! array_key_exists( 'order', $this->m_params ) ) {
00510 $orders = array(); // do not even show one sort input here
00511 } else {
00512 $sorts = explode( ',', $this->m_params['sort'] );
00513 $orders = explode( ',', $this->m_params['order'] );
00514 reset( $sorts );
00515 }
00516
00517 foreach ( $orders as $i => $order ) {
00518 $result .= "<div id=\"sort_div_$i\">" . wfMsg( 'smw_ask_sortby' ) . ' <input type="text" name="sort[' . $i . ']" value="' .
00519 htmlspecialchars( $sorts[$i] ) . "\" size=\"35\"/>\n" . '<select name="order[' . $i . ']"><option ';
00520
00521 if ( $order == 'ASC' ) $result .= 'selected="selected" ';
00522 $result .= 'value="ASC">' . wfMsg( 'smw_ask_ascorder' ) . '</option><option ';
00523 if ( $order == 'DESC' ) $result .= 'selected="selected" ';
00524
00525 $result .= 'value="DESC">' . wfMsg( 'smw_ask_descorder' ) . "</option></select>\n";
00526 $result .= '[<a href="javascript:removeInstance(\'sort_div_' . $i . '\')">' . wfMsg( 'delete' ) . '</a>]' . "\n";
00527 $result .= "</div>\n";
00528 }
00529
00530 $result .= '<div id="sorting_starter" style="display: none">' . wfMsg( 'smw_ask_sortby' ) . ' <input type="text" name="sort_num" size="35" />' . "\n";
00531 $result .= ' <select name="order_num">' . "\n";
00532 $result .= ' <option value="ASC">' . wfMsg( 'smw_ask_ascorder' ) . "</option>\n";
00533 $result .= ' <option value="DESC">' . wfMsg( 'smw_ask_descorder' ) . "</option>\n</select>\n";
00534 $result .= "</div>\n";
00535 $result .= '<div id="sorting_main"></div>' . "\n";
00536 $result .= '<a href="javascript:addInstance(\'sorting_starter\', \'sorting_main\')">' . wfMsg( 'smw_add_sortcondition' ) . '</a>' . "\n";
00537 }
00538
00539 $printer = SMWQueryProcessor::getResultPrinter( 'broadtable', SMWQueryProcessor::SPECIAL_PAGE );
00540 $url = SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( "showformatoptions=' + this.value + '" );
00541
00542 foreach ( $this->m_params as $param => $value ) {
00543 if ( $param !== 'format' ) {
00544 $url .= '¶ms[' . Xml::escapeJsString( $param ) . ']=' . Xml::escapeJsString( $value );
00545 }
00546 }
00547
00548 $result .= "<br /><br />\n<p>" . wfMsg( 'smw_ask_format_as' ) . ' <input type="hidden" name="eq" value="yes"/>' . "\n" .
00549 '<select id="formatSelector" name="p[format]" onChange="JavaScript:updateOtherOptions(\'' . $url . '\')">' . "\n" .
00550 ' <option value="broadtable"' . ( $this->m_params['format'] == 'broadtable' ? ' selected' : '' ) . '>' .
00551 $printer->getName() . ' (' . wfMsg( 'smw_ask_defaultformat' ) . ')</option>' . "\n";
00552
00553 $formats = array();
00554
00555 foreach ( array_keys( $smwgResultFormats ) as $format ) {
00556 // Special formats "count" and "debug" currently not supported.
00557 if ( $format != 'broadtable' && $format != 'count' && $format != 'debug' ) {
00558 $printer = SMWQueryProcessor::getResultPrinter( $format, SMWQueryProcessor::SPECIAL_PAGE );
00559 $formats[$format] = $printer->getName();
00560 }
00561 }
00562
00563 natcasesort( $formats );
00564
00565 foreach ( $formats as $format => $name ) {
00566 $result .= ' <option value="' . $format . '"' . ( $this->m_params['format'] == $format ? ' selected' : '' ) . '>' . $name . "</option>\n";
00567 }
00568
00569 $result .= "</select></p>\n";
00570 $result .= '<fieldset><legend>' . wfMsg( 'smw_ask_otheroptions' ) . "</legend>\n";
00571 $result .= "<div id=\"other_options\">" . $this->showFormatOptions( $this->m_params['format'], $this->m_params ) . "</div>";
00572 $result .= "</fieldset>\n";
00573 $urltail = str_replace( '&eq=yes', '', $urltail ) . '&eq=no';
00574
00575 $result .= '<br /><input type="submit" value="' . wfMsg( 'smw_ask_submit' ) . '"/>' .
00576 '<input type="hidden" name="eq" value="yes"/>' .
00577 Html::element(
00578 'a',
00579 array(
00580 'href' => SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( $urltail ),
00581 'rel' => 'nofollow'
00582 ),
00583 wfMsg( 'smw_ask_hidequery' )
00584 ) .
00585 '| ' . SMWAskPage::getEmbedToggle() .
00586 '| <a href="' . htmlspecialchars( wfMsg( 'smw_ask_doculink' ) ) . '">' . wfMsg( 'smw_ask_help' ) . '</a>' .
00587 "\n</form>";
00588 } else {
00589 $urltail = str_replace( '&eq=no', '', $urltail ) . '&eq=yes';
00590 $result .= '<p>' .
00591 Html::element(
00592 'a',
00593 array(
00594 'href' => SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( $urltail ),
00595 'rel' => 'nofollow'
00596 ),
00597 wfMsg( 'smw_ask_editquery' )
00598 ) .
00599 '| ' . SMWAskPage::getEmbedToggle() .
00600 '</p>';
00601 }
00602
00603 $result .= '<div id="inlinequeryembed" style="display: none"><div id="inlinequeryembedinstruct">' . wfMsg( 'smw_ask_embed_instr' ) . '</div><textarea id="inlinequeryembedarea" readonly="yes" cols="20" rows="6" onclick="this.select()">' .
00604 '{{#ask:' . htmlspecialchars( $this->m_querystring ) . "\n";
00605
00606 foreach ( $this->m_printouts as $printout ) {
00607 $result .= '|' . $printout->getSerialisation() . "\n";
00608 }
00609
00610 foreach ( $this->m_params as $param_name => $param_value ) {
00611 $result .= '|' . htmlspecialchars( $param_name ) . '=' . htmlspecialchars( $param_value ) . "\n";
00612 }
00613
00614 $result .= '}}</textarea></div><br />';
00615
00616 return $result;
00617 }
00618
00624 protected static function getEmbedToggle() {
00625 return '<span id="embed_show"><a href="#" rel="nofollow" onclick="' .
00626 "document.getElementById('inlinequeryembed').style.display='block';" .
00627 "document.getElementById('embed_hide').style.display='inline';" .
00628 "document.getElementById('embed_show').style.display='none';" .
00629 "document.getElementById('inlinequeryembedarea').select();" .
00630 '">' . wfMsg( 'smw_ask_show_embed' ) . '</a></span>' .
00631 '<span id="embed_hide" style="display: none"><a href="#" rel="nofollow" onclick="' .
00632 "document.getElementById('inlinequeryembed').style.display='none';" .
00633 "document.getElementById('embed_show').style.display='inline';" .
00634 "document.getElementById('embed_hide').style.display='none';" .
00635 '">' . wfMsg( 'smw_ask_hide_embed' ) . '</a></span>';
00636 }
00637
00646 protected function getNavigationBar( SMWQueryResult $res, array $urlArgs ) {
00647 global $smwgQMaxInlineLimit;
00648
00649 $offset = $this->m_params['offset'];
00650 $limit = $this->m_params['limit'];
00651
00652
00653 if ( $offset > 0 ) {
00654 $navigation = Html::element(
00655 'a',
00656 array(
00657 'href' => SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( array(
00658 'offset' => max( 0, $offset - $limit ),
00659 'limit' => $limit
00660 ) + $urlArgs ),
00661 'rel' => 'nofollow'
00662 ),
00663 wfMsg( 'smw_result_prev' )
00664 );
00665
00666 } else {
00667 $navigation = wfMsg( 'smw_result_prev' );
00668 }
00669
00670 $navigation .=
00671 '     <b>' .
00672 wfMsg( 'smw_result_results' ) . ' ' . ( $offset + 1 ) .
00673 '– ' .
00674 ( $offset + $res->getCount() ) .
00675 '</b>    ';
00676
00677 if ( $res->hasFurtherResults() ) {
00678 $navigation .= Html::element(
00679 'a',
00680 array(
00681 'href' => SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( array(
00682 'offset' => ( $offset + $limit ),
00683 'limit' => $limit
00684 ) + $urlArgs ),
00685 'rel' => 'nofollow'
00686 ),
00687 wfMsg( 'smw_result_next' )
00688 );
00689 } else {
00690 $navigation .= wfMsg( 'smw_result_next' );
00691 }
00692
00693 $first = true;
00694
00695 foreach ( array( 20, 50, 100, 250, 500 ) as $l ) {
00696 if ( $l > $smwgQMaxInlineLimit ) break;
00697
00698 if ( $first ) {
00699 $navigation .= '        (';
00700 $first = false;
00701 } else {
00702 $navigation .= ' | ';
00703 }
00704
00705 if ( $limit != $l ) {
00706 $navigation .= Html::element(
00707 'a',
00708 array(
00709 'href' => SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( array(
00710 'offset' => $offset,
00711 'limit' => $l
00712 ) + $urlArgs ),
00713 'rel' => 'nofollow'
00714 ),
00715 $l
00716 );
00717 } else {
00718 $navigation .= '<b>' . $l . '</b>';
00719 }
00720 }
00721
00722 $navigation .= ')';
00723
00724 return $navigation;
00725 }
00726
00736 protected function showFormatOptions( $format, array $paramValues ) {
00737 $printer = SMWQueryProcessor::getResultPrinter( $format, SMWQueryProcessor::SPECIAL_PAGE );
00738
00739 $params = SMWQueryProcessor::getParameters();
00740
00741 if ( method_exists( $printer, 'getValidatorParameters' ) ) {
00742 $params = array_merge( $params, $printer->getValidatorParameters() );
00743 }
00744
00745 $optionsHtml = array();
00746
00747 foreach ( $params as $param ) {
00748
00749 if ( $param->getName() == 'format' ) {
00750 continue;
00751 }
00752
00753 $currentValue = array_key_exists( $param->getName(), $paramValues ) ? $paramValues[$param->getName()] : false;
00754
00755 $optionsHtml[] =
00756 Html::rawElement(
00757 'div',
00758 array(
00759 'style' => 'width: 30%; padding: 5px; float: left;'
00760 ),
00761 htmlspecialchars( $param->getName() ) . ': ' .
00762 $this->showFormatOption( $param, $currentValue ) .
00763 '<br />' .
00764 Html::element( 'em', array(), $param->getDescription() )
00765 );
00766 }
00767
00768 for ( $i = 0, $n = count( $optionsHtml ); $i < $n; $i++ ) {
00769 if ( $i % 3 == 2 || $i == $n - 1 ) {
00770 $optionsHtml[$i] .= "<div style=\"clear: both\";></div>\n";
00771 }
00772 }
00773
00774 $i = 0;
00775 $rowHtml = '';
00776 $resultHtml = '';
00777
00778 while ( $option = array_shift( $optionsHtml ) ) {
00779 $rowHtml .= $option;
00780 $i++;
00781
00782 $resultHtml .= Html::rawElement(
00783 'div',
00784 array(
00785 'style' => 'background: ' . ( $i % 6 == 0 ? 'white' : '#dddddd' ) . ';'
00786 ),
00787 $rowHtml
00788 );
00789
00790 $rowHtml = '';
00791 }
00792
00793 return $resultHtml;
00794 }
00795
00796
00797
00808 protected function showFormatOption( Parameter $parameter, $currentValue ) {
00809 $input = new ParameterInput( $parameter );
00810 $input->setInputName( 'p[' . $parameter->getName() . ']' );
00811
00812 if ( $currentValue !== false ) {
00813 $input->setCurrentValue( $currentValue );
00814 }
00815
00816 return $input->getHtml();
00817 }
00818
00819 }