r94379 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94378‎ | r94379 | r94380 >
Date:20:18, 12 August 2011
Author:devayon
Status:deferred
Tags:
Comment:
stylefixes and moving sorting widget to base class
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
@@ -143,8 +143,8 @@
144144 protected function enableJQuery() {
145145 global $wgOut, $smwgJQueryIncluded;
146146 if ( !$smwgJQueryIncluded ) {
147 - $real_function = array( 'OutputPage', 'includeJQuery' );
148 - if ( is_callable( $real_function ) ) {
 147+ $realFunction = array( 'OutputPage', 'includeJQuery' );
 148+ if ( is_callable( $realFunction ) ) {
149149 $wgOut->includeJQuery();
150150 } else {
151151 $wgOut->addScriptFile( "$smwgScriptPath/libs/jquery-1.4.2.min.js" );
@@ -190,7 +190,7 @@
191191 global $wgOut;
192192 if ( $this->autoCompleteEnabled == false ) {
193193 $this->enableJQueryUI();
194 - $javascript_autocomplete_text = <<<END
 194+ $javascriptAutocompleteText = <<<END
195195 <script type="text/javascript">
196196 function smw_split(val) {
197197 return val.split('\\n');
@@ -235,7 +235,7 @@
236236 </script>
237237 END;
238238
239 - $wgOut->addScript( $javascript_autocomplete_text );
 239+ $wgOut->addScript( $javascriptAutocompleteText );
240240 $this->autoCompleteEnabled = true;
241241 }
242242 }
@@ -257,7 +257,7 @@
258258 */
259259 public function getNavigationBar( $limit, $offset, $hasFurtherResults ) {
260260 global $smwgQMaxInlineLimit, $wgLang;
261 - $url_tail = $this->getUrlTail();
 261+ $urlTail = $this->getUrlTail();
262262 // Prepare navigation bar.
263263 if ( $offset > 0 ) {
264264 $navigation = Html::element(
@@ -265,7 +265,7 @@
266266 array(
267267 'href' => $this->getTitle()->getLocalURL(
268268 'offset=' . max( 0, $offset - $limit ) .
269 - '&limit=' . $limit . $url_tail
 269+ '&limit=' . $limit . $urlTail
270270 ),
271271 'rel' => 'nofollow'
272272 ),
@@ -289,7 +289,7 @@
290290 array(
291291 'href' => $this->getTitle()->getLocalURL(
292292 'offset=' . ( $offset + $limit ) .
293 - '&limit=' . $limit . $url_tail
 293+ '&limit=' . $limit . $urlTail
294294 ),
295295 'rel' => 'nofollow'
296296 ),
@@ -317,7 +317,7 @@
318318 array(
319319 'href' => $this->getTitle()->getLocalURL(
320320 'offset=' . $offset .
321 - '&limit=' . $l . $url_tail
 321+ '&limit=' . $l . $urlTail
322322 ),
323323 'rel' => 'nofollow'
324324 ),
@@ -378,6 +378,94 @@
379379 }
380380
381381 /**
 382+ * Decodes printouts and sorting - related form options generated by its
 383+ * complement, getPoSortFormBox(). UIs may overload both to change form
 384+ * parameters.
 385+ *
 386+ * @global boolean $smwgQSortingSupport
 387+ * @global Language $wgContLang
 388+ * @param WebRequest $wgRequest
 389+ * @return string
 390+ */
 391+ protected function processPoSortFormBox( WebRequest $wgRequest ) {
 392+ global $smwgQSortingSupport, $wgContLang;
 393+ if ( !$smwgQSortingSupport ) return array();
 394+
 395+ $params = array();
 396+ $orderValues = $wgRequest->getArray( 'order' );
 397+ $propertyValues = $wgRequest->getArray( 'property' );
 398+ $categoryValues = $wgRequest->getArray( 'category' );
 399+ $categoryLabelValues = $wgRequest->getArray( 'cat_label' );
 400+ $mainColumnLabels = $wgRequest->getArray( 'maincol_label' );
 401+ $po = array();
 402+ $categoryNamespace = $wgContLang->getNsText( NS_CATEGORY );
 403+ if ( is_array( $mainColumnLabels ) ) {
 404+ foreach ( $mainColumnLabels as $key => $label ) {
 405+ if ( $label == '' ) {
 406+ $po[$key] = "?";
 407+ } else {
 408+ $po[$key] = "? = $label";
 409+ }
 410+
 411+ }
 412+ }
 413+ if ( is_array( $categoryValues ) ) {
 414+ foreach ( $categoryValues as $key => $value ) {
 415+ if ( trim( $value ) == '' ) {
 416+ $po[$key] = "?$categoryNamespace" ;
 417+ } else {
 418+ $po[$key] = "?$categoryNamespace:$value";
 419+ }
 420+ }
 421+ }
 422+ if ( is_array( $categoryLabelValues ) ) {
 423+ foreach ( $categoryLabelValues as $key => $value ) {
 424+ if ( trim( $value ) != '' ) {
 425+ $po[$key] .= ' = ' . $value;
 426+ }
 427+ }
 428+ }
 429+ if ( is_array( $propertyValues ) ) {
 430+ $params['sort'] = '';
 431+ $params['order'] = '';
 432+ foreach ( $propertyValues as $key => $propertyValue ) {
 433+ $propertyValues[$key] = trim( $propertyValue );
 434+ if ( $propertyValue == '' ) {
 435+ unset( $propertyValues[$key] );
 436+ }
 437+ if ( is_array( $orderValues ) && array_key_exists( $key, $orderValues ) && $orderValues[$key] != 'NONE' ) {
 438+ $prop = substr( $propertyValues[$key], 1 ); // removing the leading '?'
 439+ if ( !strpos( $prop, '#' ) === false ) $prop = strstr( $prop, '#', true ); // removing format options
 440+ if ( !strpos( $prop, '=' ) === false ) $prop = strstr( $prop, '=', true ); // removing format options
 441+
 442+ $params['sort'] .= ( $params['sort'] != '' ? ',':'' ) . $prop;
 443+ $params['order'] .= ( $params['order'] != '' ? ',':'' ) . $orderValues[$key];
 444+ }
 445+ }
 446+ if ( $params['sort'] == '' ) {
 447+ unset ( $params['sort'] );
 448+ }
 449+ if ( $params['order'] == '' ) {
 450+ unset ( $params['order'] );
 451+ }
 452+ $displayValues = $wgRequest->getArray( 'display' );
 453+ if ( is_array( $displayValues ) ) {
 454+ foreach ( $displayValues as $key => $value ) {
 455+ if ( $value == '1' && array_key_exists( $key, $propertyValues ) ) {
 456+ $propertyValues[$key] = trim( $propertyValues[$key] );
 457+ $propertyValues[$key] = ( $propertyValues[$key][0] == '?' ) ? $propertyValues[$key]:'?' . $propertyValues[$key];
 458+ $po[$key] = $propertyValues[$key];
 459+ }
 460+ }
 461+ }
 462+ }
 463+ ksort( $po );
 464+ $params = array_merge( $params, $po );
 465+ return $params;
 466+
 467+ }
 468+
 469+ /**
382470 * Generates the forms elements(s) for choosing printouts and sorting
383471 * options. Use its complement processPoSortFormBox() to decode data
384472 * sent by these elements.
@@ -385,23 +473,35 @@
386474 * @return string
387475 */
388476 protected function getPoSortFormBox( $enableAutocomplete = SMWQueryUI::ENABLE_AUTO_SUGGEST ) {
389 - global $smwgQSortingSupport, $wgRequest, $wgOut;
 477+ global $smwgQSortingSupport, $wgRequest, $wgOut, $smwgScriptPath;
390478
391479 if ( !$smwgQSortingSupport ) return '';
392 - $this->enableJQuery();
 480+ $this->enableJQueryUI();
 481+ $wgOut->addScriptFile( "$smwgScriptPath/libs/jquery-ui/jquery-ui.dialog.min.js" );
 482+ $wgOut->addStyle( "$smwgScriptPath/skins/SMW_custom.css" );
 483+
393484 $result = '';
394 - $num_sort_values = 0;
 485+ $numSortValues = 0;
395486 // START: create form elements already submitted earlier via form
396487 // attempting to load parameters from $wgRequest
397 - $property_values = $wgRequest->getArray( 'property' );
398 - $order_values = $wgRequest->getArray( 'order' );
399 - $display_values = $wgRequest->getArray( 'display' );
400 - if ( is_array( $property_values ) ) {
401 - // removing empty values
402 - foreach ( $property_values as $key => $property_value ) {
403 - $property_values[$key] = trim( $property_value );
404 - if ( $property_value == '' ) {
405 - unset( $property_values[$key] );
 488+ $propertyValues = $wgRequest->getArray( 'property' );
 489+ $orderValues = $wgRequest->getArray( 'order' );
 490+ $displayValues = $wgRequest->getArray( 'display' );
 491+ $categoryValues = $wgRequest->getArray( 'category' );
 492+ $categoryLabelValues = $wgRequest->getArray( 'cat_label' );
 493+ $mainColumnLabels = $wgRequest->getArray( 'maincol_label' );
 494+
 495+ if ( is_array( $propertyValues ) || is_array( $categoryValues ) || is_array( $mainColumnLabels ) ) {
 496+ /*
 497+ * Printouts were set via this Ui
 498+ */
 499+ if ( is_array( $propertyValues ) ) {
 500+ // remove empty property values
 501+ foreach ( $propertyValues as $key => $propertyValue ) {
 502+ $propertyValues[$key] = trim( $propertyValue );
 503+ if ( $propertyValue == '' ) {
 504+ unset( $propertyValues[$key] );
 505+ }
406506 }
407507 }
408508 } else {
@@ -424,133 +524,395 @@
425525
426526 $params = $this->uiCore->getParameters();
427527 if ( array_key_exists( 'sort', $params ) && array_key_exists( 'order', $params ) ) {
428 - $property_values = explode( ',', strtolower( $params['sort'] ) );
429 - $order_values = explode( ',', $params['order'] );
430 - reset( $property_values );
431 - reset( $order_values );
 528+ $propertyValues = explode( ',', strtolower( $params['sort'] ) );
 529+ $orderValues = explode( ',', $params['order'] );
 530+ reset( $propertyValues );
 531+ reset( $orderValues );
432532 } else {
433 - $order_values = array(); // do not even show one sort input here
434 - $property_values = array();
 533+ $orderValues = array(); // do not even show one sort input here
 534+ $propertyValues = array();
435535 }
436 -
437 - foreach ( $po as $po_key => $po_value ) {
438 - if ( !in_array( $po_value, $property_values ) ) {
439 - $property_values[] = $po_value;
 536+ foreach ( $po as $poValue ) {
 537+ if ( !in_array( $poValue, $propertyValues ) ) {
 538+ $propertyValues[] = $poValue;
440539 }
441 - }
442 - $display_values = array();
443 - reset( $property_values );
444 - foreach ( $property_values as $property_key => $property_value ) {
445 - if ( in_array( $property_value, $po ) ) {
446 - $display_values[$property_key] = "yes";
447 - }
448 - }
 540+ }
 541+ $displayValues = array();
 542+ reset( $propertyValues );
 543+ foreach ( $propertyValues as $propertyKey => $propertyValue ) {
 544+ if ( in_array( $propertyValue, $po ) ) {
 545+ $displayValues[$propertyKey] = "yes";
 546+ }
 547+ }
449548 }
450 - $num_sort_values = count( $property_values );
451 - foreach ( $property_values as $i => $property_value ) {
452 - $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i" ) ) . wfMsg( 'smw_qui_property' );
453 - $result .= Html::input( 'property[' . $i . ']', $property_value, 'text', array( 'size' => '35' ) ) . "\n";
454 - $result .= Html::openElement( 'select', array( 'name' => "order[$i]" ) );
 549+ $i = 0;
 550+ $additionalPOs = array();
 551+ if ( is_array( $propertyValues ) ) {
 552+ $keys = array_keys( $propertyValues );
 553+ foreach ( $keys as $value ) {
 554+ $additionalPOs[$value] = $propertyValues[$value]; // array_merge won't work because numeric keys need to be preserved
 555+ }
 556+ }
 557+ if ( is_array( $categoryValues ) ) {// same as testing $categoryLabelValues
 558+ $keys = array_keys( $categoryValues );
 559+ foreach ( $keys as $value ) {
 560+ $additionalPOs[$value] = $categoryValues[$value]; // array_merge won't work because numeric keys need to be preserved
 561+ }
 562+ }
 563+ if ( is_array( $mainColumnLabels ) ) {
 564+ $keys = array_keys( $mainColumnLabels );
 565+ foreach ( $keys as $value ) {
 566+ $additionalPOs[$value] = $mainColumnLabels[$value]; // array_merge won't work because numeric keys need to be preserved
 567+ }
 568+ }
 569+ ksort( $additionalPOs );
 570+ foreach ( $additionalPOs as $key => $value ) {
 571+ if ( is_array( $propertyValues ) && array_key_exists( $key, $propertyValues ) ) {
 572+ /*
 573+ * Make an element for additional properties
 574+ */
 575+ $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i", 'class' => 'smwsort' ) );
 576+ $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>';
 577+ $result .= wfMsg( 'smw_qui_property' );
 578+ $result .= Html::input( 'property[' . $i . ']', $propertyValues[$key], 'text', array( 'size' => '35', 'id' => "property$i" ) ) . "\n";
 579+ $result .= Html::openElement( 'select', array( 'name' => "order[$i]" ) );
455580
456 - $if1 = ( !is_array( $order_values ) or !array_key_exists( $i, $order_values ) or $order_values[$i] == 'NONE' );
457 - $result .= Xml::option( wfMsg( 'smw_qui_nosort' ), "NONE", $if1 );
 581+ $if1 = ( !is_array( $orderValues ) || !array_key_exists( $key, $orderValues ) || $orderValues[$key] == 'NONE' );
 582+ $result .= Xml::option( wfMsg( 'smw_qui_nosort' ), "NONE", $if1 );
458583
459 - $if2 = ( is_array( $order_values ) and array_key_exists( $i, $order_values ) and $order_values[$i] == 'ASC' );
460 - $result .= Xml::option( wfMsg( 'smw_qui_ascorder' ), "ASC", $if2 );
 584+ $if2 = ( is_array( $orderValues ) && array_key_exists( $key, $orderValues ) && $orderValues[$key] == 'ASC' );
 585+ $result .= Xml::option( wfMsg( 'smw_qui_ascorder' ), "ASC", $if2 );
461586
462 - $if3 = ( is_array( $order_values ) and array_key_exists( $i, $order_values ) and $order_values[$i] == 'DESC' );
463 - $result .= Xml::option( wfMsg( 'smw_qui_descorder' ), "DESC", $if3 );
 587+ $if3 = ( is_array( $orderValues ) && array_key_exists( $key, $orderValues ) && $orderValues[$key] == 'DESC' );
 588+ $result .= Xml::option( wfMsg( 'smw_qui_descorder' ), "DESC", $if3 );
464589
465 - $result .= Xml::closeElement( 'select' );
 590+ $result .= Xml::closeElement( 'select' );
466591
467 - $if4 = ( is_array( $display_values ) and array_key_exists( $i, $display_values ) );
468 - $result .= Xml::checkLabel( wfMsg( 'smw_qui_shownresults' ), "display[$i]", "display$i", $if4 );
 592+ $if4 = ( is_array( $displayValues ) && array_key_exists( $key, $displayValues ) );
 593+ $result .= Xml::checkLabel( wfMsg( 'smw_qui_shownresults' ), "display[$i]", "display$i", $if4 );
 594+ $result .= ' <a id="more' . $i . '" "class="smwq-more" href="javascript:smw_makePropDialog(\'' . $i . '\')"> ' . WfMsg( 'smw_qui_options' ) . ' </a> ';
469595
470 - $result .= '[<a href="javascript:removePOInstance(\'sort_div_' . $i . '\')">' . wfMsg( 'smw_qui_delete' ) . '</a>]' . "\n";
471 - $result .= Xml::closeElement( 'div' );
 596+ $result .= Xml::closeElement( 'div' );
 597+ $i++;
 598+ }
 599+ if ( is_array( $categoryValues ) && array_key_exists( $key, $categoryValues ) ) {
 600+ /*
 601+ * Make an element for additional categories
 602+ */
 603+ $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i", 'class' => 'smwsort' ) );
 604+ $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>' .
 605+ wfMsg( 'smw_qui_category' ) .
 606+ Xml::input( "category[$i]", '25', $categoryValues[$key], array( 'id' => "category$i" ) ) . " " .
 607+ wfMsg( 'smw_qui_label' ) .
 608+ Xml::input( "cat_label[$i]", '20', array_key_exists( $key, $categoryLabelValues ) ? $categoryLabelValues[$key]:false, array( 'id' => "cat_label$i" ) ) . " " .
 609+ ' <a id="more' . $i . '" "class="smwq-more" href="javascript:smw_makeCatDialog(\'' . $i . '\')"> ' . WfMsg( 'smw_qui_options' ) . ' </a> ' .
 610+ Xml::closeElement( 'div' );
 611+ $i++;
 612+ }
 613+ if ( is_array( $mainColumnLabels ) && array_key_exists( $key, $mainColumnLabels ) ) {
 614+ /*
 615+ * Make an element for main column
 616+ */
 617+ $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i", 'class' => 'smwsort' ) ) .
 618+ '<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>' .
 619+ wfMsg( 'smw_qui_rescol' ) .
 620+ Xml::input( "maincol_label[$i]", '20', $mainColumnLabels[$key], array ( 'id' => "maincol_label$i" ) ) . " " .
 621+ Xml::closeElement( 'div' );
 622+ $i++;
 623+ }
472624 }
 625+ $numSortValues = $i;
473626 // END: create form elements already submitted earlier via form
474627
475628 // create hidden form elements to be cloned later
476 - $hidden = Html::openElement( 'div', array( 'id' => 'sorting_starter', 'style' => 'display:none' ) ) .
 629+ $hiddenProperty = Html::openElement( 'div', array( 'id' => 'property_starter', 'class' => 'smwsort', 'style' => 'display:none' ) ) .
 630+ '<span class="smw-remove"><a><img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '"></a></span>' .
477631 wfMsg( 'smw_qui_property' ) .
478 - Xml::input( "property_num", '35' ) . " ";
 632+ Xml::input( "property_num", '35' ) . " " .
 633+ Html::openElement( 'select', array( 'name' => 'order_num' ) ) .
 634+ Xml::option( wfMsg( 'smw_qui_nosort' ), 'NONE' ) .
 635+ Xml::option( wfMsg( 'smw_qui_ascorder' ), 'ASC' ) .
 636+ Xml::option( wfMsg( 'smw_qui_descorder' ), 'DESC' ) .
 637+ Xml::closeElement( 'select' ) .
 638+ Xml::checkLabel( wfMsg( 'smw_qui_shownresults' ), "display_num", '', true ) .
 639+ Xml::closeElement( 'div' );
 640+ $hiddenProperty = json_encode( $hiddenProperty );
479641
480 - $hidden .= Html::openElement( 'select', array( 'name' => 'order_num' ) );
481 - $hidden .= Xml::option( wfMsg( 'smw_qui_nosort' ), 'NONE' );
482 - $hidden .= Xml::option( wfMsg( 'smw_qui_ascorder' ), 'ASC' );
483 - $hidden .= Xml::option( wfMsg( 'smw_qui_descorder' ), 'DESC' );
484 - $hidden .= Xml::closeElement( 'select' );
 642+ $hiddenCategory = Html::openElement( 'div', array( 'id' => 'category_starter', 'class' => 'smwsort', 'style' => 'display:none' ) ) .
 643+ '<span class="smw-remove"><a><img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '"></a></span>' .
 644+ wfMsg( 'smw_qui_category' ) .
 645+ Xml::input( "category_num", '25' ) . " " .
 646+ wfMsg( 'smw_qui_label' ) .
 647+ Xml::input( "cat_label_num", '20' ) . " " .
 648+ Xml::closeElement( 'div' );
 649+ $hiddenCategory = json_encode( $hiddenCategory );
485650
486 - $hidden .= Xml::checkLabel( wfMsg( 'smw_qui_shownresults' ), "display_num", '', true );
487 - $hidden .= Xml::closeElement( 'div' );
 651+ $hiddenMainColumn = Html::openElement( 'div', array( 'id' => 'maincol_starter', 'class' => 'smwsort', 'style' => 'display:none' ) ) .
 652+ '<span class="smw-remove"><a><img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '"></a></span>' .
 653+ wfMsg( 'smw_qui_rescol' ) .
 654+ Xml::input( "maincol_label_num", '20' ) . " " .
 655+ Xml::closeElement( 'div' );
 656+ $hiddenMainColumn = json_encode( $hiddenMainColumn );
488657
489 - $hidden = json_encode( $hidden );
 658+ $propertyDialogBox = Xml::openElement( 'div', array( 'id' => 'prop-dialog', 'title' => wfMsg( 'smw_prp_options' ), 'class' => 'smwpropdialog' ) ) .
 659+ Xml::inputLabel( 'Property:', '', 'd-property', 'd-property' ) . '<br/>' . // todo i18n
 660+ Xml::inputLabel( 'Label:', '', 'd-property-label', 'd-property-label' ) . '<br/>' . // todo i18n
 661+ '<label for="format-custom">Format:</label> ' .
 662+ Xml::input( 'format-custom', false, false, array( 'id' => 'd-property-format-custom' ) ) . '<br/>' .
 663+ // Xml::inputLabel( 'Limit:', 'd-property-limit', 'd-property-limit' ) . '<br/>' . // todo i18n
 664+ '<input type="hidden" name="d-property-code" id="d-property-code">' .
 665+ Xml::closeElement( 'div' );
 666+ $categoryDialogBox = Xml::openElement( 'div', array( 'id' => 'cat-dialog', 'title' => 'Category Options', 'class' => 'smwcatdialog' ) ) . // todo i18n
 667+ Xml::inputLabel( 'Label:', '', 'd-category-label', 'd-category-label' ) . '<br/>' . // todo i18n
 668+ Xml::inputLabel( 'Category:', '', 'd-category', 'd-category' ) . '<br/><br/>' . // todo i18n
 669+ Xml::inputLabel( 'Show text when category is present:', '', 'd-category-yes', 'd-category-yes' ) . '<br/><br/>' . // todo i18n
 670+ Xml::inputLabel( 'Show text when category is absent:', '', 'd-category-no', 'd-category-no' ) . '<br/><br/>' . // todo i18n
 671+ '<input type="hidden" name="d-category-code" id="d-category-code">' .
 672+ Xml::closeElement( 'div' );
490673
491674 $result .= '<div id="sorting_main"></div>' . "\n";
492 - $result .= '[<a href="javascript:addPOInstance(\'sorting_starter\', \'sorting_main\')">' . wfMsg( 'smw_qui_addnprop' ) . '</a>]' . "\n";
 675+ $result .= '[<a href="javascript:smw_addPropertyInstance(\'property_starter\', \'sorting_main\')">' . wfMsg( 'smw_qui_addnprop' ) . '</a>]' .
 676+ '[<a href="javascript:smw_addCategoryInstance(\'category_starter\', \'sorting_main\')">' . wfMsg( 'smw_qui_addcategory' ) . '</a>]' .
 677+ '[<a href="javascript:smw_addMainColInstance(\'maincol_starter\', \'sorting_main\')">' . wfMsg( 'smw_qui_addrescol' ) . '</a>]' .
 678+ "\n";
493679
494680 // Javascript code for handling adding and removing the "sort" inputs
495 - $delete_msg = wfMsg( 'smw_qui_delete' );
496 -
497681 if ( $enableAutocomplete == SMWQueryUI::ENABLE_AUTO_SUGGEST ) {
498682 $this->addAutocompletionJavascriptAndCSS();
499683 }
500 - $javascript_text = <<<EOT
 684+ // localisation messages for javascript
 685+ $optionsMsg = wfMsg( 'smw_qui_options' );
 686+ $okMsg = wfMsg( 'smw_qui_ok' );
 687+ $cancelMsg = wfMsg( 'smw_qui_cancel' );
 688+ $javascriptText = <<<EOT
501689 <script type="text/javascript">
502 -// code for handling adding and removing the "sort" inputs
 690+var num_elements = {$numSortValues};
 691+EOT;
 692+// add autocomplete
 693+ if ( $enableAutocomplete == SMWQueryUI::ENABLE_AUTO_SUGGEST ) {
 694+ $javascriptText .= <<<EOT
503695
504 -jQuery(function(){
505 - jQuery('$hidden').appendTo(document.body);
 696+function smw_property_autocomplete(){
 697+ jQuery('[name*="property"]').autocomplete({
 698+ minLength: 2,
 699+ source: function(request, response) {
 700+ url=wgScriptPath+'/api.php?action=opensearch&limit=10&namespace='+wgNamespaceIds['property']+'&format=jsonfm';
 701+
 702+ jQuery.getJSON(url, 'search='+request.term, function(data){
 703+ //remove the namespace prefix 'Property:' from returned data
 704+ for(i=0;i<data[1].length;i++) data[1][i]='?'+data[1][i].substr(data[1][i].indexOf(':')+1);
 705+ response(data[1]);
 706+ });
 707+
 708+ }
506709 });
507 -var num_elements = {$num_sort_values};
 710+}
508711
509 -function addPOInstance(starter_div_id, main_div_id) {
 712+function smw_category_autocomplete(){
 713+ jQuery('[name*="category"]').autocomplete({
 714+ minLength: 2,
 715+ source: function(request, response) {
 716+ url=wgScriptPath+'/api.php?action=opensearch&limit=10&namespace='+wgNamespaceIds['category']+'&format=jsonfm';
 717+
 718+ jQuery.getJSON(url, 'search='+request.term, function(data){
 719+ //remove the namespace prefix 'Property:' from returned data
 720+ for(i=0;i<data[1].length;i++) data[1][i]=data[1][i].substr(data[1][i].indexOf(':')+1);
 721+ response(data[1]);
 722+ });
 723+
 724+ }
 725+ });
 726+}
 727+EOT;
 728+ } else {
 729+ $javascriptText .= <<<EOT
 730+function smw_property_autocomplete(){
 731+}
 732+
 733+function smw_category_autocomplete(){
 734+}
 735+
 736+EOT;
 737+ }
 738+
 739+ $javascriptText .= <<<EOT
 740+function smw_prop_code_update(){
 741+ code = '?'+jQuery('#d-property')[0].value;
 742+ if(code!=''){
 743+ if(jQuery('#d-property-format-custom')[0].value !=''){
 744+ code = code + jQuery('#d-property-format-custom')[0].value;
 745+ }
 746+ if(jQuery('#d-property-label')[0].value !=''){
 747+ code = code + ' = '+ jQuery('#d-property-label')[0].value;
 748+ }
 749+ jQuery('#d-property-code')[0].value= code;
 750+ }
 751+}
 752+
 753+function smw_cat_code_update(){
 754+ cat = code = jQuery('#d-category').attr('value');
 755+ label = jQuery('#d-category-label').attr('value');
 756+ yes = jQuery('#d-category-yes').attr('value');
 757+ no = jQuery('#d-category-no').attr('value');
 758+ if (cat.trim()!='' && yes.trim()!=''){
 759+ code=cat+'#'+yes;
 760+ if(no.trim()!=''){
 761+ code=code+','+no;
 762+ }
 763+ }
 764+ jQuery('#d-category-code').attr('value', code);
 765+
 766+}
 767+
 768+function smw_makeCatDialog(cat_id){
 769+ jQuery('#prop-cat input').attr('value','');
 770+ cat=jQuery('#category'+cat_id)[0].value;
 771+ label=jQuery('#cat_label'+cat_id)[0].value;
 772+ cats=cat.split('#');
 773+ cat= cats[0];
 774+ if(cats[1]){
 775+ yes_no = cats[1].split(',');
 776+ if(yes_no[1]){
 777+ no=yes_no[1];
 778+ } else {
 779+ no = '';
 780+ }
 781+ yes=yes_no[0];
 782+ jQuery('#d-category-yes').attr('value',yes);
 783+ jQuery('#d-category-no').attr('value',no);
 784+ }
 785+ jQuery('#d-category-label').attr('value',label);
 786+ jQuery('#d-category').attr('value',cat);
 787+ jQuery('#cat-dialog').dialog.id=cat_id;
 788+ jQuery('#cat-dialog').dialog('open');
 789+}
 790+
 791+function smw_makePropDialog(prop_id){
 792+ jQuery('#prop-dialog input').attr('value','');
 793+ prop=val=jQuery('#property'+prop_id)[0].value;
 794+ if(val[0]='?') val=prop=prop.substr(1);
 795+ if((i=val.indexOf('='))!=-1) prop=prop.substring(0, i);
 796+ if((i=val.indexOf('#'))!=-1) prop=prop.substring(0, i);
 797+ if(val.split('=')[1]){
 798+ label=val.split('=')[1].trim();
 799+ }else{
 800+ label="";
 801+ }
 802+ format = val.split('=')[0];
 803+ if(format.indexOf('#')!=-1){
 804+ format=format.substr(format.indexOf('#'));
 805+ }else{
 806+ format="";
 807+ }
 808+
 809+ jQuery('#d-property').attr('value', prop.trim());
 810+ jQuery('#d-property-label').attr('value', label);
 811+ jQuery('#d-property-format-custom').attr('value', format.trim());
 812+ jQuery('#prop-dialog').dialog.id=prop_id;
 813+ jQuery('#prop-dialog').dialog('open');
 814+}
 815+// code for handling adding and removing the "sort" inputs
 816+
 817+function smw_addPropertyInstance(starter_div_id, main_div_id) {
510818 var starter_div = document.getElementById(starter_div_id);
511819 var main_div = document.getElementById(main_div_id);
512820
513821 //Create the new instance
514822 var new_div = starter_div.cloneNode(true);
515823 var div_id = 'sort_div_' + num_elements;
516 - new_div.className = 'multipleTemplate';
517824 new_div.id = div_id;
518825 new_div.style.display = 'block';
 826+ jQuery(new_div.getElementsByTagName('label')).attr('for', 'display'+num_elements);
 827+ var children = new_div.getElementsByTagName('*');
 828+ var x;
 829+ for (x = 0; x < children.length; x++) {
 830+ if (children[x].for) children[x].for="display"+num_elements;
 831+ if (children[x].name){
 832+ children[x].id = children[x].name.replace(/_num/, ''+num_elements);
 833+ children[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']');
 834+ }
 835+ }
519836
 837+ //Create 'more' link
 838+ var more_button =document.createElement('span');
 839+ more_button.innerHTML = ' <a class="smwq-more" href="javascript:smw_makePropDialog(\'' + num_elements + '\')">{$optionsMsg}</a> ';
 840+ more_button.id = 'more'+num_elements;
 841+ new_div.appendChild(more_button);
 842+
 843+ //Add the new instance
 844+ main_div.appendChild(new_div);
 845+
 846+ // initialize delete button
 847+ st='sort_div_'+num_elements;
 848+ jQuery('#'+new_div.id).find(".smw-remove a")[0].href="javascript:removePOInstance('"+st+"')";
 849+ num_elements++;
 850+ smw_property_autocomplete();
 851+}
 852+
 853+function smw_addCategoryInstance(starter_div_id, main_div_id) {
 854+ var starter_div = document.getElementById(starter_div_id);
 855+ var main_div = document.getElementById(main_div_id);
 856+
 857+ //Create the new instance
 858+ var new_div = starter_div.cloneNode(true);
 859+ var div_id = 'sort_div_' + num_elements;
 860+ new_div.id = div_id;
 861+ new_div.style.display = 'block';
 862+ jQuery(new_div.getElementsByTagName('label')).attr('for', 'display'+num_elements);
520863 var children = new_div.getElementsByTagName('*');
521864 var x;
522865 for (x = 0; x < children.length; x++) {
523 - if (children[x].name)
 866+ if (children[x].for) children[x].for="display"+num_elements;
 867+ if (children[x].name){
 868+ children[x].id = children[x].name.replace(/_num/, ''+num_elements);
524869 children[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']');
525870 }
 871+ }
526872
527 - //Create 'delete' link
528 - var remove_button = document.createElement('span');
529 - remove_button.innerHTML = '[<a class="smwq-remove" href="javascript:removePOInstance(\'sort_div_' + num_elements + '\')">{$delete_msg}</a>]';
530 - new_div.appendChild(remove_button);
 873+ //Create 'more' link
 874+ var more_button =document.createElement('span');
 875+ more_button.innerHTML = ' <a class="smwq-more" href="javascript:smw_makeCatDialog(\'' + num_elements + '\')">{$optionsMsg}</a> ';
 876+ more_button.id = 'more'+num_elements;
 877+ new_div.appendChild(more_button);
531878
532879 //Add the new instance
533880 main_div.appendChild(new_div);
534 -EOT;
535 - if ( $enableAutocomplete == SMWQueryUI::ENABLE_AUTO_SUGGEST ) {
536 - $javascript_text .= <<<EOT
537 - //add autocomplete
538 - jQuery('[name*="property"]').autocomplete({
539 - minLength: 2,
540 - source: function(request, response) {
541 - url=wgScriptPath+'/api.php?action=opensearch&limit=10&namespace='+wgNamespaceIds['property']+'&format=jsonfm';
542881
543 - jQuery.getJSON(url, 'search='+request.term, function(data){
544 - //remove the namespace prefix 'Property:' from returned data
545 - for(i=0;i<data[1].length;i++) data[1][i]=data[1][i].substr(data[1][i].indexOf(':')+1);
546 - response(data[1]);
547 - });
 882+ // initialize delete button
 883+ st='sort_div_'+num_elements;
 884+ jQuery('#'+new_div.id).find(".smw-remove a")[0].href="javascript:removePOInstance('"+st+"')";
 885+ num_elements++;
 886+ smw_category_autocomplete();
 887+}
 888+
 889+function smw_addMainColInstance(starter_div_id, main_div_id) {
 890+ var starter_div = document.getElementById(starter_div_id);
 891+ var main_div = document.getElementById(main_div_id);
 892+
 893+ //Create the new instance
 894+ var new_div = starter_div.cloneNode(true);
 895+ var div_id = 'sort_div_' + num_elements;
 896+ new_div.id = div_id;
 897+ new_div.style.display = 'block';
 898+ jQuery(new_div.getElementsByTagName('label')).attr('for', 'display'+num_elements);
 899+ var children = new_div.getElementsByTagName('*');
 900+ var x;
 901+ for (x = 0; x < children.length; x++) {
 902+ if (children[x].for) children[x].for="display"+num_elements;
 903+ if (children[x].name){
 904+ children[x].id = children[x].name.replace(/_num/, ''+num_elements);
 905+ children[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']');
548906 }
549 - });
550 -EOT;
551 - }
552 - $javascript_text .= <<<EOT
 907+ }
 908+
 909+ //Add the new instance
 910+ main_div.appendChild(new_div);
 911+
 912+ // initialize delete button
 913+ st='sort_div_'+num_elements;
 914+ jQuery('#'+new_div.id).find(".smw-remove a")[0].href="javascript:removePOInstance('"+st+"')";
553915 num_elements++;
554 -
 916+ smw_category_autocomplete();
555917 }
556918
557919 function removePOInstance(div_id) {
@@ -558,59 +920,65 @@
559921 var parent = olddiv.parentNode;
560922 parent.removeChild(olddiv);
561923 }
562 -</script>
563924
564 -EOT;
565 -
566 - $wgOut->addScript( $javascript_text );
567 - return $result;
568 - }
569 -
570 - /**
571 - * Decodes printouts and sorting - related form options generated by its
572 - * complement, getPoSortFormBox(). UIs may overload both to change form
573 - * parameters.
574 - *
575 - * @global boolean $smwgQSortingSupport
576 - * @param WebRequest $wgRequest
577 - * @return string
578 - */
579 - protected function processPoSortFormBox( WebRequest $wgRequest ) {
580 - global $smwgQSortingSupport;
581 - if ( !$smwgQSortingSupport ) return array();
582 -
583 - $params = array();
584 - $order_values = $wgRequest->getArray( 'order' );
585 - $property_values = $wgRequest->getArray( 'property' );
586 - $po = array();
587 - if ( is_array( $property_values ) ) {
588 - $params['sort'] = '';
589 - $params['order'] = '';
590 - foreach ( $property_values as $key => $property_value ) {
591 - $property_values[$key] = trim( $property_value );
592 - if ( $property_value == '' ) {
593 - unset( $property_values[$key] );
594 - }
595 - if ( is_array( $order_values ) and array_key_exists( $key, $order_values ) and $order_values[$key] != 'NONE' ) {
596 - $params['sort'] .= ( $params['sort'] != '' ? ',':'' ) . $property_values[$key];
597 - $params['order'] .= ( $params['order'] != '' ? ',':'' ) . $order_values[$key];
598 - }
 925+jQuery(function(){
 926+ jQuery('$hiddenProperty').appendTo(document.body);
 927+ jQuery('$hiddenCategory').appendTo(document.body);
 928+ jQuery('$hiddenMainColumn').appendTo(document.body);
 929+ jQuery('$propertyDialogBox').appendTo(document.body);
 930+ jQuery('$categoryDialogBox').appendTo(document.body);
 931+ jQuery('#cat-dialog').dialog({
 932+ autoOpen: false,
 933+ modal: true,
 934+ resizable: true,
 935+ minHeight: 200,
 936+ minWidth: 400,
 937+ buttons: {
 938+ "{$okMsg}": function(){
 939+ smw_cat_code_update();
 940+ label = jQuery('#d-category-label').attr('value');
 941+ code = jQuery('#d-category-code').attr('value');
 942+ jQuery('#category'+jQuery(this).dialog.id).attr('value',code);
 943+ jQuery('#cat_label'+jQuery(this).dialog.id).attr('value',label);
 944+ jQuery(this).dialog("close");
 945+ },
 946+ "{$cancelMsg}": function(){
 947+ jQuery('#cat-dialog input').attr('value','');
 948+ jQuery(this).dialog("close");
599949 }
600 - $display_values = $wgRequest->getArray( 'display' );
601 - if ( is_array( $display_values ) ) {
602 - foreach ( $display_values as $key => $value ) {
603 - if ( $value == '1' and array_key_exists( $key, $property_values ) ) {
604 - $po[] = '?' . trim( $property_values[$key] );
605 - }
 950+ }
 951+ });
606952
607 - }
 953+ jQuery('#prop-dialog').dialog({
 954+ autoOpen: false,
 955+ modal: true,
 956+ resizable: true,
 957+ minHeight: 200,
 958+ minWidth: 400,
 959+ buttons: {
 960+ "{$okMsg}": function(){
 961+ smw_prop_code_update();
 962+ jQuery('#property'+jQuery(this).dialog.id)[0].value=jQuery('#d-property-code')[0].value;
 963+ jQuery(this).dialog("close");
 964+ },
 965+ "{$cancelMsg}": function(){
 966+ jQuery('#prop-dialog input').attr('value','');
 967+ jQuery(this).dialog("close");
608968 }
609969 }
 970+ });
 971+ jQuery('#sort-more').click(function(){jQuery('#prop-dialog').dialog("open");});
610972
611 - $params = array_merge( $params, $po );
 973+});
612974
613 - return $params;
 975+jQuery(document).ready(smw_property_autocomplete);
 976+jQuery(document).ready(smw_category_autocomplete);
 977+</script>
614978
 979+EOT;
 980+
 981+ $wgOut->addScript( $javascriptText );
 982+ return $result;
615983 }
616984
617985 /**
@@ -670,7 +1038,7 @@
6711039 $delete_msg = wfMsg( 'smw_qui_delete' );
6721040
6731041 $this->enableJQuery();
674 - $javascript_text = <<<EOT
 1042+ $javascriptText = <<<EOT
6751043 <script type="text/javascript">
6761044 // code for handling adding and removing the "sort" inputs
6771045 jQuery(document).ready(function(){
@@ -715,7 +1083,7 @@
7161084
7171085 EOT;
7181086
719 - $wgOut->addScript( $javascript_text );
 1087+ $wgOut->addScript( $javascriptText );
7201088 return $result;
7211089 }
7221090
@@ -734,10 +1102,10 @@
7351103 if ( !$smwgQSortingSupport ) return array();
7361104
7371105 $params = array();
738 - $order_values = $wgRequest->getArray( 'order' );
739 - if ( is_array( $order_values ) ) {
 1106+ $orderValues = $wgRequest->getArray( 'order' );
 1107+ if ( is_array( $orderValues ) ) {
7401108 $params['order'] = '';
741 - foreach ( $order_values as $order_value ) {
 1109+ foreach ( $orderValues as $order_value ) {
7421110 if ( $order_value == '' ) {
7431111 $order_value = 'ASC';
7441112 }
@@ -770,7 +1138,7 @@
7711139
7721140 if ( $enableAutocomplete ) {
7731141 $this->addAutocompletionJavascriptAndCSS();
774 - $javascript_autocomplete_text = <<<EOT
 1142+ $javascriptAutocompleteText = <<<EOT
7751143 <script type="text/javascript">
7761144 jQuery(document).ready(function(){
7771145 jQuery("#add_property").autocomplete({
@@ -805,7 +1173,7 @@
8061174 </script>
8071175 EOT;
8081176
809 - $wgOut->addScript( $javascript_autocomplete_text );
 1177+ $wgOut->addScript( $javascriptAutocompleteText );
8101178
8111179 }
8121180
@@ -822,7 +1190,7 @@
8231191 */
8241192 protected function processPOFormBox( WebRequest $wgRequest ) {
8251193 $postring = $wgRequest->getText( 'po' );
826 - $po_array = array();
 1194+ $poArray = array();
8271195
8281196 if ( $postring != '' ) { // parameters from HTML input fields
8291197 $ps = explode( "\n", $postring ); // params separated by newlines here (compatible with text-input for printouts)
@@ -834,11 +1202,11 @@
8351203 $param = '?' . $param;
8361204 }
8371205
838 - $po_array[] = $param;
 1206+ $poArray[] = $param;
8391207 }
8401208 }
8411209
842 - return $po_array;
 1210+ return $poArray;
8431211 }
8441212
8451213 /**
@@ -849,33 +1217,33 @@
8501218 * @return string An url-encoded string.
8511219 */
8521220 protected function getUrlTail() {
853 - $url_tail = '&q=' . urlencode( $this->uiCore->getQuerystring() );
 1221+ $urlTail = '&q=' . urlencode( $this->uiCore->getQuerystring() );
8541222
855 - $tmp_parray = array();
 1223+ $tmpArray = array();
8561224 $params = $this->uiCore->getParameters();
8571225 foreach ( $params as $key => $value ) {
8581226 if ( !in_array( $key, array( 'sort', 'order', 'limit', 'offset', 'title' ) ) ) {
859 - $tmp_parray[$key] = $value;
 1227+ $tmpArray[$key] = $value;
8601228 }
8611229 }
862 - $url_tail .= '&p=' . urlencode( SMWInfolink::encodeParameters( $tmp_parray ) );
 1230+ $urlTail .= '&p=' . urlencode( SMWInfolink::encodeParameters( $tmpArray ) );
8631231
864 - $print_out_string = '';
 1232+ $printOutString = '';
8651233 foreach ( $this->uiCore->getPrintOuts() as $printout ) {
866 - $print_out_string .= $printout->getSerialisation() . "\n";
 1234+ $printOutString .= $printout->getSerialisation() . "\n";
8671235 }
8681236
869 - if ( $print_out_string != '' ) {
870 - $url_tail .= '&po=' . urlencode( $print_out_string );
 1237+ if ( $printOutString != '' ) {
 1238+ $urlTail .= '&po=' . urlencode( $printOutString );
8711239 }
8721240 if ( array_key_exists( 'sort', $params ) ) {
873 - $url_tail .= '&sort=' . $params['sort'];
 1241+ $urlTail .= '&sort=' . $params['sort'];
8741242 }
8751243 if ( array_key_exists( 'order', $params ) ) {
876 - $url_tail .= '&order=' . $params['order'];
 1244+ $urlTail .= '&order=' . $params['order'];
8771245 }
8781246
879 - return $url_tail;
 1247+ return $urlTail;
8801248 }
8811249
8821250 /**
@@ -893,7 +1261,7 @@
8941262
8951263 $params = method_exists( $printer, 'getValidatorParameters' ) ? $printer->getValidatorParameters() : array();
8961264
897 - $options_html = array();
 1265+ $optionsHtml = array();
8981266
8991267 foreach ( $params as $param ) {
9001268 // Ignore the parameters for which we have a special control in the GUI already.
@@ -901,54 +1269,54 @@
9021270 continue;
9031271 }
9041272
905 - $current_value = array_key_exists( $param->getName(), $paramValues ) ? $paramValues[$param->getName()] : false;
 1273+ $currentValue = array_key_exists( $param->getName(), $paramValues ) ? $paramValues[$param->getName()] : false;
9061274
907 - $options_html[] =
 1275+ $optionsHtml[] =
9081276 Html::rawElement(
9091277 'div',
9101278 array(
9111279 'style' => 'width: 30%; padding: 5px; float: left;'
9121280 ),
9131281 '<label for="p[' . htmlspecialchars( $param->getName() ) . ']">' . htmlspecialchars( $param->getName() ) . ': </label>' .
914 - $this->showFormatOption( $param, $current_value ) .
 1282+ $this->showFormatOption( $param, $currentValue ) .
9151283 '<br />' .
9161284 Html::element( 'em', array(), $param->getDescription() )
9171285 );
9181286 }
9191287
920 - for ( $i = 0, $n = count( $options_html ); $i < $n; $i++ ) {
 1288+ for ( $i = 0, $n = count( $optionsHtml ); $i < $n; $i++ ) {
9211289 if ( $i % 3 == 2 || $i == $n - 1 ) {
922 - $options_html[$i] .= "<div style=\"clear: both\";></div>\n";
 1290+ $optionsHtml[$i] .= "<div style=\"clear: both\";></div>\n";
9231291 }
9241292 }
9251293
9261294 $i = 0;
927 - $row_html = '';
928 - $result_html = '';
929 - $flip_style = true;
930 - $flip_count = 0;
931 - while ( $option = array_shift( $options_html ) ) {
932 - $row_html .= $option;
 1295+ $rowHtml = '';
 1296+ $resultHtml = '';
 1297+ $flipStyle = true;
 1298+ $flipCount = 0;
 1299+ while ( $option = array_shift( $optionsHtml ) ) {
 1300+ $rowHtml .= $option;
9331301 $i++;
9341302
935 - $result_html .= Html::rawElement(
 1303+ $resultHtml .= Html::rawElement(
9361304 'div',
9371305 array(
938 - 'style' => 'background: ' . ( $flip_style ? 'white' : '#dddddd' ) . ';'
 1306+ 'style' => 'background: ' . ( $flipStyle ? 'white' : '#dddddd' ) . ';'
9391307 ),
940 - $row_html
 1308+ $rowHtml
9411309 );
9421310
943 - $row_html = '';
944 - $flip_count++;
945 - if ( $flip_count == 3 ) {
946 - $flip_style = !$flip_style;
947 - $flip_count = 0;
 1311+ $rowHtml = '';
 1312+ $flipCount++;
 1313+ if ( $flipCount == 3 ) {
 1314+ $flipStyle = !$flipStyle;
 1315+ $flipCount = 0;
9481316 }
9491317
9501318 }
9511319
952 - return $result_html;
 1320+ return $resultHtml;
9531321 }
9541322
9551323
@@ -982,21 +1350,21 @@
9831351 * UI's may overload these methods to change behaviour or form
9841352 * parameters.
9851353 *
986 - * @param string $defaultformat The default format which remains selected in the form
 1354+ * @param string $defaultFormat The default format which remains selected in the form
9871355 * @return array The first element contains the format selector, while the second contains the Format options
9881356 */
989 - protected function getFormatSelectBoxSep( $defaultformat = 'broadtable' ) {
 1357+ protected function getFormatSelectBoxSep( $defaultFormat = 'broadtable' ) {
9901358 global $smwgResultFormats, $wgOut;
9911359
9921360 $this->enableJQuery();
9931361
9941362 // checking argument
995 - $default_format = 'broadtable';
996 - if ( array_key_exists( $defaultformat, $smwgResultFormats ) ) {
997 - $default_format = $defaultformat;
 1363+ $defFormat = 'broadtable';
 1364+ if ( array_key_exists( $defaultFormat, $smwgResultFormats ) ) {
 1365+ $defFormat = $defaultFormat;
9981366 }
9991367
1000 - $printer = SMWQueryProcessor::getResultPrinter( $default_format, SMWQueryProcessor::SPECIAL_PAGE );
 1368+ $printer = SMWQueryProcessor::getResultPrinter( $defFormat, SMWQueryProcessor::SPECIAL_PAGE );
10011369 $url = $this->getTitle()->getLocalURL( "showformatoptions=' + this.value + '" );
10021370
10031371 foreach ( $this->uiCore->getParameters() as $param => $value ) {
@@ -1006,13 +1374,13 @@
10071375 }
10081376
10091377 $result[0] = "\n" . '<select id="formatSelector" name="p[format]" onChange="JavaScript:updateOtherOptions(\'' . $url . '\')">' . "\n" .
1010 - '<option value="' . $default_format . '">' . $printer->getName() .
 1378+ '<option value="' . $defFormat . '">' . $printer->getName() .
10111379 ' (' . wfMsg( 'smw_ask_defaultformat' ) . ')</option>' . "\n";
10121380
10131381 $formats = array();
10141382 foreach ( array_keys( $smwgResultFormats ) as $format ) {
10151383 // Special formats "count" and "debug" currently not supported.
1016 - if ( $format != $default_format && $format != 'count' && $format != 'debug' ) {
 1384+ if ( $format != $defFormat && $format != 'count' && $format != 'debug' ) {
10171385 $printer = SMWQueryProcessor::getResultPrinter( $format, SMWQueryProcessor::SPECIAL_PAGE );
10181386 $formats[$format] = $printer->getName();
10191387 }
@@ -1056,21 +1424,21 @@
10571425 * @return array
10581426 */
10591427 protected function processFormatSelectBox( WebRequest $wgRequest ) {
1060 - $query_val = $wgRequest->getVal( 'p' );
 1428+ $queryVal = $wgRequest->getVal( 'p' );
10611429
1062 - if ( !empty( $query_val ) ) {
1063 - $params = SMWInfolink::decodeParameters( $query_val, false );
 1430+ if ( !empty( $queryVal ) ) {
 1431+ $params = SMWInfolink::decodeParameters( $queryVal, false );
10641432 } else {
1065 - $query_values = $wgRequest->getArray( 'p' );
 1433+ $queryValues = $wgRequest->getArray( 'p' );
10661434
1067 - if ( is_array( $query_values ) ) {
1068 - foreach ( $query_values as $key => $val ) {
1069 - if ( empty( $val ) ) unset( $query_values[$key] );
 1435+ if ( is_array( $queryValues ) ) {
 1436+ foreach ( $queryValues as $key => $val ) {
 1437+ if ( empty( $val ) ) unset( $queryValues[$key] );
10701438 }
10711439 }
10721440
10731441 // p is used for any additional parameters in certain links.
1074 - $params = SMWInfolink::decodeParameters( $query_values, false );
 1442+ $params = SMWInfolink::decodeParameters( $queryValues, false );
10751443 }
10761444
10771445 return $params;
@@ -1109,9 +1477,9 @@
11101478 */
11111479 public function getPOStrings() {
11121480 $string = '';
1113 - $print_outs = $this->uiCore->getPrintOuts();
1114 - if ( !empty( $print_outs ) ) {
1115 - foreach ( $print_outs as $value ) {
 1481+ $printOuts = $this->uiCore->getPrintOuts();
 1482+ if ( !empty( $printOuts ) ) {
 1483+ foreach ( $printOuts as $value ) {
11161484 $string .= $value->getSerialisation() . "\n";
11171485 }
11181486 }
@@ -1285,7 +1653,6 @@
12861654 * Returns a handle to the underlying Result object.
12871655 *
12881656 * @return SMWQueryResult
1289 - * @todo Check if this method can be removed.
12901657 */
12911658 public function getResultObject() {
12921659 return $this->queryResult;
@@ -1361,24 +1728,24 @@
13621729 * Each string in printouts should be of the form "?property" or
13631730 * "property".
13641731 *
1365 - * When validation is enabled, the values in $print_outs are checked
 1732+ * When validation is enabled, the values in $printOuts are checked
13661733 * against properties which exist in the wiki, and a warning string (for
13671734 * each property) is returned. Returns an empty array otherwise.
13681735 *
1369 - * @param array $print_outs Array of strings
 1736+ * @param array $printOuts Array of strings
13701737 * @param boolean $enableValidation
13711738 * @return array Array of errors messages (strings), if any.
13721739 */
1373 - public function setPrintOuts( array $print_outs = array(), $enableValidation = false ) {
 1740+ public function setPrintOuts( array $printOuts = array(), $enableValidation = false ) {
13741741 /*
13751742 * Note: property validation is not very clearly defined yet, so validation is disabled by default
13761743 */
13771744
13781745 $errors = array();
13791746 if ( $enableValidation ) {
1380 - foreach ( $print_outs as $key => $prop ) {
 1747+ foreach ( $printOuts as $key => $prop ) {
13811748 if ( $prop[0] != '?' ) {
1382 - $print_outs[$key] = "?" . $print_outs[$key];
 1749+ $printOuts[$key] = "?" . $printOuts[$key];
13831750 }
13841751 if ( !$this->validateProperty( $prop ) ) {
13851752 $errors[] = wfMsg( 'smw_qui_invalidprop', $prop );
@@ -1386,7 +1753,7 @@
13871754 }
13881755 }
13891756 }
1390 - $this -> printOutStrings = $print_outs;
 1757+ $this -> printOutStrings = $printOuts;
13911758 $this->errors = array_merge( $errors, $this->errors );
13921759 return $errors;
13931760 }
@@ -1413,7 +1780,7 @@
14141781 $errors = array();
14151782
14161783 // checking for missing parameters and adding them
1417 - if ( !array_key_exists( 'format', $params ) or ! array_key_exists ( $params['format'], $smwgResultFormats ) ) {
 1784+ if ( !array_key_exists( 'format', $params ) || ! array_key_exists ( $params['format'], $smwgResultFormats ) ) {
14181785 $params[ 'format' ] = $this->defaultResultPrinter;
14191786 }
14201787 if ( !array_key_exists( 'limit', $params ) ) {
@@ -1458,15 +1825,15 @@
14591826 public function extractParameters( $p ) {
14601827 if ( $this->context == self::SPECIAL_PAGE ) {
14611828 // assume setParams(), setPintouts and setQueryString have been called
1462 - $raw_params = array_merge( $this->parameters, array( $this->queryString ), $this->printOutStrings );
 1829+ $rawParams = array_merge( $this->parameters, array( $this->queryString ), $this->printOutStrings );
14631830 } else {// context is WIKI_LINK
1464 - $raw_params = SMWInfolink::decodeParameters( $p, true );
 1831+ $rawParams = SMWInfolink::decodeParameters( $p, true );
14651832 // calling setParams to fill in missing parameters
1466 - $this->setParams( $raw_params );
1467 - $raw_params = $this->parameters;
 1833+ $this->setParams( $rawParams );
 1834+ $rawParams = $this->parameters;
14681835 }
14691836
1470 - SMWQueryProcessor::processFunctionParams( $raw_params, $this->queryString, $this->parameters, $this->printOuts );
 1837+ SMWQueryProcessor::processFunctionParams( $rawParams, $this->queryString, $this->parameters, $this->printOuts );
14711838 }
14721839
14731840 /**
@@ -1494,28 +1861,28 @@
14951862
14961863 // BEGIN: Try to be smart for rss/ical if no description/title is given and we have a concept query
14971864 if ( $this->parameters['format'] == 'rss' ) {
1498 - $desc_key = 'rssdescription';
1499 - $titlekey = 'rsstitle';
 1865+ $descKey = 'rssdescription';
 1866+ $titleKey = 'rsstitle';
15001867 } elseif ( $this->parameters['format'] == 'icalendar' ) {
1501 - $desc_key = 'icalendardescription';
1502 - $titlekey = 'icalendartitle';
 1868+ $descKey = 'icalendardescription';
 1869+ $titleKey = 'icalendartitle';
15031870 } else {
1504 - $desc_key = false;
 1871+ $descKey = false;
15051872 }
15061873
1507 - if ( $desc_key && ( $query->getDescription() instanceof SMWConceptDescription ) &&
1508 - ( !isset( $this->parameters[$desc_key] ) || !isset( $this->parameters[$titlekey] ) ) ) {
 1874+ if ( $descKey && ( $query->getDescription() instanceof SMWConceptDescription ) &&
 1875+ ( !isset( $this->parameters[$descKey] ) || !isset( $this->parameters[$titleKey] ) ) ) {
15091876 $concept = $query->getDescription()->getConcept();
15101877
1511 - if ( !isset( $this->parameters[$titlekey] ) ) {
1512 - $this->parameters[$titlekey] = $concept->getText();
 1878+ if ( !isset( $this->parameters[$titleKey] ) ) {
 1879+ $this->parameters[$titleKey] = $concept->getText();
15131880 }
15141881
1515 - if ( !isset( $this->parameters[$desc_key] ) ) {
 1882+ if ( !isset( $this->parameters[$descKey] ) ) {
15161883 // / @bug The current SMWStore will never return SMWConceptValue (an SMWDataValue) here; it might return SMWDIConcept (an SMWDataItem)
15171884 $dv = end( smwfGetStore()->getPropertyValues( SMWWikiPageValue::makePageFromTitle( $concept ), new SMWDIProperty( '_CONC' ) ) );
15181885 if ( $dv instanceof SMWConceptValue ) {
1519 - $this->parameters[$desc_key] = $dv->getDocu();
 1886+ $this->parameters[$descKey] = $dv->getDocu();
15201887 }
15211888 }
15221889 }
@@ -1536,15 +1903,15 @@
15371904 $res = $this->queryResult;
15381905 $printer = SMWQueryProcessor::getResultPrinter( $this->parameters['format'],
15391906 SMWQueryProcessor::SPECIAL_PAGE );
1540 - $result_mime = $printer->getMimeType( $res );
 1907+ $resultMime = $printer->getMimeType( $res );
15411908
15421909 if ( $res->getCount() > 0 ) {
1543 - $query_result = $printer->getResult( $res, $this->parameters, SMW_OUTPUT_HTML );
 1910+ $queryResult = $printer->getResult( $res, $this->parameters, SMW_OUTPUT_HTML );
15441911
1545 - if ( is_array( $query_result ) ) {
1546 - $result .= $query_result[0];
 1912+ if ( is_array( $queryResult ) ) {
 1913+ $result .= $queryResult[0];
15471914 } else {
1548 - $result .= $query_result;
 1915+ $result .= $queryResult;
15491916 }
15501917 } else {
15511918 $result = wfMsg( 'smw_result_noresults' );
Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php
@@ -15,7 +15,6 @@
1616 */
1717 class SMWQueryCreatorPage extends SMWQueryUI {
1818
19 - protected $m_params = array();
2019
2120 /**
2221 * Constructor.
@@ -34,23 +33,23 @@
3534 */
3635 protected function makePage( $p ) {
3736 global $wgOut;
38 - $html_output = $this->makeResults( $p );
 37+ $htmlOutput = $this->makeResults( $p );
3938 if ( $this->uiCore->getQueryString() != "" ) {
4039 if ( $this->usesNavigationBar() ) {
41 - $html_output .= Html::rawElement( 'div', array( 'class' => 'smwqcnavbar' ),
 40+ $htmlOutput .= Html::rawElement( 'div', array( 'class' => 'smwqcnavbar' ),
4241 $this->getNavigationBar ( $this->uiCore->getLimit(), $this->uiCore->getOffset(), $this->uiCore->hasFurtherResults() )
43 - ); // ? can we preload offset and limit?
 42+ );
4443 }
4544
46 - $html_output .= Html::rawElement( 'div', array( 'class' => 'smw-qc-result' ), $this->uiCore->getHTMLResult() );
 45+ $htmlOutput .= Html::rawElement( 'div', array( 'class' => 'smw-qc-result' ), $this->uiCore->getHTMLResult() );
4746
4847 if ( $this->usesNavigationBar() ) {
49 - $html_output .= Html::rawElement( 'div', array( 'class' => 'smwqcnavbar' ),
 48+ $htmlOutput .= Html::rawElement( 'div', array( 'class' => 'smwqcnavbar' ),
5049 $this->getNavigationBar ( $this->uiCore->getLimit(), $this->uiCore->getOffset(), $this->uiCore->hasFurtherResults() )
51 - ); // ? can we preload offset and limit?
 50+ );
5251 }
5352 }
54 - $wgOut->addHTML( $html_output );
 53+ $wgOut->addHTML( $htmlOutput );
5554 }
5655
5756 /**
@@ -79,10 +78,10 @@
8079 global $wgOut, $smwgScriptPath;
8180 $this->enableJQuery();
8281 $result = "";
83 - $spec_title = $this->getTitle();
84 - $format_box = $this->getFormatSelectBoxSep( 'broadtable' );
85 - $result .= '<form name="ask" action="' . $spec_title->escapeLocalURL() . '" method="get">' . "\n" .
86 - '<input type="hidden" name="title" value="' . $spec_title->getPrefixedText() . '"/>';
 82+ $specTitle = $this->getTitle();
 83+ $formatBox = $this->getFormatSelectBoxSep( 'broadtable' );
 84+ $result .= '<form name="ask" action="' . $specTitle->escapeLocalURL() . '" method="get">' . "\n" .
 85+ '<input type="hidden" name="title" value="' . $specTitle->getPrefixedText() . '"/>';
8786 $result .= '<br>';
8887 $result .= wfMsg( 'smw_qc_query_help' );
8988 // Main query and format options
@@ -90,7 +89,7 @@
9190 '<tr><th>' . wfMsg( 'smw_ask_queryhead' ) . "</th>\n<th>" . wfMsg( 'smw_ask_format_as' ) . "</th></tr>" .
9291 '<tr>' .
9392 '<td style="width: 70%; padding-right: 7px;">' . $this->getQueryFormBox() . "</td>\n" .
94 - '<td style="padding-right: 7px; text-align:center;">' . $format_box[0];
 93+ '<td style="padding-right: 7px; text-align:center;">' . $formatBox[0];
9594
9695 //START: show|hide additional options
9796 $result .= '<span id="show_additional_options" style="display:inline;"><a href="#addtional" rel="nofollow" onclick="' .
@@ -113,7 +112,7 @@
114113 // additional options
115114 $result .= '<div id="additional_options" style="display:none">';
116115
117 - $result .= $format_box[1]; // display the format options
 116+ $result .= $formatBox[1]; // display the format options
118117
119118 $result .= '</div>'; // end of hidden additional options
120119 $result .= '<br /><input type="submit" value="' . wfMsg( 'smw_ask_submit' ) . '"/><br/>';
@@ -127,7 +126,7 @@
128127 $this->enableJQueryUI();
129128 $wgOut->addScriptFile( "$smwgScriptPath/libs/jquery-ui/jquery-ui.dialog.min.js" );
130129 $wgOut->addStyle( "$smwgScriptPath/skins/SMW_custom.css" );
131 - $javascript_text = <<<EOT
 130+ $javascriptText = <<<EOT
132131 <script type="text/javascript">
133132 jQuery(document).ready(function(){
134133 jQuery('#embed-code-dialog').dialog({
@@ -144,7 +143,7 @@
145144 });
146145 </script>
147146 EOT;
148 - $wgOut->addScript( $javascript_text );
 147+ $wgOut->addScript( $javascriptText );
149148 }
150149 $result .= '<input type="hidden" name="eq" value="no"/>' .
151150 "\n</form><br/>";
@@ -152,620 +151,5 @@
153152 return $result;
154153
155154 }
156 -
157 - /**
158 - * Decodes printouts and sorting - related form options generated by its
159 - * complement, getPoSortFormBox(). UIs may overload both to change form
160 - * parameters.
161 - *
162 - * Overrides method from SMWQueryUI (modal window added)
163 - *
164 - * @global boolean $smwgQSortingSupport
165 - * @global Language $wgContLang
166 - * @param WebRequest $wgRequest
167 - * @return string
168 - */
169 - protected function processPoSortFormBox( WebRequest $wgRequest ) {
170 - global $smwgQSortingSupport, $wgContLang;
171 - if ( !$smwgQSortingSupport ) return array();
172 -
173 - $params = array();
174 - $order_values = $wgRequest->getArray( 'order' );
175 - $property_values = $wgRequest->getArray( 'property' );
176 - $category_values = $wgRequest->getArray( 'category' );
177 - $category_label_values = $wgRequest->getArray( 'cat_label' );
178 - $main_column_labels = $wgRequest->getArray( 'maincol_label' );
179 - $po = array();
180 - $category_namespace = $wgContLang->getNsText( NS_CATEGORY );
181 - if ( is_array( $main_column_labels ) ) {
182 - foreach ( $main_column_labels as $key => $label ) {
183 - if ( $label == '' ) {
184 - $po[$key] = "?";
185 - } else {
186 - $po[$key] = "? = $label";
187 - }
188 -
189 - }
190 - }
191 - if ( is_array( $category_values ) ) {
192 - foreach ( $category_values as $key => $value ) {
193 - if ( trim( $value ) == '' ) {
194 - $po[$key] = "?$category_namespace" ;
195 - } else {
196 - $po[$key] = "?$category_namespace:$value";
197 - }
198 - }
199 - }
200 - if ( is_array( $category_label_values ) ) {
201 - foreach ( $category_label_values as $key => $value ) {
202 - if ( trim( $value ) != '' ) {
203 - $po[$key] .= ' = ' . $value;
204 - }
205 - }
206 - }
207 - if ( is_array( $property_values ) ) {
208 - $params['sort'] = '';
209 - $params['order'] = '';
210 - foreach ( $property_values as $key => $property_value ) {
211 - $property_values[$key] = trim( $property_value );
212 - if ( $property_value == '' ) {
213 - unset( $property_values[$key] );
214 - }
215 - if ( is_array( $order_values ) and array_key_exists( $key, $order_values ) and $order_values[$key] != 'NONE' ) {
216 - $prop = substr( $property_values[$key], 1 ); // removing the leading '?'
217 - if ( !strpos( $prop, '#' ) === false ) $prop = strstr( $prop, '#', true ); // removing format options
218 - if ( !strpos( $prop, '=' ) === false ) $prop = strstr( $prop, '=', true ); // removing format options
219 -
220 - $params['sort'] .= ( $params['sort'] != '' ? ',':'' ) . $prop;
221 - $params['order'] .= ( $params['order'] != '' ? ',':'' ) . $order_values[$key];
222 - }
223 - }
224 - if ( $params['sort'] == '' ) {
225 - unset ( $params['sort'] );
226 - }
227 - if ( $params['order'] == '' ) {
228 - unset ( $params['order'] );
229 - }
230 - $display_values = $wgRequest->getArray( 'display' );
231 - if ( is_array( $display_values ) ) {
232 - foreach ( $display_values as $key => $value ) {
233 - if ( $value == '1' and array_key_exists( $key, $property_values ) ) {
234 - $property_values[$key] = trim( $property_values[$key] );
235 - $property_values[$key] = ( $property_values[$key][0] == '?' ) ? $property_values[$key]:'?' . $property_values[$key];
236 - $po[$key] = $property_values[$key];
237 - }
238 - }
239 - }
240 - }
241 - ksort( $po );
242 - $params = array_merge( $params, $po );
243 - return $params;
244 -
245 - }
246 -
247 - /**
248 - * Generates the forms elements(s) for choosing printouts and sorting
249 - * options. Use its complement processPoSortFormBox() to decode data
250 - * sent by these elements.
251 - *
252 - * Overrides method from SMWQueryUI (modal window added)
253 - *
254 - * @return string
255 - */
256 - protected function getPoSortFormBox( $enableAutocomplete = SMWQueryUI::ENABLE_AUTO_SUGGEST ) {
257 - global $smwgQSortingSupport, $wgRequest, $wgOut, $smwgScriptPath;
258 -
259 - if ( !$smwgQSortingSupport ) return '';
260 - $this->enableJQueryUI();
261 - $wgOut->addScriptFile( "$smwgScriptPath/libs/jquery-ui/jquery-ui.dialog.min.js" );
262 - $wgOut->addStyle( "$smwgScriptPath/skins/SMW_custom.css" );
263 -
264 - $result = '';
265 - $num_sort_values = 0;
266 - // START: create form elements already submitted earlier via form
267 - // attempting to load parameters from $wgRequest
268 - $property_values = $wgRequest->getArray( 'property' );
269 - $order_values = $wgRequest->getArray( 'order' );
270 - $display_values = $wgRequest->getArray( 'display' );
271 - $category_values = $wgRequest->getArray( 'category' );
272 - $category_label_values = $wgRequest->getArray( 'cat_label' );
273 - $main_column_labels = $wgRequest->getArray( 'maincol_label' );
274 -
275 - if ( is_array( $property_values ) or is_array( $category_values ) or is_array( $main_column_labels ) ) {
276 - /*
277 - * Printouts were set via this Ui
278 - */
279 - if ( is_array( $property_values ) ) {
280 - // remove empty property values
281 - foreach ( $property_values as $key => $property_value ) {
282 - $property_values[$key] = trim( $property_value );
283 - if ( $property_value == '' ) {
284 - unset( $property_values[$key] );
285 - }
286 - }
287 - }
288 - } else {
289 - /*
290 - * Printouts and sorting were set via another widget/form/source, so
291 - * create elements by fetching data from $uiCore. The exact ordering
292 - * of Ui elements might not be preserved, if the above block were to
293 - * be removed. This is a bit of a hack, converting all strings to
294 - * lowercase to simplify searching procedure and using in_array.
295 - */
296 -
297 - $po = explode( '?', $this->getPOStrings() );
298 - reset( $po );
299 - foreach ( $po as $key => $value ) {
300 - $po[$key] = strtolower( trim( $value ) );
301 - if ( $po[$key] == '' ) {
302 - unset ( $po[$key] );
303 - }
304 - }
305 -
306 - $params = $this->uiCore->getParameters();
307 - if ( array_key_exists( 'sort', $params ) && array_key_exists( 'order', $params ) ) {
308 - $property_values = explode( ',', strtolower( $params['sort'] ) );
309 - $order_values = explode( ',', $params['order'] );
310 - reset( $property_values );
311 - reset( $order_values );
312 - } else {
313 - $order_values = array(); // do not even show one sort input here
314 - $property_values = array();
315 - }
316 - foreach ( $po as $po_value ) {
317 - if ( !in_array( $po_value, $property_values ) ) {
318 - $property_values[] = $po_value;
319 - }
320 - }
321 - $display_values = array();
322 - reset( $property_values );
323 - foreach ( $property_values as $property_key => $property_value ) {
324 - if ( in_array( $property_value, $po ) ) {
325 - $display_values[$property_key] = "yes";
326 - }
327 - }
328 - }
329 - $i = 0;
330 - $additional_POs = array();
331 - if ( is_array( $property_values ) ) {
332 - $keys = array_keys( $property_values );
333 - foreach ( $keys as $value ) {
334 - $additional_POs[$value] = $property_values[$value]; // array_merge won't work because numeric keys need to be preserved
335 - }
336 - }
337 - if ( is_array( $category_values ) ) {// same as testing $category_label_values
338 - $keys = array_keys( $category_values );
339 - foreach ( $keys as $value ) {
340 - $additional_POs[$value] = $category_values[$value]; // array_merge won't work because numeric keys need to be preserved
341 - }
342 - }
343 - if ( is_array( $main_column_labels ) ) {
344 - $keys = array_keys( $main_column_labels );
345 - foreach ( $keys as $value ) {
346 - $additional_POs[$value] = $main_column_labels[$value]; // array_merge won't work because numeric keys need to be preserved
347 - }
348 - }
349 - ksort( $additional_POs );
350 - foreach ( $additional_POs as $key => $value ) {
351 - if ( is_array( $property_values ) and array_key_exists( $key, $property_values ) ) {
352 - /*
353 - * Make an element for additional properties
354 - */
355 - $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i", 'class' => 'smwsort' ) );
356 - $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>';
357 - $result .= wfMsg( 'smw_qui_property' );
358 - $result .= Html::input( 'property[' . $i . ']', $property_values[$key], 'text', array( 'size' => '35', 'id' => "property$i" ) ) . "\n";
359 - $result .= Html::openElement( 'select', array( 'name' => "order[$i]" ) );
360 -
361 - $if1 = ( !is_array( $order_values ) or !array_key_exists( $key, $order_values ) or $order_values[$key] == 'NONE' );
362 - $result .= Xml::option( wfMsg( 'smw_qui_nosort' ), "NONE", $if1 );
363 -
364 - $if2 = ( is_array( $order_values ) and array_key_exists( $key, $order_values ) and $order_values[$key] == 'ASC' );
365 - $result .= Xml::option( wfMsg( 'smw_qui_ascorder' ), "ASC", $if2 );
366 -
367 - $if3 = ( is_array( $order_values ) and array_key_exists( $key, $order_values ) and $order_values[$key] == 'DESC' );
368 - $result .= Xml::option( wfMsg( 'smw_qui_descorder' ), "DESC", $if3 );
369 -
370 - $result .= Xml::closeElement( 'select' );
371 -
372 - $if4 = ( is_array( $display_values ) and array_key_exists( $key, $display_values ) );
373 - $result .= Xml::checkLabel( wfMsg( 'smw_qui_shownresults' ), "display[$i]", "display$i", $if4 );
374 - $result .= ' <a id="more' . $i . '" "class="smwq-more" href="javascript:smw_makePropDialog(\'' . $i . '\')"> ' . WfMsg( 'smw_qui_options' ) . ' </a> ';
375 -
376 - $result .= Xml::closeElement( 'div' );
377 - $i++;
378 - }
379 - if ( is_array( $category_values ) and array_key_exists( $key, $category_values ) ) {
380 - /*
381 - * Make an element for additional categories
382 - */
383 - $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i", 'class' => 'smwsort' ) );
384 - $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>' .
385 - wfMsg( 'smw_qui_category' ) .
386 - Xml::input( "category[$i]", '25', $category_values[$key], array( 'id' => "category$i" ) ) . " " .
387 - wfMsg( 'smw_qui_label' ) .
388 - Xml::input( "cat_label[$i]", '20', array_key_exists( $key, $category_label_values ) ? $category_label_values[$key]:false, array( 'id' => "cat_label$i" ) ) . " " .
389 - ' <a id="more' . $i . '" "class="smwq-more" href="javascript:smw_makeCatDialog(\'' . $i . '\')"> ' . WfMsg( 'smw_qui_options' ) . ' </a> ' .
390 - Xml::closeElement( 'div' );
391 - $i++;
392 - }
393 - if ( is_array( $main_column_labels ) and array_key_exists( $key, $main_column_labels ) ) {
394 - /*
395 - * Make an element for main column
396 - */
397 - $result .= Html::openElement( 'div', array( 'id' => "sort_div_$i", 'class' => 'smwsort' ) ) .
398 - '<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>' .
399 - wfMsg( 'smw_qui_rescol' ) .
400 - Xml::input( "maincol_label[$i]", '20', $main_column_labels[$key], array ( 'id' => "maincol_label$i" ) ) . " " .
401 - Xml::closeElement( 'div' );
402 - $i++;
403 - }
404 - }
405 - $num_sort_values = $i;
406 - // END: create form elements already submitted earlier via form
407 -
408 - // create hidden form elements to be cloned later
409 - $hidden_property = Html::openElement( 'div', array( 'id' => 'property_starter', 'class' => 'smwsort', 'style' => 'display:none' ) ) .
410 - '<span class="smw-remove"><a><img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '"></a></span>' .
411 - wfMsg( 'smw_qui_property' ) .
412 - Xml::input( "property_num", '35' ) . " " .
413 - Html::openElement( 'select', array( 'name' => 'order_num' ) ) .
414 - Xml::option( wfMsg( 'smw_qui_nosort' ), 'NONE' ) .
415 - Xml::option( wfMsg( 'smw_qui_ascorder' ), 'ASC' ) .
416 - Xml::option( wfMsg( 'smw_qui_descorder' ), 'DESC' ) .
417 - Xml::closeElement( 'select' ) .
418 - Xml::checkLabel( wfMsg( 'smw_qui_shownresults' ), "display_num", '', true ) .
419 - Xml::closeElement( 'div' );
420 - $hidden_property = json_encode( $hidden_property );
421 -
422 - $hidden_category = Html::openElement( 'div', array( 'id' => 'category_starter', 'class' => 'smwsort', 'style' => 'display:none' ) ) .
423 - '<span class="smw-remove"><a><img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '"></a></span>' .
424 - wfMsg( 'smw_qui_category' ) .
425 - Xml::input( "category_num", '25' ) . " " .
426 - wfMsg( 'smw_qui_label' ) .
427 - Xml::input( "cat_label_num", '20' ) . " " .
428 - Xml::closeElement( 'div' );
429 - $hidden_category = json_encode( $hidden_category );
430 -
431 - $hidden_main_column = Html::openElement( 'div', array( 'id' => 'maincol_starter', 'class' => 'smwsort', 'style' => 'display:none' ) ) .
432 - '<span class="smw-remove"><a><img src="' . $smwgScriptPath . '/skins/images/close-button.png" alt="' . wfMsg( 'smw_qui_delete' ) . '"></a></span>' .
433 - wfMsg( 'smw_qui_rescol' ) .
434 - Xml::input( "maincol_label_num", '20' ) . " " .
435 - Xml::closeElement( 'div' );
436 - $hidden_main_column = json_encode( $hidden_main_column );
437 -
438 - $property_dialog_box = Xml::openElement( 'div', array( 'id' => 'prop-dialog', 'title' => wfMsg( 'smw_prp_options' ), 'class' => 'smwpropdialog' ) ) .
439 - Xml::inputLabel( 'Property:', '', 'd-property', 'd-property' ) . '<br/>' . // todo i18n
440 - Xml::inputLabel( 'Label:', '', 'd-property-label', 'd-property-label' ) . '<br/>' . // todo i18n
441 - '<label for="d-format">Format:</label> ' . Html::openElement( 'select', array( 'name' => 'd-format', 'id' => 'd-format' ) ) . // todo i18n
442 - Xml::option( 'None (default)', ' ' ) . // todo i18n
443 - Xml::option( 'Simple', '#-' ) . // todo i18n
444 - Xml::closeElement( 'select' ) .
445 - Xml::input( 'format-custom', false, false, array( 'id' => 'd-property-format-custom' ) ) . '<br/>' .
446 - // Xml::inputLabel( 'Limit:', 'd-property-limit', 'd-property-limit' ) . '<br/>' . // todo i18n
447 - '<input type="hidden" name="d-property-code" id="d-property-code">' .
448 - Xml::closeElement( 'div' );
449 - $category_dialog_box = Xml::openElement( 'div', array( 'id' => 'cat-dialog', 'title' => 'Category Options', 'class' => 'smwcatdialog' ) ) . // todo i18n
450 - Xml::inputLabel( 'Label:', '', 'd-category-label', 'd-category-label' ) . '<br/>' . // todo i18n
451 - Xml::inputLabel( 'Category:', '', 'd-category', 'd-category' ) . '<br/><br/>' . // todo i18n
452 - Xml::inputLabel( 'Show text when category is present:', '', 'd-category-yes', 'd-category-yes' ) . '<br/><br/>' . // todo i18n
453 - Xml::inputLabel( 'Show text when category is absent:', '', 'd-category-no', 'd-category-no' ) . '<br/><br/>' . // todo i18n
454 - '<input type="hidden" name="d-category-code" id="d-category-code">' .
455 - Xml::closeElement( 'div' );
456 -
457 - $result .= '<div id="sorting_main"></div>' . "\n";
458 - $result .= '[<a href="javascript:smw_addPropertyInstance(\'property_starter\', \'sorting_main\')">' . wfMsg( 'smw_qui_addnprop' ) . '</a>]' .
459 - '[<a href="javascript:smw_addCategoryInstance(\'category_starter\', \'sorting_main\')">' . wfMsg( 'smw_qui_addcategory' ) . '</a>]' .
460 - '[<a href="javascript:smw_addMainColInstance(\'maincol_starter\', \'sorting_main\')">' . wfMsg( 'smw_qui_addrescol' ) . '</a>]' .
461 - "\n";
462 -
463 - // Javascript code for handling adding and removing the "sort" inputs
464 - if ( $enableAutocomplete == SMWQueryUI::ENABLE_AUTO_SUGGEST ) {
465 - $this->addAutocompletionJavascriptAndCSS();
466 - }
467 - // localisation messages for javascript
468 - $optionsMsg = wfMsg( 'smw_qui_options' );
469 - $okMsg = wfMsg( 'smw_qui_ok' );
470 - $cancelMsg = wfMsg( 'smw_qui_cancel' );
471 - $javascript_text = <<<EOT
472 -<script type="text/javascript">
473 -var num_elements = {$num_sort_values};
474 -EOT;
475 -// add autocomplete
476 - if ( $enableAutocomplete == SMWQueryUI::ENABLE_AUTO_SUGGEST ) {
477 - $javascript_text .= <<<EOT
478 -
479 -function smw_property_autocomplete(){
480 - jQuery('[name*="property"]').autocomplete({
481 - minLength: 2,
482 - source: function(request, response) {
483 - url=wgScriptPath+'/api.php?action=opensearch&limit=10&namespace='+wgNamespaceIds['property']+'&format=jsonfm';
484 -
485 - jQuery.getJSON(url, 'search='+request.term, function(data){
486 - //remove the namespace prefix 'Property:' from returned data
487 - for(i=0;i<data[1].length;i++) data[1][i]='?'+data[1][i].substr(data[1][i].indexOf(':')+1);
488 - response(data[1]);
489 - });
490 -
491 - }
492 - });
493155 }
494156
495 -function smw_category_autocomplete(){
496 - jQuery('[name*="category"]').autocomplete({
497 - minLength: 2,
498 - source: function(request, response) {
499 - url=wgScriptPath+'/api.php?action=opensearch&limit=10&namespace='+wgNamespaceIds['category']+'&format=jsonfm';
500 -
501 - jQuery.getJSON(url, 'search='+request.term, function(data){
502 - //remove the namespace prefix 'Property:' from returned data
503 - for(i=0;i<data[1].length;i++) data[1][i]=data[1][i].substr(data[1][i].indexOf(':')+1);
504 - response(data[1]);
505 - });
506 -
507 - }
508 - });
509 -}
510 -EOT;
511 - } else {
512 - $javascript_text .= <<<EOT
513 -function smw_property_autocomplete(){
514 -}
515 -
516 -function smw_category_autocomplete(){
517 -}
518 -
519 -EOT;
520 - }
521 -
522 - $javascript_text .= <<<EOT
523 -function smw_prop_code_update(){
524 - code = '?'+jQuery('#d-property')[0].value;
525 - if(code!=''){
526 - if(jQuery('#d-property-format-custom')[0].value !=''){
527 - code = code + jQuery('#d-property-format-custom')[0].value;
528 - }
529 - if(jQuery('#d-property-label')[0].value !=''){
530 - code = code + ' = '+ jQuery('#d-property-label')[0].value;
531 - }
532 - jQuery('#d-property-code')[0].value= code;
533 - }
534 -}
535 -
536 -function smw_cat_code_update(){
537 - cat = jQuery('#d-category').attr('value');
538 - label =code= jQuery('#d-category-label').attr('value');
539 - yes = jQuery('#d-category-yes').attr('value');
540 - no = jQuery('#d-category-no').attr('value');
541 - if (cat.trim()!='' && yes.trim()!=''){
542 - code=cat+'#'+yes;
543 - if(no.trim()!=''){
544 - code=code+','+no;
545 - }
546 - }
547 - jQuery('#d-category-code').attr('value', code);
548 -
549 -}
550 -
551 -function smw_makeCatDialog(cat_id){
552 - jQuery('#prop-cat input').attr('value','');
553 - cat=jQuery('#category'+cat_id)[0].value;
554 - label=jQuery('#cat_label'+cat_id)[0].value;
555 - cats=cat.split('#');
556 - cat= cats[0];
557 - if(cats[1]){
558 - yes_no = cats[1].split(',');
559 - if(yes_no[1]){
560 - no=yes_no[1];
561 - } else {
562 - no = '';
563 - }
564 - yes=yes_no[0];
565 - jQuery('#d-category-yes').attr('value',yes);
566 - jQuery('#d-category-no').attr('value',no);
567 - }
568 - jQuery('#d-category-label').attr('value',label);
569 - jQuery('#d-category').attr('value',cat);
570 - jQuery('#cat-dialog').dialog.id=cat_id;
571 - jQuery('#cat-dialog').dialog('open');
572 -}
573 -
574 -function smw_makePropDialog(prop_id){
575 - jQuery('#prop-dialog input').attr('value','');
576 - prop=val=jQuery('#property'+prop_id)[0].value;
577 - if(val[0]='?') val=prop=prop.substr(1);
578 - if((i=val.indexOf('='))!=-1) prop=prop.substring(0, i);
579 - if((i=val.indexOf('#'))!=-1) prop=prop.substring(0, i);
580 - if(val.split('=')[1]){
581 - label=val.split('=')[1].trim();
582 - }else{
583 - label="";
584 - }
585 - format = val.split('=')[0];
586 - if(format.indexOf('#')!=-1){
587 - format=format.substr(format.indexOf('#'));
588 - }else{
589 - format="";
590 - }
591 -
592 - jQuery('#d-property').attr('value', prop.trim());
593 - jQuery('#d-property-label').attr('value', label);
594 - jQuery('#d-property-format-custom').attr('value', format.trim());
595 - jQuery('#prop-dialog').dialog.id=prop_id;
596 - jQuery('#prop-dialog').dialog('open');
597 -}
598 -// code for handling adding and removing the "sort" inputs
599 -
600 -function smw_addPropertyInstance(starter_div_id, main_div_id) {
601 - var starter_div = document.getElementById(starter_div_id);
602 - var main_div = document.getElementById(main_div_id);
603 -
604 - //Create the new instance
605 - var new_div = starter_div.cloneNode(true);
606 - var div_id = 'sort_div_' + num_elements;
607 - new_div.id = div_id;
608 - new_div.style.display = 'block';
609 - jQuery(new_div.getElementsByTagName('label')).attr('for', 'display'+num_elements);
610 - var children = new_div.getElementsByTagName('*');
611 - var x;
612 - for (x = 0; x < children.length; x++) {
613 - if (children[x].for) children[x].for="display"+num_elements;
614 - if (children[x].name){
615 - children[x].id = children[x].name.replace(/_num/, ''+num_elements);
616 - children[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']');
617 - }
618 - }
619 -
620 - //Create 'more' link
621 - var more_button =document.createElement('span');
622 - more_button.innerHTML = ' <a class="smwq-more" href="javascript:smw_makePropDialog(\'' + num_elements + '\')">{$optionsMsg}</a> ';
623 - more_button.id = 'more'+num_elements;
624 - new_div.appendChild(more_button);
625 -
626 - //Add the new instance
627 - main_div.appendChild(new_div);
628 -
629 - // initialize delete button
630 - st='sort_div_'+num_elements;
631 - jQuery('#'+new_div.id).find(".smw-remove a")[0].href="javascript:removePOInstance('"+st+"')";
632 - num_elements++;
633 - smw_property_autocomplete();
634 -}
635 -
636 -function smw_addCategoryInstance(starter_div_id, main_div_id) {
637 - var starter_div = document.getElementById(starter_div_id);
638 - var main_div = document.getElementById(main_div_id);
639 -
640 - //Create the new instance
641 - var new_div = starter_div.cloneNode(true);
642 - var div_id = 'sort_div_' + num_elements;
643 - new_div.id = div_id;
644 - new_div.style.display = 'block';
645 - jQuery(new_div.getElementsByTagName('label')).attr('for', 'display'+num_elements);
646 - var children = new_div.getElementsByTagName('*');
647 - var x;
648 - for (x = 0; x < children.length; x++) {
649 - if (children[x].for) children[x].for="display"+num_elements;
650 - if (children[x].name){
651 - children[x].id = children[x].name.replace(/_num/, ''+num_elements);
652 - children[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']');
653 - }
654 - }
655 -
656 - //Create 'more' link
657 - var more_button =document.createElement('span');
658 - more_button.innerHTML = ' <a class="smwq-more" href="javascript:smw_makeCatDialog(\'' + num_elements + '\')">{$optionsMsg}</a> ';
659 - more_button.id = 'more'+num_elements;
660 - new_div.appendChild(more_button);
661 -
662 - //Add the new instance
663 - main_div.appendChild(new_div);
664 -
665 - // initialize delete button
666 - st='sort_div_'+num_elements;
667 - jQuery('#'+new_div.id).find(".smw-remove a")[0].href="javascript:removePOInstance('"+st+"')";
668 - num_elements++;
669 - smw_category_autocomplete();
670 -}
671 -
672 -function smw_addMainColInstance(starter_div_id, main_div_id) {
673 - var starter_div = document.getElementById(starter_div_id);
674 - var main_div = document.getElementById(main_div_id);
675 -
676 - //Create the new instance
677 - var new_div = starter_div.cloneNode(true);
678 - var div_id = 'sort_div_' + num_elements;
679 - new_div.id = div_id;
680 - new_div.style.display = 'block';
681 - jQuery(new_div.getElementsByTagName('label')).attr('for', 'display'+num_elements);
682 - var children = new_div.getElementsByTagName('*');
683 - var x;
684 - for (x = 0; x < children.length; x++) {
685 - if (children[x].for) children[x].for="display"+num_elements;
686 - if (children[x].name){
687 - children[x].id = children[x].name.replace(/_num/, ''+num_elements);
688 - children[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']');
689 - }
690 - }
691 -
692 - //Add the new instance
693 - main_div.appendChild(new_div);
694 -
695 - // initialize delete button
696 - st='sort_div_'+num_elements;
697 - jQuery('#'+new_div.id).find(".smw-remove a")[0].href="javascript:removePOInstance('"+st+"')";
698 - num_elements++;
699 - smw_category_autocomplete();
700 -}
701 -
702 -function removePOInstance(div_id) {
703 - var olddiv = document.getElementById(div_id);
704 - var parent = olddiv.parentNode;
705 - parent.removeChild(olddiv);
706 -}
707 -
708 -jQuery(function(){
709 - jQuery('$hidden_property').appendTo(document.body);
710 - jQuery('$hidden_category').appendTo(document.body);
711 - jQuery('$hidden_main_column').appendTo(document.body);
712 - jQuery('$property_dialog_box').appendTo(document.body);
713 - jQuery('$category_dialog_box').appendTo(document.body);
714 - jQuery('#cat-dialog').dialog({
715 - autoOpen: false,
716 - modal: true,
717 - resizable: true,
718 - minHeight: 200,
719 - minWidth: 400,
720 - buttons: {
721 - "{$okMsg}": function(){
722 - smw_cat_code_update();
723 - label = jQuery('#d-category-label').attr('value');
724 - code = jQuery('#d-category-code').attr('value');
725 - jQuery('#category'+jQuery(this).dialog.id).attr('value',code);
726 - jQuery('#cat_label'+jQuery(this).dialog.id).attr('value',label);
727 - jQuery(this).dialog("close");
728 - },
729 - "{$cancelMsg}": function(){
730 - jQuery('#cat-dialog input').attr('value','');
731 - jQuery(this).dialog("close");
732 - }
733 - }
734 - });
735 -
736 - jQuery('#prop-dialog').dialog({
737 - autoOpen: false,
738 - modal: true,
739 - resizable: true,
740 - minHeight: 200,
741 - minWidth: 400,
742 - buttons: {
743 - "{$okMsg}": function(){
744 - smw_prop_code_update();
745 - jQuery('#property'+jQuery(this).dialog.id)[0].value=jQuery('#d-property-code')[0].value;
746 - jQuery(this).dialog("close");
747 - },
748 - "{$cancelMsg}": function(){
749 - jQuery('#prop-dialog input').attr('value','');
750 - jQuery(this).dialog("close");
751 - }
752 - }
753 - });
754 - jQuery('#sort-more').click(function(){jQuery('#prop-dialog').dialog("open");});
755 -
756 - jQuery('#d-format').bind('change', function(event){
757 - jQuery('#d-property-format-custom').attr('value', jQuery('#d-format').attr('value'));
758 - smw_prop_code_update();
759 - });
760 -});
761 -
762 -jQuery(document).ready(smw_property_autocomplete);
763 -jQuery(document).ready(smw_category_autocomplete);
764 -</script>
765 -
766 -EOT;
767 -
768 - $wgOut->addScript( $javascript_text );
769 - return $result;
770 - }
771 -}
772 -