r94231 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94230‎ | r94231 | r94232 >
Date:07:22, 11 August 2011
Author:devayon
Status:deferred
Tags:
Comment:
follow-up: r94116
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php
@@ -37,13 +37,17 @@
3838 $html_output = $this->makeResults( $p );
3939 if ( $this->uiCore->getQueryString() != "" ) {
4040 if ( $this->usesNavigationBar() ) {
41 - $html_output .= $this->getNavigationBar ( $this->uiCore->getLimit(), $this->uiCore->getOffset(), $this->uiCore->hasFurtherResults() ); // ? can we preload offset and limit?
 41+ $html_output .= Html::rawElement( 'div', array( 'class' => 'smw-qc-navbar' ),
 42+ $this->getNavigationBar ( $this->uiCore->getLimit(), $this->uiCore->getOffset(), $this->uiCore->hasFurtherResults() )
 43+ ); // ? can we preload offset and limit?
4244 }
4345
44 - $html_output .= "<br/>" . $this->uiCore->getHTMLResult() . "<br>";
 46+ $html_output .= Html::rawElement( 'div', array( 'class' => 'smw-qc-result' ), $this->uiCore->getHTMLResult() );
4547
4648 if ( $this->usesNavigationBar() ) {
47 - $html_output .= $this->getNavigationBar ( $this->uiCore->getLimit(), $this->uiCore->getOffset(), $this->uiCore->hasFurtherResults() ); // ? can we preload offset and limit?
 49+ $html_output .= Html::rawElement( 'div', array( 'class' => 'smw-qc-navbar' ),
 50+ $this->getNavigationBar ( $this->uiCore->getLimit(), $this->uiCore->getOffset(), $this->uiCore->hasFurtherResults() )
 51+ ); // ? can we preload offset and limit?
4852 }
4953 }
5054 $wgOut->addHTML( $html_output );
@@ -112,7 +116,7 @@
113117 $result .= '</div>'; // end of hidden additional options
114118 $result .= '<br /><input type="submit" value="' . wfMsg( 'smw_ask_submit' ) . '"/>' .
115119 '<input type="hidden" name="eq" value="no"/>' .
116 - "\n</form>";
 120+ "\n</form><br/>";
117121
118122 return $result;
119123
@@ -126,11 +130,12 @@
127131 * Overrides method from SMWQueryUI (modal window added)
128132 *
129133 * @global boolean $smwgQSortingSupport
 134+ * @global Language $wgContLang
