Siebrand has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/129123

Change subject: Pass phpcs-strict on maintenance/ (6/8)
......................................................................

Pass phpcs-strict on maintenance/ (6/8)

Change-Id: Icefd7660072aedb963fe3082ec40fb8ffcfd6286
---
M maintenance/compareParsers.php
M maintenance/convertLinks.php
M maintenance/createAndPromote.php
M maintenance/deleteArchivedRevisions.php
M maintenance/deleteBatch.php
M maintenance/deleteImageMemcached.php
M maintenance/deleteOrphanedRevisions.php
M maintenance/deleteRevision.php
M maintenance/doMaintenance.php
M maintenance/dumpIterator.php
10 files changed, 168 insertions(+), 46 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/23/129123/1

diff --git a/maintenance/compareParsers.php b/maintenance/compareParsers.php
index f33ff40..3929a5b 100644
--- a/maintenance/compareParsers.php
+++ b/maintenance/compareParsers.php
@@ -47,11 +47,31 @@
                $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 @@
                $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 @@
                        $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 6e6df24..6840a01 100644
--- a/maintenance/convertLinks.php
+++ b/maintenance/convertLinks.php
@@ -36,14 +36,29 @@
 
        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 @@
 
                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 @@
 
                # 
--------------------------------------------------------------------
 
-               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 @@
                                $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 @@
                        $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->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 @@
                                        }
                                }
                                $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 @@
                                        $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 aa25ee6..a8de640 100644
--- a/maintenance/createAndPromote.php
+++ b/maintenance/createAndPromote.php
@@ -31,13 +31,15 @@
  * @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 @@
                        $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 ffd581c..30883ba 100644
--- a/maintenance/deleteArchivedRevisions.php
+++ b/maintenance/deleteArchivedRevisions.php
@@ -36,7 +36,8 @@
 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 @@
                        $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 c1cc03c..b21d950 100644
--- a/maintenance/deleteBatch.php
+++ b/maintenance/deleteBatch.php
@@ -79,7 +79,9 @@
                $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 835de35..b44a424 100644
--- a/maintenance/deleteImageMemcached.php
+++ b/maintenance/deleteImageMemcached.php
@@ -60,7 +60,12 @@
 
                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 9922a1d..7f1ffe4 100644
--- a/maintenance/deleteOrphanedRevisions.php
+++ b/maintenance/deleteOrphanedRevisions.php
@@ -49,7 +49,8 @@
 
                # 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 6bc0f7c..31f206d 100644
--- a/maintenance/deleteRevision.php
+++ b/maintenance/deleteRevision.php
@@ -70,13 +70,34 @@
                                $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 2b637cb..47e6a89 100644
--- a/maintenance/doMaintenance.php
+++ b/maintenance/doMaintenance.php
@@ -82,8 +82,10 @@
                // @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 ( $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 cf3523e..078c598 100644
--- a/maintenance/dumpIterator.php
+++ b/maintenance/dumpIterator.php
@@ -57,8 +57,11 @@
                        $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 @@
                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 @@
                        $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" );
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/129123
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icefd7660072aedb963fe3082ec40fb8ffcfd6286
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Siebrand <siebr...@kitano.nl>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to