From 80dd48238c3a356bab8ba7df1936fbb7349c4630 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Wed, 23 Apr 2014 10:53:03 +0200 Subject: [PATCH] Pass phpcs-strict on maintenance/ (5/8) Change-Id: I156b547b504e7267ea43deff4b8c532635508e81 --- maintenance/findHooks.php | 17 ++++-- maintenance/fixDoubleRedirects.php | 3 +- maintenance/fixExtLinksProtocolRelative.php | 13 ++++- maintenance/fixSlaveDesync.php | 42 ++++++++++++--- maintenance/fixTimestamps.php | 3 +- maintenance/fixUserRegistration.php | 14 ++++- maintenance/generateSitemap.php | 60 +++++++++++++++++---- maintenance/getText.php | 5 +- maintenance/importDump.php | 13 +++-- maintenance/importImages.inc | 9 ++-- 10 files changed, 145 insertions(+), 34 deletions(-) diff --git a/maintenance/findHooks.php b/maintenance/findHooks.php index 82c5b95647..7c6c824282 100644 --- a/maintenance/findHooks.php +++ b/maintenance/findHooks.php @@ -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]; } diff --git a/maintenance/fixDoubleRedirects.php b/maintenance/fixDoubleRedirects.php index 41458d1858..af8a58e24e 100644 --- a/maintenance/fixDoubleRedirects.php +++ b/maintenance/fixDoubleRedirects.php @@ -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; diff --git a/maintenance/fixExtLinksProtocolRelative.php b/maintenance/fixExtLinksProtocolRelative.php index 02d65ed154..920b2b099c 100644 --- a/maintenance/fixExtLinksProtocolRelative.php +++ b/maintenance/fixExtLinksProtocolRelative.php @@ -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; diff --git a/maintenance/fixSlaveDesync.php b/maintenance/fixSlaveDesync.php index a09a7421bb..cbb2e9d019 100644 --- a/maintenance/fixSlaveDesync.php +++ b/maintenance/fixSlaveDesync.php @@ -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" ); diff --git a/maintenance/fixTimestamps.php b/maintenance/fixTimestamps.php index b0609d1768..f96a917117 100644 --- a/maintenance/fixTimestamps.php +++ b/maintenance/fixTimestamps.php @@ -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" ); diff --git a/maintenance/fixUserRegistration.php b/maintenance/fixUserRegistration.php index 097936c982..878593c71c 100644 --- a/maintenance/fixUserRegistration.php +++ b/maintenance/fixUserRegistration.php @@ -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" ); diff --git a/maintenance/generateSitemap.php b/maintenance/generateSitemap.php index 959cc8fd58..b5681c186a 100644 --- a/maintenance/generateSitemap.php +++ b/maintenance/generateSitemap.php @@ -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() ) ); } diff --git a/maintenance/getText.php b/maintenance/getText.php index 9c4bdfb84b..7d7c1cc480 100644 --- a/maintenance/getText.php +++ b/maintenance/getText.php @@ -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 ); diff --git a/maintenance/importDump.php b/maintenance/importDump.php index 61189b7072..88e7120af1 100644 --- a/maintenance/importDump.php +++ b/maintenance/importDump.php @@ -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 = <<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 ); } diff --git a/maintenance/importImages.inc b/maintenance/importImages.inc index ae93287df1..7caedeaccc 100644 --- a/maintenance/importImages.inc +++ b/maintenance/importImages.inc @@ -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( '##', $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( '##', $body, $matches ) == 0 ) { return false; -- 2.20.1