Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_QueryUIHelper.php |
— | — | @@ -143,8 +143,8 @@ |
144 | 144 | protected function enableJQuery() { |
145 | 145 | global $wgOut, $smwgJQueryIncluded; |
146 | 146 | if ( !$smwgJQueryIncluded ) { |
147 | | - $real_function = array( 'OutputPage', 'includeJQuery' ); |
148 | | - if ( is_callable( $real_function ) ) { |
| 147 | + $realFunction = array( 'OutputPage', 'includeJQuery' ); |
| 148 | + if ( is_callable( $realFunction ) ) { |
149 | 149 | $wgOut->includeJQuery(); |
150 | 150 | } else { |
151 | 151 | $wgOut->addScriptFile( "$smwgScriptPath/libs/jquery-1.4.2.min.js" ); |
— | — | @@ -190,7 +190,7 @@ |
191 | 191 | global $wgOut; |
192 | 192 | if ( $this->autoCompleteEnabled == false ) { |
193 | 193 | $this->enableJQueryUI(); |
194 | | - $javascript_autocomplete_text = <<<END |
| 194 | + $javascriptAutocompleteText = <<<END |
195 | 195 | <script type="text/javascript"> |
196 | 196 | function smw_split(val) { |
197 | 197 | return val.split('\\n'); |
— | — | @@ -235,7 +235,7 @@ |
236 | 236 | </script> |
237 | 237 | END; |
238 | 238 | |
239 | | - $wgOut->addScript( $javascript_autocomplete_text ); |
| 239 | + $wgOut->addScript( $javascriptAutocompleteText ); |
240 | 240 | $this->autoCompleteEnabled = true; |
241 | 241 | } |
242 | 242 | } |
— | — | @@ -257,7 +257,7 @@ |
258 | 258 | */ |
259 | 259 | public function getNavigationBar( $limit, $offset, $hasFurtherResults ) { |
260 | 260 | global $smwgQMaxInlineLimit, $wgLang; |
261 | | - $url_tail = $this->getUrlTail(); |
| 261 | + $urlTail = $this->getUrlTail(); |
262 | 262 | // Prepare navigation bar. |
263 | 263 | if ( $offset > 0 ) { |
264 | 264 | $navigation = Html::element( |
— | — | @@ -265,7 +265,7 @@ |
266 | 266 | array( |
267 | 267 | 'href' => $this->getTitle()->getLocalURL( |
268 | 268 | 'offset=' . max( 0, $offset - $limit ) . |
269 | | - '&limit=' . $limit . $url_tail |
| 269 | + '&limit=' . $limit . $urlTail |
270 | 270 | ), |
271 | 271 | 'rel' => 'nofollow' |
272 | 272 | ), |
— | — | @@ -289,7 +289,7 @@ |
290 | 290 | array( |
291 | 291 | 'href' => $this->getTitle()->getLocalURL( |
292 | 292 | 'offset=' . ( $offset + $limit ) . |
293 | | - '&limit=' . $limit . $url_tail |
| 293 | + '&limit=' . $limit . $urlTail |
294 | 294 | ), |
295 | 295 | 'rel' => 'nofollow' |
296 | 296 | ), |
— | — | @@ -317,7 +317,7 @@ |
318 | 318 | array( |
319 | 319 | 'href' => $this->getTitle()->getLocalURL( |
320 | 320 | 'offset=' . $offset . |
321 | | - '&limit=' . $l . $url_tail |
| 321 | + '&limit=' . $l . $urlTail |
322 | 322 | ), |
323 | 323 | 'rel' => 'nofollow' |
324 | 324 | ), |
— | — | @@ -378,6 +378,94 @@ |
379 | 379 | } |
380 | 380 | |
381 | 381 | /** |
| 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 | + /** |
382 | 470 | * Generates the forms elements(s) for choosing printouts and sorting |
383 | 471 | * options. Use its complement processPoSortFormBox() to decode data |
384 | 472 | * sent by these elements. |
— | — | @@ -385,23 +473,35 @@ |
386 | 474 | * @return string |
387 | 475 | */ |
388 | 476 | protected function getPoSortFormBox( $enableAutocomplete = SMWQueryUI::ENABLE_AUTO_SUGGEST ) { |
389 | | - global $smwgQSortingSupport, $wgRequest, $wgOut; |
| 477 | + global $smwgQSortingSupport, $wgRequest, $wgOut, $smwgScriptPath; |
390 | 478 | |
391 | 479 | 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 | + |
393 | 484 | $result = ''; |
394 | | - $num_sort_values = 0; |
| 485 | + $numSortValues = 0; |
395 | 486 | // START: create form elements already submitted earlier via form |
396 | 487 | // 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 | + } |
406 | 506 | } |
407 | 507 | } |
408 | 508 | } else { |
— | — | @@ -424,133 +524,395 @@ |
425 | 525 | |
426 | 526 | $params = $this->uiCore->getParameters(); |
427 | 527 | 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 ); |
432 | 532 | } 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(); |
435 | 535 | } |
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; |
440 | 539 | } |
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 | + } |
449 | 548 | } |
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]" ) ); |
455 | 580 | |
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 ); |
458 | 583 | |
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 ); |
461 | 586 | |
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 ); |
464 | 589 | |
465 | | - $result .= Xml::closeElement( 'select' ); |
| 590 | + $result .= Xml::closeElement( 'select' ); |
466 | 591 | |
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> '; |
469 | 595 | |
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 | + } |
472 | 624 | } |
| 625 | + $numSortValues = $i; |
473 | 626 | // END: create form elements already submitted earlier via form |
474 | 627 | |
475 | 628 | // 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>' . |
477 | 631 | 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 ); |
479 | 641 | |
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 ); |
485 | 650 | |
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 ); |
488 | 657 | |
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' ); |
490 | 673 | |
491 | 674 | $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"; |
493 | 679 | |
494 | 680 | // Javascript code for handling adding and removing the "sort" inputs |
495 | | - $delete_msg = wfMsg( 'smw_qui_delete' ); |
496 | | - |
497 | 681 | if ( $enableAutocomplete == SMWQueryUI::ENABLE_AUTO_SUGGEST ) { |
498 | 682 | $this->addAutocompletionJavascriptAndCSS(); |
499 | 683 | } |
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 |
501 | 689 | <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 |
503 | 695 | |
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 | + } |
506 | 709 | }); |
507 | | -var num_elements = {$num_sort_values}; |
| 710 | +} |
508 | 711 | |
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) { |
510 | 818 | var starter_div = document.getElementById(starter_div_id); |
511 | 819 | var main_div = document.getElementById(main_div_id); |
512 | 820 | |
513 | 821 | //Create the new instance |
514 | 822 | var new_div = starter_div.cloneNode(true); |
515 | 823 | var div_id = 'sort_div_' + num_elements; |
516 | | - new_div.className = 'multipleTemplate'; |
517 | 824 | new_div.id = div_id; |
518 | 825 | 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 | + } |
519 | 836 | |
| 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); |
520 | 863 | var children = new_div.getElementsByTagName('*'); |
521 | 864 | var x; |
522 | 865 | 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); |
524 | 869 | children[x].name = children[x].name.replace(/_num/, '[' + num_elements + ']'); |
525 | 870 | } |
| 871 | + } |
526 | 872 | |
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); |
531 | 878 | |
532 | 879 | //Add the new instance |
533 | 880 | 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'; |
542 | 881 | |
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 + ']'); |
548 | 906 | } |
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+"')"; |
553 | 915 | num_elements++; |
554 | | - |
| 916 | + smw_category_autocomplete(); |
555 | 917 | } |
556 | 918 | |
557 | 919 | function removePOInstance(div_id) { |
— | — | @@ -558,59 +920,65 @@ |
559 | 921 | var parent = olddiv.parentNode; |
560 | 922 | parent.removeChild(olddiv); |
561 | 923 | } |
562 | | -</script> |
563 | 924 | |
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"); |
599 | 949 | } |
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 | + }); |
606 | 952 | |
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"); |
608 | 968 | } |
609 | 969 | } |
| 970 | + }); |
| 971 | + jQuery('#sort-more').click(function(){jQuery('#prop-dialog').dialog("open");}); |
610 | 972 | |
611 | | - $params = array_merge( $params, $po ); |
| 973 | +}); |
612 | 974 | |
613 | | - return $params; |
| 975 | +jQuery(document).ready(smw_property_autocomplete); |
| 976 | +jQuery(document).ready(smw_category_autocomplete); |
| 977 | +</script> |
614 | 978 | |
| 979 | +EOT; |
| 980 | + |
| 981 | + $wgOut->addScript( $javascriptText ); |
| 982 | + return $result; |
615 | 983 | } |
616 | 984 | |
617 | 985 | /** |
— | — | @@ -670,7 +1038,7 @@ |
671 | 1039 | $delete_msg = wfMsg( 'smw_qui_delete' ); |
672 | 1040 | |
673 | 1041 | $this->enableJQuery(); |
674 | | - $javascript_text = <<<EOT |
| 1042 | + $javascriptText = <<<EOT |
675 | 1043 | <script type="text/javascript"> |
676 | 1044 | // code for handling adding and removing the "sort" inputs |
677 | 1045 | jQuery(document).ready(function(){ |
— | — | @@ -715,7 +1083,7 @@ |
716 | 1084 | |
717 | 1085 | EOT; |
718 | 1086 | |
719 | | - $wgOut->addScript( $javascript_text ); |
| 1087 | + $wgOut->addScript( $javascriptText ); |
720 | 1088 | return $result; |
721 | 1089 | } |
722 | 1090 | |
— | — | @@ -734,10 +1102,10 @@ |
735 | 1103 | if ( !$smwgQSortingSupport ) return array(); |
736 | 1104 | |
737 | 1105 | $params = array(); |
738 | | - $order_values = $wgRequest->getArray( 'order' ); |
739 | | - if ( is_array( $order_values ) ) { |
| 1106 | + $orderValues = $wgRequest->getArray( 'order' ); |
| 1107 | + if ( is_array( $orderValues ) ) { |
740 | 1108 | $params['order'] = ''; |
741 | | - foreach ( $order_values as $order_value ) { |
| 1109 | + foreach ( $orderValues as $order_value ) { |
742 | 1110 | if ( $order_value == '' ) { |
743 | 1111 | $order_value = 'ASC'; |
744 | 1112 | } |
— | — | @@ -770,7 +1138,7 @@ |
771 | 1139 | |
772 | 1140 | if ( $enableAutocomplete ) { |
773 | 1141 | $this->addAutocompletionJavascriptAndCSS(); |
774 | | - $javascript_autocomplete_text = <<<EOT |
| 1142 | + $javascriptAutocompleteText = <<<EOT |
775 | 1143 | <script type="text/javascript"> |
776 | 1144 | jQuery(document).ready(function(){ |
777 | 1145 | jQuery("#add_property").autocomplete({ |
— | — | @@ -805,7 +1173,7 @@ |
806 | 1174 | </script> |
807 | 1175 | EOT; |
808 | 1176 | |
809 | | - $wgOut->addScript( $javascript_autocomplete_text ); |
| 1177 | + $wgOut->addScript( $javascriptAutocompleteText ); |
810 | 1178 | |
811 | 1179 | } |
812 | 1180 | |
— | — | @@ -822,7 +1190,7 @@ |
823 | 1191 | */ |
824 | 1192 | protected function processPOFormBox( WebRequest $wgRequest ) { |
825 | 1193 | $postring = $wgRequest->getText( 'po' ); |
826 | | - $po_array = array(); |
| 1194 | + $poArray = array(); |
827 | 1195 | |
828 | 1196 | if ( $postring != '' ) { // parameters from HTML input fields |
829 | 1197 | $ps = explode( "\n", $postring ); // params separated by newlines here (compatible with text-input for printouts) |
— | — | @@ -834,11 +1202,11 @@ |
835 | 1203 | $param = '?' . $param; |
836 | 1204 | } |
837 | 1205 | |
838 | | - $po_array[] = $param; |
| 1206 | + $poArray[] = $param; |
839 | 1207 | } |
840 | 1208 | } |
841 | 1209 | |
842 | | - return $po_array; |
| 1210 | + return $poArray; |
843 | 1211 | } |
844 | 1212 | |
845 | 1213 | /** |
— | — | @@ -849,33 +1217,33 @@ |
850 | 1218 | * @return string An url-encoded string. |
851 | 1219 | */ |
852 | 1220 | protected function getUrlTail() { |
853 | | - $url_tail = '&q=' . urlencode( $this->uiCore->getQuerystring() ); |
| 1221 | + $urlTail = '&q=' . urlencode( $this->uiCore->getQuerystring() ); |
854 | 1222 | |
855 | | - $tmp_parray = array(); |
| 1223 | + $tmpArray = array(); |
856 | 1224 | $params = $this->uiCore->getParameters(); |
857 | 1225 | foreach ( $params as $key => $value ) { |
858 | 1226 | if ( !in_array( $key, array( 'sort', 'order', 'limit', 'offset', 'title' ) ) ) { |
859 | | - $tmp_parray[$key] = $value; |
| 1227 | + $tmpArray[$key] = $value; |
860 | 1228 | } |
861 | 1229 | } |
862 | | - $url_tail .= '&p=' . urlencode( SMWInfolink::encodeParameters( $tmp_parray ) ); |
| 1230 | + $urlTail .= '&p=' . urlencode( SMWInfolink::encodeParameters( $tmpArray ) ); |
863 | 1231 | |
864 | | - $print_out_string = ''; |
| 1232 | + $printOutString = ''; |
865 | 1233 | foreach ( $this->uiCore->getPrintOuts() as $printout ) { |
866 | | - $print_out_string .= $printout->getSerialisation() . "\n"; |
| 1234 | + $printOutString .= $printout->getSerialisation() . "\n"; |
867 | 1235 | } |
868 | 1236 | |
869 | | - if ( $print_out_string != '' ) { |
870 | | - $url_tail .= '&po=' . urlencode( $print_out_string ); |
| 1237 | + if ( $printOutString != '' ) { |
| 1238 | + $urlTail .= '&po=' . urlencode( $printOutString ); |
871 | 1239 | } |
872 | 1240 | if ( array_key_exists( 'sort', $params ) ) { |
873 | | - $url_tail .= '&sort=' . $params['sort']; |
| 1241 | + $urlTail .= '&sort=' . $params['sort']; |
874 | 1242 | } |
875 | 1243 | if ( array_key_exists( 'order', $params ) ) { |
876 | | - $url_tail .= '&order=' . $params['order']; |
| 1244 | + $urlTail .= '&order=' . $params['order']; |
877 | 1245 | } |
878 | 1246 | |
879 | | - return $url_tail; |
| 1247 | + return $urlTail; |
880 | 1248 | } |
881 | 1249 | |
882 | 1250 | /** |
— | — | @@ -893,7 +1261,7 @@ |
894 | 1262 | |
895 | 1263 | $params = method_exists( $printer, 'getValidatorParameters' ) ? $printer->getValidatorParameters() : array(); |
896 | 1264 | |
897 | | - $options_html = array(); |
| 1265 | + $optionsHtml = array(); |
898 | 1266 | |
899 | 1267 | foreach ( $params as $param ) { |
900 | 1268 | // Ignore the parameters for which we have a special control in the GUI already. |
— | — | @@ -901,54 +1269,54 @@ |
902 | 1270 | continue; |
903 | 1271 | } |
904 | 1272 | |
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; |
906 | 1274 | |
907 | | - $options_html[] = |
| 1275 | + $optionsHtml[] = |
908 | 1276 | Html::rawElement( |
909 | 1277 | 'div', |
910 | 1278 | array( |
911 | 1279 | 'style' => 'width: 30%; padding: 5px; float: left;' |
912 | 1280 | ), |
913 | 1281 | '<label for="p[' . htmlspecialchars( $param->getName() ) . ']">' . htmlspecialchars( $param->getName() ) . ': </label>' . |
914 | | - $this->showFormatOption( $param, $current_value ) . |
| 1282 | + $this->showFormatOption( $param, $currentValue ) . |
915 | 1283 | '<br />' . |
916 | 1284 | Html::element( 'em', array(), $param->getDescription() ) |
917 | 1285 | ); |
918 | 1286 | } |
919 | 1287 | |
920 | | - for ( $i = 0, $n = count( $options_html ); $i < $n; $i++ ) { |
| 1288 | + for ( $i = 0, $n = count( $optionsHtml ); $i < $n; $i++ ) { |
921 | 1289 | 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"; |
923 | 1291 | } |
924 | 1292 | } |
925 | 1293 | |
926 | 1294 | $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; |
933 | 1301 | $i++; |
934 | 1302 | |
935 | | - $result_html .= Html::rawElement( |
| 1303 | + $resultHtml .= Html::rawElement( |
936 | 1304 | 'div', |
937 | 1305 | array( |
938 | | - 'style' => 'background: ' . ( $flip_style ? 'white' : '#dddddd' ) . ';' |
| 1306 | + 'style' => 'background: ' . ( $flipStyle ? 'white' : '#dddddd' ) . ';' |
939 | 1307 | ), |
940 | | - $row_html |
| 1308 | + $rowHtml |
941 | 1309 | ); |
942 | 1310 | |
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; |
948 | 1316 | } |
949 | 1317 | |
950 | 1318 | } |
951 | 1319 | |
952 | | - return $result_html; |
| 1320 | + return $resultHtml; |
953 | 1321 | } |
954 | 1322 | |
955 | 1323 | |
— | — | @@ -982,21 +1350,21 @@ |
983 | 1351 | * UI's may overload these methods to change behaviour or form |
984 | 1352 | * parameters. |
985 | 1353 | * |
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 |
987 | 1355 | * @return array The first element contains the format selector, while the second contains the Format options |
988 | 1356 | */ |
989 | | - protected function getFormatSelectBoxSep( $defaultformat = 'broadtable' ) { |
| 1357 | + protected function getFormatSelectBoxSep( $defaultFormat = 'broadtable' ) { |
990 | 1358 | global $smwgResultFormats, $wgOut; |
991 | 1359 | |
992 | 1360 | $this->enableJQuery(); |
993 | 1361 | |
994 | 1362 | // 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; |
998 | 1366 | } |
999 | 1367 | |
1000 | | - $printer = SMWQueryProcessor::getResultPrinter( $default_format, SMWQueryProcessor::SPECIAL_PAGE ); |
| 1368 | + $printer = SMWQueryProcessor::getResultPrinter( $defFormat, SMWQueryProcessor::SPECIAL_PAGE ); |
1001 | 1369 | $url = $this->getTitle()->getLocalURL( "showformatoptions=' + this.value + '" ); |
1002 | 1370 | |
1003 | 1371 | foreach ( $this->uiCore->getParameters() as $param => $value ) { |
— | — | @@ -1006,13 +1374,13 @@ |
1007 | 1375 | } |
1008 | 1376 | |
1009 | 1377 | $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() . |
1011 | 1379 | ' (' . wfMsg( 'smw_ask_defaultformat' ) . ')</option>' . "\n"; |
1012 | 1380 | |
1013 | 1381 | $formats = array(); |
1014 | 1382 | foreach ( array_keys( $smwgResultFormats ) as $format ) { |
1015 | 1383 | // 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' ) { |
1017 | 1385 | $printer = SMWQueryProcessor::getResultPrinter( $format, SMWQueryProcessor::SPECIAL_PAGE ); |
1018 | 1386 | $formats[$format] = $printer->getName(); |
1019 | 1387 | } |
— | — | @@ -1056,21 +1424,21 @@ |
1057 | 1425 | * @return array |
1058 | 1426 | */ |
1059 | 1427 | protected function processFormatSelectBox( WebRequest $wgRequest ) { |
1060 | | - $query_val = $wgRequest->getVal( 'p' ); |
| 1428 | + $queryVal = $wgRequest->getVal( 'p' ); |
1061 | 1429 | |
1062 | | - if ( !empty( $query_val ) ) { |
1063 | | - $params = SMWInfolink::decodeParameters( $query_val, false ); |
| 1430 | + if ( !empty( $queryVal ) ) { |
| 1431 | + $params = SMWInfolink::decodeParameters( $queryVal, false ); |
1064 | 1432 | } else { |
1065 | | - $query_values = $wgRequest->getArray( 'p' ); |
| 1433 | + $queryValues = $wgRequest->getArray( 'p' ); |
1066 | 1434 | |
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] ); |
1070 | 1438 | } |
1071 | 1439 | } |
1072 | 1440 | |
1073 | 1441 | // p is used for any additional parameters in certain links. |
1074 | | - $params = SMWInfolink::decodeParameters( $query_values, false ); |
| 1442 | + $params = SMWInfolink::decodeParameters( $queryValues, false ); |
1075 | 1443 | } |
1076 | 1444 | |
1077 | 1445 | return $params; |
— | — | @@ -1109,9 +1477,9 @@ |
1110 | 1478 | */ |
1111 | 1479 | public function getPOStrings() { |
1112 | 1480 | $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 ) { |
1116 | 1484 | $string .= $value->getSerialisation() . "\n"; |
1117 | 1485 | } |
1118 | 1486 | } |
— | — | @@ -1285,7 +1653,6 @@ |
1286 | 1654 | * Returns a handle to the underlying Result object. |
1287 | 1655 | * |
1288 | 1656 | * @return SMWQueryResult |
1289 | | - * @todo Check if this method can be removed. |
1290 | 1657 | */ |
1291 | 1658 | public function getResultObject() { |
1292 | 1659 | return $this->queryResult; |
— | — | @@ -1361,24 +1728,24 @@ |
1362 | 1729 | * Each string in printouts should be of the form "?property" or |
1363 | 1730 | * "property". |
1364 | 1731 | * |
1365 | | - * When validation is enabled, the values in $print_outs are checked |
| 1732 | + * When validation is enabled, the values in $printOuts are checked |
1366 | 1733 | * against properties which exist in the wiki, and a warning string (for |
1367 | 1734 | * each property) is returned. Returns an empty array otherwise. |
1368 | 1735 | * |
1369 | | - * @param array $print_outs Array of strings |
| 1736 | + * @param array $printOuts Array of strings |
1370 | 1737 | * @param boolean $enableValidation |
1371 | 1738 | * @return array Array of errors messages (strings), if any. |
1372 | 1739 | */ |
1373 | | - public function setPrintOuts( array $print_outs = array(), $enableValidation = false ) { |
| 1740 | + public function setPrintOuts( array $printOuts = array(), $enableValidation = false ) { |
1374 | 1741 | /* |
1375 | 1742 | * Note: property validation is not very clearly defined yet, so validation is disabled by default |
1376 | 1743 | */ |
1377 | 1744 | |
1378 | 1745 | $errors = array(); |
1379 | 1746 | if ( $enableValidation ) { |
1380 | | - foreach ( $print_outs as $key => $prop ) { |
| 1747 | + foreach ( $printOuts as $key => $prop ) { |
1381 | 1748 | if ( $prop[0] != '?' ) { |
1382 | | - $print_outs[$key] = "?" . $print_outs[$key]; |
| 1749 | + $printOuts[$key] = "?" . $printOuts[$key]; |
1383 | 1750 | } |
1384 | 1751 | if ( !$this->validateProperty( $prop ) ) { |
1385 | 1752 | $errors[] = wfMsg( 'smw_qui_invalidprop', $prop ); |
— | — | @@ -1386,7 +1753,7 @@ |
1387 | 1754 | } |
1388 | 1755 | } |
1389 | 1756 | } |
1390 | | - $this -> printOutStrings = $print_outs; |
| 1757 | + $this -> printOutStrings = $printOuts; |
1391 | 1758 | $this->errors = array_merge( $errors, $this->errors ); |
1392 | 1759 | return $errors; |
1393 | 1760 | } |
— | — | @@ -1413,7 +1780,7 @@ |
1414 | 1781 | $errors = array(); |
1415 | 1782 | |
1416 | 1783 | // 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 ) ) { |
1418 | 1785 | $params[ 'format' ] = $this->defaultResultPrinter; |
1419 | 1786 | } |
1420 | 1787 | if ( !array_key_exists( 'limit', $params ) ) { |
— | — | @@ -1458,15 +1825,15 @@ |
1459 | 1826 | public function extractParameters( $p ) { |
1460 | 1827 | if ( $this->context == self::SPECIAL_PAGE ) { |
1461 | 1828 | // 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 ); |
1463 | 1830 | } else {// context is WIKI_LINK |
1464 | | - $raw_params = SMWInfolink::decodeParameters( $p, true ); |
| 1831 | + $rawParams = SMWInfolink::decodeParameters( $p, true ); |
1465 | 1832 | // 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; |
1468 | 1835 | } |
1469 | 1836 | |
1470 | | - SMWQueryProcessor::processFunctionParams( $raw_params, $this->queryString, $this->parameters, $this->printOuts ); |
| 1837 | + SMWQueryProcessor::processFunctionParams( $rawParams, $this->queryString, $this->parameters, $this->printOuts ); |
1471 | 1838 | } |
1472 | 1839 | |
1473 | 1840 | /** |
— | — | @@ -1494,28 +1861,28 @@ |
1495 | 1862 | |
1496 | 1863 | // BEGIN: Try to be smart for rss/ical if no description/title is given and we have a concept query |
1497 | 1864 | if ( $this->parameters['format'] == 'rss' ) { |
1498 | | - $desc_key = 'rssdescription'; |
1499 | | - $titlekey = 'rsstitle'; |
| 1865 | + $descKey = 'rssdescription'; |
| 1866 | + $titleKey = 'rsstitle'; |
1500 | 1867 | } elseif ( $this->parameters['format'] == 'icalendar' ) { |
1501 | | - $desc_key = 'icalendardescription'; |
1502 | | - $titlekey = 'icalendartitle'; |
| 1868 | + $descKey = 'icalendardescription'; |
| 1869 | + $titleKey = 'icalendartitle'; |
1503 | 1870 | } else { |
1504 | | - $desc_key = false; |
| 1871 | + $descKey = false; |
1505 | 1872 | } |
1506 | 1873 | |
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] ) ) ) { |
1509 | 1876 | $concept = $query->getDescription()->getConcept(); |
1510 | 1877 | |
1511 | | - if ( !isset( $this->parameters[$titlekey] ) ) { |
1512 | | - $this->parameters[$titlekey] = $concept->getText(); |
| 1878 | + if ( !isset( $this->parameters[$titleKey] ) ) { |
| 1879 | + $this->parameters[$titleKey] = $concept->getText(); |
1513 | 1880 | } |
1514 | 1881 | |
1515 | | - if ( !isset( $this->parameters[$desc_key] ) ) { |
| 1882 | + if ( !isset( $this->parameters[$descKey] ) ) { |
1516 | 1883 | // / @bug The current SMWStore will never return SMWConceptValue (an SMWDataValue) here; it might return SMWDIConcept (an SMWDataItem) |
1517 | 1884 | $dv = end( smwfGetStore()->getPropertyValues( SMWWikiPageValue::makePageFromTitle( $concept ), new SMWDIProperty( '_CONC' ) ) ); |
1518 | 1885 | if ( $dv instanceof SMWConceptValue ) { |
1519 | | - $this->parameters[$desc_key] = $dv->getDocu(); |
| 1886 | + $this->parameters[$descKey] = $dv->getDocu(); |
1520 | 1887 | } |
1521 | 1888 | } |
1522 | 1889 | } |
— | — | @@ -1536,15 +1903,15 @@ |
1537 | 1904 | $res = $this->queryResult; |
1538 | 1905 | $printer = SMWQueryProcessor::getResultPrinter( $this->parameters['format'], |
1539 | 1906 | SMWQueryProcessor::SPECIAL_PAGE ); |
1540 | | - $result_mime = $printer->getMimeType( $res ); |
| 1907 | + $resultMime = $printer->getMimeType( $res ); |
1541 | 1908 | |
1542 | 1909 | 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 ); |
1544 | 1911 | |
1545 | | - if ( is_array( $query_result ) ) { |
1546 | | - $result .= $query_result[0]; |
| 1912 | + if ( is_array( $queryResult ) ) { |
| 1913 | + $result .= $queryResult[0]; |
1547 | 1914 | } else { |
1548 | | - $result .= $query_result; |
| 1915 | + $result .= $queryResult; |
1549 | 1916 | } |
1550 | 1917 | } else { |
1551 | 1918 | $result = wfMsg( 'smw_result_noresults' ); |
Index: trunk/extensions/SemanticMediaWiki/specials/AskSpecial/SMW_SpecialQueryCreator.php |
— | — | @@ -15,7 +15,6 @@ |
16 | 16 | */ |
17 | 17 | class SMWQueryCreatorPage extends SMWQueryUI { |
18 | 18 | |
19 | | - protected $m_params = array(); |
20 | 19 | |
21 | 20 | /** |
22 | 21 | * Constructor. |
— | — | @@ -34,23 +33,23 @@ |
35 | 34 | */ |
36 | 35 | protected function makePage( $p ) { |
37 | 36 | global $wgOut; |
38 | | - $html_output = $this->makeResults( $p ); |
| 37 | + $htmlOutput = $this->makeResults( $p ); |
39 | 38 | if ( $this->uiCore->getQueryString() != "" ) { |
40 | 39 | if ( $this->usesNavigationBar() ) { |
41 | | - $html_output .= Html::rawElement( 'div', array( 'class' => 'smwqcnavbar' ), |
| 40 | + $htmlOutput .= Html::rawElement( 'div', array( 'class' => 'smwqcnavbar' ), |
42 | 41 | $this->getNavigationBar ( $this->uiCore->getLimit(), $this->uiCore->getOffset(), $this->uiCore->hasFurtherResults() ) |
43 | | - ); // ? can we preload offset and limit? |
| 42 | + ); |
44 | 43 | } |
45 | 44 | |
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() ); |
47 | 46 | |
48 | 47 | if ( $this->usesNavigationBar() ) { |
49 | | - $html_output .= Html::rawElement( 'div', array( 'class' => 'smwqcnavbar' ), |
| 48 | + $htmlOutput .= Html::rawElement( 'div', array( 'class' => 'smwqcnavbar' ), |
50 | 49 | $this->getNavigationBar ( $this->uiCore->getLimit(), $this->uiCore->getOffset(), $this->uiCore->hasFurtherResults() ) |
51 | | - ); // ? can we preload offset and limit? |
| 50 | + ); |
52 | 51 | } |
53 | 52 | } |
54 | | - $wgOut->addHTML( $html_output ); |
| 53 | + $wgOut->addHTML( $htmlOutput ); |
55 | 54 | } |
56 | 55 | |
57 | 56 | /** |
— | — | @@ -79,10 +78,10 @@ |
80 | 79 | global $wgOut, $smwgScriptPath; |
81 | 80 | $this->enableJQuery(); |
82 | 81 | $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() . '"/>'; |
87 | 86 | $result .= '<br>'; |
88 | 87 | $result .= wfMsg( 'smw_qc_query_help' ); |
89 | 88 | // Main query and format options |
— | — | @@ -90,7 +89,7 @@ |
91 | 90 | '<tr><th>' . wfMsg( 'smw_ask_queryhead' ) . "</th>\n<th>" . wfMsg( 'smw_ask_format_as' ) . "</th></tr>" . |
92 | 91 | '<tr>' . |
93 | 92 | '<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]; |
95 | 94 | |
96 | 95 | //START: show|hide additional options |
97 | 96 | $result .= '<span id="show_additional_options" style="display:inline;"><a href="#addtional" rel="nofollow" onclick="' . |
— | — | @@ -113,7 +112,7 @@ |
114 | 113 | // additional options |
115 | 114 | $result .= '<div id="additional_options" style="display:none">'; |
116 | 115 | |
117 | | - $result .= $format_box[1]; // display the format options |
| 116 | + $result .= $formatBox[1]; // display the format options |
118 | 117 | |
119 | 118 | $result .= '</div>'; // end of hidden additional options |
120 | 119 | $result .= '<br /><input type="submit" value="' . wfMsg( 'smw_ask_submit' ) . '"/><br/>'; |
— | — | @@ -127,7 +126,7 @@ |
128 | 127 | $this->enableJQueryUI(); |
129 | 128 | $wgOut->addScriptFile( "$smwgScriptPath/libs/jquery-ui/jquery-ui.dialog.min.js" ); |
130 | 129 | $wgOut->addStyle( "$smwgScriptPath/skins/SMW_custom.css" ); |
131 | | - $javascript_text = <<<EOT |
| 130 | + $javascriptText = <<<EOT |
132 | 131 | <script type="text/javascript"> |
133 | 132 | jQuery(document).ready(function(){ |
134 | 133 | jQuery('#embed-code-dialog').dialog({ |
— | — | @@ -144,7 +143,7 @@ |
145 | 144 | }); |
146 | 145 | </script> |
147 | 146 | EOT; |
148 | | - $wgOut->addScript( $javascript_text ); |
| 147 | + $wgOut->addScript( $javascriptText ); |
149 | 148 | } |
150 | 149 | $result .= '<input type="hidden" name="eq" value="no"/>' . |
151 | 150 | "\n</form><br/>"; |
— | — | @@ -152,620 +151,5 @@ |
153 | 152 | return $result; |
154 | 153 | |
155 | 154 | } |
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 | | - }); |
493 | 155 | } |
494 | 156 | |
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 | | - |