Pass phpcs-strict on maintenance/ (5/8)
authorSiebrand Mazeland <siebrand@kitano.nl>
Wed, 23 Apr 2014 08:53:03 +0000 (10:53 +0200)
committerSiebrand Mazeland <siebrand@kitano.nl>
Wed, 23 Apr 2014 09:27:25 +0000 (11:27 +0200)
Change-Id: I156b547b504e7267ea43deff4b8c532635508e81

maintenance/findHooks.php
maintenance/fixDoubleRedirects.php
maintenance/fixExtLinksProtocolRelative.php
maintenance/fixSlaveDesync.php
maintenance/fixTimestamps.php
maintenance/fixUserRegistration.php
maintenance/generateSitemap.php
maintenance/getText.php
maintenance/importDump.php
maintenance/importImages.inc

index 82c5b95..7c6c824 100644 (file)
@@ -158,7 +158,10 @@ class FindHooks extends Maintenance {
         */
        private function getHooksFromOnlineDoc() {
                        // All hooks
-                       $allhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:MediaWiki_hooks&cmlimit=500&format=php' );
+                       $allhookdata = Http::get(
+                               'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&'
+                                       . 'cmtitle=Category:MediaWiki_hooks&cmlimit=500&format=php'
+                       );
                        $allhookdata = unserialize( $allhookdata );
                        $allhooks = array();
                        foreach ( $allhookdata['query']['categorymembers'] as $page ) {
@@ -169,7 +172,10 @@ class FindHooks extends Maintenance {
                                }
                        }
                        // Removed hooks
-                       $oldhookdata = Http::get( 'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Removed_hooks&cmlimit=500&format=php' );
+                       $oldhookdata = Http::get(
+                               'http://www.mediawiki.org/w/api.php?action=query&list=categorymembers&'
+                                       . 'cmtitle=Category:Removed_hooks&cmlimit=500&format=php'
+                       );
                        $oldhookdata = unserialize( $oldhookdata );
                        $removed = array();
                        foreach ( $oldhookdata['query']['categorymembers'] as $page ) {
@@ -190,7 +196,12 @@ class FindHooks extends Maintenance {
        private function getHooksFromFile( $file ) {
                $content = file_get_contents( $file );
                $m = array();
-               preg_match_all( '/(?:wfRunHooks|Hooks\:\:run|ContentHandler\:\:runLegacyHooks)\(\s*([\'"])(.*?)\1/', $content, $m );
+               preg_match_all(
+                       '/(?:wfRunHooks|Hooks\:\:run|ContentHandler\:\:runLegacyHooks)\(\s*([\'"])(.*?)\1/',
+                       $content,
+                       $m
+               );
+
                return $m[2];
        }
 
index 41458d1..af8a58e 100644 (file)
@@ -106,7 +106,8 @@ class FixDoubleRedirects extends Maintenance {
                        if ( !$async ) {
                                $success = ( $dryrun ? true : $job->run() );
                                if ( !$success ) {
-                                       $this->error( "Error fixing " . $titleA->getPrefixedText() . ": " . $job->getLastError() . "\n" );
+                                       $this->error( "Error fixing " . $titleA->getPrefixedText()
+                                               . ": " . $job->getLastError() . "\n" );
                                }
                        } else {
                                $jobs[] = $job;
index 02d65ed..920b2b0 100644 (file)
@@ -34,7 +34,8 @@ require_once __DIR__ . '/Maintenance.php';
 class FixExtLinksProtocolRelative extends LoggedUpdateMaintenance {
        public function __construct() {
                parent::__construct();
-               $this->mDescription = "Fixes any entries in the externallinks table containing protocol-relative URLs";
+               $this->mDescription =
+                       "Fixes any entries in the externallinks table containing protocol-relative URLs";
        }
 
        protected function getUpdateKey() {
@@ -79,7 +80,15 @@ class FixExtLinksProtocolRelative extends LoggedUpdateMaintenance {
                                        )
                                ), __METHOD__, array( 'IGNORE' )
                        );
-                       $db->delete( 'externallinks', array( 'el_index' => $row->el_index, 'el_from' => $row->el_from, 'el_to' => $row->el_to ), __METHOD__ );
+                       $db->delete(
+                               'externallinks',
+                               array(
+                                       'el_index' => $row->el_index,
+                                       'el_from' => $row->el_from,
+                                       'el_to' => $row->el_to
+                               ),
+                               __METHOD__
+                       );
                }
                $this->output( "Done, $count rows updated.\n" );
                return true;
index a09a742..cbb2e9d 100644 (file)
@@ -30,6 +30,9 @@ require_once __DIR__ . '/Maintenance.php';
  * @ingroup Maintenance
  */
 class FixSlaveDesync extends Maintenance {
+       /** @var array */
+       private $slaveIndexes;
+
        public function __construct() {
                parent::__construct();
                $this->mDescription = "";
@@ -41,7 +44,8 @@ class FixSlaveDesync extends Maintenance {
 
        public function execute() {
                $this->slaveIndexes = array();
-               for ( $i = 1; $i < wfGetLB()->getServerCount(); $i++ ) {
+               $serverCount = wfGetLB()->getServerCount();
+               for ( $i = 1; $i < $serverCount; $i++ ) {
                        if ( wfGetLB()->isNonZeroLoad( $i ) ) {
                                $this->slaveIndexes[] = $i;
                        }
@@ -66,7 +70,12 @@ class FixSlaveDesync extends Maintenance {
                $n = 0;
                $dbw = wfGetDB( DB_MASTER );
                $masterIDs = array();
-               $res = $dbw->select( 'page', array( 'page_id', 'page_latest' ), array( 'page_id<6054123' ), __METHOD__ );
+               $res = $dbw->select(
+                       'page',
+                       array( 'page_id', 'page_latest' ),
+                       array( 'page_id<6054123' ),
+                       __METHOD__
+               );
                $this->output( "Number of pages: " . $res->numRows() . "\n" );
                foreach ( $res as $row ) {
                        $masterIDs[$row->page_id] = $row->page_latest;
@@ -78,7 +87,12 @@ class FixSlaveDesync extends Maintenance {
 
                foreach ( $this->slaveIndexes as $i ) {
                        $db = wfGetDB( $i );
-                       $res = $db->select( 'page', array( 'page_id', 'page_latest' ), array( 'page_id<6054123' ), __METHOD__ );
+                       $res = $db->select(
+                               'page',
+                               array( 'page_id', 'page_latest' ),
+                               array( 'page_id<6054123' ),
+                               __METHOD__
+                       );
                        foreach ( $res as $row ) {
                                if ( isset( $masterIDs[$row->page_id] ) && $masterIDs[$row->page_id] != $row->page_latest ) {
                                        $desync[$row->page_id] = true;
@@ -141,7 +155,8 @@ class FixSlaveDesync extends Maintenance {
                if ( count( $masterIDs ) < count( $slaveIDs ) ) {
                        $missingIDs = array_diff( $slaveIDs, $masterIDs );
                        if ( count( $missingIDs ) ) {
-                               $this->output( "Found " . count( $missingIDs ) . " lost in master, copying from slave... " );
+                               $this->output( "Found " . count( $missingIDs )
+                                       . " lost in master, copying from slave... " );
                                $dbFrom = $dbw;
                                $found = true;
                                $toMaster = true;
@@ -151,7 +166,8 @@ class FixSlaveDesync extends Maintenance {
                } else {
                        $missingIDs = array_diff( $masterIDs, $slaveIDs );
                        if ( count( $missingIDs ) ) {
-                               $this->output( "Found " . count( $missingIDs ) . " missing revision(s), copying from master... " );
+                               $this->output( "Found " . count( $missingIDs )
+                                       . " missing revision(s), copying from master... " );
                                $dbFrom = $dbw;
                                $found = true;
                                $toMaster = false;
@@ -199,11 +215,23 @@ class FixSlaveDesync extends Maintenance {
                if ( $found ) {
                        $this->output( "Fixing page_latest... " );
                        if ( $toMaster ) {
-                               # $dbw->update( 'page', array( 'page_latest' => $realLatest ), array( 'page_id' => $pageID ), __METHOD__ );
+                               /*
+                               $dbw->update(
+                                       'page',
+                                       array( 'page_latest' => $realLatest ),
+                                       array( 'page_id' => $pageID ),
+                                       __METHOD__
+                               );
+                               */
                        } else {
                                foreach ( $this->slaveIndexes as $i ) {
                                        $db = wfGetDB( $i );
-                                       $db->update( 'page', array( 'page_latest' => $realLatest ), array( 'page_id' => $pageID ), __METHOD__ );
+                                       $db->update(
+                                               'page',
+                                               array( 'page_latest' => $realLatest ),
+                                               array( 'page_id' => $pageID ),
+                                               __METHOD__
+                                       );
                                }
                        }
                        $this->output( "done\n" );
index b0609d1..f96a917 100644 (file)
@@ -117,7 +117,8 @@ class FixTimestamps extends Maintenance {
 
                $fixup = -$offset;
                $sql = "UPDATE $revisionTable " .
-                       "SET rev_timestamp=DATE_FORMAT(DATE_ADD(rev_timestamp, INTERVAL $fixup SECOND), '%Y%m%d%H%i%s') " .
+                       "SET rev_timestamp="
+                               . "DATE_FORMAT(DATE_ADD(rev_timestamp, INTERVAL $fixup SECOND), '%Y%m%d%H%i%s') " .
                        "WHERE rev_id IN (" . $dbw->makeList( $badRevs ) . ')';
                $dbw->query( $sql, __METHOD__ );
                $this->output( "Done\n" );
index 097936c..878593c 100644 (file)
@@ -44,10 +44,20 @@ class FixUserRegistration extends Maintenance {
                foreach ( $res as $row ) {
                        $id = $row->user_id;
                        // Get first edit time
-                       $timestamp = $dbr->selectField( 'revision', 'MIN(rev_timestamp)', array( 'rev_user' => $id ), __METHOD__ );
+                       $timestamp = $dbr->selectField(
+                               'revision',
+                               'MIN(rev_timestamp)',
+                               array( 'rev_user' => $id ),
+                               __METHOD__
+                       );
                        // Update
                        if ( !empty( $timestamp ) ) {
-                               $dbw->update( 'user', array( 'user_registration' => $timestamp ), array( 'user_id' => $id ), __METHOD__ );
+                               $dbw->update(
+                                       'user',
+                                       array( 'user_registration' => $timestamp ),
+                                       array( 'user_id' => $id ),
+                                       __METHOD__
+                               );
                                $this->output( "$id $timestamp\n" );
                        } else {
                                $this->output( "$id NULL\n" );
index 959cc8f..b5681c1 100644 (file)
@@ -63,7 +63,8 @@ class GenerateSitemap extends Maintenance {
        public $fspath;
 
        /**
-        * The URL path to prepend to filenames in the index; should resolve to the same directory as $fspath
+        * The URL path to prepend to filenames in the index;
+        * should resolve to the same directory as $fspath.
         *
         * @var string
         */
@@ -145,11 +146,32 @@ class GenerateSitemap extends Maintenance {
        public function __construct() {
                parent::__construct();
                $this->mDescription = "Creates a sitemap for the site";
-               $this->addOption( 'fspath', 'The file system path to save to, e.g. /tmp/sitemap; defaults to current directory', false, true );
-               $this->addOption( 'urlpath', 'The URL path corresponding to --fspath, prepended to filenames in the index; defaults to an empty string', false, true );
-               $this->addOption( 'compress', 'Compress the sitemap files, can take value yes|no, default yes', false, true );
+               $this->addOption(
+                       'fspath',
+                       'The file system path to save to, e.g. /tmp/sitemap; defaults to current directory',
+                       false,
+                       true
+               );
+               $this->addOption(
+                       'urlpath',
+                       'The URL path corresponding to --fspath, prepended to filenames in the index; '
+                               . 'defaults to an empty string',
+                       false,
+                       true
+               );
+               $this->addOption(
+                       'compress',
+                       'Compress the sitemap files, can take value yes|no, default yes',
+                       false,
+                       true
+               );
                $this->addOption( 'skip-redirects', 'Do not include redirecting articles in the sitemap' );
-               $this->addOption( 'identifier', 'What site identifier to use for the wiki, defaults to $wgDBname', false, true );
+               $this->addOption(
+                       'identifier',
+                       'What site identifier to use for the wiki, defaults to $wgDBname',
+                       false,
+                       true
+               );
        }
 
        /**
@@ -266,7 +288,9 @@ class GenerateSitemap extends Maintenance {
         * @return string
         */
        function priority( $namespace ) {
-               return isset( $this->priorities[$namespace] ) ? $this->priorities[$namespace] : $this->guessPriority( $namespace );
+               return isset( $this->priorities[$namespace] )
+                       ? $this->priorities[$namespace]
+                       : $this->guessPriority( $namespace );
        }
 
        /**
@@ -278,7 +302,9 @@ class GenerateSitemap extends Maintenance {
         * @return string
         */
        function guessPriority( $namespace ) {
-               return MWNamespace::isSubject( $namespace ) ? $this->priorities[self::GS_MAIN] : $this->priorities[self::GS_TALK];
+               return MWNamespace::isSubject( $namespace )
+                       ? $this->priorities[self::GS_MAIN]
+                       : $this->priorities[self::GS_TALK];
        }
 
        /**
@@ -324,7 +350,10 @@ class GenerateSitemap extends Maintenance {
                                        continue;
                                }
 
-                               if ( $i++ === 0 || $i === $this->url_limit + 1 || $length + $this->limit[1] + $this->limit[2] > $this->size_limit ) {
+                               if ( $i++ === 0
+                                       || $i === $this->url_limit + 1
+                                       || $length + $this->limit[1] + $this->limit[2] > $this->size_limit
+                               ) {
                                        if ( $this->file !== false ) {
                                                $this->write( $this->file, $this->closeFile() );
                                                $this->close( $this->file );
@@ -349,7 +378,11 @@ class GenerateSitemap extends Maintenance {
                                                if ( $vCode == $wgContLang->getCode() ) {
                                                        continue; // we don't want default variant
                                                }
-                                               $entry = $this->fileEntry( $title->getCanonicalURL( '', $vCode ), $date, $this->priority( $namespace ) );
+                                               $entry = $this->fileEntry(
+                                                       $title->getCanonicalURL( '', $vCode ),
+                                                       $date,
+                                                       $this->priority( $namespace )
+                                               );
                                                $length += strlen( $entry );
                                                $this->write( $this->file, $entry );
                                        }
@@ -379,7 +412,8 @@ class GenerateSitemap extends Maintenance {
        function open( $file, $flags ) {
                $resource = $this->compress ? gzopen( $file, $flags ) : fopen( $file, $flags );
                if ( $resource === false ) {
-                       throw new MWException( __METHOD__ . " error opening file $file with flags $flags. Check permissions?" );
+                       throw new MWException( __METHOD__
+                               . " error opening file $file with flags $flags. Check permissions?" );
                }
                return $resource;
        }
@@ -523,7 +557,11 @@ class GenerateSitemap extends Maintenance {
 
                $this->limit = array(
                        strlen( $this->openFile() ),
-                       strlen( $this->fileEntry( $title->getCanonicalURL(), wfTimestamp( TS_ISO_8601, wfTimestamp() ), $this->priority( $namespace ) ) ),
+                       strlen( $this->fileEntry(
+                               $title->getCanonicalURL(),
+                               wfTimestamp( TS_ISO_8601, wfTimestamp() ),
+                               $this->priority( $namespace )
+                       ) ),
                        strlen( $this->closeFile() )
                );
        }
index 9c4bdfb..7d7c1cc 100644 (file)
@@ -52,7 +52,10 @@ class GetTextMaint extends Maintenance {
                        $titleText = $title->getPrefixedText();
                        $this->error( "Page $titleText does not exist.\n", true );
                }
-               $content = $rev->getContent( $this->hasOption( 'show-private' ) ? Revision::RAW : Revision::FOR_PUBLIC );
+               $content = $rev->getContent( $this->hasOption( 'show-private' )
+                       ? Revision::RAW
+                       : Revision::FOR_PUBLIC );
+
                if ( $content === false ) {
                        $titleText = $title->getPrefixedText();
                        $this->error( "Couldn't extract the text from $titleText.\n", true );
index 61189b7..88e7120 100644 (file)
@@ -42,8 +42,12 @@ class BackupReader extends Maintenance {
 
        function __construct() {
                parent::__construct();
-               $gz = in_array( 'compress.zlib', stream_get_wrappers() ) ? 'ok' : '(disabled; requires PHP zlib module)';
-               $bz2 = in_array( 'compress.bzip2', stream_get_wrappers() ) ? 'ok' : '(disabled; requires PHP bzip2 module)';
+               $gz = in_array( 'compress.zlib', stream_get_wrappers() )
+                       ? 'ok'
+                       : '(disabled; requires PHP zlib module)';
+               $bz2 = in_array( 'compress.bzip2', stream_get_wrappers() )
+                       ? 'ok'
+                       : '(disabled; requires PHP bzip2 module)';
 
                $this->mDescription = <<<TEXT
 This script reads pages from an XML file as produced from Special:Export or
@@ -67,7 +71,10 @@ TEXT;
                $this->addOption( 'dry-run', 'Parse dump without actually importing pages' );
                $this->addOption( 'debug', 'Output extra verbose debug information' );
                $this->addOption( 'uploads', 'Process file upload data if included (experimental)' );
-               $this->addOption( 'no-updates', 'Disable link table updates. Is faster but leaves the wiki in an inconsistent state' );
+               $this->addOption(
+                       'no-updates',
+                       'Disable link table updates. Is faster but leaves the wiki in an inconsistent state'
+               );
                $this->addOption( 'image-base-path', 'Import files from a specified path', false, true );
                $this->addArg( 'file', 'Dump file to import [else use stdin]', false );
        }
index ae93287..7caedea 100644 (file)
@@ -110,9 +110,11 @@ function findAuxFile( $file, $auxExtension, $maxStrip = 1 ) {
        return false;
 }
 
-# FIXME: Access the api in a saner way and performing just one query (preferably batching files too).
+# @todo FIXME: Access the api in a saner way and performing just one query
+# (preferably batching files too).
 function getFileCommentFromSourceWiki( $wiki_host, $file ) {
-       $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:' . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=comment';
+       $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:'
+               . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=comment';
        $body = Http::get( $url );
        if ( preg_match( '#<ii comment="([^"]*)" />#', $body, $matches ) == 0 ) {
                return false;
@@ -122,7 +124,8 @@ function getFileCommentFromSourceWiki( $wiki_host, $file ) {
 }
 
 function getFileUserFromSourceWiki( $wiki_host, $file ) {
-       $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:' . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=user';
+       $url = $wiki_host . '/api.php?action=query&format=xml&titles=File:'
+               . rawurlencode( $file ) . '&prop=imageinfo&&iiprop=user';
        $body = Http::get( $url );
        if ( preg_match( '#<ii user="([^"]*)" />#', $body, $matches ) == 0 ) {
                return false;