Redo addArgs() as addArg() so we can actually do useful things with arguments like...
authorChad Horohoe <demon@users.mediawiki.org>
Tue, 18 Aug 2009 23:06:24 +0000 (23:06 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Tue, 18 Aug 2009 23:06:24 +0000 (23:06 +0000)
17 files changed:
maintenance/Maintenance.php
maintenance/addwiki.php
maintenance/cleanupSpam.php
maintenance/createAndPromote.php
maintenance/deleteBatch.php
maintenance/edit.php
maintenance/fixTimestamps.php
maintenance/mctest.php
maintenance/moveBatch.php
maintenance/nukePage.php
maintenance/patchSql.php
maintenance/reassignEdits.php
maintenance/rebuildFileCache.php
maintenance/refreshLinks.php
maintenance/renamewiki.php
maintenance/undelete.php
maintenance/waitForSlave.php

index 9ef2ef7..394b0a4 100644 (file)
@@ -137,10 +137,17 @@ abstract class Maintenance {
        }
 
        /**
-        * Add some args that are needed. Used in formatting help
-        */
-       protected function addArgs( $args ) {
-               $this->mArgList = array_merge( $this->mArgList, $args );
+        * Add some args that are needed
+        * @param $arg String Name of the arg, like 'start'
+        * @param $description String Short description of the arg
+        * @param $required Boolean Is this required?
+        */
+       protected function addArg( $arg, $description, $required = true ) {
+               $this->mArgList[] = array( 
+                       'name' => $arg,
+                       'desc' => $description, 
+                       'require' => $required 
+               );
        }
 
        /**
@@ -462,17 +469,23 @@ abstract class Maintenance {
         * Run some validation checks on the params, etc
         */
        private function validateParamsAndArgs() {
-               # Check to make sure we've got all the required ones
+               $die = false;
+               # Check to make sure we've got all the required options
                foreach( $this->mParams as $opt => $info ) {
                        if( $info['require'] && !$this->hasOption( $opt ) ) {
-                               $this->error( "Param $opt required.", true );
+                               $this->error( "Param $opt required!" );
+                               $die = true;
                        }
                }
-
-               # Also make sure we've got enough arguments
-               if ( count( $this->mArgs ) < count( $this->mArgList ) ) {
-                       $this->error( "Not enough arguments passed", true );
+               # Check arg list too
+               foreach( $this->mArgList as $k => $info ) {
+                       if( $info['require'] && !$this->hasArg($k) ) {
+                               $this->error( "Argument <" . $info['name'] . "> required!" );
+                               $die = true;
+                       }
                }
+               
+               if( $die ) $this->maybeHelp( true );
        }
 
        /**
@@ -505,12 +518,20 @@ abstract class Maintenance {
                                $this->output( " [--" . implode( array_keys( $this->mParams ), "|--" ) . "]" );
                        }
                        if( $this->mArgList ) {
-                               $this->output( " <" . implode( $this->mArgList, "> <" ) . ">" );
+                               $this->output( " <" );
+                               foreach( $this->mArgList as $k => $arg ) {
+                                       $this->output( $arg['name'] . ">" );
+                                       if( $k < count( $this->mArgList ) - 1 )
+                                               $this->output( " <" );
+                               }
                        }
                        $this->output( "\n" );
                        foreach( $this->mParams as $par => $info ) {
                                $this->output( "\t$par : " . $info['desc'] . "\n" );
                        }
+                       foreach( $this->mArgList as $info ) {
+                               $this->output( "\t<" . $info['name'] . "> : " . $info['desc'] . "\n" );
+                       }
                        die( 1 );
                }
        }
index 46818e6..9603d2b 100644 (file)
@@ -29,7 +29,9 @@ class AddWiki extends Maintenance {
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Add a new wiki to the family. Wikimedia specific!";
-               $this->addArgs( 'language', 'site', 'dbname' );
+               $this->addArg( 'language', 'Language code of new site' );
+               $this->addArg( 'site', 'Type of site' );
+               $this->addArg( 'dbname', 'Name of database to create' );
        }
 
        protected function getDbType() {
index f9e897e..fb76e31 100644 (file)
@@ -27,7 +27,7 @@ class CleanupSpam extends Maintenance {
                parent::__construct();
                $this->mDescription = "Cleanup all spam from a given hostname";
                $this->addOption( 'all', 'Check all wikis in $wgLocalDatabases' );
-               $this->addArgs( array( 'hostname' ) );
+               $this->addArg( 'hostname', 'Hostname that was spamming' );
        }
 
        public function execute() {
index 694f999..391d122 100644 (file)
@@ -30,7 +30,8 @@ class CreateAndPromote extends Maintenance {
                parent::__construct();
                $this->mDescription = "Create a new user account with administrator rights";
                $this->addOption( "bureaucrat", "Grant the account bureaucrat rights" );
-               $this->addArgs( array( "username", "password" ) );
+               $this->addArg( "username", "Username of new user" );
+               $this->addArg( "password", "Password to set" );
        }
 
        public function execute() {
index 6aecda7..6946b0c 100644 (file)
@@ -37,7 +37,7 @@ class DeleteBatch extends Maintenance {
                $this->addOption( 'u', "User to perform deletion", false, true );
                $this->addOption( 'r', "Reason to delete page", false, true );
                $this->addOption( 'i', "Interval to sleep between deletions" );
-               $this->addArgs( array( 'listfile' ) );
+               $this->addArg( 'listfile', 'File with titles to delete, separated by newlines', false );
        }
        
        public function execute() {
index d736090..8d0068c 100644 (file)
@@ -32,7 +32,7 @@ class EditCLI extends Maintenance {
                $this->addOption( 'b', 'Bot edit' );
                $this->addOption( 'a', 'Enable autosummary' );
                $this->addOption( 'no-rc', 'Do not show the change in recent changes' );
-               $this->addArgs( array( 'title' ) );
+               $this->addArg( 'title', 'Title of article to edit' );
        }
 
        public function execute() {
index 2cbec44..ea102fb 100644 (file)
@@ -30,7 +30,9 @@ class FixTimestamps extends Maintenance {
        public function __construct() {
                parent::__construct();
                $this->mDescription = "";
-               $this->addArgs( array( 'offset', 'start', 'end' ) );
+               $this->addArg( 'offset', '' );
+               $this->addArg( 'start', 'Starting timestamp' );
+               $this->addArg( 'end', 'Ending timestamp' );
        }
 
        public function execute() {
index b77ffcb..4e424b1 100644 (file)
@@ -29,7 +29,7 @@ class mcTest extends Maintenance {
                $this->mDescription = "Makes several 'set', 'incr' and 'get' requests on every"
                                                          . " memcached server and shows a report";
                $this->addOption( 'i', 'Number of iterations', false, true );
-               $this->addArgs( array( 'server' ) );
+               $this->addArg( 'server', 'Memcached server to test' );
        }
 
        public function execute() {
index 878b649..9f23677 100644 (file)
@@ -42,7 +42,7 @@ class MoveBatch extends Maintenance {
                $this->addOption( 'u', "User to perform move", false, true );
                $this->addOption( 'r', "Reason to move page", false, true );
                $this->addOption( 'i', "Interval to sleep between moves" );
-               $this->addArgs( array( 'listfile' ) );
+               $this->addArg( 'listfile', 'List of pages to move, newline delimited', false );
        }
        
        public function execute() {
index 1cf3c79..16ff2e4 100644 (file)
@@ -29,7 +29,7 @@ class NukePage extends Maintenance {
                parent::__construct();
                $this->mDescription = "Remove a page record from the database";
                $this->addOption( 'delete', "Actually delete the page" );
-               $this->addArgs( array( 'title' ) );
+               $this->addArg( 'title', 'Title to delete' );
        }
 
        public function execute() {
index 122f23a..6071323 100644 (file)
@@ -27,7 +27,7 @@ class PatchSql extends Maintenance {
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Run an SQL file into the DB, replacing prefix and charset vars";
-               $this->addArgs( array( 'patch-name' ) );
+               $this->addArg( 'patch-name', 'Name of the patch file, either full path or in maintenance/archives' );
        }
 
        protected function getDbType() {
index 926ee5c..0ce08cc 100644 (file)
@@ -31,7 +31,8 @@ class ReassignEdits extends Maintenance {
                $this->addOption( "force", "Reassign even if the target user doesn't exist" );
                $this->addOption( "norc", "Don't update the recent changes table" );
                $this->addOption( "report", "Print out details of what would be changed, but don't update it" );
-               $this->addArgs( array( 'from', 'to' ) );
+               $this->addArg( 'from', 'Old user to take edits from' );
+               $this->addArg( 'to', 'New user to give edits to' );
        }
        
        public function execute() {
index 0173726..2a4e488 100644 (file)
@@ -26,8 +26,8 @@ class RebuildFileCache extends Maintenance {
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Build file cache for content pages";
-               //$this->addArgs( array( 'start' ) );
-               $this->addOption( 'overwrite', 'Refresh page cache', false );
+               $this->addArg( 'start', 'Page_id to start from', true );
+               $this->addArg( 'overwrite', 'Refresh page cache', false );
                $this->setBatchSize( 100 );
        }
 
index c43d8c6..58c789c 100644 (file)
@@ -30,7 +30,7 @@ class RefreshLinks extends Maintenance {
                $this->addOption( 'old-redirects-only', 'Only fix redirects with no redirect table entry' );
                $this->addOption( 'm', 'Maximum replication lag', false, true );
                $this->addOption( 'e', 'Last page id to refresh', false, true );
-               $this->addArgs( array( 'start' => true ) );
+               $this->addArg( 'start', 'Page_id to start from, default 1' );
                $this->setBatchSize( 100 );
        }
 
index da8742e..a022477 100644 (file)
@@ -28,7 +28,8 @@ class RenameWiki extends Maintenance {
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Rename external storage dbs and leave a new one";
-               $this->addArgs( array( 'olddb', 'newdb' ) );
+               $this->addArg( 'olddb' 'Old DB name' );
+               $this->addArg( 'newdb' 'New DB name' );
        }
        
        protected function getDbType() {
index b392ac9..099ea88 100644 (file)
@@ -14,7 +14,7 @@ class Undelete extends Maintenance {
                $this->mDescription = "Undelete a page";
                $this->addOption( 'u', 'The user to perform the undeletion', false, true );
                $this->addOption( 'r', 'The reason to undelete', false, true );
-               $this->addArgs( array( 'pagename' ) );
+               $this->addArg( 'pagename', 'Page to undelete' );
        }
 
        public function execute() {
index cf9bd00..f2a532c 100644 (file)
@@ -23,7 +23,7 @@ require_once( dirname(__FILE__) . '/Maintenance.php' );
 
 class WaitForSlave extends Maintenance {
        public function __construct() {
-               $this->addArgs( array( 'maxlag' ) );
+               $this->addArg( 'maxlag', 'How long to wait for the slaves, default 10 seconds', false );
        }
        public function execute() {
                wfWaitForSlaves( $this->getArg( 0, 10 ) );