* bypassers ($force, --help) moved to the top. Less error prone.
authorAntoine Musso <hashar@users.mediawiki.org>
Mon, 25 Oct 2010 16:23:56 +0000 (16:23 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Mon, 25 Oct 2010 16:23:56 +0000 (16:23 +0000)
* 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)

maintenance/Maintenance.php
maintenance/tests/phpunit/includes/IPTest.php

index b660e8d..714f51f 100644 (file)
@@ -633,44 +633,56 @@ abstract class Maintenance {
         * @param $force boolean Whether to force the help to show, default false
         */
        protected function maybeHelp( $force = false ) {
+               if( !$force && !$this->hasOption( 'help' ) ) {
+                       return;
+               }
+
                $screenWidth = 80; // TODO: Caculate this!
                $tab = "    ";
                $descWidth = $screenWidth - ( 2 * strlen( $tab ) );
 
                ksort( $this->mParams );
-               if ( $this->hasOption( 'help' ) || $force ) {
-                       $this->mQuiet = false;
+               $this->mQuiet = false;
 
-                       if ( $this->mDescription ) {
-                               $this->output( "\n" . $this->mDescription . "\n" );
-                       }
-                       $output = "\nUsage: php " . basename( $this->mSelf );
-                       if ( $this->mParams ) {
-                               $output .= " [--" . implode( array_keys( $this->mParams ), "|--" ) . "]";
-                       }
-                       if ( $this->mArgList ) {
-                               $output .= " <";
-                               foreach ( $this->mArgList as $k => $arg ) {
-                                       $output .= $arg['name'] . ">";
-                                       if ( $k < count( $this->mArgList ) - 1 )
-                                               $output .= " <";
-                               }
-                       }
-                       $this->output( "$output\n" );
-                       foreach ( $this->mParams as $par => $info ) {
-                               $this->output(
-                                       wordwrap( "$tab$par : " . $info['desc'], $descWidth,
-                                                       "\n$tab$tab" ) . "\n"
-                               );
-                       }
-                       foreach ( $this->mArgList as $info ) {
-                               $this->output(
-                                       wordwrap( "$tab<" . $info['name'] . "> : " .
-                                               $info['desc'], $descWidth, "\n$tab$tab" ) . "\n"
-                               );
+               // Description ...
+               if ( $this->mDescription ) {
+                       $this->output( "\n" . $this->mDescription . "\n" );
+               }
+               $output = "\nUsage: php " . basename( $this->mSelf );
+               
+               // ... append parameters ...
+               if ( $this->mParams ) {
+                       $output .= " [--" . implode( array_keys( $this->mParams ), "|--" ) . "]";
+               }
+
+               // ... and append arguments.
+               if ( $this->mArgList ) {
+                       $output .= " <";
+                       foreach ( $this->mArgList as $k => $arg ) {
+                               $output .= $arg['name'] . ">";
+                               if ( $k < count( $this->mArgList ) - 1 )
+                                       $output .= " <";
                        }
-                       die( 1 );
                }
+               $this->output( "$output\n\n" );
+
+               // Parameters description
+               foreach ( $this->mParams as $par => $info ) {
+                       $this->output(
+                               wordwrap( "$tab--$par: " . $info['desc'], $descWidth,
+                                               "\n$tab$tab" ) . "\n"
+                       );
+               }
+
+               // Arguments description
+               foreach ( $this->mArgList as $info ) {
+                       $this->output(
+                               wordwrap( "$tab<" . $info['name'] . ">: " .
+                                       $info['desc'], $descWidth, "\n$tab$tab" ) . "\n"
+                       );
+               }
+
+               die( 1 );
        }
 
        /**
index 2336086..181379c 100644 (file)
@@ -140,4 +140,14 @@ class IPTest extends PHPUnit_Framework_TestCase {
                $this->assertNet( '10.128.0.0' , '10.135.0.0/9' );
                $this->assertNet( '134.0.0.0'  , '134.0.5.1/8'  ); 
        }
+
+       function testIPv6SpecialRanges() {
+               $this->assertTrue( IPv6::isULA( 'fdc1:9d57:401e::' ) );
+               $this->assertTrue( IPv6::isULA( 'FDC1:9D57:401E::' ) );
+               $this->assertTrue( IPv6::isULA( 'fc::' ) );
+               $this->assertTrue( IPv6::isULA( 'fdff:ffff:ffff::' ) );
+       
+               $this->assertFalse( IPv6::isULA( '2001:0DB8::A:1::' ) );
+               $this->assertFalse( IPv6::isULA( '::1' ) );
+       }
 }