r75361 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75360‎ | r75361 | r75362 >
Date:16:23, 25 October 2010
Author:hashar
Status:ok
Tags:
Comment:
* bypassers ($force, --help) moved to the top. Less error prone.
* prefix parameters with double dashes '--'
* get ride of spaces before semi-column ':'
* some comments to help us read the code

tip: reviewers should strip white spaces (svn diff -x -ub)
Modified paths:
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/IPTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/phpunit/includes/IPTest.php
@@ -140,4 +140,14 @@
141141 $this->assertNet( '10.128.0.0' , '10.135.0.0/9' );
142142 $this->assertNet( '134.0.0.0' , '134.0.5.1/8' );
143143 }
 144+
 145+ function testIPv6SpecialRanges() {
 146+ $this->assertTrue( IPv6::isULA( 'fdc1:9d57:401e::' ) );
 147+ $this->assertTrue( IPv6::isULA( 'FDC1:9D57:401E::' ) );
 148+ $this->assertTrue( IPv6::isULA( 'fc::' ) );
 149+ $this->assertTrue( IPv6::isULA( 'fdff:ffff:ffff::' ) );
 150+
 151+ $this->assertFalse( IPv6::isULA( '2001:0DB8::A:1::' ) );
 152+ $this->assertFalse( IPv6::isULA( '::1' ) );
 153+ }
144154 }
Index: trunk/phase3/maintenance/Maintenance.php
@@ -633,44 +633,56 @@
634634 * @param $force boolean Whether to force the help to show, default false
635635 */
636636 protected function maybeHelp( $force = false ) {
 637+ if( !$force && !$this->hasOption( 'help' ) ) {
 638+ return;
 639+ }
 640+
637641 $screenWidth = 80; // TODO: Caculate this!
638642 $tab = " ";
639643 $descWidth = $screenWidth - ( 2 * strlen( $tab ) );
640644
641645 ksort( $this->mParams );
642 - if ( $this->hasOption( 'help' ) || $force ) {
643 - $this->mQuiet = false;
 646+ $this->mQuiet = false;
644647
645 - if ( $this->mDescription ) {
646 - $this->output( "\n" . $this->mDescription . "\n" );
 648+ // Description ...
 649+ if ( $this->mDescription ) {
 650+ $this->output( "\n" . $this->mDescription . "\n" );
 651+ }
 652+ $output = "\nUsage: php " . basename( $this->mSelf );
 653+
 654+ // ... append parameters ...
 655+ if ( $this->mParams ) {
 656+ $output .= " [--" . implode( array_keys( $this->mParams ), "|--" ) . "]";
 657+ }
 658+
 659+ // ... and append arguments.
 660+ if ( $this->mArgList ) {
 661+ $output .= " <";
 662+ foreach ( $this->mArgList as $k => $arg ) {
 663+ $output .= $arg['name'] . ">";
 664+ if ( $k < count( $this->mArgList ) - 1 )
 665+ $output .= " <";
647666 }
648 - $output = "\nUsage: php " . basename( $this->mSelf );
649 - if ( $this->mParams ) {
650 - $output .= " [--" . implode( array_keys( $this->mParams ), "|--" ) . "]";
651 - }
652 - if ( $this->mArgList ) {
653 - $output .= " <";
654 - foreach ( $this->mArgList as $k => $arg ) {
655 - $output .= $arg['name'] . ">";
656 - if ( $k < count( $this->mArgList ) - 1 )
657 - $output .= " <";
658 - }
659 - }
660 - $this->output( "$output\n" );
661 - foreach ( $this->mParams as $par => $info ) {
662 - $this->output(
663 - wordwrap( "$tab$par : " . $info['desc'], $descWidth,
664 - "\n$tab$tab" ) . "\n"
665 - );
666 - }
667 - foreach ( $this->mArgList as $info ) {
668 - $this->output(
669 - wordwrap( "$tab<" . $info['name'] . "> : " .
670 - $info['desc'], $descWidth, "\n$tab$tab" ) . "\n"
671 - );
672 - }
673 - die( 1 );
674667 }
 668+ $this->output( "$output\n\n" );
 669+
 670+ // Parameters description
 671+ foreach ( $this->mParams as $par => $info ) {
 672+ $this->output(
 673+ wordwrap( "$tab--$par: " . $info['desc'], $descWidth,
 674+ "\n$tab$tab" ) . "\n"
 675+ );
 676+ }
 677+
 678+ // Arguments description
 679+ foreach ( $this->mArgList as $info ) {
 680+ $this->output(
 681+ wordwrap( "$tab<" . $info['name'] . ">: " .
 682+ $info['desc'], $descWidth, "\n$tab$tab" ) . "\n"
 683+ );
 684+ }
 685+
 686+ die( 1 );
675687 }
676688
677689 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r75364Follow up r75361 : removing a work in progress test casehashar16:28, 25 October 2010

Status & tagging log