}
/**
- * 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
+ );
}
/**
* 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 );
}
/**
$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 );
}
}
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() {
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() {
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() {
$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() {
$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() {
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() {
$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() {
$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() {
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() {
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() {
$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() {
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 );
}
$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 );
}
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() {
$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() {
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 ) );