*/
protected function error( $err, $die = false ) {
$f = fopen( 'php://stderr', 'w' );
- fwrite( $f, $err );
+ fwrite( $f, $err . "\n" );
fclose( $f );
if( $die ) die();
}
require_once( $classFile );
}
if( !class_exists( $maintClass ) ) {
- $this->error( "Cannot spawn child: $maintClass\n" );
+ $this->error( "Cannot spawn child: $maintClass" );
}
}
# Abort if called from a web server
if ( isset( $_SERVER ) && array_key_exists( 'REQUEST_METHOD', $_SERVER ) ) {
- $this->error( "This script must be run from the command line\n", true );
+ $this->error( "This script must be run from the command line", true );
}
# Make sure we can handle script parameters
if( !ini_get( 'register_argc_argv' ) ) {
- $this->error( "Cannot get command line arguments, register_argc_argv is set to false\n", true );
+ $this->error( "Cannot get command line arguments, register_argc_argv is set to false", true );
}
if( version_compare( phpversion(), '5.2.4' ) >= 0 ) {
if ( isset( $this->mParams[$option] ) && $this->mParams[$option]['withArg'] ) {
$param = next( $argv );
if ( $param === false ) {
- $this->error( "$arg needs a value after it\n", true );
+ $this->error( "$arg needs a value after it", true );
}
$options[$option] = $param;
} else {
if ( $this->mParams[$option]['withArg'] ) {
$param = next( $argv );
if ( $param === false ) {
- $this->error( "$arg needs a value after it\n", true );
+ $this->error( "$arg needs a value after it", true );
}
$options[$option] = $param;
} else {
# Check to make sure we've got all the required ones
foreach( $this->mParams as $opt => $info ) {
if( $info['require'] && !$this->hasOption($opt) ) {
- $this->error( "Param $opt required.\n", true );
+ $this->error( "Param $opt required.", true );
}
}
# Also make sure we've got enough arguments
if ( count( $this->mArgs ) < count( $this->mArgList ) ) {
- $this->error( "Not enough arguments passed\n", true );
+ $this->error( "Not enough arguments passed", true );
}
}
if ( ! is_readable( $settingsFile ) ) {
$this->error( "A copy of your installation's LocalSettings.php\n" .
- "must exist and be readable in the source directory.\n", true );
+ "must exist and be readable in the source directory.", true );
}
$wgCommandLineMode = true;
$DP = $IP;
$dbName = $this->getArg(2);
if ( !isset( $wgLanguageNames[$lang] ) ) {
- $this->error( "Language $lang not found in \$wgLanguageNames\n", true );
+ $this->error( "Language $lang not found in \$wgLanguageNames", true );
}
$name = $wgLanguageNames[$lang];
public function execute() {
global $wgUseSquid;
if( !$wgUseSquid ) {
- $this->error( "Squid purge benchmark doesn't do much without squid support on.\n". true );
+ $this->error( "Squid purge benchmark doesn't do much without squid support on.". true );
} else {
$this->output( "There are " . count( $wgSquidServers ) . " defined squid servers:\n" );
if( $this->hasOption( 'count' ) ) {
public function execute() {
$user = User::newFromName( $this->getOption('user') );
if( !$user->getId() ) {
- $this->error( "No such user: " . $this->getOption('user') . "\n", true );
+ $this->error( "No such user: " . $this->getOption('user'), true );
}
try {
$user->setPassword( $this->getOption('password') );
$spec = $this->getArg();
$like = LinkFilter::makeLike( $spec );
if ( !$like ) {
- $this->error( "Not a valid hostname specification: $spec\n", true );
+ $this->error( "Not a valid hostname specification: $spec", true );
}
$dbr = wfGetDB( DB_SLAVE );
private function cleanupArticle( $id, $domain ) {
$title = Title::newFromID( $id );
if ( !$title ) {
- $this->error( "Internal error: no page for ID $id\n" );
+ $this->error( "Internal error: no page for ID $id" );
return;
}
$user = User::newFromName( $username );
if( !is_object( $user ) ) {
- $this->error( "invalid username.\n", true );
+ $this->error( "invalid username.", true );
} elseif( 0 != $user->idForName() ) {
- $this->error( "account exists.\n", true );
+ $this->error( "account exists.", true );
}
# Try to set the password
# Setup
if( !$file ) {
- $this->error( "Unable to read file, exiting\n", true );
+ $this->error( "Unable to read file, exiting", true );
}
$wgUser = User::newFromName( $user );
$dbw = wfGetDB( DB_MASTER );
public function execute() {
$this->output( "Delete old revisions\n\n" );
if( count( $this->mArgs ) < 1 ) {
- $this->error( "Must pass at least 1 page_id\n", true );
+ $this->error( "Must pass at least 1 page_id", true );
}
$this->doDelete( $this->hasOption( 'delete' ), $this->mArgs );
}
$wgUser = User::newFromName( $userName );
if ( !$wgUser ) {
- $this->error( "Invalid username\n", true );
+ $this->error( "Invalid username", true );
}
if ( $wgUser->isAnon() ) {
$wgUser->addToDatabase();
$wgTitle = Title::newFromText( $this->getArg() );
if ( !$wgTitle ) {
- $this->error( "Invalid title\n", true );
+ $this->error( "Invalid title", true );
}
$wgArticle = new Article( $wgTitle );
$row = $dbw->fetchObject( $res );
if ( is_null( $row->minrev ) ) {
- $this->error( "No revisions in search period.\n", true );
+ $this->error( "No revisions in search period.", true );
}
$minRev = $row->minrev;
was incorrectly set forward, negative means the clock was incorrectly set back.
If the offset is right, then increase the search interval until there are enough
- good revisions to provide a majority reference.
- ", true );
+ good revisions to provide a majority reference.", true );
} elseif ( $numBadRevs == 0 ) {
$this->output( "No bad revisions found.\n" );
exit(0);
if( $lb->getServerCount() == 1 ) {
$this->error( "This script dumps replication lag times, but you don't seem to have\n"
- . "a multi-host db server configuration.\n" );
+ . "a multi-host db server configuration." );
} else {
$lags = $lb->getLagTimes();
foreach( $lags as $n => $lag ) {
# Setup
if( !$file ) {
- $this->error( "Unable to read file, exiting\n", true );
+ $this->error( "Unable to read file, exiting", true );
}
$wgUser = User::newFromName( $user );
}
$parts = array_map( 'trim', explode( '|', $line ) );
if ( count( $parts ) != 2 ) {
- $this->error( "Error on line $linenum, no pipe character\n" );
+ $this->error( "Error on line $linenum, no pipe character" );
continue;
}
$source = Title::newFromText( $parts[0] );
$dest = Title::newFromText( $parts[1] );
if ( is_null( $source ) || is_null( $dest ) ) {
- $this->error( "Invalid title on line $linenum\n" );
+ $this->error( "Invalid title on line $linenum" );
continue;
}
public function execute() {
$db = wfGetDB( DB_MASTER );
if ( !$db->tableExists( 'log_search' ) ) {
- $this->error( "log_search does not exist\n", true );
+ $this->error( "log_search does not exist", true );
}
$start = $db->selectField( 'logging', 'MIN(log_id)', false, __FUNCTION__ );
if( !$start ) {
public function execute() {
$db = wfGetDB( DB_MASTER );
if ( !$db->tableExists( 'revision' ) ) {
- $this->error( "revision table does not exist\n", true );
+ $this->error( "revision table does not exist", true );
}
$this->output( "Populating rev_parent_id column\n" );
$start = $db->selectField( 'revision', 'MIN(rev_id)', false, __FUNCTION__ );
$wgUser = User::newFromName( $userName );
$restrictions = array( 'edit' => $protection, 'move' => $protection );
- $wgTitle = Title::newFromText( $args[0] );
+ $wgTitle = Title::newFromText( $this->getArg() );
if ( !$wgTitle ) {
- $this->error( "Invalid title\n", true );
+ $this->error( "Invalid title", true );
}
$wgArticle = new Article( $wgTitle );
$this->output( "Run the script again without --report to update.\n" );
} else {
$ton = $to->getName();
- $this->error( "User '{$ton}' not found.\n" );
+ $this->error( "User '{$ton}' not found." );
}
}
}
public function execute() {
global $wgUseFileCache, $wgDisableCounters, $wgTitle, $wgArticle, $wgOut;
if( !$wgUseFileCache ) {
- $this->error( "Nothing to do -- \$wgUseFileCache is disabled.\n", true );
+ $this->error( "Nothing to do -- \$wgUseFileCache is disabled.", true );
}
$wgDisableCounters = false;
$start = intval( $this->getArg( 0, 0 ) );
$start = $start > 0 ? $start : $dbr->selectField( 'page', 'MIN(page_id)', false, __FUNCTION__ );
$end = $dbr->selectField( 'page', 'MAX(page_id)', false, __FUNCTION__ );
if( !$start ) {
- $this->error( "Nothing to do.\n", true );
+ $this->error( "Nothing to do.", true );
}
$_SERVER['HTTP_ACCEPT_ENCODING'] = 'bgzip'; // hack, no real client
// Only do this for MySQL
$database = wfGetDB( DB_MASTER );
if( !$database instanceof DatabaseMysql ) {
- $this->error( "This script is only for MySQL.\n", true );
+ $this->error( "This script is only for MySQL.", true );
}
$wgTitle = Title::newFromText( "Rebuild text index script" );
}
$touched = $this->getOption( 'ignore-touched', "1" );
if( !ctype_digit( $touched ) ) {
- $this->error( "Please put a valid positive integer on the --ignore-touched parameter.\n", true );
+ $this->error( "Please put a valid positive integer on the --ignore-touched parameter.", true );
}
$touchedSeconds = 86400 * $touched;
while( $row = $dbr->fetchObject( $res ) ) {
}
if( $old === false || $new === false ) {
- $this->error( "Invalid prefix!\n", true );
+ $this->error( "Invalid prefix!", true );
}
if( $old === $new ) {
$this->output( "Same prefix. Nothing to rename!\n", true );
if ( $this->hasOption( 'procs' ) ) {
$procs = intval( $this->getOption('procs') );
if ( $procs < 1 || $procs > 1000 ) {
- $this->error( "Invalid argument to --procs\n", true );
+ $this->error( "Invalid argument to --procs", true );
}
$fc = new ForkController( $procs );
if ( $fc->start( $procs ) != 'child' ) {
}
if ( !$file )
- $this->error( "Unable to open input file\n", true );
+ $this->error( "Unable to open input file", true );
$dbw = wfGetDB( DB_MASTER );
$error = $dbw->sourceStream( $file, $promptCallback, array( $this, 'sqlPrintResult' ) );
// Can't do stats if
if( get_class( $wgMemc ) == 'FakeMemCachedClient' ) {
- $this->error( "You are running FakeMemCachedClient, I can not provide any statistics.\n", true );
+ $this->error( "You are running FakeMemCachedClient, I can not provide any statistics.", true );
}
$session = intval($wgMemc->get(wfMemcKey('stats','request_with_session')));
$noSession = intval($wgMemc->get(wfMemcKey('stats','request_without_session')));
$total = $session + $noSession;
if ( $total == 0 ) {
- $this->error( "You either have no stats or the cache isn't running. Aborting.\n", true );
+ $this->error( "You either have no stats or the cache isn't running. Aborting.", true );
}
$this->output( "Requests\n" );
$this->output( sprintf( "with session: %-10d %6.2f%%\n", $session, $session/$total*100 ) );
public function execute() {
$db = wfGetDB( DB_MASTER );
if( !$db->tableExists( 'page_restrictions' ) ) {
- $this->error( "page_restrictions table does not exist\n", true );
+ $this->error( "page_restrictions table does not exist", true );
}
$start = $db->selectField( 'page', 'MIN(page_id)', false, __METHOD__ );
if( !$start ) {
- $this->error( "Nothing to do.\n", true );
+ $this->error( "Nothing to do.", true );
}
$end = $db->selectField( 'page', 'MAX(page_id)', false, __METHOD__ );
foreach( $wgSpecialPageCacheUpdates as $special => $call ) {
if( !is_callable($call) ) {
- $this->error( "Uncallable function $call!\n" );
+ $this->error( "Uncallable function $call!" );
continue;
}
$t1 = explode( ' ', microtime() );
if ( !wfGetLB()->pingAll()) {
$this->output( "\n" );
do {
- $this->error( "Connection failed, reconnecting in 10 seconds...\n" );
+ $this->error( "Connection failed, reconnecting in 10 seconds..." );
sleep(10);
} while ( !wfGetLB()->pingAll() );
$this->output( "Reconnected\n\n" );