r94055 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94054‎ | r94055 | r94056 >
Date:11:26, 8 August 2011
Author:devayon
Status:deferred
Tags:
Comment:
follow-up:r93878 (stable)
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/skins/SMW_custom.css (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php
@@ -73,7 +73,7 @@
7474 '</tr>' .
7575 "</table>\n";
7676 // sorting and prinouts
77 - $result .= '<div class="smw-qc-sortbox" style="padding-left:10px;">'.$this->getPoSortFormBox().'</div>';
 77+ $result .= '<div class="smw-qc-sortbox" style="padding-left:10px;">' . $this->getPoSortFormBox() . '</div>';
7878 // show|hide additional options and querying help
7979 $result .= '<br><span id="show_additional_options" style="display:inline;"><a href="#addtional" rel="nofollow" onclick="' .
8080 "document.getElementById('additional_options').style.display='block';" .
@@ -104,6 +104,59 @@
105105 }
106106
107107 /**
 108+ * Decodes printouts and sorting - related form options generated by its
 109+ * complement, getPoSortFormBox(). UIs may overload both to change form
 110+ * parameters.
 111+ *
 112+ * Overrides method from SMWQueryUI (modal window added)
 113+ *
 114+ * @global boolean $smwgQSortingSupport
 115+ * @param WebRequest $wgRequest
 116+ * @return string
 117+ */
 118+ protected function processPoSortFormBox( WebRequest $wgRequest ) {
 119+ global $smwgQSortingSupport;
 120+ if ( !$smwgQSortingSupport ) return array();
 121+
 122+ $params = array();
 123+ $order_values = $wgRequest->getArray( 'order' );
 124+ $property_values = $wgRequest->getArray( 'property' );
 125+ $po = array();
 126+ if ( is_array( $property_values ) ) {
 127+ $params['sort'] = '';
 128+ $params['order'] = '';
 129+ foreach ( $property_values as $key => $property_value ) {
 130+ $property_values[$key] = trim( $property_value );
 131+ if ( $property_value == '' ) {
 132+ unset( $property_values[$key] );
 133+ }
 134+ if ( is_array( $order_values ) and array_key_exists( $key, $order_values ) and $order_values[$key] != 'NONE' ) {
 135+ $prop = substr( $property_values[$key], 1 ); // removing the leading '?'
 136+ if ( !strpos( $prop, '#' ) === false ) $prop = strstr( $prop, '#', true ); // removing format options
 137+ if ( !strpos( $prop, '=' ) === false ) $prop = strstr( $prop, '=', true ); // removing format options
 138+
 139+ $params['sort'] .= ( $params['sort'] != '' ? ',':'' ) . $prop;
 140+ $params['order'] .= ( $params['order'] != '' ? ',':'' ) . $order_values[$key];
 141+ }
 142+ }
 143+ $display_values = $wgRequest->getArray( 'display' );
 144+ if ( is_array( $display_values ) ) {
 145+ foreach ( $display_values as $key => $value ) {
 146+ if ( $value == '1' and array_key_exists( $key, $property_values ) ) {
 147+ $po[] = trim( $property_values[$key] );
 148+ }
 149+
 150+ }
 151+ }
 152+ }
 153+
 154+ $params = array_merge( $params, $po );
 155+
 156+ return $params;
 157+
 158+ }
 159+
 160+ /**
108161 * Generates the forms elements(s) for choosing printouts and sorting
109162 * options. Use its complement processPoSortFormBox() to decode data
110163 * sent by these elements.
@@ -118,7 +171,6 @@
119172 if ( !$smwgQSortingSupport ) return '';
120173 $this->enableJQueryUI();
121174 $wgOut->addScriptFile( "$smwgScriptPath/libs/jquery-ui/jquery-ui.dialog.min.js" );
122 - $wgOut->addScriptFile( "$smwgScriptPath/libs/jquery-ui/jquery-ui.tabs.min.js" );
123175 $wgOut->addStyle( "$smwgScriptPath/skins/SMW_custom.css" );
124176
125177 $result = '';
@@ -181,10 +233,10 @@
182234 $num_sort_values = count( $property_values );
183235 foreach ( $property_values as $i => $property_value ) {
184236
185 - $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i" ) );
186 - $result .= '<span class="smw-remove"><a href="javascript:removePOInstance(\'sort_div_' . $i . '\')"><img src="'.$smwgScriptPath.'/skins/images/close-button.png" alt="'. wfMsg('smw_qui_delete').'"></a></span>';
 237+ $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i", 'class' => 'smw-sort' ) );
 238+ $result .= '<span class="smw-remove"><a href="javascript:removePOInstance(\'sort_div_' . $i . '\')"><img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '"></a></span>';
187239 $result .= wfMsg( 'smw_qui_property' );
188 - $result .= Html::input( 'property[' . $i . ']', $property_value, 'text', array( 'size' => '35' ) ) . "\n";
 240+ $result .= Html::input( 'property[' . $i . ']', $property_value, 'text', array( 'size' => '35', 'id' => "property$i" ) ) . "\n";
189241 $result .= Html::openElement( 'select', array( 'name' => "order[$i]" ) );
190242
191243 $if1 = ( !is_array( $order_values ) or !array_key_exists( $i, $order_values ) or $order_values[$i] == 'NONE' );
@@ -200,14 +252,15 @@
201253
202254 $if4 = ( is_array( $display_values ) and array_key_exists( $i, $display_values ) );
203255 $result .= Xml::checkLabel( wfMsg( 'smw_qui_shownresults' ), "display[$i]", "display$i", $if4 );
 256+ $result .= ' <a id="more' . $i . '" "class="smwq-more" href="javascript:smw_makeDialog(\'' . $i . '\')"> options </a> '; // TODO: i18n
204257
205258 $result .= Xml::closeElement( 'div' );
206259 }
207260 // END: create form elements already submitted earlier via form
208261
209262 // create hidden form elements to be cloned later
210 - $hidden = Html::openElement( 'div', array( 'id' => 'sorting_starter', 'class'=>'smw-sort', 'style' => 'display:none' ) ) .
211 - '<span class="smw-remove"><a><img src="'.$smwgScriptPath.'/skins/images/close-button.png" alt="'. wfMsg('smw_qui_delete').'"></a></span>' .
 263+ $hidden = Html::openElement( 'div', array( 'id' => 'sorting_starter', 'class' => 'smw-sort', 'style' => 'display:none' ) ) .
 264+ '<span class="smw-remove"><a><img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '"></a></span>' .
212265 wfMsg( 'smw_qui_property' ) .
213266 Xml::input( "property_num", '35' ) . " ";
214267
@@ -222,38 +275,17 @@
223276
224277 $hidden = json_encode( $hidden );
225278
226 - $dialogbox = Xml::openElement( 'div', array( 'id' => 'dialog', 'title' => 'Advanced Print-Out Options' ) ) . // todo i18n
227 - Xml::checkLabel( wfMsg( 'smw_qui_shownresults' ), '', 'dialog-show-results', true ) .
228 - '<div id="tab-box">' .
229 - '<ul>' .
230 - '<li><a href="#property-tab">Property</a></li>' . // todo i18n
231 - '<li><a href="#category-tab">Category</a></li>' . // todo i18n
232 - '</ul>' .
233 - '<div id="property-tab">' .
234 - Xml::inputLabel( 'Property', '', 'tab-property', 'tab-property' ) . '<br/>' . // todo i18n
235 - Xml::inputLabel( 'Label (optional):', '', 'tab-property-label', 'tab-property-label' ) . '<br/>' . // todo i18n
236 - 'Format: ' . Html::openElement( 'select', array( 'name' => 'tab-format' ) ) . // todo i18n
237 - Xml::option( 'None (default)', 'NONE' ) . // todo i18n
238 - Xml::option( 'Simple', '-' ) . // todo i18n
239 - Xml::option( 'Numeric', 'n' ) . // todo i18n
240 - Xml::option( 'Unit', 'u' ) . // todo i18n
241 - Xml::option( 'Custom', 'CUSTOM' ) . // todo i18n
 279+ $dialogbox = Xml::openElement( 'div', array( 'id' => 'dialog', 'title' => 'Property Options', 'class' => 'smw-prop-dialog' ) ) . // todo i18n
 280+ Xml::inputLabel( 'Property:', '', 'd-property', 'd-property' ) . '<br/>' . // todo i18n
 281+ Xml::inputLabel( 'Label:', '', 'd-property-label', 'd-property-label' ) . '<br/>' . // todo i18n
 282+ 'Format: ' . Html::openElement( 'select', array( 'name' => 'd-format', 'id' => 'd-format' ) ) . // todo i18n
 283+ Xml::option( 'None (default)', ' ' ) . // todo i18n
 284+ Xml::option( 'Simple', '#-' ) . // todo i18n
242285 Xml::closeElement( 'select' ) .
243 - Xml::input( 'format-custom' ) . '<br/>' .
244 - Xml::inputLabel( 'limit (optional):', '', 'tab-property-limit', 'tab-property-limit' ) . '<br/>' . // todo i18n
245 - '</div>' .
246 - '<div id="category-tab">' .
247 - Xml::inputLabel( 'Label (optional):', '', 'tab-category-label', 'tab-category-label' ) . '<br/>' . // todo i18n
248 - Xml::inputLabel( 'Specify a category (optional)', '', 'tab-category', 'tab-category' ) . '<br/>' . // todo i18n
249 - 'If result belongs to category, display' . Html::input( 'tab-yes', 'X' ) . '<br/>' .
250 - 'else display' . Html::input( 'tab-yes', ' ' ) .
251 - '</div>' .
252 - '</div>' .
253 - '<br>Sort by: <select id ="dialog-order">' . // todo i18n
254 - '<option value="NONE">' . wfMsg( 'smw_qui_nosort' ) . '</option>' .
255 - '<option value="ASC">' . wfMsg( 'smw_qui_ascorder' ) . '</option>' .
256 - '<option value="DESC">' . wfMsg( 'smw_qui_descorder' ) . '</option>' .
257 - '</select>' . '</form></div>';
 286+ Xml::input( 'format-custom', false, false, array( 'id' => 'd-property-format-custom' ) ) . '<br/>' .
 287+ // Xml::inputLabel( 'Limit:', 'd-property-limit', 'd-property-limit' ) . '<br/>' . // todo i18n
 288+ '<input type="hidden" name="d-property-code" id="d-property-code">' .
 289+ Xml::closeElement( 'div' );
258290
259291 $result .= '<div id="sorting_main"></div>' . "\n";
260292 $result .= '[<a href="javascript:addPOInstance(\'sorting_starter\', \'sorting_main\')">' . wfMsg( 'smw_qui_addnprop' ) . '</a>]' . "\n";
@@ -264,39 +296,44 @@
265297 }
266298 $javascript_text = <<<EOT
267299 <script type="text/javascript">
 300+var num_elements = {$num_sort_values};
268301 // code for handling adding and removing the "sort" inputs
269 -
270 -jQuery(function(){
271 - jQuery('$hidden').appendTo(document.body);
272 - jQuery('$dialogbox').appendTo(document.body);
273 - jQuery('#dialog').dialog({
274 - autoOpen: false,
275 - modal: true,
276 - resizable: true,
277 - minHeight: 300,
278 - minWidth: 500
279 - });
280 - jQuery('#tab-box').tabs({
281 - selected:1
282 - });
283 -});
284 -jQuery(document).ready(function(){
285 - jQuery('#sort-more').click(function(){jQuery('#dialog').dialog("open");});
286 - jQuery('#dialog-show-results').click(function(){
287 - if(jQuery('#dialog-show-results')[0].checked){
288 - jQuery('#tab-box').show('blind');
289 - } else {
290 - jQuery('#tab-box').hide('blind');
 302+function smw_prop_code_update(){
 303+ code = '?'+\$j('#d-property')[0].value;
 304+ if(code!=''){
 305+ if(\$j('#d-property-format-custom')[0].value !=''){
 306+ code = code + \$j('#d-property-format-custom')[0].value;
 307+ }
 308+ if(\$j('#d-property-label')[0].value !=''){
 309+ code = code + ' = '+ \$j('#d-property-label')[0].value;
 310+ }
 311+ \$j('#d-property-code')[0].value= code;
291312 }
292 - });
293 -});
 313+}
294314 function smw_makeDialog(prop_id){
295 - \$j('#tab-property')[0].value=\$j('#property'+prop_id)[0].value;
 315+ jQuery('#dialog input').attr('value','');
 316+ prop=val=\$j('#property'+prop_id)[0].value;
 317+ if(val[0]='?') val=prop=prop.substr(1);
 318+ if((i=val.indexOf('='))!=-1) prop=prop.substring(0, i);
 319+ if((i=val.indexOf('#'))!=-1) prop=prop.substring(0, i);
 320+ if(val.split('=')[1]){
 321+ label=val.split('=')[1].trim();
 322+ }else{
 323+ label="";
 324+ }
 325+ format = val.split('=')[0];
 326+ if(format.indexOf('#')!=-1){
 327+ format=format.substr(format.indexOf('#'));
 328+ }else{
 329+ format="";
 330+ }
 331+
 332+ \$j('#d-property').attr('value', prop.trim());
 333+ \$j('#d-property-label').attr('value', label);
 334+ \$j('#d-property-format-custom').attr('value', format.trim());
 335+ \$j('#dialog').dialog.id=prop_id;
296336 \$j('#dialog').dialog('open');
297337 }
298 -
299 -var num_elements = {$num_sort_values};
300 -
301338 function addPOInstance(starter_div_id, main_div_id) {
302339 var starter_div = document.getElementById(starter_div_id);
303340 var main_div = document.getElementById(main_div_id);
@@ -306,10 +343,11 @@
307344 var div_id = 'sort_div_' + num_elements;
308345 new_div.id = div_id;
309346 new_div.style.display = 'block';
310 -
 347+ jQuery(new_div.getElementsByTagName('label')).attr('for', 'display'+num_elements);
311348 var children = new_div.getElementsByTagName('*');
312349 var x;
313350 for (x = 0; x < children.length; x++) {
 351+ if (children[x].for) children[x].for="display"+num_elements;
314352 if (children[x].name){
315353 children[x].id = children[x].name.replace(/_num/, ''+num_elements);
316354 children[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']');
@@ -318,7 +356,7 @@
319357
320358 //Create 'more' link
321359 var more_button =document.createElement('span');
322 - more_button.innerHTML = ' <a class="smwq-more" href="javascript:smw_makeDialog(\'' + num_elements + '\')">more</a> '; //TODO: i18n
 360+ more_button.innerHTML = ' <a class="smwq-more" href="javascript:smw_makeDialog(\'' + num_elements + '\')">options</a> '; //TODO: i18n
323361 more_button.id = 'more'+num_elements;
324362 new_div.appendChild(more_button);
325363
@@ -328,9 +366,42 @@
329367 // initialize delete button
330368 st='sort_div_'+num_elements;
331369 jQuery('#'+new_div.id).find(".smw-remove a")[0].href="javascript:removePOInstance('"+st+"')";
 370+ num_elements++;
 371+}
 372+
 373+function removePOInstance(div_id) {
 374+ var olddiv = document.getElementById(div_id);
 375+ var parent = olddiv.parentNode;
 376+ parent.removeChild(olddiv);
 377+}
 378+
 379+jQuery(function(){
 380+ jQuery('$hidden').appendTo(document.body);
 381+ jQuery('$dialogbox').appendTo(document.body);
 382+ jQuery('#dialog').dialog({
 383+ autoOpen: false,
 384+ modal: true,
 385+ resizable: true,
 386+ minHeight: 200,
 387+ minWidth: 400,
 388+ buttons: {
 389+ "Ok": function(){ //todo: i18n
 390+ smw_prop_code_update();
 391+ \$j('#property'+\$j('#dialog').dialog.id)[0].value=\$j('#d-property-code')[0].value;
 392+ jQuery(this).dialog("close");
 393+ },
 394+ "Cancel": function(){ //todo: i18n
 395+ jQuery('#dialog input').attr('value','');
 396+ jQuery(this).dialog("close");
 397+ }
 398+ }
 399+ });
 400+});
 401+
 402+jQuery(document).ready(function(){
332403 EOT;
333 - if ( $enableAutocomplete == SMWQueryUI::ENABLE_AUTO_SUGGEST ) {
334 - $javascript_text .= <<<EOT
 404+ if ( $enableAutocomplete == SMWQueryUI::ENABLE_AUTO_SUGGEST ) {
 405+ $javascript_text .= <<<EOT
335406 //add autocomplete
336407 jQuery('[name*="property"]').autocomplete({
337408 minLength: 2,
@@ -339,23 +410,24 @@
340411
341412 jQuery.getJSON(url, 'search='+request.term, function(data){
342413 //remove the namespace prefix 'Property:' from returned data
343 - for(i=0;i<data[1].length;i++) data[1][i]=data[1][i].substr(data[1][i].indexOf(':')+1);
 414+ for(i=0;i<data[1].length;i++) data[1][i]='?'+data[1][i].substr(data[1][i].indexOf(':')+1);
344415 response(data[1]);
345416 });
 417+
346418 }
347419 });
348420 EOT;
349 - }
 421+ }
350422 $javascript_text .= <<<EOT
351 - num_elements++;
 423+ jQuery('#sort-more').click(function(){jQuery('#dialog').dialog("open");});
 424+ jQuery('#dialog input').bind('keyup click', smw_prop_code_update );
352425
353 -}
 426+ jQuery('#d-format').bind('change', function(event){
 427+ jQuery('#d-property-format-custom').attr('value', jQuery('#d-format').attr('value'));
 428+ smw_prop_code_update();
 429+ });
 430+});
354431
355 -function removePOInstance(div_id) {
356 - var olddiv = document.getElementById(div_id);
357 - var parent = olddiv.parentNode;
358 - parent.removeChild(olddiv);
359 -}
360432 </script>
361433
362434 EOT;
Index: trunk/extensions/SemanticMediaWiki/skins/SMW_custom.css
@@ -133,6 +133,7 @@
134134 /* ui buttons for QueryUI */
135135 .smw-sort input, .smw-sort a, .smw-sort select, .smw-sort checkbox{
136136 margin-left: 5px;
 137+ margin-bottom: 5px;
137138 }
138139 span.smw-remove a img{
139140 text-decoration: none;
@@ -140,7 +141,12 @@
141142 vertical-align: -3px;
142143 }
143144
 145+.smw-prop-dialog input, .smw-prop-dialog select{
 146+ margin-top: 10px;
 147+ margin-right: 5px;
 148+}
144149
 150+
145151 /* search, browse, RDF icons */
146152
147153 span.smwsearchicon { /*FIXME: this was only used for Factbox docu, should be removed from code*/

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r93878adding modal window for sorting optionsdevayon10:44, 4 August 2011