r93421 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93420‎ | r93421 | r93422 >
Date:19:52, 28 July 2011
Author:devayon
Status:deferred
Tags:
Comment:
small bug fixes and follow-up to r93168
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php
@@ -73,7 +73,7 @@
7474 $this->uiCore = SMWQueryUIHelper::makeForUI(
7575 $this->processQueryFormBox( $wgRequest ),
7676 $params,
77 - $this->processPOFormBox( $wgRequest ),
 77+ array(),
7878 false );
7979 if ( $this->uiCore->getQueryString() != "" ) {
8080 $this->uiCore->execute( $p );
@@ -366,71 +366,88 @@
367367 $result = '';
368368 $num_sort_values = 0;
369369 // START: create form elements already submitted earlier via form
370 -
371370 // attempting to load parameters from $wgRequest
372371 $property_values = $wgRequest->getArray( 'property' );
373372 $order_values = $wgRequest->getArray( 'order' );
374373 $display_values = $wgRequest->getArray( 'display' );
375 - if ( is_array( $property_values ) and is_array( $order_values ) and is_array( $display_values ) ) {
376 - $num_sort_values = count( $property_values );
377 - foreach ( $property_values as $i => $property_value ) {
378 - $result .= Html::rawElement( 'div', array( 'id' => "sort_div_$i" ) ) . 'Property'; // TODO: add i18n
379 - $result .= Html::input( 'property[' . $i . ']', $property_value, 'text', array( 'size' => '35' ) );
380 - $result .= html::rawElement( 'select', array( 'order' => "order[' . $i . ']" ) );
381 - if ( $order_values[$i] == 'NONE' ) {
382 - $result .= '<option selected="selected" value="NONE">' . 'No sorting' . "</option>\n"; // TODO: add i18n
383 - } else {
384 - $result .= '<option value="NONE">' . 'No sorting' . "</option>\n"; // TODO: add i18n
 374+ if ( is_array( $property_values ) ) {
 375+ // removing empty values
 376+ foreach ( $property_values as $key => $property_value ) {
 377+ $property_values[$key] = trim( $property_value );
 378+ if ( $property_value == '' ) {
 379+ unset( $property_values[$key] );
385380 }
386 - if ( $order_values[$i] == 'ASC' ) {
387 - $result .= '<option selected="selected" value="ASC">' . wfMsg( 'smw_ask_ascorder' ) . "</option>\n";
388 - } else {
389 - $result .= '<option value="ASC">' . wfMsg( 'smw_ask_ascorder' ) . "</option>\n";
390 - }
391 - if ( $order_values[$i] == 'DESC' ) {
392 - $result .= '<option selected="selected" value="DESC">' . wfMsg( 'smw_ask_descorder' ) . "</option>\n";
393 - } else {
394 - $result .= '<option value="DESC">' . wfMsg( 'smw_ask_deccorder' ) . "</option>\n";
395 - }
396 - $result .= Html::closeElement( 'select' ) . "\n";
397 - if ( array_key_exists( $i, $display_values ) ) {
398 - $result .= 'show in results: <input type="checkbox" checked name="display_[' . $i . ']" value="yes">' . "\n"; // TODO: add i18n
399 - } else {
400 - $result .= 'show in results: <input type="checkbox" name="display_[' . $i . ']" value="yes">' . "\n"; // TODO: add i18n
401 - }
402 - $result .= '[<a href="javascript:removePOInstance(\'sort_div_' . $i . '\')">' . wfMsg( 'delete' ) . '</a>]' . "\n";
403 - $result .= Html::closeElement( 'div' ) . "\n";
404381 }
405 - } else { // printouts and sorting were set via another widget, so create elements by fetching data from $uiCore
 382+ } else {
 383+ /*
 384+ * Printouts and sorting were set via another widget/form/source, so
 385+ * create elements by fetching data from $uiCore. The exact ordering
 386+ * of Ui elements might not be preserved, if the above block were to
 387+ * be removed. This is a bit of a hack, converting all strings to
 388+ * lowercase to simplify searching procedure and using in_array.
 389+ */
 390+
 391+ $po = explode( '?', $this->getPOStrings() );
 392+ reset( $po );
 393+ foreach ( $po as $key => $value ) {
 394+ $po[$key] = strtolower( trim( $value ) );
 395+ if ( $po[$key] == '' ) {
 396+ unset ( $po[$key] );
 397+ }
 398+ }
 399+
406400 $params = $this->uiCore->getParameters();
407401 if ( array_key_exists( 'sort', $params ) && array_key_exists( 'order', $params ) ) {
408 - $sorts = explode( ',', $params['sort'] );
409 - $orders = explode( ',', $params['order'] );
410 - reset( $sorts );
 402+ $property_values = explode( ',', strtolower( $params['sort'] ) );
 403+ $order_values = explode( ',', $params['order'] );
 404+ reset( $property_values );
 405+ reset( $order_values );
411406 } else {
412 - $orders = array(); // do not even show one sort input here
 407+ $order_values = array(); // do not even show one sort input here
 408+ $property_values = array();
413409 }
414410
415 - if ( !array_key_exists( 'sort', $params ) ) {
416 - $sort_values = $wgRequest->getArray( 'sort' );
417 - if ( is_array( $sort_values ) ) {
418 - $params['sort'] = implode( ',', $sort_values );
419 - $num_sort_values = count( $sort_values );
420 - }
 411+ foreach ( $po as $po_key => $po_value ) {
 412+ if ( !in_array( $po_value, $property_values ) ) {
 413+ $property_values[] = $po_value;
 414+ }
 415+ }
 416+ $display_values = array();
 417+ reset( $property_values );
 418+ foreach ( $property_values as $property_key => $property_value ) {
 419+ if ( in_array( $property_value, $po ) ) {
 420+ $display_values[$property_key] = "yes";
 421+ }
 422+ }
 423+ }
 424+ $num_sort_values = count( $property_values );
 425+ foreach ( $property_values as $i => $property_value ) {
 426+ $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i" ) ) . 'Property '; // TODO: add i18n
 427+ $result .= Html::input( 'property[' . $i . ']', $property_value, 'text', array( 'size' => '35' ) ) . "\n";
 428+ $result .= html::openElement( 'select', array( 'name' => "order[$i]" ) );
 429+ if ( !is_array( $order_values ) or !array_key_exists( $i, $order_values ) or $order_values[$i] == 'NONE'){
 430+ $result .= '<option selected value="NONE">' . 'No sorting' . "</option>\n"; // TODO: add i18n
 431+ } else {
 432+ $result .= '<option value="NONE">' . 'No sorting' . "</option>\n"; // TODO: add i18n
421433 }
422 -
423 - foreach ( $orders as $i => $order ) {
424 - $result .= "<div id=\"sort_div_$i\">" . 'Property' . // TODO: add i18n
425 - ' <input type="text" name="property[' . $i . ']" value="' .
426 - htmlspecialchars( $sorts[$i] ) . "\" size=\"35\"/>\n" . '<select name="order[' . $i . ']"><option ';
427 - if ( $order == 'ASC' ) $result .= 'selected="selected" ';
428 - $result .= 'value="ASC">' . wfMsg( 'smw_ask_ascorder' ) . '</option><option ';
429 - if ( $order == 'DESC' ) $result .= 'selected="selected" ';
430 - $result .= 'value="DESC">' . wfMsg( 'smw_ask_descorder' ) . "</option></select>\n";
431 - $result .= 'show in results: <input type="checkbox" checked name="display_num" value="yes">' . "\n"; // TODO: add i18n'
432 - $result .= '[<a href="javascript:removePOInstance(\'sort_div_' . $i . '\')">' . wfMsg( 'delete' ) . '</a>]' . "\n";
433 - $result .= "</div>\n";
 434+ if(is_array( $order_values ) and array_key_exists( $i, $order_values ) and $order_values[$i] == 'ASC' ) {
 435+ $result .= '<option selected value="ASC">' . wfMsg( 'smw_ask_ascorder' ) . "</option>\n";
 436+ } else {
 437+ $result .= '<option value="ASC">' . wfMsg( 'smw_ask_ascorder' ) . "</option>\n";
434438 }
 439+ if ( is_array( $order_values ) and array_key_exists( $i, $order_values ) and $order_values[$i] == 'DESC' ) {
 440+ $result .= '<option selected value="DESC">' . wfMsg( 'smw_ask_descorder' ) . "</option>\n";
 441+ } else {
 442+ $result .= '<option value="DESC">' . wfMsg( 'smw_ask_descorder' ) . "</option>\n";
 443+ }
 444+ $result .= "</select> \n";
 445+ if ( is_array( $display_values ) and array_key_exists( $i, $display_values ) ) {
 446+ $result .= 'show in results: <input type="checkbox" checked name="display[' . $i . ']" value="yes">' . "\n"; // TODO: add i18n
 447+ } else {
 448+ $result .= 'show in results: <input type="checkbox" name="display[' . $i . ']" value="yes">' . "\n"; // TODO: add i18n
 449+ }
 450+ $result .= '[<a href="javascript:removePOInstance(\'sort_div_' . $i . '\')">' . wfMsg( 'delete' ) . '</a>]' . "\n";
 451+ $result .= "</div> \n";
435452 }
436453 // END: create form elements already submitted earlier via form
437454
@@ -534,25 +551,28 @@
535552 $params = array();
536553 $order_values = $wgRequest->getArray( 'order' );
537554 $property_values = $wgRequest->getArray( 'property' );
 555+ $po = array();
538556 if ( is_array( $property_values ) ) {
539557 $params['sort'] = '';
540558 $params['order'] = '';
541 - foreach ( $order_values as $key => $order_value ) {
542 - if ( $order_value != 'NONE' ) {
 559+ foreach ( $property_values as $key => $property_value ) {
 560+ $property_values[$key] = trim( $property_value );
 561+ if ( $property_value == '' ) {
 562+ unset( $property_values[$key] );
 563+ }
 564+ if ( is_array( $order_values ) and array_key_exists( $key, $order_values ) and $order_values[$key] != 'NONE' ) {
543565 $params['sort'] .= ( $params['sort'] != '' ? ',':'' ) . $property_values[$key];
544566 $params['order'] .= ( $params['order'] != '' ? ',':'' ) . $order_values[$key];
545567 }
546568 }
547 - }
 569+ $display_values = $wgRequest->getArray( 'display' );
 570+ if ( is_array( $display_values ) ) {
 571+ foreach ( $display_values as $key => $value ) {
 572+ if ( $value == 'yes' and array_key_exists($key, $property_values )) {
 573+ $po[] = '?' . trim( $property_values[$key] );
 574+ }
548575
549 - $display_values = $wgRequest->getArray( 'display' );
550 - $po = array();
551 - if ( is_array( $display_values ) ) {
552 - foreach ( $display_values as $key => $value ) {
553 - if ( $value == 'yes' ) {
554 - $po[] = '?' . $property_values[$key];
555576 }
556 -
557577 }
558578 }
559579
@@ -1395,7 +1415,7 @@
13961416 $rawparams = SMWInfolink::decodeParameters( $p, true );
13971417 // calling setParams to fill in missing parameters
13981418 $this->setParams( $rawparams );
1399 - $rawparams = array_merge( $this->parameters, $rawparams );
 1419+ $rawparams = $this->parameters;
14001420 }
14011421
14021422 SMWQueryProcessor::processFunctionParams( $rawparams, $this->queryString, $this->parameters, $this->printOuts );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r93168preliminary work combining PO and sortingdevayon12:21, 26 July 2011