r54240 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54239‎ | r54240 | r54241 >
Date:21:55, 2 August 2009
Author:demon
Status:ok (Comments)
Tags:
Comment:
Don't put \n on the end of every error() call, just do it in error() itself. Still have to use on output(), because people like "Something...done" stuff.
Modified paths:
  • /trunk/phase3/maintenance/Maintenance.php (modified) (history)
  • /trunk/phase3/maintenance/addwiki.php (modified) (history)
  • /trunk/phase3/maintenance/benchmarkPurge.php (modified) (history)
  • /trunk/phase3/maintenance/changePassword.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/deleteOldRevisions.php (modified) (history)
  • /trunk/phase3/maintenance/edit.php (modified) (history)
  • /trunk/phase3/maintenance/fixTimestamps.php (modified) (history)
  • /trunk/phase3/maintenance/getLagTimes.php (modified) (history)
  • /trunk/phase3/maintenance/moveBatch.php (modified) (history)
  • /trunk/phase3/maintenance/populateLogSearch.php (modified) (history)
  • /trunk/phase3/maintenance/populateParentId.php (modified) (history)
  • /trunk/phase3/maintenance/protect.php (modified) (history)
  • /trunk/phase3/maintenance/reassignEdits.php (modified) (history)
  • /trunk/phase3/maintenance/rebuildFileCache.php (modified) (history)
  • /trunk/phase3/maintenance/rebuildtextindex.php (modified) (history)
  • /trunk/phase3/maintenance/removeUnusedAccounts.php (modified) (history)
  • /trunk/phase3/maintenance/renameDbPrefix.php (modified) (history)
  • /trunk/phase3/maintenance/runJobs.php (modified) (history)
  • /trunk/phase3/maintenance/sql.php (modified) (history)
  • /trunk/phase3/maintenance/stats.php (modified) (history)
  • /trunk/phase3/maintenance/updateRestrictions.php (modified) (history)
  • /trunk/phase3/maintenance/updateSpecialPages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/updateRestrictions.php
