Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php |
— | — | @@ -91,6 +91,7 @@ |
92 | 92 | $this->autocompleteenabled = true; |
93 | 93 | } |
94 | 94 | } |
| 95 | + |
95 | 96 | protected function makeResults( $p ) { |
96 | 97 | /* |
97 | 98 | * TODO: extract parameters from $p and decide: |
— | — | @@ -245,17 +246,39 @@ |
246 | 247 | $result = "<br>Stub: The Form elements come here<br><br>"; |
247 | 248 | return $result; |
248 | 249 | } |
249 | | - protected function getQueryFormBox( $contents, $errors = "" ) { |
| 250 | + |
| 251 | + /** |
| 252 | + * A method which generates the form element(s) for the Query-string. Use its |
| 253 | + * complement processQueryFormBox() to decode data sent through these elements. |
| 254 | + * UI's may overload both to change form parameters. |
| 255 | + * |
| 256 | + * @param string $contents |
| 257 | + * @param string $errors |
| 258 | + * @return string |
| 259 | + */ |
| 260 | + protected function getQueryFormBox( $content, $errors = "" ) { |
250 | 261 | $result = ""; |
251 | | - $result = Html::element( 'textarea', array( 'name' => 'q', 'id' => 'querybox', 'rows' => '6' ), $contents ); |
| 262 | + $result = Html::element( 'textarea', array( 'name' => 'q', 'id' => 'querybox', 'rows' => '6' ), $content ); |
252 | 263 | // TODO:enable/disable on checking for errors; perhaps show error messages right below the box |
253 | 264 | return $result; |
254 | 265 | } |
255 | 266 | |
256 | 267 | /** |
257 | | - * A method which generates the form box for PrintOuts. |
258 | | - * UIs may overload this to change the form parameter or the html elements. |
| 268 | + * A method which decodes form data sent through form-elements generated by |
| 269 | + * its complement, getQueryFormBox. UIs may overload both to change form parameters. |
259 | 270 | * |
| 271 | + * @param WebRequest $wgRequest |
| 272 | + * @return string |
| 273 | + */ |
| 274 | + protected function processQueryFormBox(WebRequest $wgRequest){ |
| 275 | + $query = $wgRequest->getVal('q'); |
| 276 | + return $query; |
| 277 | + } |
| 278 | + |
| 279 | + /** |
| 280 | + * A method which generates the form element(s) for PrintOuts. |
| 281 | + * Use its complement processPOFormBox() to decode data sent through these |
| 282 | + * form elements. UIs may overload both to change the form parameter or the html elements. |
260 | 283 | * |
261 | 284 | * @global OutputPage $wgOut |
262 | 285 | * @param string $content The content expected to appear in the box |
— | — | @@ -311,6 +334,33 @@ |
312 | 335 | } |
313 | 336 | |
314 | 337 | /** |
| 338 | + * A method which decodes form data sent through form-elements generated by |
| 339 | + * its complement, getPOFormBox. UIs may overload both to change form parameters. |
| 340 | + * |
| 341 | + * @param WebRequest $wgRequest |
| 342 | + * @return array |
| 343 | + */ |
| 344 | + protected function processPOFormBox(WebRequest $wgRequest){ |
| 345 | + $postring = $wgRequest->getText( 'po' ); |
| 346 | + $poarray=array(); |
| 347 | + |
| 348 | + if ( $postring != '' ) { // parameters from HTML input fields |
| 349 | + $ps = explode( "\n", $postring ); // params separated by newlines here (compatible with text-input for printouts) |
| 350 | + |
| 351 | + foreach ( $ps as $param ) { // add initial ? if omitted (all params considered as printouts) |
| 352 | + $param = trim( $param ); |
| 353 | + |
| 354 | + if ( ( $param != '' ) && ( $param { 0 } != '?' ) ) { |
| 355 | + $param = '?' . $param; |
| 356 | + } |
| 357 | + |
| 358 | + $poarray[] = $param; |
| 359 | + } |
| 360 | + } |
| 361 | + return $poarray; |
| 362 | + } |
| 363 | + |
| 364 | + /** |
315 | 365 | * A method which generates the url parameters based on passed parameters. |
316 | 366 | * UI implementations need to overload this if they use different form parameters. |
317 | 367 | * |
— | — | @@ -337,9 +387,11 @@ |
338 | 388 | if ( array_key_exists( 'order', $params ) ) $urltail .= '&order=' . $params['order']; |
339 | 389 | return $urltail; |
340 | 390 | } |
| 391 | + |
341 | 392 | protected function makeHtmlResult() { |
342 | 393 | // STUB |
343 | 394 | } |
| 395 | + |
344 | 396 | /** |
345 | 397 | * Display a form section showing the options for a given format, |
346 | 398 | * based on the getParameters() value for that format's query printer. |
— | — | @@ -411,8 +463,6 @@ |
412 | 464 | * Returns a Validator style Parameter definition. |
413 | 465 | * SMW 1.5.x style definitions are converted. |
414 | 466 | * |
415 | | - * @since 1.6 |
416 | | - * |
417 | 467 | * @param mixed $param |
418 | 468 | * |
419 | 469 | * @return Parameter |
— | — | @@ -450,8 +500,6 @@ |
451 | 501 | /** |
452 | 502 | * Get the HTML for a single parameter input. |
453 | 503 | * |
454 | | - * @since 1.6 |
455 | | - * |
456 | 504 | * @param Parameter $parameter |
457 | 505 | * @param mixed $currentValue |
458 | 506 | * |
— | — | @@ -470,11 +518,15 @@ |
471 | 519 | |
472 | 520 | /** |
473 | 521 | * 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. |
| 522 | + * format. Use in conjunction with processFormatOptions() to supply formats |
| 523 | + * options using ajax. Also, use its complement processFormatSelectBox() to |
| 524 | + * decode form data sent by these elements. UI's may overload these methods |
| 525 | + * to change behaviour or form parameters. |
| 526 | + * |
| 527 | + * @param string $defaultformat The default format which remains selected in the form |
476 | 528 | * @return string |
477 | 529 | */ |
478 | | - protected function makeFormatSelectBox( $defaultformat = 'broadtable' ) { |
| 530 | + protected function getFormatSelectBox( $defaultformat = 'broadtable' ) { |
479 | 531 | |
480 | 532 | global $smwgResultFormats, $smwgJQueryIncluded, $wgOut; |
481 | 533 | |
— | — | @@ -531,8 +583,6 @@ |
532 | 584 | |
533 | 585 | // BEGIN: add javascript for updating formating options by ajax |
534 | 586 | 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 | 587 | $javascript = <<<END |
538 | 588 | <script type="text/javascript"> |
539 | 589 | function updateOtherOptions(strURL) { |
— | — | @@ -550,12 +600,42 @@ |
551 | 601 | } |
552 | 602 | |
553 | 603 | /** |
554 | | - * Returns form elements for a requested format. Use in conjunction with makeFormatSelectBox() |
| 604 | + * A method which decodes form data sent through form-elements generated by |
| 605 | + * its complement, getFormatSelectBox(). UIs may overload both to change form parameters. |
| 606 | + * |
| 607 | + * @param WebRequest $wgRequest |
| 608 | + * @return array |
| 609 | + */ |
| 610 | + protected function processFormatSelectBox(WebRequest $wgRequest){ |
| 611 | + $query_val = $wgRequest->getVal( 'p' ); |
| 612 | + if ( !empty( $query_val ) ) |
| 613 | + $params = SMWInfolink::decodeParameters( $query_val, false ); |
| 614 | + else { |
| 615 | + $query_values = $wgRequest->getArray( 'p' ); |
| 616 | + |
| 617 | + if ( is_array( $query_values ) ) { |
| 618 | + foreach ( $query_values as $key => $val ) { |
| 619 | + if ( empty( $val ) ) unset( $query_values[$key] ); |
| 620 | + } |
| 621 | + } |
| 622 | + |
| 623 | + // p is used for any additional parameters in certain links. |
| 624 | + $params = SMWInfolink::decodeParameters( $query_values, false ); |
| 625 | + } |
| 626 | + return $query_values; |
| 627 | + } |
| 628 | + |
| 629 | + /** |
| 630 | + * Generates form elements for a (web)requested format. |
555 | 631 | * |
| 632 | + * Required by getFormatSelectBox() to recieve form elements from the web. |
| 633 | + * UIs may need to overload processFormatOptions(), getgetFormatSelectBox() |
| 634 | + * and getFormatSelectBox() to change behavior. |
| 635 | + * |
556 | 636 | * @param WebRequest $wgRequest |
557 | | - * @return boolean Returns true if formatoptions were requested and returned, else false |
| 637 | + * @return boolean Returns true if format options were requested and returned, else false |
558 | 638 | */ |
559 | | - protected function handleFormatOptions( $wgRequest ) { |
| 639 | + protected function processFormatOptions( $wgRequest ) { |
560 | 640 | global $wgOut; |
561 | 641 | if ( $wgRequest->getCheck( 'showformatoptions' ) ) { |
562 | 642 | // handle Ajax action |
— | — | @@ -568,6 +648,12 @@ |
569 | 649 | return false; |
570 | 650 | } |
571 | 651 | } |
| 652 | + |
| 653 | + /** |
| 654 | + * Returns true if this page shows the navigationBar. Overload to change behavior. |
| 655 | + * |
| 656 | + * @return boolean |
| 657 | + */ |
572 | 658 | protected function usesNavigationBar() { |
573 | 659 | return true; |
574 | 660 | } |
— | — | @@ -577,6 +663,9 @@ |
578 | 664 | /** |
579 | 665 | * This class helps to implement a Special Page for creating and executing queries. |
580 | 666 | * |
| 667 | + * It captures the primary activities of what a semantic search pages does: |
| 668 | + * (take parameters, validate them and generate results, or errors, if any). |
| 669 | + * |
581 | 670 | * Query UIs may use this class and override methods to create a customised UI |
582 | 671 | * interface. |
583 | 672 | * |