130135 * @param WebRequest $wgRequest
131136 * @return string
132137 */
133138 protected function processPoSortFormBox( WebRequest $wgRequest ) {
134 - global $smwgQSortingSupport;
 139+ global $smwgQSortingSupport, $wgContLang;
135140 if ( !$smwgQSortingSupport ) return array();
136141
137142 $params = array();
@@ -139,12 +144,13 @@
140145 $category_values = $wgRequest->getArray( 'category' );
141146 $category_label_values = $wgRequest->getArray( 'cat_label' );
142147 $po = array();
 148+ $category_namespace = $wgContLang->getNsText( NS_CATEGORY );
143149 if ( is_array( $category_values ) ) {
144150 foreach ( $category_values as $key => $value ) {
145151 if ( trim( $value ) == '' ) {
146 - $po[$key] = '?Category'; // Todo: i18n
 152+ $po[$key] = "?$category_namespace" ;
147153 } else {
148 - $po[$key] = '?Category:' . $value; // Todo: i18n
 154+ $po[$key] = "?$category_namespace:$value";
149155 }
150156 }
151157 }
@@ -222,12 +228,17 @@
223229 $category_values = $wgRequest->getArray( 'category' );
224230 $category_label_values = $wgRequest->getArray( 'cat_label' );
225231
226 - if ( is_array( $property_values ) ) {
227 - // removing empty values
228 - foreach ( $property_values as $key => $property_value ) {
229 - $property_values[$key] = trim( $property_value );
230 - if ( $property_value == '' ) {
231 - unset( $property_values[$key] );
 232+ if ( is_array( $property_values ) or is_array( $category_values ) ) {
 233+ /*
 234+ * Printouts were set via this Ui
 235+ */
 236+ if ( is_array( $property_values ) ) {
 237+ // remove empty property values
 238+ foreach ( $property_values as $key => $property_value ) {
 239+ $property_values[$key] = trim( $property_value );
 240+ if ( $property_value == '' ) {
 241+ unset( $property_values[$key] );
 242+ }
232243 }
233244 }
234245 } else {
@@ -258,19 +269,18 @@
259270 $order_values = array(); // do not even show one sort input here
260271 $property_values = array();
261272 }
262 -
263 - foreach ( $po as $po_key => $po_value ) {
 273+ foreach ( $po as $po_value ) {
264274 if ( !in_array( $po_value, $property_values ) ) {
265275 $property_values[] = $po_value;
266276 }
267 - }
268 - $display_values = array();
269 - reset( $property_values );
270 - foreach ( $property_values as $property_key => $property_value ) {
271 - if ( in_array( $property_value, $po ) ) {
272 - $display_values[$property_key] = "yes";
273 - }
274 - }
 277+ }
 278+ $display_values = array();
 279+ reset( $property_values );
 280+ foreach ( $property_values as $property_key => $property_value ) {
 281+ if ( in_array( $property_value, $po ) ) {
 282+ $display_values[$property_key] = "yes";
 283+ }
 284+ }
275285 }
276286 $i = 0;
277287 $additional_POs = array();
@@ -278,11 +288,14 @@
279289 $additional_POs = array_merge( $additional_POs, $property_values );
280290 }
281291 if ( is_array( $category_values ) ) {// same as testing $category_label_values
282 - $additional_POs = array_merge( $additional_POs, $category_values );
 292+ $keys = array_keys( $category_values );
 293+ foreach ( $keys as $value ) {
 294+ $additional_POs[$value] = $category_values[$value]; // array_merge won't work because numeric keys need to be preserved
 295+ }
283296 }
284297 ksort( $additional_POs );
285298 foreach ( $additional_POs as $key => $value ) {
286 - if ( array_key_exists( $key, $property_values ) ) {
 299+ if ( is_array( $property_values ) and array_key_exists( $key, $property_values ) ) {
287300 // make a element for additional properties
288301 $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i", 'class' => 'smw-sort' ) );
289302 $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>';
@@ -312,9 +325,9 @@
313326 $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i", 'class' => 'smw-sort' ) );
314327 $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>' .
315328 'Category (optional)' . // todo: i18n
316 - Xml::input( "category[$i]", '20', $category_values[$key] ) . " " .
 329+ Xml::input( "category[$i]", '20', $category_values[$key], array( 'id' => "category$i" ) ) . " " .
317330 'Label' . // todo: i18n
318 - Xml::input( "cat_label[$i]", '20', array_key_exists( $key, $category_label_values ) ? $category_label_values[$key]:false ) . " " .
 331+ Xml::input( "cat_label[$i]", '20', array_key_exists( $key, $category_label_values ) ? $category_label_values[$key]:false, array( 'id' => "cat_label$i" ) ) . " " .
319332 ' <a id="more' . $i . '" "class="smwq-more" href="javascript:smw_makeCatDialog(\'' . $i . '\')"> options </a> ' . // TODO: i18n
320333 Xml::closeElement( 'div' );
321334 $i++;
@@ -349,7 +362,7 @@
350363 $property_dialog_box = Xml::openElement( 'div', array( 'id' => 'prop-dialog', 'title' => 'Property Options', 'class' => 'smw-prop-dialog' ) ) . // todo i18n
351364 Xml::inputLabel( 'Property:', '', 'd-property', 'd-property' ) . '<br/>' . // todo i18n
352365 Xml::inputLabel( 'Label:', '', 'd-property-label', 'd-property-label' ) . '<br/>' . // todo i18n
353 - 'Format: ' . Html::openElement( 'select', array( 'name' => 'd-format', 'id' => 'd-format' ) ) . // todo i18n
 366+ '<label for="d-format">Format:</label> ' . Html::openElement( 'select', array( 'name' => 'd-format', 'id' => 'd-format' ) ) . // todo i18n
354367 Xml::option( 'None (default)', ' ' ) . // todo i18n
355368 Xml::option( 'Simple', '#-' ) . // todo i18n
356369 Xml::closeElement( 'select' ) .
@@ -397,6 +410,7 @@
398411 }
399412 });
400413 }
 414+
401415 function smw_category_autocomplete(){
402416 jQuery('[name*="category"]').autocomplete({
403417 minLength: 2,
@@ -417,47 +431,63 @@
418432 $javascript_text .= <<<EOT
419433 function smw_property_autocomplete(){
420434 }
 435+
421436 function smw_category_autocomplete(){
422437 }
 438+
423439 EOT;
424440 }
425441
426442 $javascript_text .= <<<EOT
427443 function smw_prop_code_update(){
428 - code = '?'+\$j('#d-property')[0].value;
429 - if(code!=''){
430 - if(\$j('#d-property-format-custom')[0].value !=''){
431 - code = code + \$j('#d-property-format-custom')[0].value;
432 - }
433 - if(\$j('#d-property-label')[0].value !=''){
434 - code = code + ' = '+ \$j('#d-property-label')[0].value;
435 - }
436 - \$j('#d-property-code')[0].value= code;
 444+ code = '?'+jQuery('#d-property')[0].value;
 445+ if(code!=''){
 446+ if(jQuery('#d-property-format-custom')[0].value !=''){
 447+ code = code + jQuery('#d-property-format-custom')[0].value;
437448 }
 449+ if(jQuery('#d-property-label')[0].value !=''){
 450+ code = code + ' = '+ jQuery('#d-property-label')[0].value;
 451+ }
 452+ jQuery('#d-property-code')[0].value= code;
 453+ }
438454 }
 455+
 456+function smw_cat_code_update(){
 457+
 458+}
 459+
 460+function smw_makeCatDialog(cat_id){
 461+ jQuery('#prop-cat input').attr('value','');
 462+ cat=jQuery('#category'+cat_id)[0].value;
 463+ jQuery('#d-category').attr('value',cat);
 464+ label=jQuery('#cat_label'+cat_id)[0].value;
 465+ jQuery('#d-category-label').attr('value',label);
 466+ //jQuery('#cat-dialog').dialog('open');
 467+}
 468+
439469 function smw_makePropDialog(prop_id){
440 - jQuery('#prop-dialog input').attr('value','');
441 - prop=val=\$j('#property'+prop_id)[0].value;
442 - if(val[0]='?') val=prop=prop.substr(1);
443 - if((i=val.indexOf('='))!=-1) prop=prop.substring(0, i);
444 - if((i=val.indexOf('#'))!=-1) prop=prop.substring(0, i);
445 - if(val.split('=')[1]){
446 - label=val.split('=')[1].trim();
447 - }else{
448 - label="";
449 - }
450 - format = val.split('=')[0];
451 - if(format.indexOf('#')!=-1){
452 - format=format.substr(format.indexOf('#'));
453 - }else{
454 - format="";
455 - }
 470+ jQuery('#prop-dialog input').attr('value','');
 471+ prop=val=jQuery('#property'+prop_id)[0].value;
 472+ if(val[0]='?') val=prop=prop.substr(1);
 473+ if((i=val.indexOf('='))!=-1) prop=prop.substring(0, i);
 474+ if((i=val.indexOf('#'))!=-1) prop=prop.substring(0, i);
 475+ if(val.split('=')[1]){
 476+ label=val.split('=')[1].trim();
 477+ }else{
 478+ label="";
 479+ }
 480+ format = val.split('=')[0];
 481+ if(format.indexOf('#')!=-1){
 482+ format=format.substr(format.indexOf('#'));
 483+ }else{
 484+ format="";
 485+ }
456486
457 - \$j('#d-property').attr('value', prop.trim());
458 - \$j('#d-property-label').attr('value', label);
459 - \$j('#d-property-format-custom').attr('value', format.trim());
460 - \$j('#prop-dialog').dialog.id=prop_id;
461 - \$j('#prop-dialog').dialog('open');
 487+ jQuery('#d-property').attr('value', prop.trim());
 488+ jQuery('#d-property-label').attr('value', label);
 489+ jQuery('#d-property-format-custom').attr('value', format.trim());
 490+ jQuery('#prop-dialog').dialog.id=prop_id;
 491+ jQuery('#prop-dialog').dialog('open');
462492 }
463493 // code for handling adding and removing the "sort" inputs
464494
@@ -550,7 +580,20 @@
551581 resizable: true,
552582 minHeight: 200,
553583 minWidth: 400,
 584+ buttons: {
 585+ "Ok": function(){ //todo i18
 586+ smw_cat_code_update();
 587+ // todo: move modal window data to main window form controls;
 588+ jQuery(this).dialog("close");
 589+ },
 590+ "Cancel": function(){ //todo:i18n
 591+ jQuery('#cat-dialog input').attr('value','');
 592+ jQuery(this).dialog("close");
 593+ }
 594+ }
554595 });
 596+ //todo: run smw_cat_code_update() when input values in category modal windows changes
 597+
555598 jQuery('#prop-dialog').dialog({
556599 autoOpen: false,
557600 modal: true,
@@ -560,7 +603,7 @@
561604 buttons: {
562605 "Ok": function(){ //todo: i18n
563606 smw_prop_code_update();
564 - \$j('#property'+\$j('#prop-dialog').dialog.id)[0].value=\$j('#d-property-code')[0].value;
 607+ jQuery('#property'+jQuery('#prop-dialog').dialog.id)[0].value=jQuery('#d-property-code')[0].value;
565608 jQuery(this).dialog("close");
566609 },
567610 "Cancel": function(){ //todo: i18n
@@ -577,10 +620,9 @@
578621 smw_prop_code_update();
579622 });
580623 });
581 -function smw_makeCatDialog(cat_id){
582 - //\$j('#cat-dialog').dialog('open');
583 -}
 624+
584625 jQuery(document).ready(smw_property_autocomplete);
 626+jQuery(document).ready(smw_category_autocomplete);
585627 </script>
586628
587629 EOT;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r94116added control for category optionsdevayon15:44, 9 August 2011