Index: branches/maintenance-work/maintenance/Maintenance.php |
— | — | @@ -85,12 +85,29 @@ |
86 | 86 | * Add some args that are needed. Used in formatting help |
87 | 87 | */ |
88 | 88 | protected function addArgs( $args ) { |
89 | | - foreach( $args as $arg ) { |
90 | | - $this->mArgList[] = $arg; |
91 | | - } |
| 89 | + $this->mArgList = array_merge( $this->mArgList, $args ); |
92 | 90 | } |
| 91 | + |
| 92 | + /** |
| 93 | + * Does a given argument exist? |
| 94 | + * @param $argId int The integer value (from zero) for the arg |
| 95 | + * @return boolean |
| 96 | + */ |
| 97 | + protected function hasArg( $argId = 0 ) { |
| 98 | + return isset( $this->mArgs[ $argId ] ) ; |
| 99 | + } |
93 | 100 | |
94 | 101 | /** |
| 102 | + * Get an argument. |
| 103 | + * @param $argId int The integer value (from zero) for the arg |
| 104 | + * @param $default mixed The default if it doesn't exist |
| 105 | + * @return mixed |
| 106 | + */ |
| 107 | + protected function getArg( $argId = 0, $default = null ) { |
| 108 | + return $this->hasArg($name) ? $this->mArgs[$name] : $default; |
| 109 | + } |
| 110 | + |
| 111 | + /** |
95 | 112 | * Return input from stdin. |
96 | 113 | * @param $length int The number of bytes to read |
97 | 114 | * @return mixed |
— | — | @@ -305,8 +322,10 @@ |
306 | 323 | if( $this->mDescription ) { |
307 | 324 | $this->output( $this->mDescription . "\n" ); |
308 | 325 | } |
309 | | - $this->output( "\nUsage: php " . $this->mSelf . " [--" . |
310 | | - implode( array_keys( $this->mParams ), "|--" ) . "]" ); |
| 326 | + $this->output( "\nUsage: php " . $this->mSelf ); |
| 327 | + if( $this->mParams ) { |
| 328 | + $this->output( " [--" . implode( array_keys( $this->mParams ), "|--" ) . "]" ); |
| 329 | + } |
311 | 330 | if( $this->mArgList ) { |
312 | 331 | $this->output( " <" . implode( $this->mArgList, "> <" ) . ">" ); |
313 | 332 | } |
Index: branches/maintenance-work/maintenance/checkUsernames.php |
— | — | @@ -7,36 +7,33 @@ |
8 | 8 | * @ingroup Maintenance |
9 | 9 | */ |
10 | 10 | |
11 | | -error_reporting(E_ALL ^ E_NOTICE); |
12 | | -require_once 'commandLine.inc'; |
13 | 11 | |
14 | | -class checkUsernames { |
15 | | - var $stderr, $log; |
| 12 | +require_once( "Maintenance.php" ); |
16 | 13 | |
17 | | - function checkUsernames() { |
18 | | - $this->stderr = fopen( 'php://stderr', 'wt' ); |
| 14 | +class CheckUsernames extends Maintenance { |
| 15 | + |
| 16 | + public function __construct() { |
| 17 | + parent::__construct(); |
| 18 | + $this->mDescription = "Verify that database usernames are actually valid"; |
19 | 19 | } |
20 | | - function main() { |
21 | | - $fname = 'checkUsernames::main'; |
22 | 20 | |
| 21 | + function execute() { |
23 | 22 | $dbr = wfGetDB( DB_SLAVE ); |
24 | 23 | |
25 | 24 | $res = $dbr->select( 'user', |
26 | 25 | array( 'user_id', 'user_name' ), |
27 | 26 | null, |
28 | | - $fname |
| 27 | + __METHOD__ |
29 | 28 | ); |
30 | 29 | |
31 | 30 | while ( $row = $dbr->fetchObject( $res ) ) { |
32 | 31 | if ( ! User::isValidUserName( $row->user_name ) ) { |
33 | | - $out = sprintf( "%s: %6d: '%s'\n", wfWikiID(), $row->user_id, $row->user_name ); |
34 | | - fwrite( $this->stderr, $out ); |
| 32 | + $this->error( sprintf( "%s: %6d: '%s'\n", wfWikiID(), $row->user_id, $row->user_name ) ); |
35 | 33 | wfDebugLog( 'checkUsernames', $out ); |
36 | 34 | } |
37 | 35 | } |
38 | 36 | } |
39 | 37 | } |
40 | 38 | |
41 | | -$cun = new checkUsernames(); |
42 | | -$cun->main(); |
43 | | - |
| 39 | +$maintClass = "CheckUsernames"; |
| 40 | +require_once( "doMaintenance.php" ); |
Index: branches/maintenance-work/maintenance/deleteRevision.php |
— | — | @@ -6,42 +6,52 @@ |
7 | 7 | * @ingroup Maintenance |
8 | 8 | */ |
9 | 9 | |
10 | | -require_once( 'commandLine.inc' ); |
| 10 | +require_once( "Maintenance.php" ); |
11 | 11 | |
12 | | -$dbw = wfGetDB( DB_MASTER ); |
| 12 | +class DeleteRevision extends Maintenance { |
| 13 | + |
| 14 | + public function __construct() { |
| 15 | + parent::__construct(); |
| 16 | + $this->mDescription = "Delete one or more revisions by moving them to the archive table"; |
| 17 | + } |
| 18 | + |
| 19 | + public function execute() { |
| 20 | + if( count( $this->mArgs ) == 0 ) { |
| 21 | + $this->error( "No revisions specified", true ); |
| 22 | + } |
13 | 23 | |
14 | | -if ( count( $args ) == 0 ) { |
15 | | - echo "Usage: php deleteRevision.php <revid> [<revid> ...]\n"; |
16 | | - exit(1); |
17 | | -} |
18 | | - |
19 | | -echo "Deleting revision(s) " . implode( ',', $args ) . " from ".wfWikiID()."...\n"; |
20 | | - |
21 | | -$affected = 0; |
22 | | -foreach ( $args as $revID ) { |
23 | | - $dbw->insertSelect( 'archive', array( 'page', 'revision' ), |
24 | | - array( |
25 | | - 'ar_namespace' => 'page_namespace', |
26 | | - 'ar_title' => 'page_title', |
27 | | - 'ar_comment' => 'rev_comment', |
28 | | - 'ar_user' => 'rev_user', |
29 | | - 'ar_user_text' => 'rev_user_text', |
30 | | - 'ar_timestamp' => 'rev_timestamp', |
31 | | - 'ar_minor_edit' => 'rev_minor_edit', |
32 | | - 'ar_rev_id' => 'rev_id', |
33 | | - 'ar_text_id' => 'rev_text_id', |
34 | | - ), array( |
35 | | - 'rev_id' => $revID, |
36 | | - 'page_id = rev_page' |
37 | | - ), $fname |
38 | | - ); |
39 | | - if ( !$dbw->affectedRows() ) { |
40 | | - echo "Revision $revID not found\n"; |
41 | | - } else { |
42 | | - $affected += $dbw->affectedRows(); |
43 | | - $dbw->delete( 'revision', array( 'rev_id' => $revID ) ); |
| 24 | + $this->output( "Deleting revision(s) " . implode( ',', $this->mArgs ) . |
| 25 | + " from " . wfWikiID() . "...\n" ); |
| 26 | + $dbw = wfGetDB( DB_MASTER ); |
| 27 | + |
| 28 | + $affected = 0; |
| 29 | + foreach ( $this->mArgs as $revID ) { |
| 30 | + $dbw->insertSelect( 'archive', array( 'page', 'revision' ), |
| 31 | + array( |
| 32 | + 'ar_namespace' => 'page_namespace', |
| 33 | + 'ar_title' => 'page_title', |
| 34 | + 'ar_comment' => 'rev_comment', |
| 35 | + 'ar_user' => 'rev_user', |
| 36 | + 'ar_user_text' => 'rev_user_text', |
| 37 | + 'ar_timestamp' => 'rev_timestamp', |
| 38 | + 'ar_minor_edit' => 'rev_minor_edit', |
| 39 | + 'ar_rev_id' => 'rev_id', |
| 40 | + 'ar_text_id' => 'rev_text_id', |
| 41 | + ), array( |
| 42 | + 'rev_id' => $revID, |
| 43 | + 'page_id = rev_page' |
| 44 | + ), __METHOD__ |
| 45 | + ); |
| 46 | + if ( !$dbw->affectedRows() ) { |
| 47 | + $this->output( "Revision $revID not found\n" ); |
| 48 | + } else { |
| 49 | + $affected += $dbw->affectedRows(); |
| 50 | + $dbw->delete( 'revision', array( 'rev_id' => $revID ) ); |
| 51 | + } |
| 52 | + } |
| 53 | + $this->output( "Deleted $affected revisions\n" ); |
44 | 54 | } |
45 | 55 | } |
46 | 56 | |
47 | | -print "Deleted $affected revisions\n"; |
48 | | - |
| 57 | +$maintClass = "DeleteRevision"; |
| 58 | +require_once( DO_MAINTENANCE ); |
Index: branches/maintenance-work/maintenance/waitForSlave.php |
— | — | @@ -5,11 +5,16 @@ |
6 | 6 | * @ingroup Maintenance |
7 | 7 | */ |
8 | 8 | |
9 | | -require_once( "commandLine.inc" ); |
10 | | -if ( isset( $args[0] ) ) { |
11 | | - wfWaitForSlaves($args[0]); |
12 | | -} else { |
13 | | - wfWaitForSlaves(10); |
| 9 | +require_once( "Maintenance.php" ); |
| 10 | + |
| 11 | +class WaitForSlave extends Maintenance { |
| 12 | + public function __construct() { |
| 13 | + $this->addArgs( array( 'maxlag' ) ); |
| 14 | + } |
| 15 | + public function execute() { |
| 16 | + wfWaitForSlaves( $this->getArg( 0, 10 ) ); |
| 17 | + } |
14 | 18 | } |
15 | 19 | |
16 | | - |
| 20 | +$maintClass = "WaitForSlave"; |
| 21 | +require_once( DO_MAINTENANCE ); |