From f2f31fadc7d3aba8588b1ea6410f92166de1ac0a Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Wed, 23 Apr 2014 20:08:42 +0200 Subject: [PATCH] Update formatting in maintenance/ (2/4) Change-Id: I2b791d3bff0de464b6bdaaeae0622c065389c31c --- .../benchmarks/bench_delete_truncate.php | 2 +- .../benchmarks/bench_strtr_str_replace.php | 4 +- .../benchmarks/bench_utf8_title_check.php | 18 ++--- .../benchmarks/bench_wfBaseConvert.php | 7 +- maintenance/benchmarks/bench_wfIsWindows.php | 5 +- maintenance/benchmarks/benchmarkHooks.php | 5 +- maintenance/benchmarks/benchmarkParse.php | 4 +- maintenance/benchmarks/benchmarkPurge.php | 4 ++ maintenance/checkBadRedirects.php | 2 +- maintenance/checkImages.php | 1 - maintenance/checkSyntax.php | 13 +++- maintenance/checkUsernames.php | 2 +- maintenance/cleanupAncientTables.php | 4 +- maintenance/cleanupCaps.php | 3 + maintenance/cleanupImages.php | 9 ++- maintenance/cleanupSpam.php | 4 +- maintenance/cleanupWatchlist.php | 9 ++- maintenance/compareParsers.php | 4 +- maintenance/convertLinks.php | 25 ++++--- maintenance/convertUserOptions.php | 1 + maintenance/copyFileBackend.php | 1 + maintenance/copyJobQueue.php | 1 + maintenance/createAndPromote.php | 1 + maintenance/deleteArchivedFiles.inc | 10 ++- maintenance/deleteArchivedFiles.php | 1 + maintenance/deleteArchivedRevisions.inc | 1 - maintenance/deleteBatch.php | 10 +-- maintenance/deleteDefaultMessages.php | 3 +- maintenance/deleteEqualMessages.php | 2 + maintenance/deleteImageMemcached.php | 1 + maintenance/deleteRevision.php | 30 +++++---- maintenance/dev/includes/router.php | 2 + maintenance/dumpBackup.php | 2 +- maintenance/dumpIterator.php | 1 + maintenance/dumpTextPass.php | 2 +- maintenance/dumpUploads.php | 2 +- maintenance/fetchText.php | 14 ++-- maintenance/findHooks.php | 67 ++++++++++--------- maintenance/fixDoubleRedirects.php | 1 + 39 files changed, 169 insertions(+), 109 deletions(-) diff --git a/maintenance/benchmarks/bench_delete_truncate.php b/maintenance/benchmarks/bench_delete_truncate.php index ed3fe5c1c6..8ae4f03094 100644 --- a/maintenance/benchmarks/bench_delete_truncate.php +++ b/maintenance/benchmarks/bench_delete_truncate.php @@ -75,7 +75,7 @@ class BenchmarkDeleteTruncate extends Benchmarker { private function insertData( $dbw ) { $range = range( 0, 1024 ); $data = array(); - foreach( $range as $r ) { + foreach ( $range as $r ) { $data[] = array( 'text' => $r ); } $dbw->insert( 'test', $data, __METHOD__ ); diff --git a/maintenance/benchmarks/bench_strtr_str_replace.php b/maintenance/benchmarks/bench_strtr_str_replace.php index 99e9cfd3ee..44c8e03266 100644 --- a/maintenance/benchmarks/bench_strtr_str_replace.php +++ b/maintenance/benchmarks/bench_strtr_str_replace.php @@ -50,7 +50,7 @@ class BenchStrtrStrReplace extends Benchmarker { array( 'function' => array( $this, 'benchstr_replace' ) ), array( 'function' => array( $this, 'benchstrtr_indirect' ) ), array( 'function' => array( $this, 'benchstr_replace_indirect' ) ), - )); + ) ); print $this->getFormattedResults(); } @@ -59,7 +59,7 @@ class BenchStrtrStrReplace extends Benchmarker { } function benchstr_replace() { - str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]"); + str_replace( "_", " ", "[[MediaWiki:Some_random_test_page]]" ); } function benchstrtr_indirect() { diff --git a/maintenance/benchmarks/bench_utf8_title_check.php b/maintenance/benchmarks/bench_utf8_title_check.php index 1c31256886..b742f66679 100644 --- a/maintenance/benchmarks/bench_utf8_title_check.php +++ b/maintenance/benchmarks/bench_utf8_title_check.php @@ -61,7 +61,7 @@ class BenchUtf8TitleCheck extends Benchmarker { ); // @codingStandardsIgnoreEnd - $this->canRun = function_exists ( 'mb_check_encoding' ); + $this->canRun = function_exists( 'mb_check_encoding' ); if ( $this->canRun ) { $this->mDescription = "Benchmark for using a regexp vs. mb_check_encoding " . @@ -77,22 +77,22 @@ class BenchUtf8TitleCheck extends Benchmarker { return; } $benchmarks = array(); - foreach ($this->data as $val) { + foreach ( $this->data as $val ) { $benchmarks[] = array( 'function' => array( $this, 'use_regexp' ), - 'args' => array( rawurldecode ( $val ) ) + 'args' => array( rawurldecode( $val ) ) ); $benchmarks[] = array( 'function' => array( $this, 'use_regexp_non_capturing' ), - 'args' => array( rawurldecode ( $val ) ) + 'args' => array( rawurldecode( $val ) ) ); $benchmarks[] = array( 'function' => array( $this, 'use_regexp_once_only' ), - 'args' => array( rawurldecode ( $val ) ) + 'args' => array( rawurldecode( $val ) ) ); $benchmarks[] = array( 'function' => array( $this, 'use_mb_check_encoding' ), - 'args' => array( rawurldecode ( $val ) ) + 'args' => array( rawurldecode( $val ) ) ); } $this->bench( $benchmarks ); @@ -103,19 +103,19 @@ class BenchUtf8TitleCheck extends Benchmarker { function use_regexp( $s ) { $this->isutf8 = preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' . - '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s ); + '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s ); } function use_regexp_non_capturing( $s ) { // Same as above with a non-capturing subgroup. $this->isutf8 = preg_match( '/^(?:[\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' . - '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s ); + '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s ); } function use_regexp_once_only( $s ) { // Same as above with a once-only subgroup. $this->isutf8 = preg_match( '/^(?>[\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' . - '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s ); + '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s ); } function use_mb_check_encoding( $s ) { diff --git a/maintenance/benchmarks/bench_wfBaseConvert.php b/maintenance/benchmarks/bench_wfBaseConvert.php index d08a0b0653..b4be12bc8c 100644 --- a/maintenance/benchmarks/bench_wfBaseConvert.php +++ b/maintenance/benchmarks/bench_wfBaseConvert.php @@ -57,7 +57,7 @@ class BenchWfBaseConvert extends Benchmarker { 'function' => 'wfBaseConvert', 'args' => array( $number, $inbase, $outbase, 0, true, 'gmp' ) ), - )); + ) ); $this->output( $this->getFormattedResults() ); } @@ -65,9 +65,10 @@ class BenchWfBaseConvert extends Benchmarker { protected static function makeRandomNumber( $base, $length ) { $baseChars = "0123456789abcdefghijklmnopqrstuvwxyz"; $res = ""; - for( $i = 0; $i < $length; $i++ ) { - $res .= $baseChars[mt_rand(0, $base - 1)]; + for ( $i = 0; $i < $length; $i++ ) { + $res .= $baseChars[mt_rand( 0, $base - 1 )]; } + return $res; } } diff --git a/maintenance/benchmarks/bench_wfIsWindows.php b/maintenance/benchmarks/bench_wfIsWindows.php index b5cb02584d..8446694ba3 100644 --- a/maintenance/benchmarks/bench_wfIsWindows.php +++ b/maintenance/benchmarks/bench_wfIsWindows.php @@ -41,7 +41,7 @@ class BenchWfIsWindows extends Benchmarker { $this->bench( array( array( 'function' => array( $this, 'wfIsWindows' ) ), array( 'function' => array( $this, 'wfIsWindowsCached' ) ), - )); + ) ); print $this->getFormattedResults(); } @@ -57,9 +57,10 @@ class BenchWfIsWindows extends Benchmarker { // bench function 2 function wfIsWindowsCached() { static $isWindows = null; - if( $isWindows == null ) { + if ( $isWindows == null ) { $isWindows = self::is_win(); } + return $isWindows; } } diff --git a/maintenance/benchmarks/benchmarkHooks.php b/maintenance/benchmarks/benchmarkHooks.php index bb7af2b9d5..fb25b9d930 100644 --- a/maintenance/benchmarks/benchmarkHooks.php +++ b/maintenance/benchmarks/benchmarkHooks.php @@ -45,13 +45,13 @@ class BenchmarkHooks extends Benchmarker { $time = $this->benchHooks(); $this->output( 'Loaded (one) hook: ' . $time . "\n" ); - for( $i = 0; $i < 9; $i++ ) { + for ( $i = 0; $i < 9; $i++ ) { $wgHooks['Test'][] = array( $this, 'test' ); } $time = $this->benchHooks(); $this->output( 'Loaded (ten) hook: ' . $time . "\n" ); - for( $i = 0; $i < 90; $i++ ) { + for ( $i = 0; $i < 90; $i++ ) { $wgHooks['Test'][] = array( $this, 'test' ); } $time = $this->benchHooks(); @@ -70,6 +70,7 @@ class BenchmarkHooks extends Benchmarker { } $delta = microtime( true ) - $start; $pertrial = $delta / $trials; + return sprintf( "Took %6.3fms", $pertrial * 1000 ); } diff --git a/maintenance/benchmarks/benchmarkParse.php b/maintenance/benchmarks/benchmarkParse.php index cec2bebacd..b81f9fd424 100644 --- a/maintenance/benchmarks/benchmarkParse.php +++ b/maintenance/benchmarks/benchmarkParse.php @@ -47,7 +47,7 @@ class BenchmarkParse extends Maintenance { false, true ); $this->addOption( 'tpl-time', 'Use templates which were current at the given time (except that moves and ' . - 'deletes are not handled properly)', + 'deletes are not handled properly)', false, true ); } @@ -94,7 +94,7 @@ class BenchmarkParse extends Maintenance { printf( "CPU time = %.3f s, wall clock time = %.3f s\n", // CPU time $endUsage['ru_utime.tv_sec'] + $endUsage['ru_utime.tv_usec'] * 1e-6 - - $startUsage['ru_utime.tv_sec'] - $startUsage['ru_utime.tv_usec'] * 1e-6, + - $startUsage['ru_utime.tv_sec'] - $startUsage['ru_utime.tv_usec'] * 1e-6, // Wall clock time $endTime - $startTime ); } diff --git a/maintenance/benchmarks/benchmarkPurge.php b/maintenance/benchmarks/benchmarkPurge.php index dcaacab6f2..42c1eb78a3 100644 --- a/maintenance/benchmarks/benchmarkPurge.php +++ b/maintenance/benchmarks/benchmarkPurge.php @@ -68,6 +68,7 @@ class BenchmarkPurge extends Benchmarker { $delta = microtime( true ) - $start; $pertrial = $delta / $trials; $pertitle = $pertrial / count( $urls ); + return sprintf( "%4d titles in %6.2fms (%6.2fms each)", count( $urls ), $pertrial * 1000.0, $pertitle * 1000.0 ); } @@ -82,6 +83,7 @@ class BenchmarkPurge extends Benchmarker { for ( $i = 0; $i < $length; $i++ ) { $list[] = $this->randomUrl(); } + return $list; } @@ -92,6 +94,7 @@ class BenchmarkPurge extends Benchmarker { */ private function randomUrl() { global $wgServer, $wgArticlePath; + return $wgServer . str_replace( '$1', $this->randomTitle(), $wgArticlePath ); } @@ -106,6 +109,7 @@ class BenchmarkPurge extends Benchmarker { for ( $i = 0; $i < $length; $i++ ) { $str .= chr( mt_rand( ord( 'a' ), ord( 'z' ) ) ); } + return ucfirst( $str ); } } diff --git a/maintenance/checkBadRedirects.php b/maintenance/checkBadRedirects.php index a96e9b80da..fec92910e4 100644 --- a/maintenance/checkBadRedirects.php +++ b/maintenance/checkBadRedirects.php @@ -44,7 +44,7 @@ class CheckBadRedirects extends Maintenance { $count = $result->numRows(); $this->output( "Found $count redirects.\n" . - "Checking for bad redirects:\n\n" ); + "Checking for bad redirects:\n\n" ); foreach ( $result as $row ) { $title = Title::makeTitle( $row->page_namespace, $row->page_title ); diff --git a/maintenance/checkImages.php b/maintenance/checkImages.php index e91464521c..3921c07910 100644 --- a/maintenance/checkImages.php +++ b/maintenance/checkImages.php @@ -80,7 +80,6 @@ class CheckImages extends Maintenance { $numGood++; } - } while ( $res->numRows() ); $this->output( "Good images: $numGood/$numImages\n" ); diff --git a/maintenance/checkSyntax.php b/maintenance/checkSyntax.php index e01767e9e1..6ef4909e1a 100644 --- a/maintenance/checkSyntax.php +++ b/maintenance/checkSyntax.php @@ -96,7 +96,7 @@ class CheckSyntax extends Maintenance { $this->mIgnorePaths = array( // Compat stuff, explodes on PHP 5.3 "includes/NamespaceCompat.php$", - ); + ); $this->mNoStyleCheckPaths = array( // Third-party code we don't care about @@ -110,13 +110,14 @@ class CheckSyntax extends Maintenance { "QPoll/Excel/", "/geshi/", "/smarty/", - ); + ); if ( $this->hasOption( 'path' ) ) { $path = $this->getOption( 'path' ); if ( !$this->addPath( $path ) ) { $this->error( "Error: can't find file or directory $path\n", true ); } + return; // process only this path } elseif ( $this->hasOption( 'list-file' ) ) { $file = $this->getOption( 'list-file' ); @@ -131,6 +132,7 @@ class CheckSyntax extends Maintenance { $this->addPath( $path ); } fclose( $f ); + return; } elseif ( $this->hasOption( 'modified' ) ) { $this->output( "Retrieving list from Git... " ); @@ -141,6 +143,7 @@ class CheckSyntax extends Maintenance { $this->mFiles[] = $file; } } + return; } @@ -241,6 +244,7 @@ class CheckSyntax extends Maintenance { return false; } } + return true; } @@ -251,6 +255,7 @@ class CheckSyntax extends Maintenance { */ private function addPath( $path ) { global $IP; + return $this->addFileOrDir( $path ) || $this->addFileOrDir( "$IP/$path" ); } @@ -267,6 +272,7 @@ class CheckSyntax extends Maintenance { } else { return false; } + return true; } @@ -313,6 +319,7 @@ class CheckSyntax extends Maintenance { $this->mFailures[$file] = $errors; } } + return $ret; } @@ -326,8 +333,10 @@ class CheckSyntax extends Maintenance { if ( strpos( $res, 'No syntax errors detected' ) === false ) { $this->mFailures[$file] = $res; $this->output( $res . "\n" ); + return false; } + return true; } diff --git a/maintenance/checkUsernames.php b/maintenance/checkUsernames.php index 6df189fcc8..777c83349c 100644 --- a/maintenance/checkUsernames.php +++ b/maintenance/checkUsernames.php @@ -55,7 +55,7 @@ class CheckUsernames extends Maintenance { ); foreach ( $res as $row ) { - if ( ! User::isValidUserName( $row->user_name ) ) { + if ( !User::isValidUserName( $row->user_name ) ) { $this->error( sprintf( "%s: %6d: '%s'\n", wfWikiID(), $row->user_id, $row->user_name ) ); wfDebugLog( 'checkUsernames', $row->user_name ); } diff --git a/maintenance/cleanupAncientTables.php b/maintenance/cleanupAncientTables.php index 428484b376..2dbf8bc1bb 100644 --- a/maintenance/cleanupAncientTables.php +++ b/maintenance/cleanupAncientTables.php @@ -83,7 +83,7 @@ class CleanupAncientTables extends Maintenance { if ( $db->indexExists( 'text', $index, __METHOD__ ) ) { $this->output( "Dropping index $index from the text table..." ); $db->query( "DROP INDEX " . $db->addIdentifierQuotes( $index ) - . " ON " . $db->tableName( 'text' ) ); + . " ON " . $db->tableName( 'text' ) ); $this->output( "done.\n" ); } } @@ -102,7 +102,7 @@ class CleanupAncientTables extends Maintenance { if ( $db->fieldExists( 'text', $field, __METHOD__ ) ) { $this->output( "Dropping the $field field from the text table..." ); $db->query( "ALTER TABLE " . $db->tableName( 'text' ) - . " DROP COLUMN " . $db->addIdentifierQuotes( $field ) ); + . " DROP COLUMN " . $db->addIdentifierQuotes( $field ) ); $this->output( "done.\n" ); } } diff --git a/maintenance/cleanupCaps.php b/maintenance/cleanupCaps.php index 321f089064..9e88c13593 100644 --- a/maintenance/cleanupCaps.php +++ b/maintenance/cleanupCaps.php @@ -71,6 +71,7 @@ class CapsCleanup extends TableCleanup { $lower = $wgContLang->lcfirst( $row->page_title ); if ( $upper == $lower ) { $this->output( "\"$display\" already lowercase.\n" ); + return $this->progress( 0 ); } @@ -78,6 +79,7 @@ class CapsCleanup extends TableCleanup { $targetDisplay = $target->getPrefixedText(); if ( $target->exists() ) { $this->output( "\"$display\" skipped; \"$targetDisplay\" already exists\n" ); + return $this->progress( 0 ); } @@ -98,6 +100,7 @@ class CapsCleanup extends TableCleanup { } } } + return $this->progress( 0 ); } } diff --git a/maintenance/cleanupImages.php b/maintenance/cleanupImages.php index 1b46ab87a4..915a2c0801 100644 --- a/maintenance/cleanupImages.php +++ b/maintenance/cleanupImages.php @@ -56,6 +56,7 @@ class ImageCleanup extends TableCleanup { if ( $source == '' ) { // Ye olde empty rows. Just kill them. $this->killRow( $source ); + return $this->progress( 1 ); } @@ -82,6 +83,7 @@ class ImageCleanup extends TableCleanup { return $this->progress( 0 ); } $this->pokeFile( $source, $safe ); + return $this->progress( 1 ); } @@ -89,6 +91,7 @@ class ImageCleanup extends TableCleanup { $munged = $title->getDBkey(); $this->output( "page $source ($munged) doesn't match self.\n" ); $this->pokeFile( $source, $munged ); + return $this->progress( 1 ); } @@ -114,6 +117,7 @@ class ImageCleanup extends TableCleanup { if ( !isset( $this->repo ) ) { $this->repo = RepoGroup::singleton()->getLocalRepo(); } + return $this->repo->getRootDirectory() . '/' . $this->repo->getHashPath( $name ) . $name; } @@ -135,6 +139,7 @@ class ImageCleanup extends TableCleanup { if ( !file_exists( $path ) ) { $this->output( "missing file: $path\n" ); $this->killRow( $orig ); + return; } @@ -150,7 +155,7 @@ class ImageCleanup extends TableCleanup { $version = 0; $final = $new; $conflict = ( $this->imageExists( $final, $db ) || - ( $this->pageExists( $orig, $db ) && $this->pageExists( $final, $db ) ) ); + ( $this->pageExists( $orig, $db ) && $this->pageExists( $final, $db ) ) ); while ( $conflict ) { $this->output( "Rename conflicts with '$final'...\n" ); @@ -184,6 +189,7 @@ class ImageCleanup extends TableCleanup { if ( !wfMkdirParents( $dir, null, __METHOD__ ) ) { $this->output( "RENAME FAILED, COULD NOT CREATE $dir" ); $db->rollback( __METHOD__ ); + return; } } @@ -210,6 +216,7 @@ class ImageCleanup extends TableCleanup { $test = Title::makeTitleSafe( NS_FILE, $x ); if ( is_null( $test ) || $test->getDBkey() !== $x ) { $this->error( "Unable to generate safe title from '$name', got '$x'" ); + return false; } diff --git a/maintenance/cleanupSpam.php b/maintenance/cleanupSpam.php index 8551f8f625..f4a5147a56 100644 --- a/maintenance/cleanupSpam.php +++ b/maintenance/cleanupSpam.php @@ -101,6 +101,7 @@ class CleanupSpam extends Maintenance { $title = Title::newFromID( $id ); if ( !$title ) { $this->error( "Internal error: no page for ID $id" ); + return; } @@ -109,7 +110,8 @@ class CleanupSpam extends Maintenance { $currentRevId = $rev->getId(); while ( $rev && ( $rev->isDeleted( Revision::DELETED_TEXT ) - || LinkFilter::matchEntry( $rev->getContent( Revision::RAW ), $domain ) ) ) { + || LinkFilter::matchEntry( $rev->getContent( Revision::RAW ), $domain ) ) + ) { $rev = $rev->getPrevious(); } diff --git a/maintenance/cleanupWatchlist.php b/maintenance/cleanupWatchlist.php index 22fd05fc4d..eb7d7b1895 100644 --- a/maintenance/cleanupWatchlist.php +++ b/maintenance/cleanupWatchlist.php @@ -69,6 +69,7 @@ class WatchlistCleanup extends TableCleanup { . "({$row->wl_namespace}, \"{$row->wl_title}\")\n" ); $updated = $this->removeWatch( $row ); $this->progress( $updated ); + return; } $this->progress( 0 ); @@ -77,12 +78,16 @@ class WatchlistCleanup extends TableCleanup { private function removeWatch( $row ) { if ( !$this->dryrun && $this->hasOption( 'fix' ) ) { $dbw = wfGetDB( DB_MASTER ); - $dbw->delete( 'watchlist', array( + $dbw->delete( + 'watchlist', array( 'wl_user' => $row->wl_user, 'wl_namespace' => $row->wl_namespace, 'wl_title' => $row->wl_title ), - __METHOD__ ); + __METHOD__ + ); + $this->output( "- removed\n" ); + return 1; } else { return 0; diff --git a/maintenance/compareParsers.php b/maintenance/compareParsers.php index 3929a5b457..e67c439baf 100644 --- a/maintenance/compareParsers.php +++ b/maintenance/compareParsers.php @@ -116,6 +116,7 @@ class CompareParsers extends DumpIterator { if ( !$this->stripParametersEnabled ) { return $text; } + return preg_replace( '/(]+>/', '$1>', $text ); } @@ -179,10 +180,9 @@ class CompareParsers extends DumpIterator { /* Look for the parser in a file appropiately named in the current folder */ if ( !class_exists( $parserName ) && file_exists( "$parserName.php" ) ) { global $wgAutoloadClasses; - $wgAutoloadClasses[ $parserName ] = realpath( '.' ) . "/$parserName.php"; + $wgAutoloadClasses[$parserName] = realpath( '.' ) . "/$parserName.php"; } } - } $maintClass = "CompareParsers"; diff --git a/maintenance/convertLinks.php b/maintenance/convertLinks.php index 6840a01bb8..11a81eb45d 100644 --- a/maintenance/convertLinks.php +++ b/maintenance/convertLinks.php @@ -71,6 +71,7 @@ class ConvertLinks extends Maintenance { $type = $dbw->getType(); if ( $type != 'mysql' ) { $this->output( "Link table conversion not necessary for $type\n" ); + return; } @@ -111,12 +112,14 @@ class ConvertLinks extends Maintenance { if ( $dbw->tableExists( 'pagelinks' ) ) { $this->output( "...have pagelinks; skipping old links table updates\n" ); + return; } $res = $dbw->query( "SELECT l_from FROM $links LIMIT 1" ); if ( $dbw->fieldType( $res, 0 ) == "int" ) { $this->output( "Schema already converted\n" ); + return; } @@ -131,7 +134,7 @@ class ConvertLinks extends Maintenance { } else { $fh = false; if ( $this->logPerformance ) { - $fh = fopen ( $perfLogFilename, "w" ); + $fh = fopen( $perfLogFilename, "w" ); if ( !$fh ) { $this->error( "Couldn't open $perfLogFilename" ); $this->logPerformance = false; @@ -140,8 +143,8 @@ class ConvertLinks extends Maintenance { $baseTime = $startTime = $this->getMicroTime(); # Create a title -> cur_id map $this->output( "Loading IDs from $cur table...\n" ); - $this->performanceLog ( $fh, "Reading $numRows rows from cur table...\n" ); - $this->performanceLog ( $fh, "rows read vs seconds elapsed:\n" ); + $this->performanceLog( $fh, "Reading $numRows rows from cur table...\n" ); + $this->performanceLog( $fh, "rows read vs seconds elapsed:\n" ); $dbw->bufferResults( false ); $res = $dbw->query( "SELECT cur_namespace,cur_title,cur_id FROM $cur" ); @@ -239,7 +242,7 @@ class ConvertLinks extends Maintenance { "Total execution time: " . ( $this->getMicroTime() - $startTime ) . " seconds.\n" ); if ( $this->logPerformance ) { - fclose ( $fh ); + fclose( $fh ); } } # -------------------------------------------------------------------- @@ -268,6 +271,7 @@ class ConvertLinks extends Maintenance { if ( !( $dbConn->isOpen() ) ) { $this->output( "Opening connection to database failed.\n" ); + return; } $links_temp = $dbConn->tableName( 'links_temp' ); @@ -279,14 +283,14 @@ class ConvertLinks extends Maintenance { $this->output( "Creating temporary links table..." ); if ( $this->hasOption( 'noKeys' ) ) { $dbConn->query( "CREATE TABLE $links_temp ( " . - "l_from int(8) unsigned NOT NULL default '0', " . - "l_to int(8) unsigned NOT NULL default '0')" ); + "l_from int(8) unsigned NOT NULL default '0', " . + "l_to int(8) unsigned NOT NULL default '0')" ); } else { $dbConn->query( "CREATE TABLE $links_temp ( " . - "l_from int(8) unsigned NOT NULL default '0', " . - "l_to int(8) unsigned NOT NULL default '0', " . - "UNIQUE KEY l_from(l_from,l_to), " . - "KEY (l_to))" ); + "l_from int(8) unsigned NOT NULL default '0', " . + "l_to int(8) unsigned NOT NULL default '0', " . + "UNIQUE KEY l_from(l_from,l_to), " . + "KEY (l_to))" ); } $this->output( " done.\n\n" ); } @@ -299,6 +303,7 @@ class ConvertLinks extends Maintenance { private function getMicroTime() { # return time in seconds, with microsecond accuracy list( $usec, $sec ) = explode( " ", microtime() ); + return ( (float)$usec + (float)$sec ); } } diff --git a/maintenance/convertUserOptions.php b/maintenance/convertUserOptions.php index 24be2b453a..bf572448fe 100644 --- a/maintenance/convertUserOptions.php +++ b/maintenance/convertUserOptions.php @@ -46,6 +46,7 @@ class ConvertUserOptions extends Maintenance { if ( !$dbw->fieldExists( 'user', 'user_options', __METHOD__ ) ) { $this->output( "nothing to migrate. " ); + return; } while ( $id !== null ) { diff --git a/maintenance/copyFileBackend.php b/maintenance/copyFileBackend.php index 86e47af9be..9ed63c3c56 100644 --- a/maintenance/copyFileBackend.php +++ b/maintenance/copyFileBackend.php @@ -373,6 +373,7 @@ class CopyFileBackend extends Maintenance { $same = ( $src->getFileSha1Base36( array( 'src' => $sPath, 'latest' => 1 ) ) === $dst->getFileSha1Base36( array( 'src' => $dPath, 'latest' => 1 ) ) ); } + return $same; } } diff --git a/maintenance/copyJobQueue.php b/maintenance/copyJobQueue.php index c5a78278f7..a9c9547ec7 100644 --- a/maintenance/copyJobQueue.php +++ b/maintenance/copyJobQueue.php @@ -89,6 +89,7 @@ class CopyJobQueue extends Maintenance { $totalOK += count( $batch ); $dst->waitForBackups(); } + return array( $total, $totalOK ); } } diff --git a/maintenance/createAndPromote.php b/maintenance/createAndPromote.php index a8de640b01..79f725426d 100644 --- a/maintenance/createAndPromote.php +++ b/maintenance/createAndPromote.php @@ -76,6 +76,7 @@ class CreateAndPromote extends Maintenance { if ( $exists && !$password && count( $promotions ) === 0 ) { $this->output( "Account exists and nothing to do.\n" ); + return; } elseif ( count( $promotions ) !== 0 ) { $promoText = "User:{$username} into " . implode( ', ', $promotions ) . "...\n"; diff --git a/maintenance/deleteArchivedFiles.inc b/maintenance/deleteArchivedFiles.inc index d58e9a407e..33da666724 100644 --- a/maintenance/deleteArchivedFiles.inc +++ b/maintenance/deleteArchivedFiles.inc @@ -49,9 +49,13 @@ class DeleteArchivedFilesImplementation { $sha1 = LocalRepo::getHashFromKey( $key ); } // Check if the file is used anywhere... - $inuse = $dbw->selectField( 'oldimage', '1', - array( 'oi_sha1' => $sha1, - 'oi_deleted & ' . File::DELETED_FILE => File::DELETED_FILE ), + $inuse = $dbw->selectField( + 'oldimage', + '1', + array( + 'oi_sha1' => $sha1, + 'oi_deleted & ' . File::DELETED_FILE => File::DELETED_FILE + ), __METHOD__, array( 'FOR UPDATE' ) ); diff --git a/maintenance/deleteArchivedFiles.php b/maintenance/deleteArchivedFiles.php index ad7b54d078..286b1f246b 100644 --- a/maintenance/deleteArchivedFiles.php +++ b/maintenance/deleteArchivedFiles.php @@ -47,6 +47,7 @@ class DeleteArchivedFiles extends Maintenance { public function execute() { if ( !$this->hasOption( 'delete' ) ) { $this->output( "Use --delete to actually confirm this script\n" ); + return; } $force = $this->hasOption( 'force' ); diff --git a/maintenance/deleteArchivedRevisions.inc b/maintenance/deleteArchivedRevisions.inc index 62465abdfc..ed620ee36a 100644 --- a/maintenance/deleteArchivedRevisions.inc +++ b/maintenance/deleteArchivedRevisions.inc @@ -30,7 +30,6 @@ class DeleteArchivedRevisionsImplementation { /** * Perform the delete on archived revisions. - * @param object $maint An object (typically of class Maintenance) * that implements two methods: handleOutput() and * purgeRedundantText(). See Maintenance for a description of diff --git a/maintenance/deleteBatch.php b/maintenance/deleteBatch.php index b21d950bc3..a751396734 100644 --- a/maintenance/deleteBatch.php +++ b/maintenance/deleteBatch.php @@ -3,11 +3,11 @@ * Deletes a batch of pages. * Usage: php deleteBatch.php [-u ] [-r ] [-i ] [listfile] * where - * [listfile] is a file where each line contains the title of a page to be - * deleted, standard input is used if listfile is not given. - * is the username - * is the delete reason - * is the number of seconds to sleep for after each delete + * [listfile] is a file where each line contains the title of a page to be + * deleted, standard input is used if listfile is not given. + * is the username + * is the delete reason + * is the number of seconds to sleep for after each delete * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/maintenance/deleteDefaultMessages.php b/maintenance/deleteDefaultMessages.php index 7d8c80e497..5aeeb8e115 100644 --- a/maintenance/deleteDefaultMessages.php +++ b/maintenance/deleteDefaultMessages.php @@ -34,7 +34,7 @@ class DeleteDefaultMessages extends Maintenance { public function __construct() { parent::__construct(); $this->mDescription = "Deletes all pages in the MediaWiki namespace" . - " which were last edited by \"MediaWiki default\""; + " which were last edited by \"MediaWiki default\""; } public function execute() { @@ -54,6 +54,7 @@ class DeleteDefaultMessages extends Maintenance { if ( $dbr->numRows( $res ) == 0 ) { # No more messages left $this->output( "done.\n" ); + return; } diff --git a/maintenance/deleteEqualMessages.php b/maintenance/deleteEqualMessages.php index 81758913dd..c30a86e4a7 100644 --- a/maintenance/deleteEqualMessages.php +++ b/maintenance/deleteEqualMessages.php @@ -130,6 +130,7 @@ class DeleteEqualMessages extends Maintenance { if ( $messageInfo['equalPages'] === 0 ) { // No more equal messages left $this->output( "\ndone.\n" ); + return; } @@ -151,6 +152,7 @@ class DeleteEqualMessages extends Maintenance { $this->output( " (include --delete-talk to also delete the talk pages)" ); } $this->output( "\n" ); + return; } diff --git a/maintenance/deleteImageMemcached.php b/maintenance/deleteImageMemcached.php index b44a4248c5..4799e5e0d7 100644 --- a/maintenance/deleteImageMemcached.php +++ b/maintenance/deleteImageMemcached.php @@ -80,6 +80,7 @@ class DeleteImageCache extends Maintenance { private function getImageCount() { $dbr = wfGetDB( DB_SLAVE ); + return $dbr->selectField( 'image', 'COUNT(*)', array(), __METHOD__ ); } } diff --git a/maintenance/deleteRevision.php b/maintenance/deleteRevision.php index 31f206df62..818ee360dd 100644 --- a/maintenance/deleteRevision.php +++ b/maintenance/deleteRevision.php @@ -42,29 +42,31 @@ class DeleteRevision extends Maintenance { } $this->output( "Deleting revision(s) " . implode( ',', $this->mArgs ) . - " from " . wfWikiID() . "...\n" ); + " from " . wfWikiID() . "...\n" ); $dbw = wfGetDB( DB_MASTER ); $affected = 0; foreach ( $this->mArgs as $revID ) { $dbw->insertSelect( 'archive', array( 'page', 'revision' ), array( - 'ar_namespace' => 'page_namespace', - 'ar_title' => 'page_title', - 'ar_page_id' => 'page_id', - 'ar_comment' => 'rev_comment', - 'ar_user' => 'rev_user', - 'ar_user_text' => 'rev_user_text', - 'ar_timestamp' => 'rev_timestamp', + 'ar_namespace' => 'page_namespace', + 'ar_title' => 'page_title', + 'ar_page_id' => 'page_id', + 'ar_comment' => 'rev_comment', + 'ar_user' => 'rev_user', + 'ar_user_text' => 'rev_user_text', + 'ar_timestamp' => 'rev_timestamp', 'ar_minor_edit' => 'rev_minor_edit', - 'ar_rev_id' => 'rev_id', - 'ar_text_id' => 'rev_text_id', - 'ar_deleted' => 'rev_deleted', - 'ar_len' => 'rev_len', - ), array( + 'ar_rev_id' => 'rev_id', + 'ar_text_id' => 'rev_text_id', + 'ar_deleted' => 'rev_deleted', + 'ar_len' => 'rev_len', + ), + array( 'rev_id' => $revID, 'page_id = rev_page' - ), __METHOD__ + ), + __METHOD__ ); if ( !$dbw->affectedRows() ) { $this->output( "Revision $revID not found\n" ); diff --git a/maintenance/dev/includes/router.php b/maintenance/dev/includes/router.php index a3cc0ba3f8..246d6fc649 100644 --- a/maintenance/dev/includes/router.php +++ b/maintenance/dev/includes/router.php @@ -59,6 +59,7 @@ if ( $ext == 'php' || $ext == 'php5' ) { # the php webserver will discard post data and things like login # will not function in the dev environment. require $file; + return true; } $mime = false; @@ -93,6 +94,7 @@ if ( $mime ) { header( "Content-Length: " . filesize( $file ) ); // Stream that out to the browser fpassthru( $f ); + return true; } diff --git a/maintenance/dumpBackup.php b/maintenance/dumpBackup.php index 02bfd60017..18c78dcda7 100644 --- a/maintenance/dumpBackup.php +++ b/maintenance/dumpBackup.php @@ -127,5 +127,5 @@ Fancy stuff: (Works? Add examples please.) --filter=[:] Add a filter on an output branch ENDS -); + ); } diff --git a/maintenance/dumpIterator.php b/maintenance/dumpIterator.php index 078c598ad5..4b2ff717e3 100644 --- a/maintenance/dumpIterator.php +++ b/maintenance/dumpIterator.php @@ -123,6 +123,7 @@ abstract class DumpIterator extends Maintenance { $title = $rev->getTitle(); if ( !$title ) { $this->error( "Got bogus revision with null title!" ); + return; } diff --git a/maintenance/dumpTextPass.php b/maintenance/dumpTextPass.php index 71895bd1e6..7c176071ad 100644 --- a/maintenance/dumpTextPass.php +++ b/maintenance/dumpTextPass.php @@ -61,5 +61,5 @@ Options: --spawn Spawn a subprocess for loading text records --help Display this help message ENDS -); + ); } diff --git a/maintenance/dumpUploads.php b/maintenance/dumpUploads.php index d6c70f8e8f..9d53f07c1d 100644 --- a/maintenance/dumpUploads.php +++ b/maintenance/dumpUploads.php @@ -64,7 +64,7 @@ By default, outputs relative paths against the parent directory of \$wgUploadDir $this->mSharedSupplement = true; } } - $this->{ $this->mAction } ( $this->mShared ); + $this->{$this->mAction} ( $this->mShared ); if ( $this->mSharedSupplement ) { $this->fetchUsed( true ); } diff --git a/maintenance/fetchText.php b/maintenance/fetchText.php index df5a2085f6..fc676b89d7 100644 --- a/maintenance/fetchText.php +++ b/maintenance/fetchText.php @@ -37,11 +37,11 @@ class FetchText extends Maintenance { /** * returns a string containing the following in order: - * textid - * \n - * length of text (-1 on error = failure to retrieve/unserialize/gunzip/etc) - * \n - * text (may be empty) + * textid + * \n + * length of text (-1 on error = failure to retrieve/unserialize/gunzip/etc) + * \n + * text (may be empty) * * note that that the text string itself is *not* followed by newline */ @@ -59,8 +59,7 @@ class FetchText extends Maintenance { if ( $text === false ) { # actual error, not zero-length text $textLen = "-1"; - } - else { + } else { $textLen = strlen( $text ); } $this->output( $textId . "\n" . $textLen . "\n" . $text ); @@ -83,6 +82,7 @@ class FetchText extends Maintenance { if ( $text === false ) { return false; } + return $text; } } diff --git a/maintenance/findHooks.php b/maintenance/findHooks.php index 7c6c824282..86c01f4c40 100644 --- a/maintenance/findHooks.php +++ b/maintenance/findHooks.php @@ -146,10 +146,11 @@ class FindHooks extends Maintenance { * @return array Array of documented hooks */ private function getHooksFromLocalDoc( $doc ) { - $m = array(); - $content = file_get_contents( $doc ); - preg_match_all( "/\n'(.*?)':/", $content, $m ); - return array_unique( $m[1] ); + $m = array(); + $content = file_get_contents( $doc ); + preg_match_all( "/\n'(.*?)':/", $content, $m ); + + return array_unique( $m[1] ); } /** @@ -157,35 +158,36 @@ class FindHooks extends Maintenance { * @return array of documented hooks */ private function getHooksFromOnlineDoc() { - // All hooks - $allhookdata = Http::get( - 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&' - . 'cmtitle=Category:MediaWiki_hooks&cmlimit=500&format=php' - ); - $allhookdata = unserialize( $allhookdata ); - $allhooks = array(); - foreach ( $allhookdata['query']['categorymembers'] as $page ) { - $found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches ); - if ( $found ) { - $hook = str_replace( ' ', '_', $matches[1] ); - $allhooks[] = $hook; - } + // All hooks + $allhookdata = Http::get( + 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&' + . 'cmtitle=Category:MediaWiki_hooks&cmlimit=500&format=php' + ); + $allhookdata = unserialize( $allhookdata ); + $allhooks = array(); + foreach ( $allhookdata['query']['categorymembers'] as $page ) { + $found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches ); + if ( $found ) { + $hook = str_replace( ' ', '_', $matches[1] ); + $allhooks[] = $hook; } - // Removed hooks - $oldhookdata = Http::get( - 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&' - . 'cmtitle=Category:Removed_hooks&cmlimit=500&format=php' - ); - $oldhookdata = unserialize( $oldhookdata ); - $removed = array(); - foreach ( $oldhookdata['query']['categorymembers'] as $page ) { - $found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches ); - if ( $found ) { - $hook = str_replace( ' ', '_', $matches[1] ); - $removed[] = $hook; - } + } + // Removed hooks + $oldhookdata = Http::get( + 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&' + . 'cmtitle=Category:Removed_hooks&cmlimit=500&format=php' + ); + $oldhookdata = unserialize( $oldhookdata ); + $removed = array(); + foreach ( $oldhookdata['query']['categorymembers'] as $page ) { + $found = preg_match( '/Manual\:Hooks\/([a-zA-Z0-9- :]+)/', $page['title'], $matches ); + if ( $found ) { + $hook = str_replace( ' ', '_', $matches[1] ); + $removed[] = $hook; } - return array_diff( $allhooks, $removed ); + } + + return array_diff( $allhooks, $removed ); } /** @@ -221,6 +223,7 @@ class FindHooks extends Maintenance { } closedir( $dh ); } + return $hooks; } @@ -238,6 +241,7 @@ class FindHooks extends Maintenance { foreach ( $m[0] as $match ) { $list[] = $match . "(" . $file . ")"; } + return $list; } @@ -258,6 +262,7 @@ class FindHooks extends Maintenance { } closedir( $dh ); } + return $hooks; } diff --git a/maintenance/fixDoubleRedirects.php b/maintenance/fixDoubleRedirects.php index af8a58e24e..0b3cdba4c2 100644 --- a/maintenance/fixDoubleRedirects.php +++ b/maintenance/fixDoubleRedirects.php @@ -85,6 +85,7 @@ class FixDoubleRedirects extends Maintenance { if ( !$res->numRows() ) { $this->output( "No double redirects found.\n" ); + return; } -- 2.20.1