r51780 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51779‎ | r51780 | r51781 >
Date:03:25, 12 June 2009
Author:demon
Status:deferred
Tags:
Comment:
* Port checkUsernames, deleteRevision and waitForSlave
* Prettify help some more
* Add similar has/get for args.
Modified paths:
  • /branches/maintenance-work/maintenance/Maintenance.php (modified) (history)
  • /branches/maintenance-work/maintenance/checkUsernames.php (modified) (history)
  • /branches/maintenance-work/maintenance/deleteRevision.php (modified) (history)
  • /branches/maintenance-work/maintenance/waitForSlave.php (modified) (history)

Diff [purge]

Index: branches/maintenance-work/maintenance/Maintenance.php
@@ -85,12 +85,29 @@
8686 * Add some args that are needed. Used in formatting help
8787 */
8888 protected function addArgs( $args ) {
89 - foreach( $args as $arg ) {
90 - $this->mArgList[] = $arg;
91 - }
 89+ $this->mArgList = array_merge( $this->mArgList, $args );
9290 }
 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+ }
93100
94101 /**
 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+ /**
95112 * Return input from stdin.
96113 * @param $length int The number of bytes to read
97114 * @return mixed
@@ -305,8 +322,10 @@
306323 if( $this->mDescription ) {
307324 $this->output( $this->mDescription . "\n" );
308325 }
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+ }
311330 if( $this->mArgList ) {
312331 $this->output( " <" . implode( $this->mArgList, "> <" ) . ">" );
313332 }
Index: branches/maintenance-work/maintenance/checkUsernames.php
@@ -7,36 +7,33 @@
88 * @ingroup Maintenance
99 */
1010
11 -error_reporting(E_ALL ^ E_NOTICE);
12 -require_once 'commandLine.inc';
1311
14 -class checkUsernames {
15 - var $stderr, $log;
 12+require_once( "Maintenance.php" );
1613
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";
1919 }
20 - function main() {
21 - $fname = 'checkUsernames::main';
2220
 21+ function execute() {
2322 $dbr = wfGetDB( DB_SLAVE );
2423
2524 $res = $dbr->select( 'user',
2625 array( 'user_id', 'user_name' ),
2726 null,
28 - $fname
 27+ __METHOD__
2928 );
3029
3130 while ( $row = $dbr->fetchObject( $res ) ) {
3231 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 ) );
3533 wfDebugLog( 'checkUsernames', $out );
3634 }
3735 }
3836 }
3937 }
4038
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 @@
77 * @ingroup Maintenance
88 */
99
10 -require_once( 'commandLine.inc' );
 10+require_once( "Maintenance.php" );
1111
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+ }
1323
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" );
4454 }
4555 }
4656
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 @@
66 * @ingroup Maintenance
77 */
88
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+ }
1418 }
1519
16 -
 20+$maintClass = "WaitForSlave";
 21+require_once( DO_MAINTENANCE );

Status & tagging log