Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php |
— | — | @@ -73,7 +73,7 @@ |
74 | 74 | $this->uiCore = SMWQueryUIHelper::makeForUI( |
75 | 75 | $this->processQueryFormBox( $wgRequest ), |
76 | 76 | $params, |
77 | | - $this->processPOFormBox( $wgRequest ), |
| 77 | + array(), |
78 | 78 | false ); |
79 | 79 | if ( $this->uiCore->getQueryString() != "" ) { |
80 | 80 | $this->uiCore->execute( $p ); |
— | — | @@ -366,71 +366,88 @@ |
367 | 367 | $result = ''; |
368 | 368 | $num_sort_values = 0; |
369 | 369 | // START: create form elements already submitted earlier via form |
370 | | - |
371 | 370 | // attempting to load parameters from $wgRequest |
372 | 371 | $property_values = $wgRequest->getArray( 'property' ); |
373 | 372 | $order_values = $wgRequest->getArray( 'order' ); |
374 | 373 | $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] ); |
385 | 380 | } |
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"; |
404 | 381 | } |
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 | + |
406 | 400 | $params = $this->uiCore->getParameters(); |
407 | 401 | 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 ); |
411 | 406 | } 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(); |
413 | 409 | } |
414 | 410 | |
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 |
421 | 433 | } |
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"; |
434 | 438 | } |
| 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"; |
435 | 452 | } |
436 | 453 | // END: create form elements already submitted earlier via form |
437 | 454 | |
— | — | @@ -534,25 +551,28 @@ |
535 | 552 | $params = array(); |
536 | 553 | $order_values = $wgRequest->getArray( 'order' ); |
537 | 554 | $property_values = $wgRequest->getArray( 'property' ); |
| 555 | + $po = array(); |
538 | 556 | if ( is_array( $property_values ) ) { |
539 | 557 | $params['sort'] = ''; |
540 | 558 | $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' ) { |
543 | 565 | $params['sort'] .= ( $params['sort'] != '' ? ',':'' ) . $property_values[$key]; |
544 | 566 | $params['order'] .= ( $params['order'] != '' ? ',':'' ) . $order_values[$key]; |
545 | 567 | } |
546 | 568 | } |
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 | + } |
548 | 575 | |
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]; |
555 | 576 | } |
556 | | - |
557 | 577 | } |
558 | 578 | } |
559 | 579 | |
— | — | @@ -1395,7 +1415,7 @@ |
1396 | 1416 | $rawparams = SMWInfolink::decodeParameters( $p, true ); |
1397 | 1417 | // calling setParams to fill in missing parameters |
1398 | 1418 | $this->setParams( $rawparams ); |
1399 | | - $rawparams = array_merge( $this->parameters, $rawparams ); |
| 1419 | + $rawparams = $this->parameters; |
1400 | 1420 | } |
1401 | 1421 | |
1402 | 1422 | SMWQueryProcessor::processFunctionParams( $rawparams, $this->queryString, $this->parameters, $this->printOuts ); |