Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php |
— | — | @@ -321,9 +321,9 @@ |
322 | 322 | * @return string |
323 | 323 | */ |
324 | 324 | protected function addSortingFormBox() { |
| 325 | + global $smwgQSortingSupport, $wgRequest, $wgOut, $smwgJQueryIncluded; |
325 | 326 | $result = ''; |
326 | 327 | if ( $smwgQSortingSupport ) { |
327 | | - global $wgRequest, $wgOut, $smwgJQueryIncluded; |
328 | 328 | |
329 | 329 | if ( ! array_key_exists( 'sort', $this->m_params ) || ! array_key_exists( 'order', $this->m_params ) ) { |
330 | 330 | $orders = array(); // do not even show one sort input here |
Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php |
— | — | @@ -32,6 +32,13 @@ |
33 | 33 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
34 | 34 | } |
35 | 35 | |
| 36 | + /** |
| 37 | + * The main entrypoint. Call the various methods of SMWQueryUI and |
| 38 | + * SMWQueryUIHelper to build ui elements and to process them. |
| 39 | + * |
| 40 | + * @global OutputPage $wgOut |
| 41 | + * @param string $p |
| 42 | + */ |
36 | 43 | protected function makePage( $p ) { |
37 | 44 | global $wgOut; |
38 | 45 | $htmloutput = $this->makeResults( $p ); |
— | — | @@ -50,10 +57,16 @@ |
51 | 58 | } |
52 | 59 | |
53 | 60 | /** |
54 | | - * Adds the input query form. Overloaded from SMWQueryUI |
| 61 | + * Creates the input form |
| 62 | + * |
| 63 | + * @global OutputPage $wgOut |
| 64 | + * @global booolean $smwgQSortingSupport |
| 65 | + * @return string |
| 66 | + * |
| 67 | + * TODO: clean up the lines handling sorting |
55 | 68 | */ |
56 | | - protected function makeResults( $p ) { |
57 | | - global $wgOut, $smwgQSortingSupport; |
| 69 | + protected function makeResults() { |
| 70 | + global $wgOut; |
58 | 71 | $result = ""; |
59 | 72 | $spectitle = $this->getTitle(); |
60 | 73 | $result .= '<form name="ask" action="' . $spectitle->escapeLocalURL() . '" method="get">' . "\n" . |
— | — | @@ -82,9 +95,8 @@ |
83 | 96 | '<p>' . $this->getPOFormBox( $this->getPOStrings(), SMWQueryUI::ENABLE_AUTO_SUGGEST ) . '</p>' . "\n"; |
84 | 97 | |
85 | 98 | // sorting inputs |
86 | | - if ( $smwgQSortingSupport ) { |
87 | | - $result .= $this->addSortingOptions( $result ); |
88 | | - } |
| 99 | + $result .= $this -> addSortingFormBox(); |
| 100 | + |
89 | 101 | $result .= "<br><br>" . $this->getFormatSelectBox( 'broadtable' ); |
90 | 102 | |
91 | 103 | if ( $this->uiCore->getQueryString() != '' ) // hide #ask if there isnt any query defined |
— | — | @@ -99,120 +111,6 @@ |
100 | 112 | |
101 | 113 | } |
102 | 114 | |
103 | | - /** |
104 | | - * Javascript and HTML code to enable sorting over columns. |
105 | | - * |
106 | | - * @return string |
107 | | - */ |
108 | | - |
109 | | - protected function addSortingOptions() { |
110 | | - global $wgRequest, $wgOut, $smwgJQueryIncluded; |
111 | | - |
112 | | - |
113 | | - $result = ''; |
114 | | - if ( ! array_key_exists( 'sort', $this->m_params ) || ! array_key_exists( 'order', $this->m_params ) ) { |
115 | | - $orders = array(); // do not even show one sort input here |
116 | | - } else { |
117 | | - $sorts = explode( ',', $this->m_params['sort'] ); |
118 | | - $orders = explode( ',', $this->m_params['order'] ); |
119 | | - reset( $sorts ); |
120 | | - } |
121 | | - |
122 | | - foreach ( $orders as $i => $order ) { |
123 | | - $result .= "<div id=\"sort_div_$i\">" . wfMsg( 'smw_ask_sortby' ) . ' <input type="text" name="sort[' . $i . ']" value="' . |
124 | | - htmlspecialchars( $sorts[$i] ) . "\" size=\"35\"/>\n" . '<select name="order[' . $i . ']"><option '; |
125 | | - if ( $order == 'ASC' ) $result .= 'selected="selected" '; |
126 | | - $result .= 'value="ASC">' . wfMsg( 'smw_ask_ascorder' ) . '</option><option '; |
127 | | - if ( $order == 'DESC' ) $result .= 'selected="selected" '; |
128 | | - |
129 | | - $result .= 'value="DESC">' . wfMsg( 'smw_ask_descorder' ) . "</option></select>\n"; |
130 | | - $result .= '[<a href="javascript:removeInstance(\'sort_div_' . $i . '\')">' . wfMsg( 'delete' ) . '</a>]' . "\n"; |
131 | | - $result .= "</div>\n"; |
132 | | - } |
133 | | - |
134 | | - $result .= '<div id="sorting_starter" style="display: none">' . wfMsg( 'smw_ask_sortby' ) . ' <input type="text" name="sort_num" size="35" />' . "\n"; |
135 | | - $result .= ' <select name="order_num">' . "\n"; |
136 | | - $result .= ' <option value="ASC">' . wfMsg( 'smw_ask_ascorder' ) . "</option>\n"; |
137 | | - $result .= ' <option value="DESC">' . wfMsg( 'smw_ask_descorder' ) . "</option>\n</select>\n"; |
138 | | - $result .= "</div>\n"; |
139 | | - $result .= '<div id="sorting_main"></div>' . "\n"; |
140 | | - $result .= '<a href="javascript:addInstance(\'sorting_starter\', \'sorting_main\')">' . wfMsg( 'smw_add_sortcondition' ) . '</a>' . "\n"; |
141 | | - |
142 | | - |
143 | | - |
144 | | - |
145 | | - $this->m_num_sort_values = 0; |
146 | | - |
147 | | - if ( !array_key_exists( 'sort', $this->m_params ) ) { |
148 | | - $sort_values = $wgRequest->getArray( 'sort' ); |
149 | | - if ( is_array( $sort_values ) ) { |
150 | | - $this->m_params['sort'] = implode( ',', $sort_values ); |
151 | | - $this->m_num_sort_values = count( $sort_values ); |
152 | | - } |
153 | | - } |
154 | | - // Javascript code for handling adding and removing the "sort" inputs |
155 | | - $delete_msg = wfMsg( 'delete' ); |
156 | | - |
157 | | - |
158 | | - $javascript_text = <<<END |
159 | | -<script type="text/javascript"> |
160 | | -// code for handling adding and removing the "sort" inputs |
161 | | -var num_elements = {$this->m_num_sort_values}; |
162 | | - |
163 | | -function addInstance(starter_div_id, main_div_id) { |
164 | | - var starter_div = document.getElementById(starter_div_id); |
165 | | - var main_div = document.getElementById(main_div_id); |
166 | | - |
167 | | - //Create the new instance |
168 | | - var new_div = starter_div.cloneNode(true); |
169 | | - var div_id = 'sort_div_' + num_elements; |
170 | | - new_div.className = 'multipleTemplate'; |
171 | | - new_div.id = div_id; |
172 | | - new_div.style.display = 'block'; |
173 | | - |
174 | | - var children = new_div.getElementsByTagName('*'); |
175 | | - var x; |
176 | | - for (x = 0; x < children.length; x++) { |
177 | | - if (children[x].name) |
178 | | - children[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']'); |
179 | | - } |
180 | | - |
181 | | - //Create 'delete' link |
182 | | - var remove_button = document.createElement('span'); |
183 | | - remove_button.innerHTML = '[<a href="javascript:removeInstance(\'sort_div_' + num_elements + '\')">{$delete_msg}</a>]'; |
184 | | - new_div.appendChild(remove_button); |
185 | | - |
186 | | - //Add the new instance |
187 | | - main_div.appendChild(new_div); |
188 | | - num_elements++; |
189 | | -} |
190 | | - |
191 | | -function removeInstance(div_id) { |
192 | | - var olddiv = document.getElementById(div_id); |
193 | | - var parent = olddiv.parentNode; |
194 | | - parent.removeChild(olddiv); |
195 | | -} |
196 | | -</script> |
197 | | - |
198 | | -END; |
199 | | - |
200 | | - $wgOut->addScript( $javascript_text ); |
201 | | - |
202 | | - if ( !$smwgJQueryIncluded ) { |
203 | | - $realFunction = array( 'OutputPage', 'includeJQuery' ); |
204 | | - if ( is_callable( $realFunction ) ) { |
205 | | - $wgOut->includeJQuery(); |
206 | | - } else { |
207 | | - $scripts[] = "$smwgScriptPath/libs/jquery-1.4.2.min.js"; |
208 | | - } |
209 | | - |
210 | | - $smwgJQueryIncluded = true; |
211 | | - } |
212 | | - |
213 | | - return $result; |
214 | | - } |
215 | | - |
216 | | - |
217 | 115 | /** |
218 | 116 | * Compatibility method to get the skin; MW 1.18 introduces a getSkin method in SpecialPage. |
219 | 117 | * |