r92051 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92050‎ | r92051 | r92052 >
Date:06:59, 13 July 2011
Author:devayon
Status:deferred
Tags:
Comment:
Sorting fixes and some cleanup, follow-up to r91979
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php
@@ -321,9 +321,9 @@
322322 * @return string
323323 */
324324 protected function addSortingFormBox() {
 325+ global $smwgQSortingSupport, $wgRequest, $wgOut, $smwgJQueryIncluded;
325326 $result = '';
326327 if ( $smwgQSortingSupport ) {
327 - global $wgRequest, $wgOut, $smwgJQueryIncluded;
328328
329329 if ( ! array_key_exists( 'sort', $this->m_params ) || ! array_key_exists( 'order', $this->m_params ) ) {
330330 $orders = array(); // do not even show one sort input here
Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php
@@ -32,6 +32,13 @@
3333 smwfLoadExtensionMessages( 'SemanticMediaWiki' );
3434 }
3535
 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+ */
3643 protected function makePage( $p ) {
3744 global $wgOut;
3845 $htmloutput = $this->makeResults( $p );
@@ -50,10 +57,16 @@
5158 }
5259
5360 /**
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
5568 */
56 - protected function makeResults( $p ) {
57 - global $wgOut, $smwgQSortingSupport;
 69+ protected function makeResults() {
 70+ global $wgOut;
5871 $result = "";
5972 $spectitle = $this->getTitle();
6073 $result .= '<form name="ask" action="' . $spectitle->escapeLocalURL() . '" method="get">' . "\n" .
@@ -82,9 +95,8 @@
8396 '<p>' . $this->getPOFormBox( $this->getPOStrings(), SMWQueryUI::ENABLE_AUTO_SUGGEST ) . '</p>' . "\n";
8497
8598 // sorting inputs
86 - if ( $smwgQSortingSupport ) {
87 - $result .= $this->addSortingOptions( $result );
88 - }
 99+ $result .= $this -> addSortingFormBox();
 100+
89101 $result .= "<br><br>" . $this->getFormatSelectBox( 'broadtable' );
90102
91103 if ( $this->uiCore->getQueryString() != '' ) // hide #ask if there isnt any query defined
@@ -99,120 +111,6 @@
100112
101113 }
102114
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 -
217115 /**
218116 * Compatibility method to get the skin; MW 1.18 introduces a getSkin method in SpecialPage.
219117 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r92157Fixed sorting, follow-up to r92051devayon13:31, 14 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r91979added #ask output, limited sorting support and squashed some bugsdevayon18:00, 12 July 2011