@@ -35,12 +35,12 @@
3636 public function execute() {
3737 $db = wfGetDB( DB_MASTER );
3838 if( !$db->tableExists( 'page_restrictions' ) ) {
39 - $this->error( "page_restrictions table does not exist\n", true );
 39+ $this->error( "page_restrictions table does not exist", true );
4040 }
4141
4242 $start = $db->selectField( 'page', 'MIN(page_id)', false, __METHOD__ );
4343 if( !$start ) {
44 - $this->error( "Nothing to do.\n", true );
 44+ $this->error( "Nothing to do.", true );
4545 }
4646 $end = $db->selectField( 'page', 'MAX(page_id)', false, __METHOD__ );
4747
Index: trunk/phase3/maintenance/deleteOldRevisions.php
@@ -34,7 +34,7 @@
3535 public function execute() {
3636 $this->output( "Delete old revisions\n\n" );
3737 if( count( $this->mArgs ) < 1 ) {
38 - $this->error( "Must pass at least 1 page_id\n", true );
 38+ $this->error( "Must pass at least 1 page_id", true );
3939 }
4040 $this->doDelete( $this->hasOption( 'delete' ), $this->mArgs );
4141 }
Index: trunk/phase3/maintenance/protect.php
@@ -46,9 +46,9 @@
4747 $wgUser = User::newFromName( $userName );
4848 $restrictions = array( 'edit' => $protection, 'move' => $protection );
4949
50 - $wgTitle = Title::newFromText( $args[0] );
 50+ $wgTitle = Title::newFromText( $this->getArg() );
5151 if ( !$wgTitle ) {
52 - $this->error( "Invalid title\n", true );
 52+ $this->error( "Invalid title", true );
5353 }
5454
5555 $wgArticle = new Article( $wgTitle );
Index: trunk/phase3/maintenance/removeUnusedAccounts.php
@@ -48,7 +48,7 @@
4949 }
5050 $touched = $this->getOption( 'ignore-touched', "1" );
5151 if( !ctype_digit( $touched ) ) {
52 - $this->error( "Please put a valid positive integer on the --ignore-touched parameter.\n", true );
 52+ $this->error( "Please put a valid positive integer on the --ignore-touched parameter.", true );
5353 }
5454 $touchedSeconds = 86400 * $touched;
5555 while( $row = $dbr->fetchObject( $res ) ) {
Index: trunk/phase3/maintenance/edit.php
@@ -47,7 +47,7 @@
4848
4949 $wgUser = User::newFromName( $userName );
5050 if ( !$wgUser ) {
51 - $this->error( "Invalid username\n", true );
 51+ $this->error( "Invalid username", true );
5252 }
5353 if ( $wgUser->isAnon() ) {
5454 $wgUser->addToDatabase();
@@ -55,7 +55,7 @@
5656
5757 $wgTitle = Title::newFromText( $this->getArg() );
5858 if ( !$wgTitle ) {
59 - $this->error( "Invalid title\n", true );
 59+ $this->error( "Invalid title", true );
6060 }
6161
6262 $wgArticle = new Article( $wgTitle );
Index: trunk/phase3/maintenance/fixTimestamps.php
@@ -47,7 +47,7 @@
4848 $row = $dbw->fetchObject( $res );
4949
5050 if ( is_null( $row->minrev ) ) {
51 - $this->error( "No revisions in search period.\n", true );
 51+ $this->error( "No revisions in search period.", true );
5252 }
5353
5454 $minRev = $row->minrev;
@@ -98,8 +98,7 @@
9999 was incorrectly set forward, negative means the clock was incorrectly set back.
100100
101101 If the offset is right, then increase the search interval until there are enough
102 - good revisions to provide a majority reference.
103 - ", true );
 102+ good revisions to provide a majority reference.", true );
104103 } elseif ( $numBadRevs == 0 ) {
105104 $this->output( "No bad revisions found.\n" );
106105 exit(0);
Index: trunk/phase3/maintenance/reassignEdits.php
@@ -50,7 +50,7 @@
5151 $this->output( "Run the script again without --report to update.\n" );
5252 } else {
5353 $ton = $to->getName();
54 - $this->error( "User '{$ton}' not found.\n" );
 54+ $this->error( "User '{$ton}' not found." );
5555 }
5656 }
5757 }
Index: trunk/phase3/maintenance/getLagTimes.php
@@ -31,7 +31,7 @@
3232
3333 if( $lb->getServerCount() == 1 ) {
3434 $this->error( "This script dumps replication lag times, but you don't seem to have\n"
35 - . "a multi-host db server configuration.\n" );
 35+ . "a multi-host db server configuration." );
