| Conditions | 21 |
| Paths | > 20000 |
| Total Lines | 274 |
| Code Lines | 185 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 411 | protected function getForm() { |
||
| 412 | $this->opts['title'] = $this->getPageTitle()->getPrefixedText(); |
||
| 413 | if ( !isset( $this->opts['target'] ) ) { |
||
| 414 | $this->opts['target'] = ''; |
||
| 415 | } else { |
||
| 416 | $this->opts['target'] = str_replace( '_', ' ', $this->opts['target'] ); |
||
| 417 | } |
||
| 418 | |||
| 419 | if ( !isset( $this->opts['namespace'] ) ) { |
||
| 420 | $this->opts['namespace'] = ''; |
||
| 421 | } |
||
| 422 | |||
| 423 | if ( !isset( $this->opts['nsInvert'] ) ) { |
||
| 424 | $this->opts['nsInvert'] = ''; |
||
| 425 | } |
||
| 426 | |||
| 427 | if ( !isset( $this->opts['associated'] ) ) { |
||
| 428 | $this->opts['associated'] = false; |
||
| 429 | } |
||
| 430 | |||
| 431 | if ( !isset( $this->opts['contribs'] ) ) { |
||
| 432 | $this->opts['contribs'] = 'user'; |
||
| 433 | } |
||
| 434 | |||
| 435 | if ( !isset( $this->opts['year'] ) ) { |
||
| 436 | $this->opts['year'] = ''; |
||
| 437 | } |
||
| 438 | |||
| 439 | if ( !isset( $this->opts['month'] ) ) { |
||
| 440 | $this->opts['month'] = ''; |
||
| 441 | } |
||
| 442 | |||
| 443 | if ( $this->opts['contribs'] == 'newbie' ) { |
||
| 444 | $this->opts['target'] = ''; |
||
| 445 | } |
||
| 446 | |||
| 447 | if ( !isset( $this->opts['tagfilter'] ) ) { |
||
| 448 | $this->opts['tagfilter'] = ''; |
||
| 449 | } |
||
| 450 | |||
| 451 | if ( !isset( $this->opts['topOnly'] ) ) { |
||
| 452 | $this->opts['topOnly'] = false; |
||
| 453 | } |
||
| 454 | |||
| 455 | if ( !isset( $this->opts['newOnly'] ) ) { |
||
| 456 | $this->opts['newOnly'] = false; |
||
| 457 | } |
||
| 458 | |||
| 459 | if ( !isset( $this->opts['hideMinor'] ) ) { |
||
| 460 | $this->opts['hideMinor'] = false; |
||
| 461 | } |
||
| 462 | |||
| 463 | $form = Html::openElement( |
||
| 464 | 'form', |
||
| 465 | [ |
||
| 466 | 'method' => 'get', |
||
| 467 | 'action' => wfScript(), |
||
| 468 | 'class' => 'mw-contributions-form' |
||
| 469 | ] |
||
| 470 | ); |
||
| 471 | |||
| 472 | # Add hidden params for tracking except for parameters in $skipParameters |
||
| 473 | $skipParameters = [ |
||
| 474 | 'namespace', |
||
| 475 | 'nsInvert', |
||
| 476 | 'deletedOnly', |
||
| 477 | 'target', |
||
| 478 | 'contribs', |
||
| 479 | 'year', |
||
| 480 | 'month', |
||
| 481 | 'topOnly', |
||
| 482 | 'newOnly', |
||
| 483 | 'hideMinor', |
||
| 484 | 'associated', |
||
| 485 | 'tagfilter' |
||
| 486 | ]; |
||
| 487 | |||
| 488 | foreach ( $this->opts as $name => $value ) { |
||
| 489 | if ( in_array( $name, $skipParameters ) ) { |
||
| 490 | continue; |
||
| 491 | } |
||
| 492 | $form .= "\t" . Html::hidden( $name, $value ) . "\n"; |
||
| 493 | } |
||
| 494 | |||
| 495 | $tagFilter = ChangeTags::buildTagFilterSelector( $this->opts['tagfilter'] ); |
||
| 496 | |||
| 497 | if ( $tagFilter ) { |
||
| 498 | $filterSelection = Html::rawElement( |
||
| 499 | 'div', |
||
| 500 | [], |
||
| 501 | implode( ' ', $tagFilter ) |
||
| 502 | ); |
||
| 503 | } else { |
||
| 504 | $filterSelection = Html::rawElement( 'div', [], '' ); |
||
| 505 | } |
||
| 506 | |||
| 507 | $this->getOutput()->addModules( 'mediawiki.userSuggest' ); |
||
| 508 | |||
| 509 | $labelNewbies = Xml::radioLabel( |
||
| 510 | $this->msg( 'sp-contributions-newbies' )->text(), |
||
| 511 | 'contribs', |
||
| 512 | 'newbie', |
||
| 513 | 'newbie', |
||
| 514 | $this->opts['contribs'] == 'newbie', |
||
| 515 | [ 'class' => 'mw-input' ] |
||
| 516 | ); |
||
| 517 | $labelUsername = Xml::radioLabel( |
||
| 518 | $this->msg( 'sp-contributions-username' )->text(), |
||
| 519 | 'contribs', |
||
| 520 | 'user', |
||
| 521 | 'user', |
||
| 522 | $this->opts['contribs'] == 'user', |
||
| 523 | [ 'class' => 'mw-input' ] |
||
| 524 | ); |
||
| 525 | $input = Html::input( |
||
| 526 | 'target', |
||
| 527 | $this->opts['target'], |
||
| 528 | 'text', |
||
| 529 | [ |
||
| 530 | 'size' => '40', |
||
| 531 | 'required' => '', |
||
| 532 | 'class' => [ |
||
| 533 | 'mw-input', |
||
| 534 | 'mw-ui-input-inline', |
||
| 535 | 'mw-autocomplete-user', // used by mediawiki.userSuggest |
||
| 536 | ], |
||
| 537 | ] + ( |
||
| 538 | // Only autofocus if target hasn't been specified or in non-newbies mode |
||
| 539 | ( $this->opts['contribs'] === 'newbie' || $this->opts['target'] ) |
||
| 540 | ? [] : [ 'autofocus' => true ] |
||
| 541 | ) |
||
| 542 | ); |
||
| 543 | |||
| 544 | $targetSelection = Html::rawElement( |
||
| 545 | 'div', |
||
| 546 | [], |
||
| 547 | $labelNewbies . '<br>' . $labelUsername . ' ' . $input . ' ' |
||
| 548 | ); |
||
| 549 | |||
| 550 | $namespaceSelection = Xml::tags( |
||
| 551 | 'div', |
||
| 552 | [], |
||
| 553 | Xml::label( |
||
| 554 | $this->msg( 'namespace' )->text(), |
||
| 555 | 'namespace', |
||
| 556 | '' |
||
| 557 | ) . ' ' . |
||
| 558 | Html::namespaceSelector( |
||
| 559 | [ 'selected' => $this->opts['namespace'], 'all' => '' ], |
||
| 560 | [ |
||
| 561 | 'name' => 'namespace', |
||
| 562 | 'id' => 'namespace', |
||
| 563 | 'class' => 'namespaceselector', |
||
| 564 | ] |
||
| 565 | ) . ' ' . |
||
| 566 | Html::rawElement( |
||
| 567 | 'span', |
||
| 568 | [ 'class' => 'mw-input-with-label' ], |
||
| 569 | Xml::checkLabel( |
||
| 570 | $this->msg( 'invert' )->text(), |
||
| 571 | 'nsInvert', |
||
| 572 | 'nsInvert', |
||
| 573 | $this->opts['nsInvert'], |
||
| 574 | [ |
||
| 575 | 'title' => $this->msg( 'tooltip-invert' )->text(), |
||
| 576 | 'class' => 'mw-input' |
||
| 577 | ] |
||
| 578 | ) . ' ' |
||
| 579 | ) . |
||
| 580 | Html::rawElement( 'span', [ 'class' => 'mw-input-with-label' ], |
||
| 581 | Xml::checkLabel( |
||
| 582 | $this->msg( 'namespace_association' )->text(), |
||
| 583 | 'associated', |
||
| 584 | 'associated', |
||
| 585 | $this->opts['associated'], |
||
| 586 | [ |
||
| 587 | 'title' => $this->msg( 'tooltip-namespace_association' )->text(), |
||
| 588 | 'class' => 'mw-input' |
||
| 589 | ] |
||
| 590 | ) . ' ' |
||
| 591 | ) |
||
| 592 | ); |
||
| 593 | |||
| 594 | $filters = []; |
||
| 595 | |||
| 596 | if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) { |
||
| 597 | $filters[] = Html::rawElement( |
||
| 598 | 'span', |
||
| 599 | [ 'class' => 'mw-input-with-label' ], |
||
| 600 | Xml::checkLabel( |
||
| 601 | $this->msg( 'history-show-deleted' )->text(), |
||
| 602 | 'deletedOnly', |
||
| 603 | 'mw-show-deleted-only', |
||
| 604 | $this->opts['deletedOnly'], |
||
| 605 | [ 'class' => 'mw-input' ] |
||
| 606 | ) |
||
| 607 | ); |
||
| 608 | } |
||
| 609 | |||
| 610 | $filters[] = Html::rawElement( |
||
| 611 | 'span', |
||
| 612 | [ 'class' => 'mw-input-with-label' ], |
||
| 613 | Xml::checkLabel( |
||
| 614 | $this->msg( 'sp-contributions-toponly' )->text(), |
||
| 615 | 'topOnly', |
||
| 616 | 'mw-show-top-only', |
||
| 617 | $this->opts['topOnly'], |
||
| 618 | [ 'class' => 'mw-input' ] |
||
| 619 | ) |
||
| 620 | ); |
||
| 621 | $filters[] = Html::rawElement( |
||
| 622 | 'span', |
||
| 623 | [ 'class' => 'mw-input-with-label' ], |
||
| 624 | Xml::checkLabel( |
||
| 625 | $this->msg( 'sp-contributions-newonly' )->text(), |
||
| 626 | 'newOnly', |
||
| 627 | 'mw-show-new-only', |
||
| 628 | $this->opts['newOnly'], |
||
| 629 | [ 'class' => 'mw-input' ] |
||
| 630 | ) |
||
| 631 | ); |
||
| 632 | $filters[] = Html::rawElement( |
||
| 633 | 'span', |
||
| 634 | [ 'class' => 'mw-input-with-label' ], |
||
| 635 | Xml::checkLabel( |
||
| 636 | $this->msg( 'sp-contributions-hideminor' )->text(), |
||
| 637 | 'hideMinor', |
||
| 638 | 'mw-hide-minor-edits', |
||
| 639 | $this->opts['hideMinor'], |
||
| 640 | [ 'class' => 'mw-input' ] |
||
| 641 | ) |
||
| 642 | ); |
||
| 643 | |||
| 644 | Hooks::run( |
||
| 645 | 'SpecialContributions::getForm::filters', |
||
| 646 | [ $this, &$filters ] |
||
| 647 | ); |
||
| 648 | |||
| 649 | $extraOptions = Html::rawElement( |
||
| 650 | 'div', |
||
| 651 | [], |
||
| 652 | implode( '', $filters ) |
||
| 653 | ); |
||
| 654 | |||
| 655 | $dateSelectionAndSubmit = Xml::tags( 'div', [], |
||
| 656 | Xml::dateMenu( |
||
| 657 | $this->opts['year'] === '' ? MWTimestamp::getInstance()->format( 'Y' ) : $this->opts['year'], |
||
| 658 | $this->opts['month'] |
||
| 659 | ) . ' ' . |
||
| 660 | Html::submitButton( |
||
| 661 | $this->msg( 'sp-contributions-submit' )->text(), |
||
| 662 | [ 'class' => 'mw-submit' ], [ 'mw-ui-progressive' ] |
||
| 663 | ) |
||
| 664 | ); |
||
| 665 | |||
| 666 | $form .= Xml::fieldset( |
||
| 667 | $this->msg( 'sp-contributions-search' )->text(), |
||
| 668 | $targetSelection . |
||
| 669 | $namespaceSelection . |
||
| 670 | $filterSelection . |
||
| 671 | $extraOptions . |
||
| 672 | $dateSelectionAndSubmit, |
||
| 673 | [ 'class' => 'mw-contributions-table' ] |
||
| 674 | ); |
||
| 675 | |||
| 676 | $explain = $this->msg( 'sp-contributions-explain' ); |
||
| 677 | if ( !$explain->isBlank() ) { |
||
| 678 | $form .= "<p id='mw-sp-contributions-explain'>{$explain->parse()}</p>"; |
||
| 679 | } |
||
| 680 | |||
| 681 | $form .= Xml::closeElement( 'form' ); |
||
| 682 | |||
| 683 | return $form; |
||
| 684 | } |
||
| 685 | |||
| 708 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: