From 752c7081495438e7199d966c3a8757a11489e16e Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Wed, 23 Apr 2014 11:22:55 +0200 Subject: [PATCH] Pass phpcs-strict on maintenance/ (6/8) Change-Id: Icefd7660072aedb963fe3082ec40fb8ffcfd6286 --- maintenance/compareParsers.php | 44 ++++++++++-- maintenance/convertLinks.php | 90 +++++++++++++++++++------ maintenance/createAndPromote.php | 13 ++-- maintenance/deleteArchivedRevisions.php | 6 +- maintenance/deleteBatch.php | 2 + maintenance/deleteImageMemcached.php | 7 +- maintenance/deleteOrphanedRevisions.php | 3 +- maintenance/deleteRevision.php | 29 ++++++-- maintenance/doMaintenance.php | 7 +- maintenance/dumpIterator.php | 13 ++-- 10 files changed, 168 insertions(+), 46 deletions(-) diff --git a/maintenance/compareParsers.php b/maintenance/compareParsers.php index f33ff40d41..3929a5b457 100644 --- a/maintenance/compareParsers.php +++ b/maintenance/compareParsers.php @@ -47,11 +47,31 @@ class CompareParsers extends DumpIterator { $this->addOption( 'parser1', 'The first parser to compare.', true, true ); $this->addOption( 'parser2', 'The second parser to compare.', true, true ); $this->addOption( 'tidy', 'Run tidy on the articles.', false, false ); - $this->addOption( 'save-failed', 'Folder in which articles which differ will be stored.', false, true ); + $this->addOption( + 'save-failed', + 'Folder in which articles which differ will be stored.', + false, + true + ); $this->addOption( 'show-diff', 'Show a diff of the two renderings.', false, false ); - $this->addOption( 'diff-bin', 'Binary to use for diffing (can also be provided by DIFF env var).', false, false ); - $this->addOption( 'strip-parameters', 'Remove parameters of html tags to increase readability.', false, false ); - $this->addOption( 'show-parsed-output', 'Show the parsed html if both Parsers give the same output.', false, false ); + $this->addOption( + 'diff-bin', + 'Binary to use for diffing (can also be provided by DIFF env var).', + false, + false + ); + $this->addOption( + 'strip-parameters', + 'Remove parameters of html tags to increase readability.', + false, + false + ); + $this->addOption( + 'show-parsed-output', + 'Show the parsed html if both Parsers give the same output.', + false, + false + ); } public function checkOptions() { @@ -118,7 +138,9 @@ class CompareParsers extends DumpIterator { $content = $rev->getContent(); if ( $content->getModel() !== CONTENT_MODEL_WIKITEXT ) { - $this->error( "Page {$title->getPrefixedText()} does not contain wikitext but {$content->getModel()}\n" ); + $this->error( "Page {$title->getPrefixedText()} does not contain wikitext " + . "but {$content->getModel()}\n" ); + return; } @@ -132,13 +154,21 @@ class CompareParsers extends DumpIterator { $this->error( "Parsing for {$title->getPrefixedText()} differs\n" ); if ( $this->saveFailed ) { - file_put_contents( $this->saveFailed . '/' . rawurlencode( $title->getPrefixedText() ) . ".txt", $text ); + file_put_contents( + $this->saveFailed . '/' . rawurlencode( $title->getPrefixedText() ) . ".txt", + $text + ); } if ( $this->showDiff ) { - $this->output( wfDiff( $this->stripParameters( $output1->getText() ), $this->stripParameters( $output2->getText() ), '' ) ); + $this->output( wfDiff( + $this->stripParameters( $output1->getText() ), + $this->stripParameters( $output2->getText() ), + '' + ) ); } } else { $this->output( $title->getPrefixedText() . "\tOK\n" ); + if ( $this->showParsedOutput ) { $this->output( $this->stripParameters( $output1->getText() ) ); } diff --git a/maintenance/convertLinks.php b/maintenance/convertLinks.php index 6e6df24be6..6840a01bb8 100644 --- a/maintenance/convertLinks.php +++ b/maintenance/convertLinks.php @@ -36,14 +36,29 @@ class ConvertLinks extends Maintenance { public function __construct() { parent::__construct(); - $this->mDescription = "Convert from the old links schema (string->ID) to the new schema (ID->ID). -The wiki should be put into read-only mode while this script executes"; + $this->mDescription = + "Convert from the old links schema (string->ID) to the new schema (ID->ID)." + . "The wiki should be put into read-only mode while this script executes"; $this->addArg( 'logperformance', "Log performance to perfLogFilename.", false ); - $this->addArg( 'perfLogFilename', "Filename where performance is logged if --logperformance was set (defaults to 'convLinksPerf.txt').", false ); - $this->addArg( 'keep-links-table', "Don't overwrite the old links table with the new one, leave the new table at links_temp.", false ); - $this->addArg( 'nokeys', "Don't create keys, and so allow duplicates in the new links table.\n -This gives a huge speed improvement for very large links tables which are MyISAM." /* (What about InnoDB?) */, false ); + $this->addArg( + 'perfLogFilename', + "Filename where performance is logged if --logperformance was set " + . "(defaults to 'convLinksPerf.txt').", + false + ); + $this->addArg( + 'keep-links-table', + "Don't overwrite the old links table with the new one, leave the new table at links_temp.", + false + ); + $this->addArg( + 'nokeys', + /* (What about InnoDB?) */ + "Don't create keys, and so allow duplicates in the new links table.\n" + . "This gives a huge speed improvement for very large links tables which are MyISAM.", + false + ); } public function getDbType() { @@ -61,17 +76,28 @@ This gives a huge speed improvement for very large links tables which are MyISAM global $wgContLang; - $numBadLinks = $curRowsRead = 0; # counters etc - $totalTuplesInserted = 0; # total tuples INSERTed into links_temp + # counters etc + $numBadLinks = $curRowsRead = 0; - $reportCurReadProgress = true; # whether or not to give progress reports while reading IDs from cur table - $curReadReportInterval = 1000; # number of rows between progress reports + # total tuples INSERTed into links_temp + $totalTuplesInserted = 0; - $reportLinksConvProgress = true; # whether or not to give progress reports during conversion - $linksConvInsertInterval = 1000; # number of rows per INSERT + # whether or not to give progress reports while reading IDs from cur table + $reportCurReadProgress = true; + + # number of rows between progress reports + $curReadReportInterval = 1000; + + # whether or not to give progress reports during conversion + $reportLinksConvProgress = true; + + # number of rows per INSERT + $linksConvInsertInterval = 1000; $initialRowOffset = 0; - # $finalRowOffset = 0; # not used yet; highest row number from links table to process + + # not used yet; highest row number from links table to process + # $finalRowOffset = 0; $overwriteLinksTable = !$this->hasOption( 'keep-links-table' ); $noKeys = $this->hasOption( 'noKeys' ); @@ -80,7 +106,8 @@ This gives a huge speed improvement for very large links tables which are MyISAM # -------------------------------------------------------------------- - list( $cur, $links, $links_temp, $links_backup ) = $dbw->tableNamesN( 'cur', 'links', 'links_temp', 'links_backup' ); + list( $cur, $links, $links_temp, $links_backup ) = + $dbw->tableNamesN( 'cur', 'links', 'links_temp', 'links_backup' ); if ( $dbw->tableExists( 'pagelinks' ) ) { $this->output( "...have pagelinks; skipping old links table updates\n" ); @@ -129,7 +156,10 @@ This gives a huge speed improvement for very large links tables which are MyISAM $curRowsRead++; if ( $reportCurReadProgress ) { if ( ( $curRowsRead % $curReadReportInterval ) == 0 ) { - $this->performanceLog( $fh, $curRowsRead . " " . ( $this->getMicroTime() - $baseTime ) . "\n" ); + $this->performanceLog( + $fh, + $curRowsRead . " " . ( $this->getMicroTime() - $baseTime ) . "\n" + ); $this->output( "\t$curRowsRead rows of $cur table read.\n" ); } } @@ -137,7 +167,10 @@ This gives a huge speed improvement for very large links tables which are MyISAM $dbw->freeResult( $res ); $dbw->bufferResults( true ); $this->output( "Finished loading IDs.\n\n" ); - $this->performanceLog( $fh, "Took " . ( $this->getMicroTime() - $baseTime ) . " seconds to load IDs.\n\n" ); + $this->performanceLog( + $fh, + "Took " . ( $this->getMicroTime() - $baseTime ) . " seconds to load IDs.\n\n" + ); # -------------------------------------------------------------------- @@ -150,7 +183,9 @@ This gives a huge speed improvement for very large links tables which are MyISAM $this->performanceLog( $fh, "Processing $numRows rows from $links table...\n" ); $this->performanceLog( $fh, "rows inserted vs seconds elapsed:\n" ); - for ( $rowOffset = $initialRowOffset; $rowOffset < $numRows; $rowOffset += $linksConvInsertInterval ) { + for ( $rowOffset = $initialRowOffset; $rowOffset < $numRows; + $rowOffset += $linksConvInsertInterval + ) { $sqlRead = "SELECT * FROM $links "; $sqlRead = $dbw->limitResult( $sqlRead, $linksConvInsertInterval, $rowOffset ); $res = $dbw->query( $sqlRead ); @@ -176,7 +211,8 @@ This gives a huge speed improvement for very large links tables which are MyISAM } } $dbw->freeResult( $res ); - # $this->output( "rowOffset: $rowOffset\ttuplesAdded: $tuplesAdded\tnumBadLinks: $numBadLinks\n" ); + # $this->output( "rowOffset: $rowOffset\ttuplesAdded: " + # . "$tuplesAdded\tnumBadLinks: $numBadLinks\n" ); if ( $tuplesAdded != 0 ) { if ( $reportLinksConvProgress ) { $this->output( "Inserting $tuplesAdded tuples into $links_temp..." ); @@ -185,13 +221,23 @@ This gives a huge speed improvement for very large links tables which are MyISAM $totalTuplesInserted += $tuplesAdded; if ( $reportLinksConvProgress ) { $this->output( " done. Total $totalTuplesInserted tuples inserted.\n" ); - $this->performanceLog( $fh, $totalTuplesInserted . " " . ( $this->getMicroTime() - $baseTime ) . "\n" ); + $this->performanceLog( + $fh, + $totalTuplesInserted . " " . ( $this->getMicroTime() - $baseTime ) . "\n" + ); } } } - $this->output( "$totalTuplesInserted valid titles and $numBadLinks invalid titles were processed.\n\n" ); - $this->performanceLog( $fh, "$totalTuplesInserted valid titles and $numBadLinks invalid titles were processed.\n" ); - $this->performanceLog( $fh, "Total execution time: " . ( $this->getMicroTime() - $startTime ) . " seconds.\n" ); + $this->output( "$totalTuplesInserted valid titles and " + . "$numBadLinks invalid titles were processed.\n\n" ); + $this->performanceLog( + $fh, + "$totalTuplesInserted valid titles and $numBadLinks invalid titles were processed.\n" + ); + $this->performanceLog( + $fh, + "Total execution time: " . ( $this->getMicroTime() - $startTime ) . " seconds.\n" + ); if ( $this->logPerformance ) { fclose ( $fh ); } diff --git a/maintenance/createAndPromote.php b/maintenance/createAndPromote.php index aa25ee6022..a8de640b01 100644 --- a/maintenance/createAndPromote.php +++ b/maintenance/createAndPromote.php @@ -31,13 +31,15 @@ require_once __DIR__ . '/Maintenance.php'; * @ingroup Maintenance */ class CreateAndPromote extends Maintenance { - - static $permitRoles = array( 'sysop', 'bureaucrat', 'bot' ); + private static $permitRoles = array( 'sysop', 'bureaucrat', 'bot' ); public function __construct() { parent::__construct(); $this->mDescription = "Create a new user account and/or grant it additional rights"; - $this->addOption( "force", "If acccount exists already, just grant it rights or change password." ); + $this->addOption( + 'force', + 'If acccount exists already, just grant it rights or change password.' + ); foreach ( self::$permitRoles as $role ) { $this->addOption( $role, "Add the account to the {$role} group" ); } @@ -67,7 +69,10 @@ class CreateAndPromote extends Maintenance { $inGroups = $user->getGroups(); } - $promotions = array_diff( array_filter( self::$permitRoles, array( $this, 'hasOption' ) ), $inGroups ); + $promotions = array_diff( + array_filter( self::$permitRoles, array( $this, 'hasOption' ) ), + $inGroups + ); if ( $exists && !$password && count( $promotions ) === 0 ) { $this->output( "Account exists and nothing to do.\n" ); diff --git a/maintenance/deleteArchivedRevisions.php b/maintenance/deleteArchivedRevisions.php index ffd581c18a..30883ba4f5 100644 --- a/maintenance/deleteArchivedRevisions.php +++ b/maintenance/deleteArchivedRevisions.php @@ -36,7 +36,8 @@ require_once __DIR__ . '/deleteArchivedRevisions.inc'; class DeleteArchivedRevisions extends Maintenance { public function __construct() { parent::__construct(); - $this->mDescription = "Deletes all archived revisions\nThese revisions will no longer be restorable"; + $this->mDescription = + "Deletes all archived revisions\nThese revisions will no longer be restorable"; $this->addOption( 'delete', 'Performs the deletion' ); } @@ -53,7 +54,8 @@ class DeleteArchivedRevisions extends Maintenance { $dbw = wfGetDB( DB_MASTER ); $res = $dbw->selectRow( 'archive', 'COUNT(*) as count', array(), __FUNCTION__ ); $this->output( "Found {$res->count} revisions to delete.\n" ); - $this->output( "Please run the script again with the --delete option to really delete the revisions.\n" ); + $this->output( "Please run the script again with the --delete option " + . "to really delete the revisions.\n" ); } } } diff --git a/maintenance/deleteBatch.php b/maintenance/deleteBatch.php index c1cc03cdc2..b21d950bc3 100644 --- a/maintenance/deleteBatch.php +++ b/maintenance/deleteBatch.php @@ -79,7 +79,9 @@ class DeleteBatch extends Maintenance { $dbw = wfGetDB( DB_MASTER ); # Handle each entry + // @codingStandardsIgnoreStart Ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed for ( $linenum = 1; !feof( $file ); $linenum++ ) { + // @codingStandardsIgnoreEnd $line = trim( fgets( $file ) ); if ( $line == '' ) { continue; diff --git a/maintenance/deleteImageMemcached.php b/maintenance/deleteImageMemcached.php index 835de352d2..b44a4248c5 100644 --- a/maintenance/deleteImageMemcached.php +++ b/maintenance/deleteImageMemcached.php @@ -60,7 +60,12 @@ class DeleteImageCache extends Maintenance { foreach ( $res as $row ) { if ( $i % $this->report == 0 ) { - $this->output( sprintf( "%s: %13s done (%s)\n", wfWikiID(), "$i/$total", wfPercent( $i / $total * 100 ) ) ); + $this->output( sprintf( + "%s: %13s done (%s)\n", + wfWikiID(), + "$i/$total", + wfPercent( $i / $total * 100 ) + ) ); } $md5 = md5( $row->img_name ); $wgMemc->delete( wfMemcKey( 'Image', $md5 ) ); diff --git a/maintenance/deleteOrphanedRevisions.php b/maintenance/deleteOrphanedRevisions.php index 9922a1d0d4..7f1ffe418b 100644 --- a/maintenance/deleteOrphanedRevisions.php +++ b/maintenance/deleteOrphanedRevisions.php @@ -49,7 +49,8 @@ class DeleteOrphanedRevisions extends Maintenance { # Find all the orphaned revisions $this->output( "Checking for orphaned revisions..." ); - $sql = "SELECT rev_id FROM {$revision} LEFT JOIN {$page} ON rev_page = page_id WHERE page_namespace IS NULL"; + $sql = "SELECT rev_id FROM {$revision} LEFT JOIN {$page} ON rev_page = page_id " + . "WHERE page_namespace IS NULL"; $res = $dbw->query( $sql, 'deleteOrphanedRevisions' ); # Stash 'em all up for deletion (if needed) diff --git a/maintenance/deleteRevision.php b/maintenance/deleteRevision.php index 6bc0f7cd01..31f206df62 100644 --- a/maintenance/deleteRevision.php +++ b/maintenance/deleteRevision.php @@ -70,13 +70,34 @@ class DeleteRevision extends Maintenance { $this->output( "Revision $revID not found\n" ); } else { $affected += $dbw->affectedRows(); - $pageID = $dbw->selectField( 'revision', 'rev_page', array( 'rev_id' => $revID ), __METHOD__ ); - $pageLatest = $dbw->selectField( 'page', 'page_latest', array( 'page_id' => $pageID ), __METHOD__ ); + $pageID = $dbw->selectField( + 'revision', + 'rev_page', + array( 'rev_id' => $revID ), + __METHOD__ + ); + $pageLatest = $dbw->selectField( + 'page', + 'page_latest', + array( 'page_id' => $pageID ), + __METHOD__ + ); $dbw->delete( 'revision', array( 'rev_id' => $revID ) ); if ( $pageLatest == $revID ) { // Database integrity - $newLatest = $dbw->selectField( 'revision', 'rev_id', array( 'rev_page' => $pageID ), __METHOD__, array( 'ORDER BY' => 'rev_timestamp DESC' ) ); - $dbw->update( 'page', array( 'page_latest' => $newLatest ), array( 'page_id' => $pageID ), __METHOD__ ); + $newLatest = $dbw->selectField( + 'revision', + 'rev_id', + array( 'rev_page' => $pageID ), + __METHOD__, + array( 'ORDER BY' => 'rev_timestamp DESC' ) + ); + $dbw->update( + 'page', + array( 'page_latest' => $newLatest ), + array( 'page_id' => $pageID ), + __METHOD__ + ); } } } diff --git a/maintenance/doMaintenance.php b/maintenance/doMaintenance.php index 2b637cb707..47e6a898b4 100644 --- a/maintenance/doMaintenance.php +++ b/maintenance/doMaintenance.php @@ -82,8 +82,10 @@ if ( defined( 'MW_CONFIG_CALLBACK' ) ) { // @todo FIXME: Replace this hack with general farm-friendly code # @todo FIXME: Wikimedia-specific stuff needs to go away to an ext # Maybe a hook? + // @codingStandardsIgnoreStart MediaWiki.NamingConventions.ValidGlobalName.wgPrefix global $cluster; $cluster = 'pmtpa'; + // @codingStandardsIgnoreEnd require "$IP/../wmf-config/wgConf.php"; } // Require the configuration (probably LocalSettings.php) @@ -91,7 +93,10 @@ if ( defined( 'MW_CONFIG_CALLBACK' ) ) { } if ( $maintenance->getDbType() === Maintenance::DB_NONE ) { - if ( $wgLocalisationCacheConf['storeClass'] === false && ( $wgLocalisationCacheConf['store'] == 'db' || ( $wgLocalisationCacheConf['store'] == 'detect' && !$wgCacheDirectory ) ) ) { + if ( $wgLocalisationCacheConf['storeClass'] === false + && ( $wgLocalisationCacheConf['store'] == 'db' + || ( $wgLocalisationCacheConf['store'] == 'detect' && !$wgCacheDirectory ) ) + ) { $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull'; } } diff --git a/maintenance/dumpIterator.php b/maintenance/dumpIterator.php index cf3523e61b..078c598ad5 100644 --- a/maintenance/dumpIterator.php +++ b/maintenance/dumpIterator.php @@ -57,8 +57,11 @@ abstract class DumpIterator extends Maintenance { $revision = new WikiRevision; $revision->setText( file_get_contents( $this->getOption( 'file' ) ) ); - $revision->setTitle( Title::newFromText( rawurldecode( basename( $this->getOption( 'file' ), '.txt' ) ) ) ); + $revision->setTitle( Title::newFromText( + rawurldecode( basename( $this->getOption( 'file' ), '.txt' ) ) + ) ); $this->handleRevision( $revision ); + return; } @@ -67,7 +70,8 @@ abstract class DumpIterator extends Maintenance { if ( $this->getOption( 'dump' ) == '-' ) { $source = new ImportStreamSource( $this->getStdin() ); } else { - $this->error( "Sorry, I don't support dump filenames yet. Use - and provide it on stdin on the meantime.", true ); + $this->error( "Sorry, I don't support dump filenames yet. " + . "Use - and provide it on stdin on the meantime.", true ); } $importer = new WikiImporter( $source ); @@ -86,8 +90,9 @@ abstract class DumpIterator extends Maintenance { $this->error( round( $this->count / $delta, 2 ) . " pages/sec" ); } - # Perform the memory_get_peak_usage() when all the other data has been output so there's no damage if it dies. - # It is only available since 5.2.0 (since 5.2.1 if you haven't compiled with --enable-memory-limit) + # Perform the memory_get_peak_usage() when all the other data has been + # output so there's no damage if it dies. It is only available since + # 5.2.0 (since 5.2.1 if you haven't compiled with --enable-memory-limit) $this->error( "Memory peak usage of " . memory_get_peak_usage() . " bytes\n" ); } -- 2.20.1