Siebrand has uploaded a new change for review.

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

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

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

Woo!

Change-Id: I6c591492db363dfab81e5ddfa4a03213347ff5cb
---
M maintenance/Maintenance.php
M maintenance/attachLatest.php
M maintenance/backup.inc
M maintenance/backupPrefetch.inc
M maintenance/backupTextPass.inc
5 files changed, 131 insertions(+), 82 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/53/129153/1

diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php
index 5c05b1e..f621200 100644
--- a/maintenance/Maintenance.php
+++ b/maintenance/Maintenance.php
@@ -49,7 +49,6 @@
  * @ingroup Maintenance
  */
 abstract class Maintenance {
-
        /**
         * Constants for DB access type
         * @see Maintenance::getDbType()
@@ -169,8 +168,16 @@
         * @param bool $withArg Is an argument required with this option?
         * @param string $shortName Character to use as short name
         */
-       protected function addOption( $name, $description, $required = false, 
$withArg = false, $shortName = false ) {
-               $this->mParams[$name] = array( 'desc' => $description, 
'require' => $required, 'withArg' => $withArg, 'shortName' => $shortName );
+       protected function addOption( $name, $description, $required = false,
+               $withArg = false, $shortName = false
+       ) {
+               $this->mParams[$name] = array(
+                       'desc' => $description,
+                       'require' => $required,
+                       'withArg' => $withArg,
+                       'shortName' => $shortName
+               );
+
                if ( $shortName !== false ) {
                        $this->mShortParamsMap[$shortName] = $name;
                }
@@ -413,7 +420,11 @@
                $this->addOption( 'conf', 'Location of LocalSettings.php, if 
not default', false, true );
                $this->addOption( 'wiki', 'For specifying the wiki ID', false, 
true );
                $this->addOption( 'globals', 'Output globals at the end of 
processing for debugging' );
-               $this->addOption( 'memory-limit', 'Set a specific memory limit 
for the script, "max" for no limit or "default" to avoid changing it' );
+               $this->addOption(
+                       'memory-limit',
+                       'Set a specific memory limit for the script, '
+                               . '"max" for no limit or "default" to avoid 
changing it'
+               );
                $this->addOption( 'server', "The protocol and server name to 
use in URLs, e.g. " .
                                "http://en.wikipedia.org. This is sometimes 
necessary because " .
                                "server name detection may fail in command line 
scripts.", false, true );
@@ -630,7 +641,8 @@
                                }
                        } elseif ( substr( $arg, 0, 1 ) == '-' ) {
                                # Short options
-                               for ( $p = 1; $p < strlen( $arg ); $p++ ) {
+                               $argLength = strlen( $arg );
+                               for ( $p = 1; $p < $argLength; $p++ ) {
                                        $option = $arg { $p };
                                        if ( !isset( $this->mParams[$option] ) 
&& isset( $this->mShortParamsMap[$option] ) ) {
                                                $option = 
$this->mShortParamsMap[$option];
@@ -871,7 +883,11 @@
                $this->afterFinalSetup();
 
                $wgShowSQLErrors = true;
-               @set_time_limit( 0 );
+
+               wfSuppressWarnings();
+               set_time_limit( 0 );
+               wfRestoreWarnings();
+
                $this->adjustMemoryLimit();
 
                // Per-script profiling; useful for debugging
diff --git a/maintenance/attachLatest.php b/maintenance/attachLatest.php
index 3333408..fba6b92 100644
--- a/maintenance/attachLatest.php
+++ b/maintenance/attachLatest.php
@@ -33,7 +33,6 @@
  * @ingroup Maintenance
  */
 class AttachLatest extends Maintenance {
-
        public function __construct() {
                parent::__construct();
                $this->addOption( "fix", "Actually fix the entries, will dry 
run otherwise" );
@@ -70,7 +69,8 @@
 
                        $revision = Revision::loadFromTimestamp( $dbw, $title, 
$latestTime );
                        if ( is_null( $revision ) ) {
-                               $this->output( wfWikiID() . " $pageId [[$name]] 
latest time $latestTime, can't find revision id\n" );
+                               $this->output( wfWikiID()
+                                       . " $pageId [[$name]] latest time 
$latestTime, can't find revision id\n" );
                                continue;
                        }
                        $id = $revision->getId();
diff --git a/maintenance/backup.inc b/maintenance/backup.inc
index 323a870..24f32c7 100644
--- a/maintenance/backup.inc
+++ b/maintenance/backup.inc
@@ -37,28 +37,30 @@
  * @ingroup Dump Maintenance
  */
 class BackupDumper {
-       var $reportingInterval = 100;
-       var $reporting = true;
-       var $pageCount = 0;
-       var $revCount = 0;
-       var $server = null; // use default
-       var $pages = null; // all pages
-       var $skipHeader = false; // don't output <mediawiki> and <siteinfo>
-       var $skipFooter = false; // don't output </mediawiki>
-       var $startId = 0;
-       var $endId = 0;
-       var $revStartId = 0;
-       var $revEndId = 0;
-       var $sink = null; // Output filters
-       var $stubText = false; // include rev_text_id instead of text; for 
2-pass dump
-       var $dumpUploads = false;
-       var $dumpUploadFileContents = false;
-       var $lastTime = 0;
-       var $pageCountLast = 0;
-       var $revCountLast = 0;
-       var $ID = 0;
+       public $reporting = true;
+       public $pages = null; // all pages
+       public $skipHeader = false; // don't output <mediawiki> and <siteinfo>
+       public $skipFooter = false; // don't output </mediawiki>
+       public $startId = 0;
+       public $endId = 0;
+       public $revStartId = 0;
+       public $revEndId = 0;
+       public $dumpUploads = false;
+       public $dumpUploadFileContents = false;
 
-       var $outputTypes = array(), $filterTypes = array();
+       protected $reportingInterval = 100;
+       protected $pageCount = 0;
+       protected $revCount = 0;
+       protected $server = null; // use default
+       protected $sink = null; // Output filters
+       protected $lastTime = 0;
+       protected $pageCountLast = 0;
+       protected $revCountLast = 0;
+
+       protected $outputTypes = array();
+       protected $filterTypes = array();
+
+       protected $ID = 0;
 
        /**
         * The dependency-injected database to use.
@@ -69,10 +71,11 @@
         */
        protected $forcedDb = null;
 
-       /**
-        * @var LoadBalancer
-        */
+       /** @var LoadBalancer */
        protected $lb;
+
+       // @todo Unused?
+       private $stubText = false; // include rev_text_id instead of text; for 
2-pass dump
 
        function __construct( $args ) {
                $this->stderr = fopen( "php://stderr", "wt" );
@@ -132,7 +135,10 @@
                foreach ( $args as $arg ) {
                        $matches = array();
                        if ( preg_match( '/^--(.+?)(?:=(.+?)(?::(.+?))?)?$/', 
$arg, $matches ) ) {
-                               @list( /* $full */ , $opt, $val, $param ) = 
$matches;
+                               wfSuppressWarnings();
+                               list( /* $full */ , $opt, $val, $param ) = 
$matches;
+                               wfRestoreWarnings();
+
                                switch ( $opt ) {
                                case "plugin":
                                        $this->loadPlugin( $val, $param );
@@ -351,8 +357,13 @@
                                $pageRatePart = '-';
                                $revRatePart = '-';
                        }
-                       $this->progress( sprintf( "%s: %s (ID %d) %d pages 
(%0.1f|%0.1f/sec all|curr), %d revs (%0.1f|%0.1f/sec all|curr), ETA %s [max 
%d]",
-                                       $now, wfWikiID(), $this->ID, 
$this->pageCount, $pageRate, $pageRatePart, $this->revCount, $revRate, 
$revRatePart, $etats, $this->maxCount ) );
+                       $this->progress( sprintf(
+                               "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec 
all|curr), "
+                                       . "%d revs (%0.1f|%0.1f/sec all|curr), 
ETA %s [max %d]",
+                               $now, wfWikiID(), $this->ID, $this->pageCount, 
$pageRate,
+                               $pageRatePart, $this->revCount, $revRate, 
$revRatePart, $etats,
+                               $this->maxCount
+                       ) );
                        $this->lastTime = $nowts;
                        $this->revCountLast = $this->revCount;
                }
diff --git a/maintenance/backupPrefetch.inc b/maintenance/backupPrefetch.inc
index 6d41c18..869ba80 100644
--- a/maintenance/backupPrefetch.inc
+++ b/maintenance/backupPrefetch.inc
@@ -40,14 +40,14 @@
  * @ingroup Maintenance
  */
 class BaseDump {
-       var $reader = null;
-       var $atEnd = false;
-       var $atPageEnd = false;
-       var $lastPage = 0;
-       var $lastRev = 0;
-       var $infiles = null;
+       protected $reader = null;
+       protected $atEnd = false;
+       protected $atPageEnd = false;
+       protected $lastPage = 0;
+       protected $lastRev = 0;
+       protected $infiles = null;
 
-       function BaseDump( $infile ) {
+       public function __construct( $infile ) {
                $this->infiles = explode( ';', $infile );
                $this->reader = new XMLReader();
                $infile = array_shift( $this->infiles );
@@ -76,18 +76,21 @@
                        $this->nextPage();
                }
                if ( $this->lastPage > $page || $this->atEnd ) {
-                       $this->debug( "BaseDump::prefetch already past page 
$page looking for rev $rev  [$this->lastPage, $this->lastRev]" );
+                       $this->debug( "BaseDump::prefetch already past page 
$page "
+                               . "looking for rev $rev  [$this->lastPage, 
$this->lastRev]" );
                        return null;
                }
                while ( $this->lastRev < $rev && !$this->atEnd && 
!$this->atPageEnd ) {
-                       $this->debug( "BaseDump::prefetch at page 
$this->lastPage, rev $this->lastRev, looking for $page, $rev" );
+                       $this->debug( "BaseDump::prefetch at page 
$this->lastPage, rev $this->lastRev, "
+                               . "looking for $page, $rev" );
                        $this->nextRev();
                }
                if ( $this->lastRev == $rev && !$this->atEnd ) {
                        $this->debug( "BaseDump::prefetch hit on $page, $rev 
[$this->lastPage, $this->lastRev]" );
                        return $this->nextText();
                } else {
-                       $this->debug( "BaseDump::prefetch already past rev $rev 
on page $page  [$this->lastPage, $this->lastRev]" );
+                       $this->debug( "BaseDump::prefetch already past rev $rev 
on page $page "
+                               . "[$this->lastPage, $this->lastRev]" );
                        return null;
                }
        }
diff --git a/maintenance/backupTextPass.inc b/maintenance/backupTextPass.inc
index d210c3a..cf6241a 100644
--- a/maintenance/backupTextPass.inc
+++ b/maintenance/backupTextPass.inc
@@ -30,52 +30,52 @@
  * @ingroup Maintenance
  */
 class TextPassDumper extends BackupDumper {
-       var $prefetch = null;
-       var $input = "php://stdin";
-       var $history = WikiExporter::FULL;
-       var $fetchCount = 0;
-       var $prefetchCount = 0;
-       var $prefetchCountLast = 0;
-       var $fetchCountLast = 0;
+       public $prefetch = null;
+       protected $input = "php://stdin";
+       protected $history = WikiExporter::FULL;
+       protected $fetchCount = 0;
+       protected $prefetchCount = 0;
+       protected $prefetchCountLast = 0;
+       protected $fetchCountLast = 0;
 
-       var $maxFailures = 5;
-       var $maxConsecutiveFailedTextRetrievals = 200;
-       var $failureTimeout = 5; // Seconds to sleep after db failure
+       protected $maxFailures = 5;
+       protected $maxConsecutiveFailedTextRetrievals = 200;
+       protected $failureTimeout = 5; // Seconds to sleep after db failure
 
-       var $php = "php";
-       var $spawn = false;
+       protected $php = "php";
+       protected $spawn = false;
 
        /**
         * @var bool|resource
         */
-       var $spawnProc = false;
+       protected $spawnProc = false;
 
        /**
         * @var bool|resource
         */
-       var $spawnWrite = false;
+       protected $spawnWrite = false;
 
        /**
         * @var bool|resource
         */
-       var $spawnRead = false;
+       protected $spawnRead = false;
 
        /**
         * @var bool|resource
         */
-       var $spawnErr = false;
+       protected $spawnErr = false;
 
-       var $xmlwriterobj = false;
+       protected $xmlwriterobj = false;
 
        // when we spend more than maxTimeAllowed seconds on this run, we 
continue
        // processing until we write out the next complete page, then save 
output file(s),
        // rename it/them and open new one(s)
-       var $maxTimeAllowed = 0;  // 0 = no limit
-       var $timeExceeded = false;
-       var $firstPageWritten = false;
-       var $lastPageWritten = false;
-       var $checkpointJustWritten = false;
-       var $checkpointFiles = array();
+       protected $maxTimeAllowed = 0;  // 0 = no limit
+       protected $timeExceeded = false;
+       protected $firstPageWritten = false;
+       protected $lastPageWritten = false;
+       protected $checkpointJustWritten = false;
+       protected $checkpointFiles = array();
 
        /**
         * @var DatabaseBase
@@ -119,14 +119,16 @@
                try {
                        $this->lb = wfGetLBFactory()->newMainLB();
                } catch ( Exception $e ) {
-                       throw new MWException( __METHOD__ . " rotating DB 
failed to obtain new load balancer (" . $e->getMessage() . ")" );
+                       throw new MWException( __METHOD__
+                               . " rotating DB failed to obtain new load 
balancer (" . $e->getMessage() . ")" );
                }
 
                // 2. The Connection, through the load balancer.
                try {
                        $this->db = $this->lb->getConnection( DB_SLAVE, 'dump' 
);
                } catch ( Exception $e ) {
-                       throw new MWException( __METHOD__ . " rotating DB 
failed to obtain new database (" . $e->getMessage() . ")" );
+                       throw new MWException( __METHOD__
+                               . " rotating DB failed to obtain new database 
(" . $e->getMessage() . ")" );
                }
        }
 
@@ -282,8 +284,14 @@
                                $pageRatePart = '-';
                                $revRatePart = '-';
                        }
-                       $this->progress( sprintf( "%s: %s (ID %d) %d pages 
(%0.1f|%0.1f/sec all|curr), %d revs (%0.1f|%0.1f/sec all|curr), %0.1f%%|%0.1f%% 
prefetched (all|curr), ETA %s [max %d]",
-                                       $now, wfWikiID(), $this->ID, 
$this->pageCount, $pageRate, $pageRatePart, $this->revCount, $revRate, 
$revRatePart, $fetchRate, $fetchRatePart, $etats, $this->maxCount ) );
+                       $this->progress( sprintf(
+                               "%s: %s (ID %d) %d pages (%0.1f|%0.1f/sec 
all|curr), "
+                                       . "%d revs (%0.1f|%0.1f/sec all|curr), 
%0.1f%%|%0.1f%% "
+                                       . "prefetched (all|curr), ETA %s [max 
%d]",
+                               $now, wfWikiID(), $this->ID, $this->pageCount, 
$pageRate,
+                               $pageRatePart, $this->revCount, $revRate, 
$revRatePart,
+                               $fetchRate, $fetchRatePart, $etats, 
$this->maxCount
+                       ) );
                        $this->lastTime = $nowts;
                        $this->revCountLast = $this->revCount;
                        $this->prefetchCountLast = $this->prefetchCount;
@@ -296,9 +304,12 @@
        }
 
        function checkIfTimeExceeded() {
-               if ( $this->maxTimeAllowed && ( $this->lastTime - 
$this->timeOfCheckpoint > $this->maxTimeAllowed ) ) {
+               if ( $this->maxTimeAllowed
+                       && ( $this->lastTime - $this->timeOfCheckpoint > 
$this->maxTimeAllowed )
+               ) {
                        return true;
                }
+
                return false;
        }
 
@@ -310,14 +321,17 @@
                foreach ( $this->checkpointFiles as $checkpointFile ) {
                        $count = substr_count ( $checkpointFile, "%s" );
                        if ( $count != 2 ) {
-                               throw new MWException( "Option checkpointfile 
must contain two '%s' for substitution of first and last pageids, count is 
$count instead, file is $checkpointFile.\n" );
+                               throw new MWException( "Option checkpointfile 
must contain two '%s' "
+                                       . "for substitution of first and last 
pageids, count is $count instead, "
+                                       . "file is $checkpointFile.\n" );
                        }
                }
 
                if ( $this->checkpointFiles ) {
                        $filenameList = (array)$this->egress->getFilenames();
                        if ( count( $filenameList ) != count( 
$this->checkpointFiles ) ) {
-                               throw new MWException( "One checkpointfile must 
be specified for each output option, if maxtime is used.\n" );
+                               throw new MWException( "One checkpointfile must 
be specified "
+                                       . "for each output option, if maxtime 
is used.\n" );
                        }
                }
        }
@@ -338,7 +352,11 @@
                $parser = xml_parser_create( "UTF-8" );
                xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, false 
);
 
-               xml_set_element_handler( $parser, array( &$this, 'startElement' 
), array( &$this, 'endElement' ) );
+               xml_set_element_handler(
+                       $parser,
+                       array( &$this, 'startElement' ),
+                       array( &$this, 'endElement' )
+               );
                xml_set_character_data_handler( $parser, array( &$this, 
'characterData' ) );
 
                $offset = 0; // for context extraction on error reporting
@@ -378,12 +396,13 @@
                                if ( ! $this->firstPageWritten ) {
                                        $firstPageID = str_pad( 0, 9, "0", 
STR_PAD_LEFT );
                                        $lastPageID = str_pad( 0, 9, "0", 
STR_PAD_LEFT );
-                               }
-                               else {
+                               } else {
                                        $firstPageID = str_pad( 
$this->firstPageWritten, 9, "0", STR_PAD_LEFT );
                                        $lastPageID = str_pad( 
$this->lastPageWritten, 9, "0", STR_PAD_LEFT );
                                }
-                               for ( $i = 0; $i < count( $filenameList ); $i++ 
) {
+
+                               $filenameCount = count( $filenameList );
+                               for ( $i = 0; $i < $filenameCount; $i++ ) {
                                        $checkpointNameFilledIn = sprintf( 
$this->checkpointFiles[$i], $firstPageID, $lastPageID );
                                        $fileinfo = pathinfo( $filenameList[$i] 
);
                                        $newFilenames[] = $fileinfo['dirname'] 
. '/' . $checkpointNameFilledIn;
@@ -775,7 +794,8 @@
                                $newFilenames = array();
                                $firstPageID = str_pad( 
$this->firstPageWritten, 9, "0", STR_PAD_LEFT );
                                $lastPageID = str_pad( $this->lastPageWritten, 
9, "0", STR_PAD_LEFT );
-                               for ( $i = 0; $i < count( $filenameList ); $i++ 
) {
+                               $filenamesCount = count( $filenameList );
+                               for ( $i = 0; $i < $filenamesCount; $i++ ) {
                                        $checkpointNameFilledIn = sprintf( 
$this->checkpointFiles[$i], $firstPageID, $lastPageID );
                                        $fileinfo = pathinfo( $filenameList[$i] 
);
                                        $newFilenames[] = $fileinfo['dirname'] 
. '/' . $checkpointNameFilledIn;
@@ -786,8 +806,7 @@
                                $this->timeOfCheckpoint = $this->lastTime;
                                $this->firstPageWritten = false;
                                $this->checkpointJustWritten = true;
-                       }
-                       else {
+                       } else {
                                $this->egress->writeClosePage( $this->buffer );
                                $this->buffer = "";
                                $this->thisPage = "";

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6c591492db363dfab81e5ddfa4a03213347ff5cb
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