r55287 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55286‎ | r55287 | r55288 >
Date:23:06, 18 August 2009
Author:demon
Status:resolved
Tags:
Comment:
Redo addArgs() as addArg() so we can actually do useful things with arguments like descriptions and proper requirement checks, similar to addOption()
Modified paths:
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)
  • /trunk/phase3/maintenance/addwiki.php (modified) (history)
  • /trunk/phase3/maintenance/cleanupSpam.php (modified) (history)
  • /trunk/phase3/maintenance/createAndPromote.php (modified) (history)
  • /trunk/phase3/maintenance/deleteBatch.php (modified) (history)
  • /trunk/phase3/maintenance/edit.php (modified) (history)
  • /trunk/phase3/maintenance/fixTimestamps.php (modified) (history)
  • /trunk/phase3/maintenance/mctest.php (modified) (history)
  • /trunk/phase3/maintenance/moveBatch.php (modified) (history)
  • /trunk/phase3/maintenance/nukePage.php (modified) (history)
  • /trunk/phase3/maintenance/patchSql.php (modified) (history)
  • /trunk/phase3/maintenance/reassignEdits.php (modified) (history)
  • /trunk/phase3/maintenance/rebuildFileCache.php (modified) (history)
  • /trunk/phase3/maintenance/refreshLinks.php (modified) (history)
  • /trunk/phase3/maintenance/renamewiki.php (modified) (history)
  • /trunk/phase3/maintenance/undelete.php (modified) (history)
  • /trunk/phase3/maintenance/waitForSlave.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/renamewiki.php
@@ -28,7 +28,8 @@
2929 public function __construct() {
3030 parent::__construct();
3131 $this->mDescription = "Rename external storage dbs and leave a new one";
32 - $this->addArgs( array( 'olddb', 'newdb' ) );
 32+ $this->addArg( 'olddb' 'Old DB name' );
 33+ $this->addArg( 'newdb' 'New DB name' );
3334 }
3435
3536 protected function getDbType() {
Index: trunk/phase3/maintenance/mctest.php
@@ -29,7 +29,7 @@
3030 $this->mDescription = "Makes several 'set', 'incr' and 'get' requests on every"
3131 . " memcached server and shows a report";
3232 $this->addOption( 'i', 'Number of iterations', false, true );
33 - $this->addArgs( array( 'server' ) );
 33+ $this->addArg( 'server', 'Memcached server to test' );
3434 }
3535
3636 public function execute() {
Index: trunk/phase3/maintenance/undelete.php
@@ -14,7 +14,7 @@
1515 $this->mDescription = "Undelete a page";
1616 $this->addOption( 'u', 'The user to perform the undeletion', false, true );
1717 $this->addOption( 'r', 'The reason to undelete', false, true );
18 - $this->addArgs( array( 'pagename' ) );
 18+ $this->addArg( 'pagename', 'Page to undelete' );
1919 }
2020
2121 public function execute() {
Index: trunk/phase3/maintenance/rebuildFileCache.php
@@ -26,8 +26,8 @@
2727 public function __construct() {
2828 parent::__construct();
2929 $this->mDescription = "Build file cache for content pages";
30 - //$this->addArgs( array( 'start' ) );
31 - $this->addOption( 'overwrite', 'Refresh page cache', false );
 30+ $this->addArg( 'start', 'Page_id to start from', true );
 31+ $this->addArg( 'overwrite', 'Refresh page cache', false );
3232 $this->setBatchSize( 100 );
3333 }
3434
Index: trunk/phase3/maintenance/refreshLinks.php
@@ -30,7 +30,7 @@
3131 $this->addOption( 'old-redirects-only', 'Only fix redirects with no redirect table entry' );
3232 $this->addOption( 'm', 'Maximum replication lag', false, true );
3333 $this->addOption( 'e', 'Last page id to refresh', false, true );
34 - $this->addArgs( array( 'start' => true ) );
 34+ $this->addArg( 'start', 'Page_id to start from, default 1' );
3535 $this->setBatchSize( 100 );
3636 }
3737
Index: trunk/phase3/maintenance/moveBatch.php
@@ -42,7 +42,7 @@
4343 $this->addOption( 'u', "User to perform move", false, true );
4444 $this->addOption( 'r', "Reason to move page", false, true );
4545 $this->addOption( 'i', "Interval to sleep between moves" );
46 - $this->addArgs( array( 'listfile' ) );
 46+ $this->addArg( 'listfile', 'List of pages to move, newline delimited', false );
