Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialAsk.php |
— | — | @@ -30,6 +30,11 @@ |
31 | 31 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
32 | 32 | } |
33 | 33 | |
| 34 | + /** |
| 35 | + * Main entrypoint for the special page. |
| 36 | + * |
| 37 | + * @param string $p |
| 38 | + */ |
34 | 39 | public function execute( $p ) { |
35 | 40 | global $wgOut, $wgRequest, $smwgQEnabled, $smwgRSSEnabled, $smwgMW_1_14; |
36 | 41 | |
— | — | @@ -48,7 +53,7 @@ |
49 | 54 | $format = $wgRequest->getVal( 'showformatoptions' ); |
50 | 55 | $params = $wgRequest->getArray( 'params' ); |
51 | 56 | $wgOut->disable(); |
52 | | - print self::showFormatOptions( $format, $params ); |
| 57 | + echo self::showFormatOptions( $format, $params ); |
53 | 58 | } else { |
54 | 59 | $this->extractQueryParameters( $p ); |
55 | 60 | $this->makeHTMLResult(); |
— | — | @@ -59,10 +64,14 @@ |
60 | 65 | wfProfileOut( 'doSpecialAsk (SMW)' ); |
61 | 66 | } |
62 | 67 | |
| 68 | + /** |
| 69 | + * This code rather hacky since there are many ways to call that special page, the most involved of |
| 70 | + * which is the way that this page calls itself when data is submitted via the form (since the shape |
| 71 | + * of the parameters then is governed by the UI structure, as opposed to being governed by reason). |
| 72 | + * |
| 73 | + * @param string $p |
| 74 | + */ |
63 | 75 | protected function extractQueryParameters( $p ) { |
64 | | - // This code rather hacky since there are many ways to call that special page, the most involved of |
65 | | - // which is the way that this page calls itself when data is submitted via the form (since the shape |
66 | | - // of the parameters then is governed by the UI structure, as opposed to being governed by reason). |
67 | 76 | global $wgRequest, $smwgQMaxInlineLimit; |
68 | 77 | |
69 | 78 | // First make all inputs into a simple parameter list that can again be parsed into components later. |
— | — | @@ -75,9 +84,11 @@ |
76 | 85 | $rawparams = SMWInfolink::decodeParameters( $query_val, false ); // p is used for any additional parameters in certain links |
77 | 86 | else { |
78 | 87 | $query_values = $wgRequest->getArray( 'p' ); |
| 88 | + |
79 | 89 | foreach ( $query_values as $key => $val ) { |
80 | 90 | if ( empty( $val ) ) unset( $query_values[$key] ); |
81 | 91 | } |
| 92 | + |
82 | 93 | $rawparams = SMWInfolink::decodeParameters( $query_values, false ); // p is used for any additional parameters in certain links |
83 | 94 | } |
84 | 95 | } else { // called from wiki, get all parameters |
— | — | @@ -98,15 +109,18 @@ |
99 | 110 | |
100 | 111 | foreach ( $ps as $param ) { // add initial ? if omitted (all params considered as printouts) |
101 | 112 | $param = trim( $param ); |
| 113 | + |
102 | 114 | if ( ( $param != '' ) && ( $param { 0 } != '?' ) ) { |
103 | 115 | $param = '?' . $param; |
104 | 116 | } |
| 117 | + |
105 | 118 | $rawparams[] = $param; |
106 | 119 | } |
107 | 120 | } |
108 | 121 | |
109 | 122 | // Now parse parameters and rebuilt the param strings for URLs |
110 | 123 | SMWQueryProcessor::processFunctionParams( $rawparams, $this->m_querystring, $this->m_params, $this->m_printouts ); |
| 124 | + |
111 | 125 | // Try to complete undefined parameter values from dedicated URL params |
112 | 126 | if ( !array_key_exists( 'format', $this->m_params ) ) { |
113 | 127 | if ( array_key_exists( 'rss', $this->m_params ) ) { // backwards compatibility (SMW<=1.1 used this) |
— | — | @@ -118,8 +132,10 @@ |
119 | 133 | |
120 | 134 | if ( !array_key_exists( 'order', $this->m_params ) ) { |
121 | 135 | $order_values = $wgRequest->getArray( 'order' ); |
| 136 | + |
122 | 137 | if ( is_array( $order_values ) ) { |
123 | 138 | $this->m_params['order'] = ''; |
| 139 | + |
124 | 140 | foreach ( $order_values as $order_value ) { |
125 | 141 | if ( $order_value == '' ) $order_value = 'ASC'; |
126 | 142 | $this->m_params['order'] .= ( $this->m_params['order'] != '' ? ',' : '' ) . $order_value; |
— | — | @@ -167,7 +183,12 @@ |
168 | 184 | $this->m_editquery = ( $wgRequest->getVal( 'eq' ) == 'yes' ) || ( $this->m_querystring == '' ); |
169 | 185 | } |
170 | 186 | |
171 | | - static protected function addAutocompletionJavascriptAndCSS() { |
| 187 | + /** |
| 188 | + * Creates and adds the JavaScript and JS needed for autocompletion to $wgOut. |
| 189 | + * |
| 190 | + * @since 1.5.2 |
| 191 | + */ |
| 192 | + protected static function addAutocompletionJavascriptAndCSS() { |
172 | 193 | global $wgOut, $smwgScriptPath, $smwgJQueryIncluded, $smwgJQueryUIIncluded; |
173 | 194 | |
174 | 195 | // Add CSS and JavaScript for jQuery and jQuery UI. |
— | — | @@ -181,6 +202,7 @@ |
182 | 203 | } else { |
183 | 204 | $scripts[] = "$smwgScriptPath/libs/jquery-1.4.2.min.js"; |
184 | 205 | } |
| 206 | + |
185 | 207 | $smwgJQueryIncluded = true; |
186 | 208 | } |
187 | 209 | |
— | — | @@ -295,6 +317,9 @@ |
296 | 318 | $wgOut->addScript( $javascript_autocomplete_text ); |
297 | 319 | } |
298 | 320 | |
| 321 | + /** |
| 322 | + * TODO: document |
| 323 | + */ |
299 | 324 | protected function makeHTMLResult() { |
300 | 325 | global $wgOut, $smwgAutocompleteInSpecialAsk; |
301 | 326 | |
— | — | @@ -419,12 +444,13 @@ |
420 | 445 | global $wgRequest; |
421 | 446 | |
422 | 447 | $hidequery = $wgRequest->getVal( 'eq' ) == 'no'; |
| 448 | + |
423 | 449 | // if it's an export format (like CSV, JSON, etc.), |
424 | 450 | // don't actually export the data if 'eq' is set to |
425 | 451 | // either 'yes' or 'no' in the query string - just |
426 | 452 | // show the link instead |
427 | | - if ( $this->m_editquery || $hidequery ) |
428 | | - $result_mime = false; |
| 453 | + if ( $this->m_editquery || $hidequery ) $result_mime = false; |
| 454 | + |
429 | 455 | if ( $result_mime == false ) { |
430 | 456 | if ( $res->getCount() > 0 ) { |
431 | 457 | if ( $this->m_editquery ) $urltail .= '&eq=yes'; |
— | — | @@ -468,11 +494,18 @@ |
469 | 495 | header( "content-disposition: attachment; filename=$result_name" ); |
470 | 496 | } |
471 | 497 | |
472 | | - print $result; |
| 498 | + echo $result; |
473 | 499 | } |
474 | 500 | } |
475 | 501 | |
476 | | - |
| 502 | + /** |
| 503 | + * TODO: document |
| 504 | + * |
| 505 | + * @param string $printoutstring |
| 506 | + * @param string $urltail |
| 507 | + * |
| 508 | + * @return string |
| 509 | + */ |
477 | 510 | protected function getInputForm( $printoutstring, $urltail ) { |
478 | 511 | global $wgUser, $smwgQSortingSupport, $wgLang, $smwgResultFormats; |
479 | 512 | |
— | — | @@ -590,6 +623,11 @@ |
591 | 624 | return $result; |
592 | 625 | } |
593 | 626 | |
| 627 | + /** |
| 628 | + * TODO: document |
| 629 | + * |
| 630 | + * @return string |
| 631 | + */ |
594 | 632 | protected static function getEmbedToggle() { |
595 | 633 | return '<span id="embed_show"><a href="#" rel="nofollow" onclick="' . |
596 | 634 | "document.getElementById('inlinequeryembed').style.display='block';" . |
— | — | @@ -606,8 +644,13 @@ |
607 | 645 | |
608 | 646 | /** |
609 | 647 | * Build the navigation for some given query result, reuse url-tail parameters. |
| 648 | + * |
| 649 | + * @param SMWQueryResult $res |
| 650 | + * @param string $urltail |
| 651 | + * |
| 652 | + * @return string |
610 | 653 | */ |
611 | | - protected function getNavigationBar( $res, $urltail ) { |
| 654 | + protected function getNavigationBar( SMWQueryResult $res, $urltail ) { |
612 | 655 | global $wgUser, $smwgQMaxInlineLimit; |
613 | 656 | |
614 | 657 | $skin = $wgUser->getSkin(); |
— | — | @@ -655,22 +698,27 @@ |
656 | 699 | |
657 | 700 | /** |
658 | 701 | * Display a form section showing the options for a given format, |
659 | | - * based on the getParameters() value for that format's query printer |
| 702 | + * based on the getParameters() value for that format's query printer. |
| 703 | + * |
| 704 | + * @param string $format |
| 705 | + * @param array $paramValues |
| 706 | + * |
| 707 | + * @return string |
660 | 708 | */ |
661 | | - function showFormatOptions( $format, $param_values ) { |
| 709 | + protected function showFormatOptions( $format, array $paramValues ) { |
662 | 710 | $text = ''; |
663 | 711 | |
664 | 712 | $printer = SMWQueryProcessor::getResultPrinter( $format, SMWQueryProcessor::SPECIAL_PAGE ); |
665 | 713 | |
666 | | - |
667 | 714 | $params = method_exists( $printer, 'getParameters' ) ? $printer->getParameters() : array(); |
668 | 715 | |
669 | 716 | foreach ( $params as $i => $param ) { |
670 | 717 | $param_name = $param['name']; |
671 | 718 | $type = $param['type']; |
672 | 719 | $desc = $param['description']; |
673 | | - $cur_value = ( array_key_exists( $param_name, $param_values ) ) ? $param_values[$param_name] : ''; |
674 | 720 | |
| 721 | + $cur_value = ( array_key_exists( $param_name, $paramValues ) ) ? $paramValues[$param_name] : ''; |
| 722 | + |
675 | 723 | // 3 values per row, with alternating colors for rows |
676 | 724 | if ( $i % 3 == 0 ) { |
677 | 725 | $bgcolor = ( $i % 6 ) == 0 ? '#dddddd' : 'white'; |
— | — | @@ -690,6 +738,7 @@ |
691 | 739 | $values = $param['values']; |
692 | 740 | $text .= "<select name=\"p[$param_name]\">\n"; |
693 | 741 | $text .= " <option value=''></option>\n"; |
| 742 | + |
694 | 743 | foreach ( $values as $val ) { |
695 | 744 | if ( $cur_value == $val ) |
696 | 745 | $selected_str = 'selected'; |
— | — | @@ -697,18 +746,19 @@ |
698 | 747 | $selected_str = ''; |
699 | 748 | $text .= " <option value='$val' $selected_str>$val</option>\n"; |
700 | 749 | } |
701 | | - $text .= "</select>"; |
| 750 | + |
| 751 | + $text .= '</select>'; |
702 | 752 | break; |
703 | 753 | case 'enum-list': |
704 | 754 | $all_values = $param['values']; |
705 | 755 | $cur_values = explode( ',', $cur_value ); |
706 | 756 | foreach ( $all_values as $val ) { |
707 | | - $checked_str = ( in_array( $val, $cur_values ) ) ? "checked" : ""; |
| 757 | + $checked_str = ( in_array( $val, $cur_values ) ) ? 'checked' : ''; |
708 | 758 | $text .= "<span style=\"white-space: nowrap; padding-right: 5px;\"><input type=\"checkbox\" name=\"p[$param_name][$val]\" value=\"true\" $checked_str /> <tt>$val</tt></span>\n"; |
709 | 759 | } |
710 | 760 | break; |
711 | 761 | case 'boolean': |
712 | | - $checked_str = ( array_key_exists( $param_name, $param_values ) ) ? 'checked' : ''; |
| 762 | + $checked_str = ( array_key_exists( $param_name, $paramValues ) ) ? 'checked' : ''; |
713 | 763 | $text .= "<input type=\"checkbox\" name=\"p[$param_name]\" value=\"true\" $checked_str />"; |
714 | 764 | break; |
715 | 765 | } |