Pass phpcs-strict on maintenance/ (6/8)
authorSiebrand Mazeland <siebrand@kitano.nl>
Wed, 23 Apr 2014 09:22:55 +0000 (11:22 +0200)
committerSiebrand <siebrand@kitano.nl>
Wed, 23 Apr 2014 09:27:41 +0000 (09:27 +0000)
Change-Id: Icefd7660072aedb963fe3082ec40fb8ffcfd6286

maintenance/compareParsers.php
maintenance/convertLinks.php
maintenance/createAndPromote.php
maintenance/deleteArchivedRevisions.php
maintenance/deleteBatch.php
maintenance/deleteImageMemcached.php
maintenance/deleteOrphanedRevisions.php
maintenance/deleteRevision.php
maintenance/doMaintenance.php
maintenance/dumpIterator.php

index f33ff40..3929a5b 100644 (file)
@@ -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() ) );
                        }
index 6e6df24..6840a01 100644 (file)
@@ -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 );
                        }
index aa25ee6..a8de640 100644 (file)
@@ -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" );
index ffd581c..30883ba 100644 (file)
@@ -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" );
                }
        }
 }
index c1cc03c..b21d950 100644 (file)
@@ -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;
index 835de35..b44a424 100644 (file)
@@ -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 ) );
index 9922a1d..7f1ffe4 100644 (file)
@@ -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)
index 6bc0f7c..31f206d 100644 (file)
@@ -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__
+                                       );
                                }
                        }
                }
index 2b637cb..47e6a89 100644 (file)
@@ -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';
        }
 }
index cf3523e..078c598 100644 (file)
@@ -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" );
        }