4747 }
4848
4949 public function execute() {
Index: trunk/phase3/maintenance/edit.php
@@ -32,7 +32,7 @@
3333 $this->addOption( 'b', 'Bot edit' );
3434 $this->addOption( 'a', 'Enable autosummary' );
3535 $this->addOption( 'no-rc', 'Do not show the change in recent changes' );
36 - $this->addArgs( array( 'title' ) );
 36+ $this->addArg( 'title', 'Title of article to edit' );
3737 }
3838
3939 public function execute() {
Index: trunk/phase3/maintenance/nukePage.php
@@ -29,7 +29,7 @@
3030 parent::__construct();
3131 $this->mDescription = "Remove a page record from the database";
3232 $this->addOption( 'delete', "Actually delete the page" );
33 - $this->addArgs( array( 'title' ) );
 33+ $this->addArg( 'title', 'Title to delete' );
3434 }
3535
3636 public function execute() {
Index: trunk/phase3/maintenance/deleteBatch.php
@@ -37,7 +37,7 @@
3838 $this->addOption( 'u', "User to perform deletion", false, true );
3939 $this->addOption( 'r', "Reason to delete page", false, true );
4040 $this->addOption( 'i', "Interval to sleep between deletions" );
41 - $this->addArgs( array( 'listfile' ) );
 41+ $this->addArg( 'listfile', 'File with titles to delete, separated by newlines', false );
4242 }
4343
4444 public function execute() {
Index: trunk/phase3/maintenance/addwiki.php
@@ -29,7 +29,9 @@
3030 public function __construct() {
3131 parent::__construct();
3232 $this->mDescription = "Add a new wiki to the family. Wikimedia specific!";
33 - $this->addArgs( 'language', 'site', 'dbname' );
 33+ $this->addArg( 'language', 'Language code of new site' );
 34+ $this->addArg( 'site', 'Type of site' );
 35+ $this->addArg( 'dbname', 'Name of database to create' );
3436 }
3537
3638 protected function getDbType() {
Index: trunk/phase3/maintenance/patchSql.php
@@ -27,7 +27,7 @@
2828 public function __construct() {
2929 parent::__construct();
3030 $this->mDescription = "Run an SQL file into the DB, replacing prefix and charset vars";
31 - $this->addArgs( array( 'patch-name' ) );
 31+ $this->addArg( 'patch-name', 'Name of the patch file, either full path or in maintenance/archives' );
3232 }
3333
3434 protected function getDbType() {
Index: trunk/phase3/maintenance/Maintenance.php
@@ -137,10 +137,17 @@
138138 }
139139
140140 /**
141 - * Add some args that are needed. Used in formatting help
 141+ * Add some args that are needed
 142+ * @param $arg String Name of the arg, like 'start'
 143+ * @param $description String Short description of the arg
 144+ * @param $required Boolean Is this required?
142145 */
143 - protected function addArgs( $args ) {
144 - $this->mArgList = array_merge( $this->mArgList, $args );
 146+ protected function addArg( $arg, $description, $required = true ) {
 147+ $this->mArgList[] = array(
 148+ 'name' => $arg,
 149+ 'desc' => $description,
 150+ 'require' => $required
 151+ );
145152 }
146153
147154 /**
@@ -462,17 +469,23 @@
463470 * Run some validation checks on the params, etc
464471 */
465472 private function validateParamsAndArgs() {
466 - # Check to make sure we've got all the required ones
 473+ $die = false;
 474+ # Check to make sure we've got all the required options
467475 foreach( $this->mParams as $opt => $info ) {
468476 if( $info['require'] && !$this->hasOption( $opt ) ) {
469 - $this->error( "Param $opt required.", true );
 477+ $this->error( "Param $opt required!" );
 478+ $die = true;
470479 }
471480 }
472 -
473 - # Also make sure we've got enough arguments
474 - if ( count( $this->mArgs ) < count( $this->mArgList ) ) {
475 - $this->error( "Not enough arguments passed", true );
 481+ # Check arg list too
 482+ foreach( $this->mArgList as $k => $info ) {
 483+ if( $info['require'] && !$this->hasArg($k) ) {
 484+ $this->error( "Argument <" . $info['name'] . "> required!" );
 485+ $die = true;
 486+ }
476487 }
 488+
 489+ if( $die ) $this->maybeHelp( true );
477490 }
478491
479492 /**
@@ -505,12 +518,20 @@
506519 $this->output( " [--" . implode( array_keys( $this->mParams ), "|--" ) . "]" );
507520 }
508521 if( $this->mArgList ) {
509 - $this->output( " <" . implode( $this->mArgList, "> <" ) . ">" );
 522+ $this->output( " <" );
 523+ foreach( $this->mArgList as $k => $arg ) {
 524+ $this->output( $arg['name'] . ">" );
 525+ if( $k < count( $this->mArgList ) - 1 )
 526+ $this->output( " <" );
 527+ }
510528 }
511529 $this->output( "\n" );
512530 foreach( $this->mParams as $par => $info ) {
513531 $this->output( "\t$par : " . $info['desc'] . "\n" );
514532 }
 533+ foreach( $this->mArgList as $info ) {
 534+ $this->output( "\t<" . $info['name'] . "> : " . $info['desc'] . "\n" );
 535+ }
515536 die( 1 );
516537 }
517538 }
Index: trunk/phase3/maintenance/createAndPromote.php
@@ -30,7 +30,8 @@
3131 parent::__construct();
3232 $this->mDescription = "Create a new user account with administrator rights";
3333 $this->addOption( "bureaucrat", "Grant the account bureaucrat rights" );
34 - $this->addArgs( array( "username", "password" ) );
 34+ $this->addArg( "username", "Username of new user" );
 35+ $this->addArg( "password", "Password to set" );
3536 }
3637
3738 public function execute() {
Index: trunk/phase3/maintenance/fixTimestamps.php
@@ -30,7 +30,9 @@
3131 public function __construct() {
3232 parent::__construct();
3333 $this->mDescription = "";
34 - $this->addArgs( array( 'offset', 'start', 'end' ) );
 34+ $this->addArg( 'offset', '' );
 35+ $this->addArg( 'start', 'Starting timestamp' );
 36+ $this->addArg( 'end', 'Ending timestamp' );
3537 }
3638
3739 public function execute() {
Index: trunk/phase3/maintenance/reassignEdits.php
@@ -31,7 +31,8 @@
3232 $this->addOption( "force", "Reassign even if the target user doesn't exist" );
3333 $this->addOption( "norc", "Don't update the recent changes table" );
3434 $this->addOption( "report", "Print out details of what would be changed, but don't update it" );
35 - $this->addArgs( array( 'from', 'to' ) );
 35+ $this->addArg( 'from', 'Old user to take edits from' );
 36+ $this->addArg( 'to', 'New user to give edits to' );
3637 }
3738
3839 public function execute() {
Index: trunk/phase3/maintenance/cleanupSpam.php
@@ -27,7 +27,7 @@
2828 parent::__construct();
2929 $this->mDescription = "Cleanup all spam from a given hostname";
3030 $this->addOption( 'all', 'Check all wikis in $wgLocalDatabases' );
31 - $this->addArgs( array( 'hostname' ) );
 31+ $this->addArg( 'hostname', 'Hostname that was spamming' );
3232 }
3333
3434 public function execute() {
Index: trunk/phase3/maintenance/waitForSlave.php
@@ -23,7 +23,7 @@
2424
2525 class WaitForSlave extends Maintenance {
2626 public function __construct() {
27 - $this->addArgs( array( 'maxlag' ) );
 27+ $this->addArg( 'maxlag', 'How long to wait for the slaves, default 10 seconds', false );
2828 }
2929 public function execute() {
3030 wfWaitForSlaves( $this->getArg( 0, 10 ) );

Follow-up revisions

RevisionCommit summaryAuthorDate
r55299Fix syntax error from r55287siebrand01:07, 19 August 2009

Status & tagging log