# Done
$dbw->commit( __METHOD__ );
-
}
$this->addDescription( "Remove old objects from the parser cache. " .
"This only works when the parser cache is in an SQL database." );
$this->addOption( 'expiredate', 'Delete objects expiring before this date.', false, true );
- $this->addOption( 'age',
+ $this->addOption(
+ 'age',
'Delete objects created more than this many seconds ago, assuming $wgParserCacheExpireTime ' .
'has been consistent.',
false, true );
$stars = floor( $percent / 2 );
$this->output( '[' . str_repeat( '*', $stars ) . str_repeat( '.', 50 - $stars ) . '] ' .
"$percentString%\r" );
-
}
}
+
$maintClass = 'PurgeParserCache';
require_once RUN_MAINTENANCE_IF_MAIN;
}
$dbw->commit( __METHOD__ );
+
return (int)$total;
}
}
}
$user->load();
+
return $user;
}
}
if ( !isset( $this->repo ) ) {
$this->repo = RepoGroup::singleton()->getLocalRepo();
}
+
return $this->repo;
}
// Create a File object from the row
// This will also upgrade it
$file = $this->getRepo()->newFileFromRow( $row );
+
return $file->getUpgraded();
}
// This will also upgrade it
if ( $row->oi_archive_name == '' ) {
$this->output( "Empty oi_archive_name for oi_name={$row->oi_name}\n" );
+
return false;
}
$file = $this->getRepo()->newFileFromRow( $row );
+
return $file->getUpgraded();
}
if ( $filename == '' ) {
$this->output( "Empty filename for $fullpath\n" );
+
return;
}
if ( !$this->dryrun ) {
$file = wfLocalFile( $filename );
if ( !$file->recordUpload(
- '',
- '(recovered file, missing upload log entry)',
- '',
- '',
- '',
- false,
- $timestamp
- )
- ) {
+ '',
+ '(recovered file, missing upload log entry)',
+ '',
+ '',
+ '',
+ false,
+ $timestamp
+ ) ) {
$this->output( "Error uploading file $fullpath\n" );
+
return;
}
}
if ( $this->hasOption( 'memory-limit' ) ) {
return parent::memoryLimit();
}
+
return '1000M';
}
/**
* Helper function to rebuild list of languages codes. Prints the code
* for each language which is rebuilt.
- * @param array $codes List of language codes to rebuild.
+ * @param array $codes List of language codes to rebuild.
* @param LocalisationCache $lc Instance of LocalisationCacheBulkLoad (?)
* @param bool $force Rebuild up-to-date languages
* @return int Number of rebuilt languages
$numRebuilt++;
}
}
+
return $numRebuilt;
}
$cutoff = time() - $wgRCMaxAge;
$dbw->insertSelect( 'recentchanges', array( 'page', 'revision' ),
array(
- 'rc_timestamp' => 'rev_timestamp',
- 'rc_user' => 'rev_user',
- 'rc_user_text' => 'rev_user_text',
- 'rc_namespace' => 'page_namespace',
- 'rc_title' => 'page_title',
- 'rc_comment' => 'rev_comment',
- 'rc_minor' => 'rev_minor_edit',
- 'rc_bot' => 0,
- 'rc_new' => 'page_is_new',
- 'rc_cur_id' => 'page_id',
+ 'rc_timestamp' => 'rev_timestamp',
+ 'rc_user' => 'rev_user',
+ 'rc_user_text' => 'rev_user_text',
+ 'rc_namespace' => 'page_namespace',
+ 'rc_title' => 'page_title',
+ 'rc_comment' => 'rev_comment',
+ 'rc_minor' => 'rev_minor_edit',
+ 'rc_bot' => 0,
+ 'rc_new' => 'page_is_new',
+ 'rc_cur_id' => 'page_id',
'rc_this_oldid' => 'rev_id',
'rc_last_oldid' => 0, // is this ok?
- 'rc_type' => $dbw->conditional( 'page_is_new != 0', RC_NEW, RC_EDIT ),
- 'rc_source' => $dbw->conditional(
- 'page_is_new != 0',
- $dbw->addQuotes( RecentChange::SRC_NEW ),
- $dbw->addQuotes( RecentChange::SRC_EDIT )
+ 'rc_type' => $dbw->conditional( 'page_is_new != 0', RC_NEW, RC_EDIT ),
+ 'rc_source' => $dbw->conditional(
+ 'page_is_new != 0',
+ $dbw->addQuotes( RecentChange::SRC_NEW ),
+ $dbw->addQuotes( RecentChange::SRC_EDIT )
),
- 'rc_deleted' => 'rev_deleted'
- ), array(
+ 'rc_deleted' => 'rev_deleted'
+ ),
+ array(
'rev_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $cutoff ) ),
'rev_page=page_id'
- ), __METHOD__,
+ ),
+ __METHOD__,
array(), // INSERT options
array( 'ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => 5000 ) // SELECT options
);
"$logging LEFT JOIN $page ON (log_namespace=page_namespace AND log_title=page_title)"
),
array(
- 'rc_timestamp' => 'log_timestamp',
- 'rc_user' => 'log_user',
- 'rc_user_text' => 'user_name',
- 'rc_namespace' => 'log_namespace',
- 'rc_title' => 'log_title',
- 'rc_comment' => 'log_comment',
- 'rc_minor' => 0,
- 'rc_bot' => 0,
- 'rc_patrolled' => 1,
- 'rc_new' => 0,
+ 'rc_timestamp' => 'log_timestamp',
+ 'rc_user' => 'log_user',
+ 'rc_user_text' => 'user_name',
+ 'rc_namespace' => 'log_namespace',
+ 'rc_title' => 'log_title',
+ 'rc_comment' => 'log_comment',
+ 'rc_minor' => 0,
+ 'rc_bot' => 0,
+ 'rc_patrolled' => 1,
+ 'rc_new' => 0,
'rc_this_oldid' => 0,
'rc_last_oldid' => 0,
- 'rc_type' => RC_LOG,
- 'rc_source' => $dbw->addQuotes( RecentChange::SRC_LOG ),
- 'rc_cur_id' => $dbw->cascadingDeletes() ? 'page_id' : 'COALESCE(page_id, 0)',
- 'rc_log_type' => 'log_type',
+ 'rc_type' => RC_LOG,
+ 'rc_source' => $dbw->addQuotes( RecentChange::SRC_LOG ),
+ 'rc_cur_id' => $dbw->cascadingDeletes() ? 'page_id' : 'COALESCE(page_id, 0)',
+ 'rc_log_type' => 'log_type',
'rc_log_action' => 'log_action',
- 'rc_logid' => 'log_id',
- 'rc_params' => 'log_params',
- 'rc_deleted' => 'log_deleted'
- ), array(
+ 'rc_logid' => 'log_id',
+ 'rc_params' => 'log_params',
+ 'rc_deleted' => 'log_deleted'
+ ),
+ array(
'log_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $cutoff ) ),
'log_user=user_id',
'log_type IN(' . implode( ',', $selectLogs ) . ')'
- ), __METHOD__,
+ ),
+ __METHOD__,
array(), // INSERT options
array( 'ORDER BY' => 'log_timestamp DESC', 'LIMIT' => 5000 ) // SELECT options
);
$messageMemc->delete( wfMemcKey( 'rcfeed', $feed, 'timestamp' ) ); # Good enough for now.
}
}
-
}
$maintClass = "RebuildRecentchanges";
false,
true
);
-
}
public function execute() {
// to weed out any inconsequential changes.
$error++;
$this->output( "Warning: File:{$row->img_name} used to have " .
- "$oldLength bytes of metadata but now has $newLength bytes.\n" );
+ "$oldLength bytes of metadata but now has $newLength bytes.\n" );
} elseif ( $verbose ) {
$this->output( "Refreshed File:{$row->img_name}.\n" );
}
if ( $newLength < $oldLength - 5 ) {
$error++;
$this->output( "Warning: File:{$row->img_name} used to have " .
- "$oldLength bytes of metadata but now has $newLength bytes. (forced)\n" );
-
+ "$oldLength bytes of metadata but now has $newLength bytes. (forced)\n" );
}
if ( $verbose ) {
$this->output( "Forcibly refreshed File:{$row->img_name}.\n" );
}
- }
- else {
+ } else {
if ( $verbose ) {
$this->output( "Skipping File:{$row->img_name}.\n" );
}
}
}
-
}
$conds2 = array( 'img_name > ' . $dbw->addQuotes( $row->img_name ) );
wfWaitForSlaves();
if ( $like ) {
$conds[] = 'img_metadata ' . $dbw->buildLike( $dbw->anyString(), $like, $dbw->anyString() );
}
+
return $conds;
}
* @param bool $oldRedirectsOnly Only fix redirects without redirect entries
*/
private function doRefreshLinks( $start, $newOnly = false, $maxLag = false,
- $end = 0, $redirectsOnly = false, $oldRedirectsOnly = false ) {
+ $end = 0, $redirectsOnly = false, $oldRedirectsOnly = false
+ ) {
global $wgParser, $wgUseTidy;
$reportingInterval = 100;
// Delete any redirect table entry for it
$dbw->delete( 'redirect', array( 'rd_from' => $id ),
__METHOD__ );
+
return;
}
if ( count( array_intersect( $instance->getEffectiveGroups(), $excludedGroups ) ) == 0
&& $this->isInactiveAccount( $row->user_id, true )
&& wfTimestamp( TS_UNIX, $row->user_touched ) < wfTimestamp( TS_UNIX, time() - $touchedSeconds )
- ) {
+ ) {
# Inactive; print out the name and flag it
$del[] = $row->user_id;
$this->output( $row->user_name . "\n" );
$title = $rev->getTitle();
if ( !$title ) {
$this->error( "Got bogus revision with null title!" );
+
return;
}
$display = $title->getPrefixedText();
$where = array();
if ( $this->nullsOnly ) {
// Have to build this by hand, because \ is escaped in helper functions
- $where = array( 'user_token = \'' . str_repeat( '\0', 32) . '\'' );
+ $where = array( 'user_token = \'' . str_repeat( '\0', 32 ) . '\'' );
}
$maxid = $dbr->selectField( 'user', 'MAX(user_id)', array(), __METHOD__ );
$max = $min + $this->mBatchSize;
wfWaitForSlaves();
-
} while ( $min <= $maxid );
-
}
private function updateUser( $userid ) {
if ( !$titles ) {
$this->output( 'No suitable titles to be rolled back' );
+
return;
}
foreach ( $results as $row ) {
$titles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
}
+
return $titles;
}
}
if ( $this->hasOption( 'memory-limit' ) ) {
return parent::memoryLimit();
}
+
// Don't eat all memory on the machine if we get a bad job.
return "150M";
}
$this->runJobsLog( $job->toString() . " STARTING" );
// Set timer to stop the job if too much CPU time is used
- set_time_limit( $maxTime ?: 0 );
+ set_time_limit( $maxTime ? : 0 );
// Run the job...
wfProfileIn( __METHOD__ . '-' . get_class( $job ) );
$t = microtime( true );
$content = stream_get_contents( $handle );
flock( $handle, LOCK_UN );
fclose( $handle );
- $backoffs = json_decode( $content, true ) ?: array();
+ $backoffs = json_decode( $content, true ) ? : array();
}
return $backoffs;
$handle = fopen( $file, 'wb+' );
flock( $handle, LOCK_EX );
$content = stream_get_contents( $handle );
- $cBackoffs = json_decode( $content, true ) ?: array();
+ $cBackoffs = json_decode( $content, true ) ? : array();
foreach ( $backoffs as $type => $timestamp ) {
$cBackoffs[$type] = isset( $cBackoffs[$type] ) ? $cBackoffs[$type] : 0;
$cBackoffs[$type] = max( $cBackoffs[$type], $backoffs[$type] );
parent::__construct();
$this->mDescription = "Show the cached statistics";
}
+
public function execute() {
$fields = array(
'ss_total_views' => 'Total views',
}
public function execute() {
- $wiki = $this->getOption( 'wikidb' ) ?: false;
+ $wiki = $this->getOption( 'wikidb' ) ? : false;
// Get the appropriate load balancer (for this wiki)
if ( $this->hasOption( 'cluster' ) ) {
$lb = wfGetLBFactory()->getExternalLB( $this->getOption( 'cluster' ), $wiki );
}
$useReadline = function_exists( 'readline_add_history' )
- && Maintenance::posix_isatty( 0 /*STDIN*/ );
+ && Maintenance::posix_isatty( 0 /*STDIN*/ );
if ( $useReadline ) {
global $IP;
$historyFile = isset( $_ENV['HOME'] ) ?
- "{$_ENV['HOME']}/.mwsql_history" : "$IP/maintenance/.mwsql_history";
+ "{$_ENV['HOME']}/.mwsql_history" : "$IP/maintenance/.mwsql_history";
readline_read_history( $historyFile );
}
$prompt = $newPrompt;
$wholeLine = '';
} catch ( DBQueryError $e ) {
- $doDie = ! Maintenance::posix_isatty( 0 );
+ $doDie = !Maintenance::posix_isatty( 0 );
$this->error( $e, $doDie );
}
}
foreach ( $columns as $col ) {
if ( !isset( $allowedTypes[strtolower( $col->type )] ) ) {
$db->close();
+
return "Table {$table->name} has column {$col->name} with non-native type '{$col->type}'";
}
}
return $e->getMessage();
}
$db->close();
+
return true;
}
-};
+}
// Should work even if we use a non-SQLite database
if ( $this->hasOption( 'check-syntax' ) ) {
$this->checkSyntax();
+
return;
}
if ( $this->db->getType() != 'sqlite' ) {
$this->error( "This maintenance script requires a SQLite database.\n" );
+
return;
}
if ( !$res || $res->numRows() == 0 ) {
$this->error( "Error: integrity check query returned nothing.\n" );
+
return;
}
// Check targets of unresolved stubs
$this->checkExternalConcatBlobs( $externalConcatBlobs );
-
// next chunk
}
);
}
unset( $oldIds[$row->blob_id] );
-
}
$extDb->freeResult( $res );
// Write revision list
if ( !file_put_contents( $revFileName, implode( "\n", $revIds ) ) ) {
echo "Error writing revision list, can't restore text\n";
+
return;
}
if ( $exitStatus ) {
echo "mwdumper died with exit status $exitStatus\n";
+
return;
}
$file = fopen( $filteredXmlFileName, 'r' );
if ( !$file ) {
echo "Unable to open filtered XML file\n";
+
return;
}
if ( $content === null ) {
echo "Revision $id is broken, we have no content available\n";
+
return;
}
// be safe, we'll skip it and leave it broken
echo "Revision $id is blank in the dump, may have been broken before export\n";
+
return;
}
if ( !$id ) {
// No ID, can't import
echo "No id tag in revision, can't import\n";
+
return;
}
$oldId = $dbr->selectField( 'revision', 'rev_text_id', array( 'rev_id' => $id ), __METHOD__ );
if ( !$oldId ) {
echo "Missing revision row for rev_id $id\n";
+
return;
}
$this->mapCache[$pageId] = $map;
$this->mapCacheSize += count( $map );
}
+
return $this->mapCache[$pageId];
}
if ( in_array( 'external', $flags ) ) {
$url = $text;
wfSuppressWarnings();
- list( /* $proto */ , $path ) = explode( '://', $url, 2 );
+ list( /* $proto */, $path ) = explode( '://', $url, 2 );
wfRestoreWarnings();
if ( $path == "" ) {
$obj->uncompress();
$text = $obj->getItem( $stub['hash'] );
+
return $text !== false;
}
}
protected function &getDB( $cluster, $groups = array(), $wiki = false ) {
$lb = wfGetLBFactory()->getExternalLB( $cluster );
+
return $lb->getConnection( DB_SLAVE );
}
$num++;
$size = strlen( $blobRow->blob_text );
$totalSize += $size;
- $hashes[ sha1( $blobRow->blob_text ) ] = true;
+ $hashes[sha1( $blobRow->blob_text )] = true;
$maxSize = max( $size, $maxSize );
}
unset( $res );
$this->output( "Number of orphans: $num\n" );
if ( $num > 0 ) {
$this->output( "Average size: " . round( $totalSize / $num, 0 ) . " bytes\n" .
- "Max size: $maxSize\n" .
- "Number of unique texts: " . count( $hashes ) . "\n" );
+ "Max size: $maxSize\n" .
+ "Number of unique texts: " . count( $hashes ) . "\n" );
}
}
}
$jobOptions[$classOption] = $options[$cmdOption];
}
}
+
return new self( $jobOptions );
}
if ( $this->debugLog ) {
$this->logToFile( $msg, $this->debugLog );
}
-
}
function info( $msg ) {
$dbr = wfGetDB( DB_SLAVE );
if ( !$dbr->tableExists( 'blob_tracking' ) ) {
$this->critical( "Error: blob_tracking table does not exist" );
+
return false;
}
$row = $dbr->selectRow( 'blob_tracking', '*', false, __METHOD__ );
if ( !$row ) {
$this->info( "Warning: blob_tracking table contains no rows, skipping this wiki." );
+
return false;
}
+
return true;
}
if ( isset( $pipes[$slaveId] ) ) {
$this->prevSlaveId = $slaveId;
$this->dispatchToSlave( $slaveId, $args );
+
return;
}
}
$args = explode( ' ', $line );
$cmd = array_shift( $args );
switch ( $cmd ) {
- case 'doPage':
- $this->doPage( intval( $args[0] ) );
- break;
- case 'doOrphanList':
- $this->doOrphanList( array_map( 'intval', $args ) );
- break;
- case 'quit':
- return;
+ case 'doPage':
+ $this->doPage( intval( $args[0] ) );
+ break;
+ case 'doOrphanList':
+ $this->doOrphanList( array_map( 'intval', $args ) );
+ break;
+ case 'quit':
+ return;
}
$this->waitForSlaves();
}
if ( $cluster === false ) {
$cluster = reset( $this->destClusters );
}
+
return $cluster;
}
*/
function getExtDB( $cluster ) {
$lb = wfGetLBFactory()->getExternalLB( $cluster );
+
return $lb->getConnection( DB_MASTER );
}
$hash = $this->cgz->addItem( $text );
$this->referrers[$textId] = $hash;
$this->texts[$textId] = $text;
+
return $this->cgz->isHappy();
}
$this->critical( "Warning: concurrent operation detected, are there two conflicting " .
"processes running, doing the same job?" );
}
+
return;
}
$this->recompress();
if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) {
print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n";
+
return;
}
$this->textClause .= 'old_text' . $dbr->buildLike( "DB://$cluster/", $dbr->anyString() );
}
}
+
return $this->textClause;
}
if ( !preg_match( '!^DB://(\w+)/(\d+)(?:/([0-9a-fA-F]+)|)$!', $text, $m ) ) {
return false;
}
+
return array(
'cluster' => $m[1],
'id' => intval( $m[2] ),
function findOrphanBlobs() {
if ( !extension_loaded( 'gmp' ) ) {
echo "Can't find orphan blobs, need bitfield support provided by GMP.\n";
+
return;
}
if ( $this->isQuiet() ) {
print $id; // give a single machine-readable number
}
+
return;
}
}
// Periodically update the position file
- $callback = function( $pos ) use ( $startFromPosFile, $posFile, $start ) {
+ $callback = function ( $pos ) use ( $startFromPosFile, $posFile, $start ) {
if ( $startFromPosFile && $pos >= $start ) { // successfully advanced
file_put_contents( $posFile, $pos, LOCK_EX );
}
if ( !$fsFile ) {
$this->error( "Unable to sync '$dPath': could not get local copy." );
$status->fatal( 'backend-fail-internal', $src->getName() );
+
return $status;
}
$fsFiles[] = $fsFile; // keep TempFSFile objects alive as needed
} else { // error
$this->error( "Unable to sync '$dPath': could not stat file." );
$status->fatal( 'backend-fail-internal', $src->getName() );
+
return $status;
}
}
}
if ( $count == 0 ) {
$this->output( "Collations up-to-date.\n" );
+
return;
}
$this->output( "Fixing collation for $count rows.\n" );
# This is an old-style row, so the sortkey needs to be
# converted.
if ( $row->cl_sortkey == $title->getText()
- || $row->cl_sortkey == $title->getPrefixedText() ) {
+ || $row->cl_sortkey == $title->getPrefixedText()
+ ) {
$prefix = '';
} else {
# Custom sortkey, use it as a prefix
$prefix .= " AND $equality";
}
}
+
return $cond;
}
$sql = "SELECT si_page FROM $searchindex
WHERE ( si_text RLIKE '$regexp' )
OR ( si_title RLIKE '$regexp' )";
+
return $dbw->query( $sql, __METHOD__ );
}
}
}
if ( !$this->hasOption( 'override' )
- && $wgDisableQueryPageUpdate && in_array( $special, $wgDisableQueryPageUpdate ) )
- {
+ && $wgDisableQueryPageUpdate && in_array( $special, $wgDisableQueryPageUpdate )
+ ) {
$this->output( sprintf( "%-30s [QueryPage] disabled\n", $special ) );
continue;
}
$info = $this->db->indexInfo( 'user', 'user_name', __METHOD__ );
if ( !$info ) {
$this->out( "WARNING: doesn't seem to have user_name index at all!\n" );
+
return false;
}
function checkDupes( $doDelete = false ) {
if ( $this->hasUniqueIndex() ) {
echo wfWikiID() . " already has a unique index on its user table.\n";
+
return true;
}
if ( $this->failed > 0 ) {
$this->out( "Something terribly awry; $this->failed duplicate accounts were not removed.\n" );
+
return false;
}
if ( $this->trimmed == 0 || $doDelete ) {
$this->out( "It is now safe to apply the unique index on user_name.\n" );
+
return true;
} else {
$this->out( "Run this script again with the --fix option to automatically delete them.\n" );
+
return false;
}
}
foreach ( $result as $row ) {
$list[] = $row->user_name;
}
+
return $list;
}
$this->db->delete( 'user', array( 'user_id' => $userid ), __METHOD__ );
$this->out( " ok" );
}
-
}
return false;
}
- $this->{ $this->mMode } ();
+ $this->{$this->mMode}();
+
return true;
}
array( 'user_id' ),
array(),
__METHOD__
- );
+ );
foreach ( $result as $id ) {
@$ret[$this->mAnOption][$userValue]++;
// @codingStandardsIgnoreEnd
}
-
} else {
foreach ( $defaultOptions as $name => $defaultValue ) {
array( 'user_id' ),
array(),
__METHOD__
- );
+ );
foreach ( $result as $id ) {
if ( !$this->mQuiet ) {
print " OK\n";
}
-
} elseif ( !$this->mQuiet ) {
print "Not changing '$username' using <{$this->mAnOption}> = '$curValue'\n";
}
foreach ( $def as $optname => $defaultValue ) {
array_push( $ret, $optname );
}
+
return $ret;
}
#
public static function showUsageAndExit() {
-print <<<USAGE
+ print <<<USAGE
This script pass through all users and change one of their options.
The new option is NOT validated.
--dry : do not save user settings back to database
USAGE;
- exit( 0 );
+ exit( 0 );
}
/**
return true;
}
-print <<<WARN
+ print <<<WARN
The script is about to change the skin for ALL USERS in the database.
Users with option <$this->mAnOption> = '$this->mOldValue' will be made to use '$this->mNewValue'.
Abort with control-c in the next five seconds....
WARN;
wfCountDown( 5 );
+
return true;
}
-
}
parent::__construct();
$this->addArg( 'maxlag', 'How long to wait for the slaves, default 10 seconds', false );
}
+
public function execute() {
wfWaitForSlaves( $this->getArg( 0, 10 ) );
}