3636 } else {
3737 $lags = $lb->getLagTimes();
3838 foreach( $lags as $n => $lag ) {
Index: trunk/phase3/maintenance/populateParentId.php
@@ -34,7 +34,7 @@
3535 public function execute() {
3636 $db = wfGetDB( DB_MASTER );
3737 if ( !$db->tableExists( 'revision' ) ) {
38 - $this->error( "revision table does not exist\n", true );
 38+ $this->error( "revision table does not exist", true );
3939 }
4040 $this->output( "Populating rev_parent_id column\n" );
4141 $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __FUNCTION__ );
Index: trunk/phase3/maintenance/populateLogSearch.php
@@ -35,7 +35,7 @@
3636 public function execute() {
3737 $db = wfGetDB( DB_MASTER );
3838 if ( !$db->tableExists( 'log_search' ) ) {
39 - $this->error( "log_search does not exist\n", true );
 39+ $this->error( "log_search does not exist", true );
4040 }
4141 $start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ );
4242 if( !$start ) {
Index: trunk/phase3/maintenance/createAndPromote.php
@@ -41,9 +41,9 @@
4242
4343 $user = User::newFromName( $username );
4444 if( !is_object( $user ) ) {
45 - $this->error( "invalid username.\n", true );
 45+ $this->error( "invalid username.", true );
4646 } elseif( 0 != $user->idForName() ) {
47 - $this->error( "account exists.\n", true );
 47+ $this->error( "account exists.", true );
4848 }
4949
5050 # Try to set the password
Index: trunk/phase3/maintenance/deleteBatch.php
@@ -59,7 +59,7 @@
6060
6161 # Setup
6262 if( !$file ) {
63 - $this->error( "Unable to read file, exiting\n", true );
 63+ $this->error( "Unable to read file, exiting", true );
6464 }
6565 $wgUser = User::newFromName( $user );
6666 $dbw = wfGetDB( DB_MASTER );
Index: trunk/phase3/maintenance/runJobs.php
@@ -42,7 +42,7 @@
4343 if ( $this->hasOption( 'procs' ) ) {
4444 $procs = intval( $this->getOption('procs') );
4545 if ( $procs < 1 || $procs > 1000 ) {
46 - $this->error( "Invalid argument to --procs\n", true );
 46+ $this->error( "Invalid argument to --procs", true );
4747 }
4848 $fc = new ForkController( $procs );
4949 if ( $fc->start( $procs ) != 'child' ) {
Index: trunk/phase3/maintenance/changePassword.php
@@ -36,7 +36,7 @@
3737 public function execute() {
3838 $user = User::newFromName( $this->getOption('user') );
3939 if( !$user->getId() ) {
40 - $this->error( "No such user: " . $this->getOption('user') . "\n", true );
 40+ $this->error( "No such user: " . $this->getOption('user'), true );
4141 }
4242 try {
4343 $user->setPassword( $this->getOption('password') );
Index: trunk/phase3/maintenance/addwiki.php
@@ -39,7 +39,7 @@
4040 $dbName = $this->getArg(2);
4141
4242 if ( !isset( $wgLanguageNames[$lang] ) ) {
43 - $this->error( "Language $lang not found in \$wgLanguageNames\n", true );
 43+ $this->error( "Language $lang not found in \$wgLanguageNames", true );
4444 }
4545 $name = $wgLanguageNames[$lang];
4646
Index: trunk/phase3/maintenance/Maintenance.php
@@ -218,7 +218,7 @@
219219 */
220220 protected function error( $err, $die = false ) {
221221 $f = fopen( 'php://stderr', 'w' );
222 - fwrite( $f, $err );
 222+ fwrite( $f, $err . "\n" );
223223 fclose( $f );
224224 if( $die ) die();
225225 }
@@ -278,7 +278,7 @@
279279 require_once( $classFile );
280280 }
281281 if( !class_exists( $maintClass ) ) {
282 - $this->error( "Cannot spawn child: $maintClass\n" );
 282+ $this->error( "Cannot spawn child: $maintClass" );
283283 }
284284 }
285285
@@ -295,12 +295,12 @@
296296
297297 # Abort if called from a web server
298298 if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
299 - $this->error( "This script must be run from the command line\n", true );
 299+ $this->error( "This script must be run from the command line", true );
300300 }
301301
302302 # Make sure we can handle script parameters
303303 if( !ini_get( 'register_argc_argv' ) ) {
304 - $this->error( "Cannot get command line arguments, register_argc_argv is set to false\n", true );
 304+ $this->error( "Cannot get command line arguments, register_argc_argv is set to false", true );
305305 }
306306
307307 if( version_compare( phpversion(), '5.2.4' ) >= 0 ) {
@@ -407,7 +407,7 @@
408408 if ( isset( $this->mParams[$option] ) && $this->mParams[$option]['withArg'] ) {
409409 $param = next( $argv );
410410 if ( $param === false ) {
411 - $this->error( "$arg needs a value after it\n", true );
 411+ $this->error( "$arg needs a value after it", true );
412412 }
413413 $options[$option] = $param;
414414 } else {
@@ -427,7 +427,7 @@
428428 if ( $this->mParams[$option]['withArg'] ) {
429429 $param = next( $argv );
430430 if ( $param === false ) {
431 - $this->error( "$arg needs a value after it\n", true );
 431+ $this->error( "$arg needs a value after it", true );
432432 }
433433 $options[$option] = $param;
434434 } else {
@@ -452,13 +452,13 @@
453453 # Check to make sure we've got all the required ones
454454 foreach( $this->mParams as $opt => $info ) {
455455 if( $info['require'] && !$this->hasOption($opt) ) {
456 - $this->error( "Param $opt required.\n", true );
 456+ $this->error( "Param $opt required.", true );
457457 }
458458 }
459459
460460 # Also make sure we've got enough arguments
461461 if ( count( $this->mArgs ) < count( $this->mArgList ) ) {
462 - $this->error( "Not enough arguments passed\n", true );
 462+ $this->error( "Not enough arguments passed", true );
463463 }
464464 }
465465
@@ -633,7 +633,7 @@
634634
635635 if ( ! is_readable( $settingsFile ) ) {
636636 $this->error( "A copy of your installation's LocalSettings.php\n" .
637 - "must exist and be readable in the source directory.\n", true );
 637+ "must exist and be readable in the source directory.", true );
638638 }
639639 $wgCommandLineMode = true;
640640 $DP = $IP;
Index: trunk/phase3/maintenance/rebuildtextindex.php
@@ -42,7 +42,7 @@
4343 // Only do this for MySQL
4444 $database = wfGetDB( DB_MASTER );
4545 if( !$database instanceof DatabaseMysql ) {
46 - $this->error( "This script is only for MySQL.\n", true );
 46+ $this->error( "This script is only for MySQL.", true );
4747 }
4848
4949 $wgTitle = Title::newFromText( "Rebuild text index script" );
Index: trunk/phase3/maintenance/stats.php
@@ -33,13 +33,13 @@
3434
3535 // Can't do stats if
3636 if( get_class( $wgMemc ) == 'FakeMemCachedClient' ) {
37 - $this->error( "You are running FakeMemCachedClient, I can not provide any statistics.\n", true );
 37+ $this->error( "You are running FakeMemCachedClient, I can not provide any statistics.", true );
3838 }
3939 $session = intval($wgMemc->get(wfMemcKey('stats','request_with_session')));
4040 $noSession = intval($wgMemc->get(wfMemcKey('stats','request_without_session')));
4141 $total = $session + $noSession;
4242 if ( $total == 0 ) {
43 - $this->error( "You either have no stats or the cache isn't running. Aborting.\n", true );
 43+ $this->error( "You either have no stats or the cache isn't running. Aborting.", true );
4444 }
4545 $this->output( "Requests\n" );
4646 $this->output( sprintf( "with session: %-10d %6.2f%%\n", $session, $session/$total*100 ) );
Index: trunk/phase3/maintenance/updateSpecialPages.php
@@ -38,7 +38,7 @@
3939
4040 foreach( $wgSpecialPageCacheUpdates as $special => $call ) {
4141 if( !is_callable($call) ) {
42 - $this->error( "Uncallable function $call!\n" );
 42+ $this->error( "Uncallable function $call!" );
4343 continue;
4444 }
4545 $t1 = explode( ' ', microtime() );
@@ -113,7 +113,7 @@
114114 if ( !wfGetLB()->pingAll()) {
115115 $this->output( "\n" );
116116 do {
117 - $this->error( "Connection failed, reconnecting in 10 seconds...\n" );
 117+ $this->error( "Connection failed, reconnecting in 10 seconds..." );
118118 sleep(10);
119119 } while ( !wfGetLB()->pingAll() );
120120 $this->output( "Reconnected\n\n" );
Index: trunk/phase3/maintenance/cleanupSpam.php
@@ -42,7 +42,7 @@
4343 $spec = $this->getArg();
4444 $like = LinkFilter::makeLike( $spec );
4545 if ( !$like ) {
46 - $this->error( "Not a valid hostname specification: $spec\n", true );
 46+ $this->error( "Not a valid hostname specification: $spec", true );
4747 }
4848
4949 $dbr = wfGetDB( DB_SLAVE );
@@ -83,7 +83,7 @@
8484 private function cleanupArticle( $id, $domain ) {
8585 $title = Title::newFromID( $id );
8686 if ( !$title ) {
87 - $this->error( "Internal error: no page for ID $id\n" );
 87+ $this->error( "Internal error: no page for ID $id" );
8888 return;
8989 }
9090
Index: trunk/phase3/maintenance/moveBatch.php
@@ -64,7 +64,7 @@
6565
6666 # Setup
6767 if( !$file ) {
68 - $this->error( "Unable to read file, exiting\n", true );
 68+ $this->error( "Unable to read file, exiting", true );
6969 }
7070 $wgUser = User::newFromName( $user );
7171
@@ -77,13 +77,13 @@
7878 }
7979 $parts = array_map( 'trim', explode( '|', $line ) );
8080 if ( count( $parts ) != 2 ) {
81 - $this->error( "Error on line $linenum, no pipe character\n" );
 81+ $this->error( "Error on line $linenum, no pipe character" );
8282 continue;
8383 }
8484 $source = Title::newFromText( $parts[0] );
8585 $dest = Title::newFromText( $parts[1] );
8686 if ( is_null( $source ) || is_null( $dest ) ) {
87 - $this->error( "Invalid title on line $linenum\n" );
 87+ $this->error( "Invalid title on line $linenum" );
8888 continue;
8989 }
9090
Index: trunk/phase3/maintenance/renameDbPrefix.php
@@ -49,7 +49,7 @@
5050 }
5151
5252 if( $old === false || $new === false ) {
53 - $this->error( "Invalid prefix!\n", true );
 53+ $this->error( "Invalid prefix!", true );
5454 }
5555 if( $old === $new ) {
5656 $this->output( "Same prefix. Nothing to rename!\n", true );
Index: trunk/phase3/maintenance/benchmarkPurge.php
@@ -33,7 +33,7 @@
3434 public function execute() {
3535 global $wgUseSquid;
3636 if( !$wgUseSquid ) {
37 - $this->error( "Squid purge benchmark doesn't do much without squid support on.\n". true );
 37+ $this->error( "Squid purge benchmark doesn't do much without squid support on.". true );
3838 } else {
3939 $this->output( "There are " . count( $wgSquidServers ) . " defined squid servers:\n" );
4040 if( $this->hasOption( 'count' ) ) {
Index: trunk/phase3/maintenance/sql.php
@@ -41,7 +41,7 @@
4242 }
4343
4444 if ( !$file )
45 - $this->error( "Unable to open input file\n", true );
 45+ $this->error( "Unable to open input file", true );
4646
4747 $dbw = wfGetDB( DB_MASTER );
4848 $error = $dbw->sourceStream( $file, $promptCallback, array( $this, 'sqlPrintResult' ) );
Index: trunk/phase3/maintenance/rebuildFileCache.php
@@ -33,7 +33,7 @@
3434 public function execute() {
3535 global $wgUseFileCache, $wgDisableCounters, $wgTitle, $wgArticle, $wgOut;
3636 if( !$wgUseFileCache ) {
37 - $this->error( "Nothing to do -- \$wgUseFileCache is disabled.\n", true );
 37+ $this->error( "Nothing to do -- \$wgUseFileCache is disabled.", true );
3838 }
3939 $wgDisableCounters = false;
4040 $start = intval( $this->getArg( 0, 0 ) );
@@ -44,7 +44,7 @@
4545 $start = $start > 0 ? $start : $dbr->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ );
4646 $end = $dbr->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ );
4747 if( !$start ) {
48 - $this->error( "Nothing to do.\n", true );
 48+ $this->error( "Nothing to do.", true );
4949 }
5050
5151 $_SERVER['HTTP_ACCEPT_ENCODING'] = 'bgzip'; // hack, no real client

Comments

#Comment by Nikerabbit (talk | contribs)   08:49, 3 August 2009

I like my "channel" based method, which allows continuation by giving the same channel id, while automatically adding newlines when channel changes. This way you can get error messages nicely on their own line. See the code.

Can someone fix the link parser?

Status & tagging log