Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | protected function addAutocompletionJavascriptAndCSS(){ |
19 | 19 | global $wgOut, $smwgScriptPath, $smwgJQueryIncluded, $smwgJQueryUIIncluded; |
20 | 20 | if($this->autocompleteenabled==false){ |
21 | | - $wgOut->addExtensionStyle( "$smwgScriptPath/skins/jquery-ui/base/jquery.ui.all.css" ); |
| 21 | + $wgOut->addExtensionStyle( "$smwgScriptPath/skins/jquery-ui/base/jquery.ui.all.css" ); |
22 | 22 | |
23 | 23 | $scripts = array(); |
24 | 24 | |
— | — | @@ -103,7 +103,7 @@ |
104 | 104 | $htmloutput=""; |
105 | 105 | $htmloutput.= $this->getForm(); |
106 | 106 | $param=array(); |
107 | | - |
| 107 | + |
108 | 108 | $this->m_ui_helper = $helper = new SMWQueryUIHelper; //or some factory method |
109 | 109 | //here come some driver lines for testing; this is very temporary |
110 | 110 | |
— | — | @@ -123,7 +123,7 @@ |
124 | 124 | if($this->usesNavigationBar()){ |
125 | 125 | $htmloutput.= $this->getNavigationBar ($helper->getLimit(),$helper->getOffset(),$helper->hasFurtherResults()); //? can we preload offset and limit? |
126 | 126 | } |
127 | | - |
| 127 | + |
128 | 128 | $htmloutput.= $helper->getHTMLResult(); |
129 | 129 | |
130 | 130 | if($this->usesNavigationBar()){ |
— | — | @@ -223,12 +223,12 @@ |
224 | 224 | |
225 | 225 | return $navigation; |
226 | 226 | } |
227 | | - |
| 227 | + |
228 | 228 | /** |
229 | | - * Creates the form elements and populates them with parameters. |
| 229 | + * Creates the form elements and populates them with parameters. |
230 | 230 | * UI implementations need to overload this if a different layout and form |
231 | 231 | * elements are desired |
232 | | - * |
| 232 | + * |
233 | 233 | * @return string Form elements in HTML |
234 | 234 | */ |
235 | 235 | protected function getForm(){ |
— | — | @@ -237,7 +237,7 @@ |
238 | 238 | * then be placed in wOut as pleased, they will |
239 | 239 | * also write javascript (if relevant) directly to wgOut. |
240 | 240 | */ |
241 | | - |
| 241 | + |
242 | 242 | //$result=""; |
243 | 243 | //$result.= getQueryFormBox($contents, $errors); |
244 | 244 | //$result.= getPOFormBox($content, $enableAutoComplete); |
— | — | @@ -265,7 +265,7 @@ |
266 | 266 | protected function getPOFormBox($content, $enableAutocomplete=true){ |
267 | 267 | if($enableAutocomplete){ |
268 | 268 | global $wgOut; |
269 | | - |
| 269 | + |
270 | 270 | if(!$this->autocompleteenabled) addAutocompletionJavascriptAndCSS(); |
271 | 271 | $javascript_autocomplete_text = <<<END |
272 | 272 | <script type="text/javascript"> |
— | — | @@ -303,7 +303,7 @@ |
304 | 304 | END; |
305 | 305 | |
306 | 306 | $wgOut->addScript( $javascript_autocomplete_text ); |
307 | | - |
| 307 | + |
308 | 308 | } |
309 | 309 | $result=""; |
310 | 310 | $result=Html::element('textarea',array('id'=> 'add_property', 'name'=> 'po', 'cols'=>'20', 'rows'=> '6'),$content); |
— | — | @@ -417,7 +417,7 @@ |
418 | 418 | * |
419 | 419 | * @return Parameter |
420 | 420 | */ |
421 | | - protected function toValidatorParam( $param ) { |
| 421 | + private function toValidatorParam( $param ) { |
422 | 422 | static $typeMap = array( |
423 | 423 | 'int' => Parameter::TYPE_INTEGER |
424 | 424 | ); |
— | — | @@ -447,7 +447,7 @@ |
448 | 448 | } |
449 | 449 | } |
450 | 450 | |
451 | | - /** |
| 451 | + /** |
452 | 452 | * Get the HTML for a single parameter input. |
453 | 453 | * |
454 | 454 | * @since 1.6 |
— | — | @@ -457,7 +457,7 @@ |
458 | 458 | * |
459 | 459 | * @return string |
460 | 460 | */ |
461 | | - protected function showFormatOption( Parameter $parameter, $currentValue ) { |
| 461 | + private function showFormatOption( Parameter $parameter, $currentValue ) { |
462 | 462 | $input = new ParameterInput( $parameter ); |
463 | 463 | $input->setInputName( 'p[' . $parameter->getName() . ']' ); |
464 | 464 | |
— | — | @@ -468,6 +468,106 @@ |
469 | 469 | return $input->getHtml(); |
470 | 470 | } |
471 | 471 | |
| 472 | + /** |
| 473 | + * Creates form elements for choosing the result-format and their associated |
| 474 | + * format. Use in conjunction with handleFormatOptions() to supply format |
| 475 | + * options using ajax. |
| 476 | + * @return string |
| 477 | + */ |
| 478 | + protected function makeFormatSelectBox( $defaultformat = 'broadtable' ) { |
| 479 | + |
| 480 | + global $smwgResultFormats, $smwgJQueryIncluded, $wgOut; |
| 481 | + |
| 482 | + if ( !$smwgJQueryIncluded ) { |
| 483 | + $realFunction = array( 'OutputPage', 'includeJQuery' ); |
| 484 | + if ( is_callable( $realFunction ) ) { |
| 485 | + $wgOut->includeJQuery(); |
| 486 | + } else { |
| 487 | + $scripts[] = "$smwgScriptPath/libs/jquery-1.4.2.min.js"; |
| 488 | + } |
| 489 | + $smwgJQueryIncluded = true; |
| 490 | + } |
| 491 | + |
| 492 | + // checking argument |
| 493 | + $default_format = 'broadtable'; |
| 494 | + if ( array_key_exists( $defaultformat, $smwgResultFormats ) ) { |
| 495 | + $default_format = $defaultformat; |
| 496 | + } |
| 497 | + |
| 498 | + $result = ""; |
| 499 | + $printer = SMWQueryProcessor::getResultPrinter( $default_format, SMWQueryProcessor::SPECIAL_PAGE ); |
| 500 | + $url = $this->getTitle()->getLocalURL( "showformatoptions=' + this.value + '" ); |
| 501 | + |
| 502 | + foreach ( $this->m_ui_helper->getParams() as $param => $value ) { |
| 503 | + if ( $param !== 'format' ) { |
| 504 | + $url .= '¶ms[' . Xml::escapeJsString( $param ) . ']=' . Xml::escapeJsString( $value ); |
| 505 | + } |
| 506 | + } |
| 507 | + |
| 508 | + $result .= "\n<p>" . wfMsg( 'smw_ask_format_as' ) . "\n" . |
| 509 | + '<select id="formatSelector" name="p[format]" onChange="JavaScript:updateOtherOptions(\'' . $url . '\')">' . "\n" . |
| 510 | + ' <option value="' . $default_format . '">' . $printer->getName() . ' (' . wfMsg( 'smw_ask_defaultformat' ) . ')</option>' . "\n"; |
| 511 | + |
| 512 | + $formats = array(); |
| 513 | + |
| 514 | + foreach ( array_keys( $smwgResultFormats ) as $format ) { |
| 515 | + // Special formats "count" and "debug" currently not supported. |
| 516 | + if ( $format != $default_format && $format != 'count' && $format != 'debug' ) { |
| 517 | + $printer = SMWQueryProcessor::getResultPrinter( $format, SMWQueryProcessor::SPECIAL_PAGE ); |
| 518 | + $formats[$format] = $printer->getName(); |
| 519 | + } |
| 520 | + } |
| 521 | + |
| 522 | + natcasesort( $formats ); |
| 523 | + $params = $this->m_ui_helper->getParams(); |
| 524 | + foreach ( $formats as $format => $name ) { |
| 525 | + $result .= ' <option value="' . $format . '"' . ( $params['format'] == $format ? ' selected' : '' ) . '>' . $name . "</option>\n"; |
| 526 | + } |
| 527 | + $result .= "</select>"; |
| 528 | + $result .= "</p>\n"; |
| 529 | + $result .= '<fieldset><legend>' . wfMsg( 'smw_ask_otheroptions' ) . "</legend>\n"; |
| 530 | + $result .= "<div id=\"other_options\">" . $this->showFormatOptions( $params['format'], $params ) . " </div>"; |
| 531 | + $result .= "</fieldset>\n"; |
| 532 | + |
| 533 | + // BEGIN: add javascript for updating formating options by ajax |
| 534 | + global $wgOut; |
| 535 | + // $default_format_url = SpecialPage::getSafeTitleFor( 'Ask' )->getLocalURL( "showformatoptions=broadtable" ); |
| 536 | + // $default_format_url .= '¶ms[title]=Special:Ask¶ms[offset]=0¶ms[limit]=20'; |
| 537 | + $javascript = <<<END |
| 538 | +<script type="text/javascript"> |
| 539 | +function updateOtherOptions(strURL) { |
| 540 | + jQuery.ajax({ url: strURL, context: document.body, success: function(data){ |
| 541 | + jQuery("#other_options").html(data); |
| 542 | + }}); |
| 543 | +} |
| 544 | +</script> |
| 545 | +END; |
| 546 | + |
| 547 | + $wgOut->addScript( $javascript ); |
| 548 | + // END: add javascript for updating formating options by ajax |
| 549 | + |
| 550 | + return $result; |
| 551 | + } |
| 552 | + |
| 553 | + /** |
| 554 | + * Returns form elements for a requested format. Use in conjunction with makeFormatSelectBox() |
| 555 | + * |
| 556 | + * @param WebRequest $wgRequest |
| 557 | + * @return boolean Returns true if formatoptions were requested and returned, else false |
| 558 | + */ |
| 559 | + protected function handleFormatOptions( $wgRequest ) { |
| 560 | + global $wgOut; |
| 561 | + if ( $wgRequest->getCheck( 'showformatoptions' ) ) { |
| 562 | + // handle Ajax action |
| 563 | + $format = $wgRequest->getVal( 'showformatoptions' ); |
| 564 | + $params = $wgRequest->getArray( 'params' ); |
| 565 | + $wgOut->disable(); |
| 566 | + echo $this->showFormatOptions( $format, $params ); |
| 567 | + return true; |
| 568 | + } else { |
| 569 | + return false; |
| 570 | + } |
| 571 | + } |
472 | 572 | protected function usesNavigationBar() { |
473 | 573 | return true; |
474 | 574 | } |
— | — | @@ -533,7 +633,7 @@ |
534 | 634 | return false; |
535 | 635 | } |
536 | 636 | } |
537 | | - |
| 637 | + |
538 | 638 | public function getResultObject(){ |
539 | 639 | return $this->getResultObject(); |
540 | 640 | } |
— | — | @@ -711,7 +811,7 @@ |
712 | 812 | } |
713 | 813 | // END: Try to be smart for rss/ical if no description/title is given and we have a concept query |
714 | 814 | } |
715 | | - |
| 815 | + |
716 | 816 | public function getHTMLResult(){ |
717 | 817 | $result = ''; |
718 | 818 | $res= $this->queryresult; |