From 606c680b218aaf65f442f62c98d60d30d3593606 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Wed, 23 Apr 2014 20:09:26 +0200 Subject: [PATCH] Update formatting in maintenance/ (4/4) Change-Id: I6b58d014a4bfd6600e4e6f80188fdcfce18482ca --- maintenance/purgeOldText.inc | 1 - maintenance/purgeParserCache.php | 5 +- maintenance/reassignEdits.php | 2 + maintenance/rebuildImages.php | 23 ++++--- maintenance/rebuildLocalisationCache.php | 4 +- maintenance/rebuildrecentchanges.php | 79 ++++++++++++----------- maintenance/refreshImageMetadata.php | 11 ++-- maintenance/refreshLinks.php | 4 +- maintenance/removeUnusedAccounts.php | 2 +- maintenance/renderDump.php | 1 + maintenance/resetUserTokens.php | 4 +- maintenance/rollbackEdits.php | 2 + maintenance/runJobs.php | 7 +- maintenance/showSiteStats.php | 1 + maintenance/sql.php | 8 +-- maintenance/sqlite.inc | 4 +- maintenance/sqlite.php | 3 + maintenance/storage/checkStorage.php | 9 ++- maintenance/storage/fixBug20757.php | 4 +- maintenance/storage/orphanStats.php | 7 +- maintenance/storage/recompressTracked.php | 26 +++++--- maintenance/storage/resolveStubs.php | 1 + maintenance/storage/trackBlobs.php | 3 + maintenance/syncFileBackend.php | 5 +- maintenance/updateCollation.php | 5 +- maintenance/updateDoubleWidthSearch.php | 1 + maintenance/updateSpecialPages.php | 4 +- maintenance/userDupes.inc | 7 +- maintenance/userOptions.inc | 18 +++--- maintenance/waitForSlave.php | 1 + 30 files changed, 152 insertions(+), 100 deletions(-) diff --git a/maintenance/purgeOldText.inc b/maintenance/purgeOldText.inc index db961d81ec..913e9f0cba 100644 --- a/maintenance/purgeOldText.inc +++ b/maintenance/purgeOldText.inc @@ -74,5 +74,4 @@ function PurgeRedundantText( $delete = false ) { # Done $dbw->commit( __METHOD__ ); - } diff --git a/maintenance/purgeParserCache.php b/maintenance/purgeParserCache.php index ca2a041448..9970c1fd5d 100644 --- a/maintenance/purgeParserCache.php +++ b/maintenance/purgeParserCache.php @@ -37,7 +37,8 @@ class PurgeParserCache extends Maintenance { $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 ); @@ -77,8 +78,8 @@ class PurgeParserCache extends Maintenance { $stars = floor( $percent / 2 ); $this->output( '[' . str_repeat( '*', $stars ) . str_repeat( '.', 50 - $stars ) . '] ' . "$percentString%\r" ); - } } + $maintClass = 'PurgeParserCache'; require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/maintenance/reassignEdits.php b/maintenance/reassignEdits.php index 9b10470ddf..679cadb96f 100644 --- a/maintenance/reassignEdits.php +++ b/maintenance/reassignEdits.php @@ -140,6 +140,7 @@ class ReassignEdits extends Maintenance { } $dbw->commit( __METHOD__ ); + return (int)$total; } @@ -189,6 +190,7 @@ class ReassignEdits extends Maintenance { } } $user->load(); + return $user; } } diff --git a/maintenance/rebuildImages.php b/maintenance/rebuildImages.php index 8b0b05748c..5a1496786f 100644 --- a/maintenance/rebuildImages.php +++ b/maintenance/rebuildImages.php @@ -79,6 +79,7 @@ class ImageBuilder extends Maintenance { if ( !isset( $this->repo ) ) { $this->repo = RepoGroup::singleton()->getLocalRepo(); } + return $this->repo; } @@ -149,6 +150,7 @@ class ImageBuilder extends Maintenance { // Create a File object from the row // This will also upgrade it $file = $this->getRepo()->newFileFromRow( $row ); + return $file->getUpgraded(); } @@ -161,9 +163,11 @@ class ImageBuilder extends Maintenance { // 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(); } @@ -201,21 +205,22 @@ class ImageBuilder extends Maintenance { 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; } } diff --git a/maintenance/rebuildLocalisationCache.php b/maintenance/rebuildLocalisationCache.php index cfcb950574..b04639c0e1 100644 --- a/maintenance/rebuildLocalisationCache.php +++ b/maintenance/rebuildLocalisationCache.php @@ -52,6 +52,7 @@ class RebuildLocalisationCache extends Maintenance { if ( $this->hasOption( 'memory-limit' ) ) { return parent::memoryLimit(); } + return '1000M'; } @@ -148,7 +149,7 @@ class RebuildLocalisationCache extends Maintenance { /** * 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 @@ -162,6 +163,7 @@ class RebuildLocalisationCache extends Maintenance { $numRebuilt++; } } + return $numRebuilt; } diff --git a/maintenance/rebuildrecentchanges.php b/maintenance/rebuildrecentchanges.php index 2c83454eba..203d79567b 100644 --- a/maintenance/rebuildrecentchanges.php +++ b/maintenance/rebuildrecentchanges.php @@ -69,29 +69,31 @@ class RebuildRecentchanges extends Maintenance { $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 ); @@ -193,31 +195,33 @@ class RebuildRecentchanges extends Maintenance { "$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 ); @@ -299,7 +303,6 @@ class RebuildRecentchanges extends Maintenance { $messageMemc->delete( wfMemcKey( 'rcfeed', $feed, 'timestamp' ) ); # Good enough for now. } } - } $maintClass = "RebuildRecentchanges"; diff --git a/maintenance/refreshImageMetadata.php b/maintenance/refreshImageMetadata.php index 95dc10bdf8..8cb23fd528 100644 --- a/maintenance/refreshImageMetadata.php +++ b/maintenance/refreshImageMetadata.php @@ -82,7 +82,6 @@ class RefreshImageMetadata extends Maintenance { false, true ); - } public function execute() { @@ -148,7 +147,7 @@ class RefreshImageMetadata extends Maintenance { // 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" ); } @@ -161,20 +160,17 @@ class RefreshImageMetadata extends Maintenance { 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(); @@ -216,6 +212,7 @@ class RefreshImageMetadata extends Maintenance { if ( $like ) { $conds[] = 'img_metadata ' . $dbw->buildLike( $dbw->anyString(), $like, $dbw->anyString() ); } + return $conds; } diff --git a/maintenance/refreshLinks.php b/maintenance/refreshLinks.php index eca207a3d9..0c2f722c42 100644 --- a/maintenance/refreshLinks.php +++ b/maintenance/refreshLinks.php @@ -65,7 +65,8 @@ class RefreshLinks extends Maintenance { * @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; @@ -196,6 +197,7 @@ class RefreshLinks extends Maintenance { // Delete any redirect table entry for it $dbw->delete( 'redirect', array( 'rd_from' => $id ), __METHOD__ ); + return; } diff --git a/maintenance/removeUnusedAccounts.php b/maintenance/removeUnusedAccounts.php index 55b23601ab..90dc62204a 100644 --- a/maintenance/removeUnusedAccounts.php +++ b/maintenance/removeUnusedAccounts.php @@ -64,7 +64,7 @@ class RemoveUnusedAccounts extends Maintenance { 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" ); diff --git a/maintenance/renderDump.php b/maintenance/renderDump.php index b76d9a12a4..169f512cfa 100644 --- a/maintenance/renderDump.php +++ b/maintenance/renderDump.php @@ -84,6 +84,7 @@ class DumpRenderer extends Maintenance { $title = $rev->getTitle(); if ( !$title ) { $this->error( "Got bogus revision with null title!" ); + return; } $display = $title->getPrefixedText(); diff --git a/maintenance/resetUserTokens.php b/maintenance/resetUserTokens.php index a1ee3deba3..08be553773 100644 --- a/maintenance/resetUserTokens.php +++ b/maintenance/resetUserTokens.php @@ -70,7 +70,7 @@ class ResetUserTokens extends Maintenance { $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__ ); @@ -98,9 +98,7 @@ class ResetUserTokens extends Maintenance { $max = $min + $this->mBatchSize; wfWaitForSlaves(); - } while ( $min <= $maxid ); - } private function updateUser( $userid ) { diff --git a/maintenance/rollbackEdits.php b/maintenance/rollbackEdits.php index 6bb0fb816d..967dda85ce 100644 --- a/maintenance/rollbackEdits.php +++ b/maintenance/rollbackEdits.php @@ -72,6 +72,7 @@ class RollbackEdits extends Maintenance { if ( !$titles ) { $this->output( 'No suitable titles to be rolled back' ); + return; } @@ -105,6 +106,7 @@ class RollbackEdits extends Maintenance { foreach ( $results as $row ) { $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title ); } + return $titles; } } diff --git a/maintenance/runJobs.php b/maintenance/runJobs.php index c3eb4ba11e..b488fe94b2 100644 --- a/maintenance/runJobs.php +++ b/maintenance/runJobs.php @@ -43,6 +43,7 @@ class RunJobs extends Maintenance { if ( $this->hasOption( 'memory-limit' ) ) { return parent::memoryLimit(); } + // Don't eat all memory on the machine if we get a bad job. return "150M"; } @@ -101,7 +102,7 @@ class RunJobs extends Maintenance { $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 ); @@ -209,7 +210,7 @@ class RunJobs extends Maintenance { $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; @@ -227,7 +228,7 @@ class RunJobs extends Maintenance { $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] ); diff --git a/maintenance/showSiteStats.php b/maintenance/showSiteStats.php index 6bf4daae94..374a66e92d 100644 --- a/maintenance/showSiteStats.php +++ b/maintenance/showSiteStats.php @@ -41,6 +41,7 @@ class ShowSiteStats extends Maintenance { parent::__construct(); $this->mDescription = "Show the cached statistics"; } + public function execute() { $fields = array( 'ss_total_views' => 'Total views', diff --git a/maintenance/sql.php b/maintenance/sql.php index b20b0cf9f0..c947a4c36f 100644 --- a/maintenance/sql.php +++ b/maintenance/sql.php @@ -39,7 +39,7 @@ class MwSql extends Maintenance { } 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 ); @@ -88,12 +88,12 @@ class MwSql extends Maintenance { } $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 ); } @@ -126,7 +126,7 @@ class MwSql extends Maintenance { $prompt = $newPrompt; $wholeLine = ''; } catch ( DBQueryError $e ) { - $doDie = ! Maintenance::posix_isatty( 0 ); + $doDie = !Maintenance::posix_isatty( 0 ); $this->error( $e, $doDie ); } } diff --git a/maintenance/sqlite.inc b/maintenance/sqlite.inc index 6520e1381c..9729a726bb 100644 --- a/maintenance/sqlite.inc +++ b/maintenance/sqlite.inc @@ -78,6 +78,7 @@ class Sqlite { 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}'"; } } @@ -86,6 +87,7 @@ class Sqlite { return $e->getMessage(); } $db->close(); + return true; } -}; +} diff --git a/maintenance/sqlite.php b/maintenance/sqlite.php index dbd8ed1f81..edc9e145ac 100644 --- a/maintenance/sqlite.php +++ b/maintenance/sqlite.php @@ -55,6 +55,7 @@ class SqliteMaintenance extends Maintenance { // Should work even if we use a non-SQLite database if ( $this->hasOption( 'check-syntax' ) ) { $this->checkSyntax(); + return; } @@ -62,6 +63,7 @@ class SqliteMaintenance extends Maintenance { if ( $this->db->getType() != 'sqlite' ) { $this->error( "This maintenance script requires a SQLite database.\n" ); + return; } @@ -101,6 +103,7 @@ class SqliteMaintenance extends Maintenance { if ( !$res || $res->numRows() == 0 ) { $this->error( "Error: integrity check query returned nothing.\n" ); + return; } diff --git a/maintenance/storage/checkStorage.php b/maintenance/storage/checkStorage.php index 6b8b5a36fa..0f996625fe 100644 --- a/maintenance/storage/checkStorage.php +++ b/maintenance/storage/checkStorage.php @@ -322,7 +322,6 @@ class CheckStorage { // Check targets of unresolved stubs $this->checkExternalConcatBlobs( $externalConcatBlobs ); - // next chunk } @@ -403,7 +402,6 @@ class CheckStorage { ); } unset( $oldIds[$row->blob_id] ); - } $extDb->freeResult( $res ); @@ -434,6 +432,7 @@ class CheckStorage { // Write revision list if ( !file_put_contents( $revFileName, implode( "\n", $revIds ) ) ) { echo "Error writing revision list, can't restore text\n"; + return; } @@ -450,12 +449,14 @@ class CheckStorage { 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; } @@ -477,6 +478,7 @@ class CheckStorage { if ( $content === null ) { echo "Revision $id is broken, we have no content available\n"; + return; } @@ -488,12 +490,14 @@ class CheckStorage { // 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; } @@ -502,6 +506,7 @@ class CheckStorage { $oldId = $dbr->selectField( 'revision', 'rev_text_id', array( 'rev_id' => $id ), __METHOD__ ); if ( !$oldId ) { echo "Missing revision row for rev_id $id\n"; + return; } diff --git a/maintenance/storage/fixBug20757.php b/maintenance/storage/fixBug20757.php index bfa269befd..d2fe3b42b8 100644 --- a/maintenance/storage/fixBug20757.php +++ b/maintenance/storage/fixBug20757.php @@ -296,6 +296,7 @@ class FixBug20757 extends Maintenance { $this->mapCache[$pageId] = $map; $this->mapCacheSize += count( $map ); } + return $this->mapCache[$pageId]; } @@ -312,7 +313,7 @@ class FixBug20757 extends Maintenance { if ( in_array( 'external', $flags ) ) { $url = $text; wfSuppressWarnings(); - list( /* $proto */ , $path ) = explode( '://', $url, 2 ); + list( /* $proto */, $path ) = explode( '://', $url, 2 ); wfRestoreWarnings(); if ( $path == "" ) { @@ -341,6 +342,7 @@ class FixBug20757 extends Maintenance { $obj->uncompress(); $text = $obj->getItem( $stub['hash'] ); + return $text !== false; } } diff --git a/maintenance/storage/orphanStats.php b/maintenance/storage/orphanStats.php index 9dc5280be8..c5213ad17f 100644 --- a/maintenance/storage/orphanStats.php +++ b/maintenance/storage/orphanStats.php @@ -38,6 +38,7 @@ class OrphanStats extends Maintenance { protected function &getDB( $cluster, $groups = array(), $wiki = false ) { $lb = wfGetLBFactory()->getExternalLB( $cluster ); + return $lb->getConnection( DB_SLAVE ); } @@ -65,7 +66,7 @@ class OrphanStats extends Maintenance { $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 ); @@ -73,8 +74,8 @@ class OrphanStats extends Maintenance { $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" ); } } } diff --git a/maintenance/storage/recompressTracked.php b/maintenance/storage/recompressTracked.php index b19a0b31a9..307d0b0d4b 100644 --- a/maintenance/storage/recompressTracked.php +++ b/maintenance/storage/recompressTracked.php @@ -95,6 +95,7 @@ class RecompressTracked { $jobOptions[$classOption] = $options[$cmdOption]; } } + return new self( $jobOptions ); } @@ -118,7 +119,6 @@ class RecompressTracked { if ( $this->debugLog ) { $this->logToFile( $msg, $this->debugLog ); } - } function info( $msg ) { @@ -190,13 +190,16 @@ class RecompressTracked { $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; } @@ -276,6 +279,7 @@ class RecompressTracked { if ( isset( $pipes[$slaveId] ) ) { $this->prevSlaveId = $slaveId; $this->dispatchToSlave( $slaveId, $args ); + return; } } @@ -443,14 +447,14 @@ class RecompressTracked { $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(); } @@ -618,6 +622,7 @@ class RecompressTracked { if ( $cluster === false ) { $cluster = reset( $this->destClusters ); } + return $cluster; } @@ -628,6 +633,7 @@ class RecompressTracked { */ function getExtDB( $cluster ) { $lb = wfGetLBFactory()->getExternalLB( $cluster ); + return $lb->getConnection( DB_MASTER ); } @@ -724,6 +730,7 @@ class CgzCopyTransaction { $hash = $this->cgz->addItem( $text ); $this->referrers[$textId] = $hash; $this->texts[$textId] = $text; + return $this->cgz->isHappy(); } @@ -787,6 +794,7 @@ class CgzCopyTransaction { $this->critical( "Warning: concurrent operation detected, are there two conflicting " . "processes running, doing the same job?" ); } + return; } $this->recompress(); diff --git a/maintenance/storage/resolveStubs.php b/maintenance/storage/resolveStubs.php index 4ac5a98b4f..dff5cb8638 100644 --- a/maintenance/storage/resolveStubs.php +++ b/maintenance/storage/resolveStubs.php @@ -77,6 +77,7 @@ function resolveStub( $id, $stubText, $flags ) { if ( strtolower( get_class( $stub ) ) !== 'historyblobstub' ) { print "Error found object of class " . get_class( $stub ) . ", expecting historyblobstub\n"; + return; } diff --git a/maintenance/storage/trackBlobs.php b/maintenance/storage/trackBlobs.php index c2df0dd2d8..a3f938625d 100644 --- a/maintenance/storage/trackBlobs.php +++ b/maintenance/storage/trackBlobs.php @@ -126,6 +126,7 @@ class TrackBlobs { $this->textClause .= 'old_text' . $dbr->buildLike( "DB://$cluster/", $dbr->anyString() ); } } + return $this->textClause; } @@ -133,6 +134,7 @@ class TrackBlobs { if ( !preg_match( '!^DB://(\w+)/(\d+)(?:/([0-9a-fA-F]+)|)$!', $text, $m ) ) { return false; } + return array( 'cluster' => $m[1], 'id' => intval( $m[2] ), @@ -305,6 +307,7 @@ class TrackBlobs { function findOrphanBlobs() { if ( !extension_loaded( 'gmp' ) ) { echo "Can't find orphan blobs, need bitfield support provided by GMP.\n"; + return; } diff --git a/maintenance/syncFileBackend.php b/maintenance/syncFileBackend.php index c505b1482e..b9493cdc0b 100644 --- a/maintenance/syncFileBackend.php +++ b/maintenance/syncFileBackend.php @@ -71,6 +71,7 @@ class SyncFileBackend extends Maintenance { if ( $this->isQuiet() ) { print $id; // give a single machine-readable number } + return; } @@ -104,7 +105,7 @@ class SyncFileBackend extends Maintenance { } // 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 ); } @@ -238,6 +239,7 @@ class SyncFileBackend extends Maintenance { 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 @@ -254,6 +256,7 @@ class SyncFileBackend extends Maintenance { } else { // error $this->error( "Unable to sync '$dPath': could not stat file." ); $status->fatal( 'backend-fail-internal', $src->getName() ); + return $status; } } diff --git a/maintenance/updateCollation.php b/maintenance/updateCollation.php index 7ca04b4134..19c1d24c79 100644 --- a/maintenance/updateCollation.php +++ b/maintenance/updateCollation.php @@ -120,6 +120,7 @@ TEXT; } if ( $count == 0 ) { $this->output( "Collations up-to-date.\n" ); + return; } $this->output( "Fixing collation for $count rows.\n" ); @@ -150,7 +151,8 @@ TEXT; # 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 @@ -236,6 +238,7 @@ TEXT; $prefix .= " AND $equality"; } } + return $cond; } diff --git a/maintenance/updateDoubleWidthSearch.php b/maintenance/updateDoubleWidthSearch.php index f863697ba5..796cedd98d 100644 --- a/maintenance/updateDoubleWidthSearch.php +++ b/maintenance/updateDoubleWidthSearch.php @@ -72,6 +72,7 @@ class UpdateDoubleWidthSearch extends Maintenance { $sql = "SELECT si_page FROM $searchindex WHERE ( si_text RLIKE '$regexp' ) OR ( si_title RLIKE '$regexp' )"; + return $dbw->query( $sql, __METHOD__ ); } } diff --git a/maintenance/updateSpecialPages.php b/maintenance/updateSpecialPages.php index 12c4a2c060..fae9063c00 100644 --- a/maintenance/updateSpecialPages.php +++ b/maintenance/updateSpecialPages.php @@ -57,8 +57,8 @@ class UpdateSpecialPages extends Maintenance { } if ( !$this->hasOption( 'override' ) - && $wgDisableQueryPageUpdate && in_array( $special, $wgDisableQueryPageUpdate ) ) - { + && $wgDisableQueryPageUpdate && in_array( $special, $wgDisableQueryPageUpdate ) + ) { $this->output( sprintf( "%-30s [QueryPage] disabled\n", $special ) ); continue; } diff --git a/maintenance/userDupes.inc b/maintenance/userDupes.inc index bc8fbcfad1..15e1174f3a 100644 --- a/maintenance/userDupes.inc +++ b/maintenance/userDupes.inc @@ -61,6 +61,7 @@ class UserDupes { $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; } @@ -102,6 +103,7 @@ class UserDupes { function checkDupes( $doDelete = false ) { if ( $this->hasUniqueIndex() ) { echo wfWikiID() . " already has a unique index on its user table.\n"; + return true; } @@ -144,14 +146,17 @@ class UserDupes { 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; } } @@ -196,6 +201,7 @@ class UserDupes { foreach ( $result as $row ) { $list[] = $row->user_name; } + return $list; } @@ -288,5 +294,4 @@ class UserDupes { $this->db->delete( 'user', array( 'user_id' => $userid ), __METHOD__ ); $this->out( " ok" ); } - } diff --git a/maintenance/userOptions.inc b/maintenance/userOptions.inc index 5998cb59a1..9b8714d188 100644 --- a/maintenance/userOptions.inc +++ b/maintenance/userOptions.inc @@ -107,7 +107,8 @@ class UserOptions { return false; } - $this->{ $this->mMode } (); + $this->{$this->mMode}(); + return true; } @@ -139,7 +140,7 @@ class UserOptions { array( 'user_id' ), array(), __METHOD__ - ); + ); foreach ( $result as $id ) { @@ -159,7 +160,6 @@ class UserOptions { @$ret[$this->mAnOption][$userValue]++; // @codingStandardsIgnoreEnd } - } else { foreach ( $defaultOptions as $name => $defaultValue ) { @@ -192,7 +192,7 @@ class UserOptions { array( 'user_id' ), array(), __METHOD__ - ); + ); foreach ( $result as $id ) { @@ -218,7 +218,6 @@ class UserOptions { if ( !$this->mQuiet ) { print " OK\n"; } - } elseif ( !$this->mQuiet ) { print "Not changing '$username' using <{$this->mAnOption}> = '$curValue'\n"; } @@ -235,6 +234,7 @@ class UserOptions { foreach ( $def as $optname => $defaultValue ) { array_push( $ret, $optname ); } + return $ret; } @@ -243,7 +243,7 @@ class UserOptions { # public static function showUsageAndExit() { -print <<mAnOption> = '$this->mOldValue' will be made to use '$this->mNewValue'. Abort with control-c in the next five seconds.... WARN; wfCountDown( 5 ); + return true; } - } diff --git a/maintenance/waitForSlave.php b/maintenance/waitForSlave.php index a62d1618ef..c9b1abba4c 100644 --- a/maintenance/waitForSlave.php +++ b/maintenance/waitForSlave.php @@ -34,6 +34,7 @@ class WaitForSlave extends Maintenance { parent::__construct(); $this->addArg( 'maxlag', 'How long to wait for the slaves, default 10 seconds', false ); } + public function execute() { wfWaitForSlaves( $this->getArg( 0, 10 ) ); } -- 2.20.1