jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/368119 )
Change subject: phpcs for WikimediaMaintenance ...................................................................... phpcs for WikimediaMaintenance Change-Id: I26914255fe19b6723778b6442d0a9b29bfa931fb --- M addWiki.php M bug-53687/fixOrphans.php M changeSkinPref.php M checkTranscacheEmpty.php M cleanupBug31576.php M cleanupBug41615.php M cleanupMl.php M cleanupPageProps.php M cleanupT92775.php A composer.json M createExtensionTables.php M createHumanReadableProjectNameFiles.php M dumpInterwiki.php M filebackend/measureZoneSizes.php M filebackend/setZoneAccess.php M fixBeXOldRenames.php M fixBug41778.php M fixCleanupTitles/revertCleanupTitles.php M fixJobQueueExplosion.php M fixUsabilityPrefs.php M fixUsabilityPrefs2.php M getJobQueueLengths.php M getPageCounts.php M importUseModWikipedia.php M makeDumpList.php M makeSizeDBLists.php M migrateWlmUploads.php M ourUsers.php M passwordAudit.php A phpcs.xml M purgeStaleMemcachedText.php M purgeUrls.php M rcParamsTypeCheck.php M removeDeletedWikis.php M renameInvalidUsernames.php M renameWiki.php M sanityCheck.php M socket-test.php M storage/testRctComplete.php M unsuppressCrossWiki.php 40 files changed, 440 insertions(+), 414 deletions(-) Approvals: Krinkle: Looks good to me, approved jenkins-bot: Verified diff --git a/addWiki.php b/addWiki.php index 968e6e4..360a5a8 100644 --- a/addWiki.php +++ b/addWiki.php @@ -87,7 +87,7 @@ null, null, __METHOD__, - array( $this, 'noExecuteCommands' ) + [ $this, 'noExecuteCommands' ] ); $dbw->sourceFile( "$IP/extensions/AntiSpoof/sql/patch-antispoof.mysql.sql" ); $dbw->sourceFile( "$IP/extensions/Babel/babel.sql" ); @@ -153,18 +153,18 @@ if ( is_array( $wgDefaultExternalStore ) ) { $stores = $wgDefaultExternalStore; } elseif ( $wgDefaultExternalStore ) { - $stores = array( $wgDefaultExternalStore ); + $stores = [ $wgDefaultExternalStore ]; } else { - $stores = array(); + $stores = []; } // Flow External Store (may be the same, so there is an array_unique) if ( is_array( $wgFlowExternalStore ) ) { $flowStores = $wgFlowExternalStore; } elseif ( $wgFlowExternalStore ) { - $flowStores = array( $wgFlowExternalStore ); + $flowStores = [ $wgFlowExternalStore ]; } else { - $flowStores = array(); + $flowStores = []; } $stores = array_unique( array_merge( $stores, $flowStores ) ); @@ -172,7 +172,7 @@ if ( count( $stores ) ) { global $wgDBuser, $wgDBpassword, $wgExternalServers; foreach ( $stores as $storeURL ) { - $m = array(); + $m = []; if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) { continue; } @@ -337,7 +337,6 @@ * @return Status */ private function setFundraisingLink( $domain, $language ) { - $title = Title::newFromText( "Mediawiki:Sitesupport-url" ); $this->output( "Writing sidebar donate link to " . $title->getPrefixedDBkey() . "\n" ); $article = WikiPage::factory( $title ); diff --git a/bug-53687/fixOrphans.php b/bug-53687/fixOrphans.php index 6b6bdf9..ad18695 100644 --- a/bug-53687/fixOrphans.php +++ b/bug-53687/fixOrphans.php @@ -23,7 +23,7 @@ } $dbw = wfGetDB( DB_MASTER ); - $verifyPairs = array( + $verifyPairs = [ 'ar_comment' => 'rev_comment', 'ar_user' => 'rev_user', 'ar_user_text' => 'rev_user_text', @@ -35,7 +35,7 @@ 'ar_page_id' => 'rev_page', 'ar_parent_id' => 'rev_parent_id', 'ar_sha1' => 'rev_sha1', - ); + ]; while ( !feof( $f ) ) { $line = fgets( $f ); @@ -52,23 +52,23 @@ $this->error( "XXX: ERROR Invalid line $lineNumber\n" ); continue; } - $info = array_combine( array( 'up_page', 'up_timestamp', 'log_namespace', - 'log_title', 'rev_id', 'ar_rev_match', 'ar_text_match' ), $parts ); + $info = array_combine( [ 'up_page', 'up_timestamp', 'log_namespace', + 'log_title', 'rev_id', 'ar_rev_match', 'ar_text_match' ], $parts ); $revId = $info['rev_id']; $this->beginTransaction( $dbw, __METHOD__ ); - $revRow = $dbw->selectRow( 'revision', '*', array( 'rev_id' => $revId ), - __METHOD__, array( 'FOR UPDATE' ) ); + $revRow = $dbw->selectRow( 'revision', '*', [ 'rev_id' => $revId ], + __METHOD__, [ 'FOR UPDATE' ] ); if ( !$revRow ) { $this->error( "$revId: ERROR revision row has disappeared!" ); $this->commitTransaction( $dbw, __METHOD__ ); continue; } - $arRow = $dbw->selectRow( 'archive', '*', array( 'ar_rev_id' => $revId ), - __METHOD__, array( 'FOR UPDATE' ) ); - $pageRow = $dbw->selectRow( 'page', '*', array( 'page_id' => $revRow->rev_page ), - __METHOD__, array( 'FOR UPDATE' ) ); + $arRow = $dbw->selectRow( 'archive', '*', [ 'ar_rev_id' => $revId ], + __METHOD__, [ 'FOR UPDATE' ] ); + $pageRow = $dbw->selectRow( 'page', '*', [ 'page_id' => $revRow->rev_page ], + __METHOD__, [ 'FOR UPDATE' ] ); if ( $pageRow ) { // rev_page is somehow connected to a valid page row @@ -121,12 +121,12 @@ } if ( $action === 'remove-archive' ) { - $dbw->delete( 'archive', array( 'ar_rev_id' => $revId ), __METHOD__ ); + $dbw->delete( 'archive', [ 'ar_rev_id' => $revId ], __METHOD__ ); } elseif ( $action === 'remove-revision' ) { - $dbw->delete( 'revision', array( 'rev_id' => $revId ), __METHOD__ ); + $dbw->delete( 'revision', [ 'rev_id' => $revId ], __METHOD__ ); } elseif ( $action === 'move-revision' ) { $dbw->insert( 'archive', - array( + [ 'ar_namespace' => $info['log_namespace'], 'ar_title' => $info['log_title'], 'ar_comment' => $revRow->rev_comment, @@ -143,9 +143,9 @@ 'ar_page_id' => $revRow->rev_page, 'ar_deleted' => $revRow->rev_deleted, 'ar_sha1' => $revRow->rev_sha1, - ), + ], __METHOD__ ); - $dbw->delete( 'revision', array( 'rev_id' => $revId ), __METHOD__ ); + $dbw->delete( 'revision', [ 'rev_id' => $revId ], __METHOD__ ); } $this->commitTransaction( $dbw, __METHOD__ ); @@ -157,5 +157,4 @@ } $maintClass = 'FixOrphans'; -require_once( RUN_MAINTENANCE_IF_MAIN ); - +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/changeSkinPref.php b/changeSkinPref.php index 11b9e7d..1de1005 100644 --- a/changeSkinPref.php +++ b/changeSkinPref.php @@ -64,4 +64,4 @@ } $maintClass = "ChangeSkinPref"; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/checkTranscacheEmpty.php b/checkTranscacheEmpty.php index fd65361..a853e4e 100644 --- a/checkTranscacheEmpty.php +++ b/checkTranscacheEmpty.php @@ -5,7 +5,7 @@ $good = 0; foreach ( $wgLocalDatabases as $wiki ) { $lb = wfGetLB( $wiki ); - $db = $lb->getConnection( DB_SLAVE, array(), $wiki ); + $db = $lb->getConnection( DB_SLAVE, [], $wiki ); $notEmpty = $db->selectField( 'transcache', '1', false, 'checkTranscacheEmpty.php' ); if ( $notEmpty ) { echo "$wiki\n"; diff --git a/cleanupBug31576.php b/cleanupBug31576.php index 8679f1e..2d54cec 100644 --- a/cleanupBug31576.php +++ b/cleanupBug31576.php @@ -5,7 +5,7 @@ protected $batchsize; - protected $processed = array(); + protected $processed = []; public function __construct() { parent::__construct(); @@ -32,18 +32,18 @@ $this->output( "Fixing pages with template links to $synonym ...\n" ); $from = null; while ( true ) { - $where = array( + $where = [ 'tl_namespace' => NS_TEMPLATE, 'tl_title ' . $dbr->buildLike( $synonym, $dbr->anyString() ) - ); + ]; if ( $from !== null ) { $where[] = 'tl_from > ' . $dbr->addQuotes( $from ); $from = null; } - $res = $dbr->select( 'templatelinks', array( 'tl_title', 'tl_from' ), + $res = $dbr->select( 'templatelinks', [ 'tl_title', 'tl_from' ], $where, __METHOD__, - array( 'ORDER BY' => array( 'tl_title', 'tl_from' ), 'LIMIT' => $this->batchsize ) + [ 'ORDER BY' => [ 'tl_title', 'tl_from' ], 'LIMIT' => $this->batchsize ] ); if ( $dbr->numRows( $res ) == 0 ) { // No more rows, we're done @@ -71,4 +71,4 @@ } $maintClass = "CleanupBug31576"; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/cleanupBug41615.php b/cleanupBug41615.php index 4fce81a..f6df60c 100644 --- a/cleanupBug41615.php +++ b/cleanupBug41615.php @@ -28,7 +28,7 @@ } # Mangle throw the log as log_comment can have newlines and such... - $binlog = array(); // lines + $binlog = []; // lines $buffer = ''; $inQuote = false; $binraw = trim( file_get_contents( $this->getOption( 'binlogdump' ) ) ); @@ -53,16 +53,16 @@ } $binlog = array_chunk( $binlog, 2 ); // there should be pairs of corresponding logs - $deletedPages = array(); + $deletedPages = []; foreach ( $binlog as $entries ) { list( $dEntry, $iEntry ) = $entries; - $m = array(); + $m = []; // 1351692955 itwiki DELETE /* WikiPage::doDeleteArticleReal Guidomac */ // FROM `page` WHERE page_id = '4258611' if ( !preg_match( "!^\d+ (\w+) DELETE .* WHERE page_id = '(\d+)'!", $dEntry, $m ) ) { $this->error( "Could not parse '$dEntry'.", 1 ); } - $info = array( 'wiki' => $m[1], 'page_id' => $m[2] ); + $info = [ 'wiki' => $m[1], 'page_id' => $m[2] ]; // 1351692955 itwiki INSERT /* ManualLogEntry::insert Guidomac */ INTO `logging` // (log_id,log_type,log_action,log_timestamp,log_user,log_user_text,log_namespace,log_title,log_page,log_comment,log_params) // VALUES (NULL,'delete','delete','20121031141555','276491','Guidomac','0','Doesn\'t_Matter','0','([[WP:IMMEDIATA|C1]]) Pagina o sottopagina vuota, di prova, senza senso o tautologica','a:0:{}') @@ -92,15 +92,15 @@ $this->output( "Inspecting {$title->getPrefixedText()}\n" ); $count = $dbw->selectField( 'revision', - 'COUNT(*)', array( 'rev_page' => $info['page_id'] ) ); + 'COUNT(*)', [ 'rev_page' => $info['page_id'] ] ); if ( $count > 0 ) { // number of affected revs for this page ID $article = WikiPage::factory( $title ); $lastRev = Revision::newFromRow( $dbw->selectRow( 'revision', '*', - array( 'rev_page' => $info['page_id'] ), + [ 'rev_page' => $info['page_id'] ], __METHOD__, - array( 'ORDER BY' => 'rev_timestamp DESC' ) + [ 'ORDER BY' => 'rev_timestamp DESC' ] ) ); // Revisions were restored using ar_page_id, not the new page created on restore. // We need to move this to the new page_id created for the old title. @@ -119,8 +119,8 @@ } if ( $this->hasOption( 'fix' ) ) { $dbw->update( 'revision', - array( 'rev_page' => $newID ), - array( 'rev_page' => $info['page_id'] ), + [ 'rev_page' => $newID ], + [ 'rev_page' => $info['page_id'] ], __METHOD__ ); $article->updateIfNewerOn( $dbw, $lastRev ); // fix page_latest diff --git a/cleanupMl.php b/cleanupMl.php index 81dc02b..ceb8d67 100644 --- a/cleanupMl.php +++ b/cleanupMl.php @@ -57,7 +57,6 @@ continue; } - if ( $unbrokenTitle->exists() ) { # Exists already, just delete this redirect $article = new Article( $brokenTitle ); diff --git a/cleanupPageProps.php b/cleanupPageProps.php index 444e8f3..a5f1315 100644 --- a/cleanupPageProps.php +++ b/cleanupPageProps.php @@ -37,12 +37,12 @@ $deleted = 0; for ( $id = 0; $id <= $high; $id += $this->mBatchSize ) { $dbw->delete( 'page_props', - array( + [ "pp_page BETWEEN $id AND $id + {$this->mBatchSize}", // Clean up bogus entries left by MobileFrontend 'pp_propname' => 'page_top_level_section_count', 'pp_value' => 0, - ), + ], __METHOD__ ); $affected = $dbw->affectedRows(); diff --git a/cleanupT92775.php b/cleanupT92775.php index ebb5168..fc8b7e7 100644 --- a/cleanupT92775.php +++ b/cleanupT92775.php @@ -15,11 +15,11 @@ class FixCUBlockLogs extends Maintenance { public function execute() { - $ids = array(); + $ids = []; $res = wfGetDB( DB_SLAVE )->select( 'logging', - array( 'log_id' ), - array( 'log_params' => "1 week\nanononly\nnocreate" ), + [ 'log_id' ], + [ 'log_params' => "1 week\nanononly\nnocreate" ], __METHOD__ ); foreach ( $res as $row ) { @@ -28,8 +28,8 @@ wfGetDB( DB_MASTER )->update( 'logging', - array( 'log_params' => "1 week\nanononly,nocreate" ), - array( 'log_id' => $ids ), + [ 'log_params' => "1 week\nanononly,nocreate" ], + [ 'log_id' => $ids ], __METHOD__ ); } diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..f498b4c --- /dev/null +++ b/composer.json @@ -0,0 +1,20 @@ +{ + "require-dev": { + "jakub-onderka/php-parallel-lint": "0.9.2", + "mediawiki/mediawiki-codesniffer": "0.10.1" + }, + "scripts": { + "lint": "parallel-lint --exclude vendor --ignore-fails .", + "phpcs": "phpcs -p -s", + "fix": "phpcbf", + "test": [ + "composer lint", + "composer phpcs" + ] + }, + "config": { + "optimize-autoloader": true, + "prepend-autoloader": false + } +} + diff --git a/createExtensionTables.php b/createExtensionTables.php index 157def1..2acb4eb 100644 --- a/createExtensionTables.php +++ b/createExtensionTables.php @@ -36,7 +36,7 @@ $dbw = $this->getDB( DB_MASTER ); $extension = $this->getArg( 0 ); - $files = array(); + $files = []; $path = ''; switch ( strtolower( $extension ) ) { @@ -50,17 +50,17 @@ $dbw->query( "SET storage_engine=InnoDB" ); $dbw->query( "CREATE DATABASE IF NOT EXISTS " . wfWikiID() ); $dbw->selectDB( wfWikiID() ); - $files = array( 'echo.sql' ); + $files = [ 'echo.sql' ]; $path = "$IP/extensions/Echo"; break; case 'educationprogram': - $files = array( 'EducationProgram.sql' ); + $files = [ 'EducationProgram.sql' ]; $path = "$IP/extensions/EducationProgram/sql"; break; case 'flaggedrevs': - $files = array( 'FlaggedRevs.sql' ); + $files = [ 'FlaggedRevs.sql' ]; $path = "$IP/extensions/FlaggedRevs/backend/schema/mysql"; break; @@ -68,55 +68,55 @@ if ( $wgFlowDefaultWikiDb !== false ) { $this->error( "This wiki uses $wgFlowDefaultWikiDb for Flow tables. They don't need to be created on the project database, which is the scope of this script.", 1 ); } - $files = array( 'flow.sql' ); + $files = [ 'flow.sql' ]; $path = "$IP/extensions/Flow"; break; case 'linter': - $files = array( 'linter.sql' ); + $files = [ 'linter.sql' ]; $path = "$IP/extensions/Linter"; break; case 'moodbar': - $files = array( + $files = [ 'MoodBar.sql', 'moodbar_feedback_response.sql', - ); + ]; $path = "$IP/extensions/MoodBar/sql"; break; case 'oathauth': - $files = array( + $files = [ 'tables.sql', - ); + ]; $path = "$IP/extensions/OATHAuth/sql/mysql"; break; case 'ores': - $files = array( + $files = [ 'ores_model.sql', 'ores_classification.sql', - ); + ]; $path = "$IP/extensions/ORES/sql"; break; case 'pageassessments': - $files = array( + $files = [ 'addProjectsTable.sql', 'addReviewsTable.sql', - ); + ]; $path = "$IP/extensions/PageAssessments/db"; break; case 'shorturl': - $files = array( + $files = [ 'shorturls.sql', - ); + ]; $path = "$IP/extensions/ShortUrl/schemas"; break; case 'translate': - $files = array( + $files = [ 'revtag.sql', 'translate_groupstats.sql', 'translate_metadata.sql', @@ -124,12 +124,12 @@ 'translate_groupreviews.sql', 'translate_messageindex.sql', 'translate_reviews.sql', - ); + ]; $path = "$IP/extensions/Translate/sql"; break; case 'wikilove': - $files = array( 'WikiLoveLog.sql' ); + $files = [ 'WikiLoveLog.sql' ]; $path = "$IP/extensions/WikiLove/patches"; break; @@ -146,5 +146,4 @@ } $maintClass = 'CreateExtensionTables'; -require_once( DO_MAINTENANCE ); - +require_once DO_MAINTENANCE; diff --git a/createHumanReadableProjectNameFiles.php b/createHumanReadableProjectNameFiles.php index a017797..34f69a2 100644 --- a/createHumanReadableProjectNameFiles.php +++ b/createHumanReadableProjectNameFiles.php @@ -42,14 +42,14 @@ } public function execute() { - $outEn = array(); - $outQqq = array(); + $outEn = []; + $outQqq = []; $counter = 0; $info = $this->getSitematrixFromAPI(); $languages = LanguageNames::getNames( 'en' ); // Wikis that have messages in WikimediaMessages - $messageMatrix = array( + $messageMatrix = [ // code => project name "wiki" => wfMessage( "wikibase-otherprojects-wikipedia" )->text(), "wiktionary" => "Wiktionary", // No message for this!? @@ -59,9 +59,9 @@ "wikisource" => wfMessage( "wikibase-sitelinks-wikisource" )->text(), "wikiversity" => "Wikiversity", // No message for this, either! "wikivoyage" => wfMessage( "wikibase-otherprojects-wikivoyage" )->text(), - ); + ]; - $failedLangWikis = array( + $failedLangWikis = [ "azbwiki" => "South Azerbaijani Wikipedia", "be_x_oldwiki" => "Belarusian (Taraškievica) Wikipedia", "bhwiki" => "Bihari Wikipedia", @@ -76,11 +76,10 @@ "zh_min_nanwikibooks" => "Min Nan Wikibooks", "zh_min_nanwikiquote" => "Min Nan Wikiquote", "zh_min_nanwikisource" => "Min Nan Wikisource", - ); - + ]; // SPECIAL WIKIS - $exceptions = array( + $exceptions = [ // code => full message "arbcom-de" => "German Wikipedia Arbitration Committee", "arbcom-en" => "English Wikipedia Arbitration Committee", @@ -136,7 +135,7 @@ "trwikimedia" => "Wikimedia Turkey", "uawikimedia" => "Wikimedia Ukraine", "ukwikimedia" => "Wikimedia UK", - ); + ]; // Go over the wikis and fill in the information foreach ( $info as $i => $languageGroup ) { @@ -166,7 +165,7 @@ // Output the line $outEn[ "project-localized-name-" . $dbname ] = $name; $outQqq[ "project-localized-name-" . $dbname ] = $this->createQQQ( $name, $url ); - $table[$dbname] = array( 'name' => $name, 'url' => $url ); + $table[$dbname] = [ 'name' => $name, 'url' => $url ]; $counter++; } @@ -189,7 +188,7 @@ // Output the line $outEn[ "project-localized-name-" . $dbname ] = $sitename; $outQqq[ "project-localized-name-" . $dbname ] = $this->createQQQ( $sitename, $url ); - $table[$dbname] = array( 'name' => $sitename, 'url' => $url ); + $table[$dbname] = [ 'name' => $sitename, 'url' => $url ]; $counter++; } @@ -216,4 +215,4 @@ } $maintClass = "CreateHumanReadableProjectNameFiles"; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/dumpInterwiki.php b/dumpInterwiki.php index 14e4b04..ab12304 100644 --- a/dumpInterwiki.php +++ b/dumpInterwiki.php @@ -54,7 +54,7 @@ * @returns array */ protected function getSites() { - return array( + return [ 'wiki' => new WMFSite( 'wiki', 'w', 'wikipedia' . $this->end ), 'wiktionary' => new WMFSite( 'wiktionary', 'wikt', 'wiktionary' . $this->end ), 'wikiquote' => new WMFSite( 'wikiquote', 'q', 'wikiquote' . $this->end ), @@ -64,7 +64,7 @@ 'wikimedia' => new WMFSite( 'wikimedia', 'chapter', 'wikimedia' . $this->end ), 'wikiversity' => new WMFSite( 'wikiversity', 'v', 'wikiversity' . $this->end ), 'wikivoyage' => new WMFSite( 'wikivoyage', 'voy', 'wikivoyage' . $this->end ), - ); + ]; } /** @@ -73,12 +73,12 @@ * @returns array */ protected function getExtraLinks() { - return array( - array( 'm', $this->urlprotocol . '//meta.wikimedia' . $this->end . '/wiki/$1', 1 ), - array( 'meta', $this->urlprotocol . '//meta.wikimedia' . $this->end . '/wiki/$1', 1 ), - array( 'sep11', $this->urlprotocol . '//sep11.wikipedia.org/wiki/$1', 1 ), - array( 'd', $this->urlprotocol . '//www.wikidata' . $this->end . '/wiki/$1', 1 ), - ); + return [ + [ 'm', $this->urlprotocol . '//meta.wikimedia' . $this->end . '/wiki/$1', 1 ], + [ 'meta', $this->urlprotocol . '//meta.wikimedia' . $this->end . '/wiki/$1', 1 ], + [ 'sep11', $this->urlprotocol . '//sep11.wikipedia.org/wiki/$1', 1 ], + [ 'd', $this->urlprotocol . '//www.wikidata' . $this->end . '/wiki/$1', 1 ], + ]; } /** @@ -86,16 +86,16 @@ * to another site * @var array */ - protected static $siteOverrides = array( - 'sourceswiki' => array( 'wikisource', 'en' ), - ); + protected static $siteOverrides = [ + 'sourceswiki' => [ 'wikisource', 'en' ], + ]; /** * Language aliases, usually configured as redirects to the real wiki in apache * Interlanguage links are made directly to the real wiki * @var array */ - protected static $languageAliases = array( + protected static $languageAliases = [ # Nasty legacy codes 'cz' => 'cs', 'dk' => 'da', @@ -117,15 +117,15 @@ 'be-tarask' => 'be-x-old', 'sgs' => 'bat-smg', 'egl' => 'eml', - ); + ]; /** * Special case prefix rewrites, for the benefit of Swedish which uses s:t * as an abbreviation for saint */ - protected static $prefixRewrites = array( - 'svwiki' => array( 's' => 'src' ), - ); + protected static $prefixRewrites = [ + 'svwiki' => [ 's' => 'src' ], + ]; /** * Set the wiki's interproject links to point to some other language code @@ -134,8 +134,8 @@ * Portuguese projects instead) * @var array */ - protected static $languageOverrides = array( - 'wikimedia' => array( + protected static $languageOverrides = [ + 'wikimedia' => [ 'ar' => 'es', 'bd' => 'bn', 'be' => 'en', @@ -154,11 +154,11 @@ 'se' => 'sv', 'ua' => 'uk', 'uk' => 'en', - ), - 'wikiversity' => array( + ], + 'wikiversity' => [ 'beta' => 'en', - ), - ); + ], + ]; /** * Additional links to provide for the needs of the different projects @@ -166,43 +166,43 @@ * @returns array */ protected function getAdditionalLinks( $project ) { - switch( $project ) { + switch ( $project ) { case 'wikibooks': - return array( - array( 'b', $this->urlprotocol . '//en.wikibooks' . $this->end . '/wiki/$1', 1 ), - ); + return [ + [ 'b', $this->urlprotocol . '//en.wikibooks' . $this->end . '/wiki/$1', 1 ], + ]; case 'wikinews': - return array( - array( 'n', $this->urlprotocol . '//en.wikinews' . $this->end . '/wiki/$1', 1 ), - ); + return [ + [ 'n', $this->urlprotocol . '//en.wikinews' . $this->end . '/wiki/$1', 1 ], + ]; case 'wikiquote': - return array( - array( 'q', $this->urlprotocol . '//en.wikiquote' . $this->end . '/wiki/$1', 1 ), - ); + return [ + [ 'q', $this->urlprotocol . '//en.wikiquote' . $this->end . '/wiki/$1', 1 ], + ]; case 'wikisource': - return array( - array( 'mul', $this->urlprotocol . '//wikisource.org/wiki/$1', 1 ), - array( 's', $this->urlprotocol . '//en.wikisource' . $this->end . '/wiki/$1', 1 ), - ); + return [ + [ 'mul', $this->urlprotocol . '//wikisource.org/wiki/$1', 1 ], + [ 's', $this->urlprotocol . '//en.wikisource' . $this->end . '/wiki/$1', 1 ], + ]; case 'wikiversity': - return array( - array( 'mul', $this->urlprotocol . '//beta.wikiversity.org/wiki/$1', 1 ), - array( 'v', $this->urlprotocol . '//en.wikiversity' . $this->end . '/wiki/$1', 1 ), - ); + return [ + [ 'mul', $this->urlprotocol . '//beta.wikiversity.org/wiki/$1', 1 ], + [ 'v', $this->urlprotocol . '//en.wikiversity' . $this->end . '/wiki/$1', 1 ], + ]; case 'wikivoyage': - return array( - array( 'voy', $this->urlprotocol . '//en.wikivoyage.org/wiki/$1', 1 ), - ); + return [ + [ 'voy', $this->urlprotocol . '//en.wikivoyage.org/wiki/$1', 1 ], + ]; case 'wiktionary': - return array( - array( 'wikt', $this->urlprotocol . '//en.wiktionary' . $this->end . '/wiki/$1', 1 ), - ); + return [ + [ 'wikt', $this->urlprotocol . '//en.wiktionary' . $this->end . '/wiki/$1', 1 ], + ]; case 'wiki': - return array( - array( 'w', $this->urlprotocol . '//en.wikipedia' . $this->end . '/wiki/$1', 1 ), - ); + return [ + [ 'w', $this->urlprotocol . '//en.wikipedia' . $this->end . '/wiki/$1', 1 ], + ]; default: - return array(); + return []; } } @@ -245,7 +245,7 @@ if ( $this->hasOption( 'o' ) ) { try { - $this->dbFile = CdbWriter::open( $this->getOption( 'o' ) ) ; + $this->dbFile = CdbWriter::open( $this->getOption( 'o' ) ); } catch ( CdbException $e ) { $this->error( "Unable to open cdb file for writing", 1 ); } @@ -271,7 +271,7 @@ $extraLinks = $this->getExtraLinks(); // Construct a list of reserved prefixes - $reserved = array(); + $reserved = []; foreach ( $this->langlist as $lang ) { $reserved[$lang] = 1; } @@ -312,14 +312,14 @@ } if ( empty( $reserved[$prefix] ) ) { - $imap = array( "iw_prefix" => $prefix, "iw_url" => $url, "iw_local" => $local ); + $imap = [ "iw_prefix" => $prefix, "iw_url" => $url, "iw_local" => $local ]; $this->makeLink( $imap, "__global" ); } } } // Exclude Wikipedia for Wikipedia - $this->makeLink( array( 'iw_prefix' => 'wikipedia', 'iw_url' => null ), "_wiki" ); + $this->makeLink( [ 'iw_prefix' => 'wikipedia', 'iw_url' => null ], "_wiki" ); // Multilanguage sites foreach ( $sites as $site ) { @@ -331,15 +331,15 @@ // Special wiki // Has interwiki links and interlanguage links to wikipedia - $this->makeLink( array( 'iw_prefix' => $db, 'iw_url' => "wiki" ), "__sites" ); + $this->makeLink( [ 'iw_prefix' => $db, 'iw_url' => "wiki" ], "__sites" ); // Links to multilanguage sites /** * @var $targetSite WMFSite */ foreach ( $sites as $targetSite ) { - $this->makeLink( array( 'iw_prefix' => $targetSite->prefix, + $this->makeLink( [ 'iw_prefix' => $targetSite->prefix, 'iw_url' => $targetSite->getURL( 'en', $this->urlprotocol ), - 'iw_local' => 1 ), $db ); + 'iw_local' => 1 ], $db ); } } else { // Find out which site this DB belongs to @@ -351,7 +351,7 @@ list( $site, $lang ) = self::$siteOverrides[$db]; $site = $sites[$site]; } else { - $matches = array(); + $matches = []; foreach ( $sites as $candidateSite ) { $suffix = $candidateSite->suffix; if ( preg_match( "/(.*)$suffix$/", $db, $matches ) ) { @@ -362,7 +362,7 @@ $lang = $matches[1]; } - $this->makeLink( array( 'iw_prefix' => $db, 'iw_url' => $site->suffix ), "__sites" ); + $this->makeLink( [ 'iw_prefix' => $db, 'iw_url' => $site->suffix ], "__sites" ); if ( !$site ) { $this->error( "Invalid database $db\n" ); continue; @@ -383,9 +383,9 @@ $lateralLang = self::$languageOverrides[$site->suffix][$lang]; } - $this->makeLink( array( 'iw_prefix' => $targetSite->prefix, + $this->makeLink( [ 'iw_prefix' => $targetSite->prefix, 'iw_url' => $targetSite->getURL( $lateralLang, $this->urlprotocol ), - 'iw_local' => 1 ), $db ); + 'iw_local' => 1 ], $db ); } } @@ -412,7 +412,6 @@ if ( !$this->dbFile ) { $this->output( "];\n" ); } - } /** @@ -426,13 +425,13 @@ // Actual languages with their own databases foreach ( $this->langlist as $targetLang ) { - $this->makeLink( array( $targetLang, $site->getURL( $targetLang, $this->urlprotocol ), 1 ), $source ); + $this->makeLink( [ $targetLang, $site->getURL( $targetLang, $this->urlprotocol ), 1 ], $source ); } // Language aliases if ( $wmfRealm === 'production' ) { foreach ( self::$languageAliases as $alias => $lang ) { - $this->makeLink( array( $alias, $site->getURL( $lang, $this->urlprotocol ), 1 ), $source ); + $this->makeLink( [ $alias, $site->getURL( $lang, $this->urlprotocol ), 1 ], $source ); } } @@ -454,7 +453,7 @@ } if ( !array_key_exists( "iw_prefix", $entry ) ) { - $entry = array( "iw_prefix" => $entry[0], "iw_url" => $entry[1], "iw_local" => $entry[2] ); + $entry = [ "iw_prefix" => $entry[0], "iw_url" => $entry[1], "iw_local" => $entry[2] ]; } if ( array_key_exists( $source, self::$prefixRewrites ) && array_key_exists( $entry['iw_prefix'], self::$prefixRewrites[$source] ) ) { @@ -486,4 +485,3 @@ $maintClass = "DumpInterwiki"; require_once RUN_MAINTENANCE_IF_MAIN; - diff --git a/filebackend/measureZoneSizes.php b/filebackend/measureZoneSizes.php index b129d71..a58eb51 100644 --- a/filebackend/measureZoneSizes.php +++ b/filebackend/measureZoneSizes.php @@ -77,20 +77,18 @@ file_put_contents( $file, "$wgDBname:\n$output", LOCK_EX | FILE_APPEND ); } $this->output( $output ); - } protected function getSizeOfDirectory( FileBackend $backend, $dir ) { $bytes = 0; $count = 0; - $list = $backend->getFileList( array( 'dir' => $dir, 'adviseStat' => true ) ); + $list = $backend->getFileList( [ 'dir' => $dir, 'adviseStat' => true ] ); foreach ( $list as $relPath ) { - $bytes += (int)$backend->getFileSize( array( 'src' => "{$dir}/{$relPath}" ) ); + $bytes += (int)$backend->getFileSize( [ 'src' => "{$dir}/{$relPath}" ] ); $count++; } - return array( $count, $bytes ); + return [ $count, $bytes ]; } } $maintClass = 'MeasureZoneSizes'; require_once RUN_MAINTENANCE_IF_MAIN; - diff --git a/filebackend/setZoneAccess.php b/filebackend/setZoneAccess.php index 2dc80ca..abb1fb0 100644 --- a/filebackend/setZoneAccess.php +++ b/filebackend/setZoneAccess.php @@ -10,18 +10,18 @@ public function execute() { $backend = FileBackendGroup::singleton()->get( $this->getOption( 'backend' ) ); - foreach ( array( 'public', 'thumb', 'transcoded', 'temp', 'deleted' ) as $zone ) { + foreach ( [ 'public', 'thumb', 'transcoded', 'temp', 'deleted' ] as $zone ) { $dir = $backend->getContainerStoragePath( "local-$zone" ); $secure = ( $zone === 'deleted' || $zone === 'temp' || $this->hasOption( 'private' ) ) - ? array( 'noAccess' => true, 'noListing' => true ) - : array(); + ? [ 'noAccess' => true, 'noListing' => true ] + : []; $this->prepareDirectory( $backend, $dir, $secure ); } - foreach ( array( 'timeline-render' ) as $container ) { + foreach ( [ 'timeline-render' ] as $container ) { $dir = $backend->getContainerStoragePath( $container ); $secure = $this->hasOption( 'private' ) - ? array( 'noAccess' => true, 'noListing' => true ) - : array(); + ? [ 'noAccess' => true, 'noListing' => true ] + : []; $this->prepareDirectory( $backend, $dir, $secure ); } } @@ -29,14 +29,14 @@ protected function prepareDirectory( FileBackend $backend, $dir, array $secure ) { // Create zone if it doesn't exist... $this->output( "Making sure $dir exists..." ); - $status = $backend->prepare( array( 'dir' => $dir ) + $secure ); + $status = $backend->prepare( [ 'dir' => $dir ] + $secure ); // Make sure zone has the right ACLs... if ( count( $secure ) ) { // private $this->output( "making '$dir' private..." ); - $status->merge( $backend->secure( array( 'dir' => $dir ) + $secure ) ); + $status->merge( $backend->secure( [ 'dir' => $dir ] + $secure ) ); } else { // public $this->output( "making '$dir' public..." ); - $status->merge( $backend->publish( array( 'dir' => $dir, 'access' => true ) ) ); + $status->merge( $backend->publish( [ 'dir' => $dir, 'access' => true ] ) ); } $this->output( "done.\n" ); if ( !$status->isOK() ) { @@ -45,4 +45,4 @@ } } $maintClass = 'SetZoneAccess'; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/fixBeXOldRenames.php b/fixBeXOldRenames.php index 2270a40..46e3454 100644 --- a/fixBeXOldRenames.php +++ b/fixBeXOldRenames.php @@ -39,7 +39,6 @@ } } fclose( $file ); - } protected function rename( $oldname ) { @@ -47,18 +46,18 @@ $oldUser->mName = $oldname; $newUser = User::newFromName( str_replace( '_', '-', $oldname ), 'usable' ); $maintScript = User::newFromName( 'Maintenance script' ); - $session = array( + $session = [ 'userId' => $maintScript->getId(), 'ip' => '127.0.0.1', 'sessionId' => '0', - 'headers' => array(), - ); - $data = array( + 'headers' => [], + ]; + $data = [ 'movepages' => true, 'suppressredirects' => true, 'reason' => '[[m:Special:MyLanguage/Single User Login finalisation announcement|SUL finalization]]', 'force' => true, - ); + ]; $globalRenameUser = new GlobalRenameUser( $maintScript, $oldUser, diff --git a/fixBug41778.php b/fixBug41778.php index 1101407..fdfed9b 100644 --- a/fixBug41778.php +++ b/fixBug41778.php @@ -8,11 +8,11 @@ $maxLength = $dbw->selectField( 'information_schema.columns', 'CHARACTER_MAXIMUM_LENGTH', - array( + [ 'table_schema' => $dbw->getDBname(), 'table_name' => 'ipblocks', 'column_name' => 'ipb_range_start' - ), + ], __METHOD__ ); print "Existing field length: $maxLength\n"; @@ -52,7 +52,7 @@ wfWaitForSlaves(); print "Regenerating field values\n"; - $res = $dbw->select( 'ipblocks', '*', array( 'ipb_range_start LIKE \'v6-%\'' ), __METHOD__ ); + $res = $dbw->select( 'ipblocks', '*', [ 'ipb_range_start LIKE \'v6-%\'' ], __METHOD__ ); foreach ( $res as $i => $row ) { list( $start, $end ) = IP::parseRange( $row->ipb_address ); if ( substr( $start, 0, 3 ) !== 'v6-' || substr( $end, 0, 3 ) !== 'v6-' ) { @@ -60,13 +60,13 @@ continue; } $dbw->update( 'ipblocks', - /* SET */ array( + /* SET */ [ 'ipb_range_start' => $start, 'ipb_range_end' => $end, - ), - /* WHERE */ array( + ], + /* WHERE */ [ 'ipb_id' => $row->ipb_id, - ) + ] ); if ( $i % 100 === 0 ) { wfWaitForSlaves(); diff --git a/fixCleanupTitles/revertCleanupTitles.php b/fixCleanupTitles/revertCleanupTitles.php index 41dde20..aa048c7 100644 --- a/fixCleanupTitles/revertCleanupTitles.php +++ b/fixCleanupTitles/revertCleanupTitles.php @@ -9,7 +9,7 @@ } $lines = array_map( 'trim', $lines ); -$opsByWiki = array(); +$opsByWiki = []; foreach ( $lines as $line ) { if ( !preg_match( '/ @@ -19,29 +19,28 @@ (\d+) \s \((\d+),\'(.*?)\'\) /x', - $line, $m ) ) - { + $line, $m ) ) { continue; } list( $whole, $wiki, $pageId, $ns, $dbk ) = $m; - $opsByWiki[$wiki][] = array( + $opsByWiki[$wiki][] = [ 'id' => $pageId, 'ns' => $ns, - 'dbk' => $dbk ); + 'dbk' => $dbk ]; } foreach ( $opsByWiki as $wiki => $ops ) { $lb = wfGetLB( $wiki ); - $db = $lb->getConnection( DB_MASTER, array(), $wiki ); + $db = $lb->getConnection( DB_MASTER, [], $wiki ); foreach ( $ops as $op ) { $msg = "{$op['id']} -> {$op['ns']}:{$op['dbk']}"; # Sanity check - $row = $db->selectRow( 'page', array( 'page_namespace', 'page_title' ), - array( 'page_id' => $op['id'] ), __METHOD__ ); + $row = $db->selectRow( 'page', [ 'page_namespace', 'page_title' ], + [ 'page_id' => $op['id'] ], __METHOD__ ); if ( !$row ) { echo "$wiki: missing: $msg\n"; continue; @@ -53,15 +52,13 @@ } $db->update( 'page', - /* SET */ array( + /* SET */ [ 'page_namespace' => $op['ns'], - 'page_title' => $op['dbk'] ), - /* WHERE */ array( - 'page_id' => $op['id'] ), + 'page_title' => $op['dbk'] ], + /* WHERE */ [ + 'page_id' => $op['id'] ], __METHOD__ ); echo "$wiki: updated: $msg\n"; } $lb->reuseConnection( $db ); } - - diff --git a/fixJobQueueExplosion.php b/fixJobQueueExplosion.php index 0aa1632..71a00c7 100644 --- a/fixJobQueueExplosion.php +++ b/fixJobQueueExplosion.php @@ -27,21 +27,21 @@ $numBatchesDone = 0; while ( true ) { $res = $dbw->select( 'job_explosion_tmp', '*', - array( + [ 'job_id > ' . $dbw->addQuotes( $start ), "NOT ( job_cmd = 'htmlCacheUpdate' AND " . "job_params LIKE '%s:13:\"categorylinks\"%' )" - ), - __METHOD__, array( 'LIMIT' => $batchSize ) ); + ], + __METHOD__, [ 'LIMIT' => $batchSize ] ); if ( !$res->numRows() ) { break; } - $insertBatch = array(); + $insertBatch = []; foreach ( $res as $row ) { $start = $row->job_id; - $insertRow = array(); + $insertRow = []; foreach ( (array)$row as $name => $value ) { $insertRow[$name] = $value; } @@ -62,4 +62,4 @@ } $maintClass = 'FixJobQueueExplosion'; -require_once( DO_MAINTENANCE ); +require_once DO_MAINTENANCE; diff --git a/fixUsabilityPrefs.php b/fixUsabilityPrefs.php index c3f2cf6..98ce9cf 100644 --- a/fixUsabilityPrefs.php +++ b/fixUsabilityPrefs.php @@ -13,24 +13,24 @@ echo "Fixing usebetatoolbar\n"; $batchSize = 100; - $allIds = array(); + $allIds = []; while ( true ) { $this->beginTransaction( $dbw, __METHOD__ ); - $res = $dbw->select( 'user_properties', array( 'up_user' ), - array( 'up_property' => 'usebetatoolbar', 'up_value' => '' ), + $res = $dbw->select( 'user_properties', [ 'up_user' ], + [ 'up_property' => 'usebetatoolbar', 'up_value' => '' ], __METHOD__, - array( 'LIMIT' => $batchSize, 'FOR UPDATE' ) ); + [ 'LIMIT' => $batchSize, 'FOR UPDATE' ] ); if ( !$res->numRows() ) { $this->commitTransaction( $dbw, __METHOD__ ); break; } - $ids = array(); + $ids = []; foreach ( $res as $row ) { $ids[] = $row->up_user; } $dbw->delete( 'user_properties', - array( 'up_property' => 'usebetatoolbar', 'up_user' => $ids ), + [ 'up_property' => 'usebetatoolbar', 'up_user' => $ids ], __METHOD__ ); $this->commitTransaction( $dbw, __METHOD__ ); $allIds = array_merge( $allIds, $ids ); @@ -42,21 +42,21 @@ $likeWikieditor = $dbw->buildLike( 'wikieditor-', $dbw->anyString() ); while ( true ) { $this->beginTransaction( $dbw, __METHOD__ ); - $res = $dbw->select( 'user_properties', array( 'DISTINCT up_user' ), - array( "up_property $likeWikieditor" ), + $res = $dbw->select( 'user_properties', [ 'DISTINCT up_user' ], + [ "up_property $likeWikieditor" ], __METHOD__, - array( 'LIMIT' => $batchSize, 'FOR UPDATE' ) ); + [ 'LIMIT' => $batchSize, 'FOR UPDATE' ] ); if ( !$res->numRows() ) { $this->commitTransaction( $dbw, __METHOD__ ); break; } - $ids = array(); + $ids = []; foreach ( $res as $row ) { $ids[] = $row->up_user; } $dbw->delete( 'user_properties', - array( "up_property $likeWikieditor", 'up_user' => $ids ), + [ "up_property $likeWikieditor", 'up_user' => $ids ], __METHOD__ ); $this->commitTransaction( $dbw, __METHOD__ ); $allIds = array_merge( $allIds, $ids ); @@ -86,6 +86,4 @@ } $maintClass = 'FixUsabilityPrefs'; -require_once( DO_MAINTENANCE ); - - +require_once DO_MAINTENANCE; diff --git a/fixUsabilityPrefs2.php b/fixUsabilityPrefs2.php index ba876d4..28c0286 100644 --- a/fixUsabilityPrefs2.php +++ b/fixUsabilityPrefs2.php @@ -13,24 +13,24 @@ echo "Fixing usebetatoolbar\n"; $batchSize = 100; - $allIds = array(); + $allIds = []; while ( true ) { $this->beginTransaction( $dbw, __METHOD__ ); - $res = $dbw->select( 'user_properties', array( 'up_user' ), - array( 'up_property' => 'usebetatoolbar', 'up_value' => '' ), + $res = $dbw->select( 'user_properties', [ 'up_user' ], + [ 'up_property' => 'usebetatoolbar', 'up_value' => '' ], __METHOD__, - array( 'LIMIT' => $batchSize, 'FOR UPDATE' ) ); + [ 'LIMIT' => $batchSize, 'FOR UPDATE' ] ); if ( !$res->numRows() ) { $this->commitTransaction( $dbw, __METHOD__ ); break; } - $ids = array(); + $ids = []; foreach ( $res as $row ) { $ids[] = $row->up_user; } - $dbw->update( 'user_properties', array( 'up_value' => 0 ), - array( 'up_property' => 'usebetatoolbar', 'up_user' => $ids ), + $dbw->update( 'user_properties', [ 'up_value' => 0 ], + [ 'up_property' => 'usebetatoolbar', 'up_user' => $ids ], __METHOD__ ); $this->commitTransaction( $dbw, __METHOD__ ); $allIds = array_merge( $allIds, $ids ); @@ -42,21 +42,21 @@ $likeWikieditor = $dbw->buildLike( 'wikieditor-', $dbw->anyString() ); while ( true ) { $this->beginTransaction( $dbw, __METHOD__ ); - $res = $dbw->select( 'user_properties', array( 'DISTINCT up_user' ), - array( "up_property $likeWikieditor" ), + $res = $dbw->select( 'user_properties', [ 'DISTINCT up_user' ], + [ "up_property $likeWikieditor" ], __METHOD__, - array( 'LIMIT' => $batchSize, 'FOR UPDATE' ) ); + [ 'LIMIT' => $batchSize, 'FOR UPDATE' ] ); if ( !$res->numRows() ) { $this->commitTransaction( $dbw, __METHOD__ ); break; } - $ids = array(); + $ids = []; foreach ( $res as $row ) { $ids[] = $row->up_user; } $dbw->delete( 'user_properties', - array( "up_property $likeWikieditor", 'up_user' => $ids ), + [ "up_property $likeWikieditor", 'up_user' => $ids ], __METHOD__ ); $this->commitTransaction( $dbw, __METHOD__ ); $allIds = array_merge( $allIds, $ids ); @@ -69,27 +69,26 @@ while ( true ) { $this->beginTransaction( $dbw, __METHOD__ ); - $res = $dbw->select( 'user_properties', array( 'DISTINCT up_user' ), - array( "up_property" => "usenavigabletoc" ), + $res = $dbw->select( 'user_properties', [ 'DISTINCT up_user' ], + [ "up_property" => "usenavigabletoc" ], __METHOD__, - array( 'LIMIT' => $batchSize, 'FOR UPDATE' ) ); + [ 'LIMIT' => $batchSize, 'FOR UPDATE' ] ); if ( !$res->numRows() ) { $this->commitTransaction( $dbw, __METHOD__ ); break; } - $ids = array(); + $ids = []; foreach ( $res as $row ) { $ids[] = $row->up_user; } $dbw->delete( 'user_properties', - array( "up_property" => "usenavigabletoc", 'up_user' => $ids ), + [ "up_property" => "usenavigabletoc", 'up_user' => $ids ], __METHOD__ ); $this->commitTransaction( $dbw, __METHOD__ ); $allIds = array_merge( $allIds, $ids ); wfWaitForSlaves( 10 ); } - echo "Invalidating user cache\n"; $i = 0; @@ -108,11 +107,8 @@ } echo "Done\n"; - } } $maintClass = 'FixUsabilityPrefs'; -require_once( DO_MAINTENANCE ); - - +require_once DO_MAINTENANCE; diff --git a/getJobQueueLengths.php b/getJobQueueLengths.php index 2d04439..9eaa1a7 100644 --- a/getJobQueueLengths.php +++ b/getJobQueueLengths.php @@ -27,7 +27,7 @@ $totalOnly = $this->hasOption( 'totalonly' ); $pendingDBs = JobQueueAggregator::singleton()->getAllReadyWikiQueues(); - $sizeByWiki = array(); // (wiki => type => count) map + $sizeByWiki = []; // (wiki => type => count) map foreach ( $pendingDBs as $type => $wikis ) { foreach ( $wikis as $wiki ) { $sizeByWiki[$wiki][$type] = @@ -61,4 +61,4 @@ } $maintClass = 'GetJobQueueLengths'; -require_once( DO_MAINTENANCE ); +require_once DO_MAINTENANCE; diff --git a/getPageCounts.php b/getPageCounts.php index e71c6f7..d9a49b5 100644 --- a/getPageCounts.php +++ b/getPageCounts.php @@ -34,7 +34,7 @@ $wikis = $wgConf->getLocalDatabases(); $exclude = array_flip( $this->getExcludedWikis() ); - $counts = array(); + $counts = []; foreach ( $wikis as $wiki ) { $wiki = trim( $wiki ); if ( $wiki === '' || $wiki[0] === '#' ) { @@ -44,15 +44,15 @@ continue; } $lb = wfGetLB( $wiki ); - $dbr = $lb->getConnection( DB_SLAVE, array(), $wiki ); - $row = $dbr->selectRow( 'site_stats', array( 'ss_total_pages', 'ss_good_articles' ), '', __METHOD__ ); + $dbr = $lb->getConnection( DB_SLAVE, [], $wiki ); + $row = $dbr->selectRow( 'site_stats', [ 'ss_total_pages', 'ss_good_articles' ], '', __METHOD__ ); if ( !$row ) { $this->error( "Error: '$wiki' has empty site_stats\n", 1 ); // Die } - $counts[$wiki] = array( + $counts[$wiki] = [ 'pages' => intval( $row->ss_total_pages ), 'contentPages' => intval( $row->ss_good_articles ), - ); + ]; $lb->reuseConnection( $dbr ); } $this->output( FormatJson::encode( $counts, true ) . "\n" ); @@ -65,17 +65,16 @@ private function dblist( $name ) { if ( !defined( 'MEDIAWIKI_DBLIST_DIR' ) ) { $this->error( "Warning: MEDIAWIKI_DBLIST_DIR is not defined, no wikis will be blacklisted\n" ); - return array(); + return []; } $fileName = MEDIAWIKI_DBLIST_DIR . "/$name.dblist"; if ( !is_readable( $fileName ) ) { $this->error( "Warning: can't read $fileName, no wikis will be blacklisted\n" ); - return array(); + return []; } return array_map( 'trim', file( $fileName ) ); } } - $maintClass = 'GetPageCounts'; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/importUseModWikipedia.php b/importUseModWikipedia.php index b95bb70..a16d41a 100644 --- a/importUseModWikipedia.php +++ b/importUseModWikipedia.php @@ -15,7 +15,7 @@ class ImportUseModWikipedia extends Maintenance { public $encodeMap, $decodeMap; - public $deepRenames = array( + public $deepRenames = [ 'JimboWales' => 983862286, 'TexaS' => 983918410, 'HistoryOfUnitedStatesTalk' => 984795423, @@ -28,74 +28,74 @@ 'GladstoneOregon' => 985368219, 'PacificBeach' => '?', 'AaRiver' => '?', - ); + ]; - public $replacements = array(); + public $replacements = []; - public $renameTextLinksOps = array( - 983846265 => array( + public $renameTextLinksOps = [ + 983846265 => [ 'TestIgnore' => 'IgnoreTest', - ), - 983848080 => array( + ], + 983848080 => [ 'UnitedLocomotiveWorks' => 'Atlas Shrugged/United Locomotive Works' - ), - 983856376 => array( + ], + 983856376 => [ 'WikiPedia' => 'Wikipedia', - ), - 983896152 => array( + ], + 983896152 => [ 'John_F_Kennedy' => 'John_F._Kennedy', - ), - 983905871 => array( + ], + 983905871 => [ 'LarrySanger' => 'Larry_Sanger' - ), - 984697068 => array( + ], + 984697068 => [ 'UnitedStates' => 'United States', - ), - 984792748 => array( + ], + 984792748 => [ 'LibertarianisM' => 'Libertarianism' - ), - 985327832 => array( + ], + 985327832 => [ 'AnarchisM' => 'Anarchism', - ), - 985290063 => array( + ], + 985290063 => [ 'HistoryOfUnitedStatesDiscussion' => 'History_Of_United_States_Discussion' - ), - 985290091 => array( + ], + 985290091 => [ 'BritishEmpire' => 'British Empire' - ), + ], /* 985468958 => array( 'ScienceFiction' => 'Science fiction', ),*/ - ); + ]; /** * Hack for observed substitution issues */ - public $skipSelfSubstitution = array( + public $skipSelfSubstitution = [ 'Pythagorean_Theorem', 'The_Most_Remarkable_Formula_In_The_World', 'Wine', - ); + ]; - public $unixLineEndingsOps = array( + public $unixLineEndingsOps = [ 987743732 => 'Wikipedia_FAQ' - ); + ]; - public $replacementsDone = array(); + public $replacementsDone = []; - public $moveLog = array(); - public $moveDests = array(); + public $moveLog = []; + public $moveDests = []; public $revId; - public $rc = array(); - public $textCache = array(); - public $blacklist = array(); + public $rc = []; + public $textCache = []; + public $blacklist = []; public $FS, $FS1, $FS2, $FS3; public $FreeLinkPattern, $UrlPattern, $LinkPattern, $InterLinkPattern; - public $cp1252Table = array( + public $cp1252Table = [ 0x80 => 0x20ac, 0x81 => 0x0081, 0x82 => 0x201a, @@ -127,7 +127,7 @@ 0x9c => 0x0153, 0x9d => 0x009d, 0x9e => 0x017e, -0x9f => 0x0178 ); +0x9f => 0x0178 ]; public function __construct() { parent::__construct(); @@ -135,7 +135,7 @@ $this->addOption( 'outfile', 'the name of the output XML file', true, true ); $this->initLinkPatterns(); - $this->encodeMap = $this->decodeMap = array(); + $this->encodeMap = $this->decodeMap = []; for ( $source = 0; $source <= 0xff; $source++ ) { if ( isset( $this->cp1252Table[$source] ) ) { @@ -161,7 +161,9 @@ $LowerLetter = "[a-z"; $AnyLetter = "[A-Za-z"; $AnyLetter .= "_0-9"; - $UpperLetter .= "]"; $LowerLetter .= "]"; $AnyLetter .= "]"; + $UpperLetter .= "]"; +$LowerLetter .= "]"; +$AnyLetter .= "]"; # Main link pattern: lowercase between uppercase, then anything $LpA = $UpperLetter . "+" . $LowerLetter . "+" . $UpperLetter @@ -250,15 +252,15 @@ echo "Error reading rclog\n"; return; } - $params = array( + $params = [ 'timestamp' => $bits[0], 'rctitle' => $bits[1], 'summary' => $bits[2], 'minor' => $bits[3], 'host' => $bits[4], 'kind' => $bits[5], - 'extra' => array() - ); + 'extra' => [] + ]; $extraList = explode( $this->FS2, $bits[6] ); for ( $i = 0; $i < count( $extraList ); $i += 2 ) { @@ -269,10 +271,10 @@ } function writeMoveLog() { - $this->moveLog = array(); + $this->moveLog = []; $deepRenames = $this->deepRenames; echo "Calculating move log...\n"; - $this->processDiffFile( array( $this, 'moveLogCallback' ) ); + $this->processDiffFile( [ $this, 'moveLogCallback' ] ); // We have the timestamp intervals, now make a guess at the actual timestamp foreach ( $this->moveLog as $newTitle => $params ) { @@ -282,8 +284,7 @@ $drTime = $deepRenames[$params['old']]; if ( $drTime !== '?' ) { if ( ( !isset( $params['endTime'] ) || $drTime < $params['endTime'] ) - && $drTime > $params['startTime'] ) - { + && $drTime > $params['startTime'] ) { $this->moveLog[$newTitle]['timestamp'] = $drTime; $this->moveLog[$newTitle]['deep'] = true; @@ -338,7 +339,6 @@ implode( "\n", array_keys( $deepRenames ) ) . "\n\n"; } - } function element( $name, $value ) { @@ -352,17 +352,16 @@ if ( $rctitle === $title ) { if ( isset( $this->moveLog[$rctitle] ) - && !isset( $this->moveLog[$rctitle]['endTime'] ) ) - { + && !isset( $this->moveLog[$rctitle]['endTime'] ) ) { // This is the latest time that the page could have been moved $this->moveLog[$rctitle]['endTime'] = $entry['timestamp']; } } else { if ( !isset( $this->moveLog[$rctitle] ) ) { // Initialise the move log entry - $this->moveLog[$rctitle] = array( + $this->moveLog[$rctitle] = [ 'old' => $title - ); + ]; } // Update the earliest time the page could have been moved $this->moveLog[$rctitle]['startTime'] = $entry['timestamp']; @@ -372,7 +371,7 @@ function writeRevisions() { $this->numGoodRevs = 0; $this->revId = 1; - $this->processDiffFile( array( $this, 'revisionCallback' ) ); + $this->processDiffFile( [ $this, 'revisionCallback' ] ); echo "\n\nImported {$this->numGoodRevs} out of {$this->numRevs}\n"; } @@ -443,13 +442,13 @@ $this->printLatin1( "$fixTime $title FIXING LINE ENDINGS\n" ); $text = $this->getText( $title ); $text = str_replace( "\r", '', $text ); - $this->saveRevision( array( + $this->saveRevision( [ 'rctitle' => $title, 'timestamp' => $fixTime, - 'extra' => array( 'name' => 'UseModWiki admin' ), + 'extra' => [ 'name' => 'UseModWiki admin' ], 'text' => $text, 'summary' => 'Fixing line endings', - ) ); + ] ); unset( $this->unixLineEndingsOps[$fixTime] ); } } @@ -479,7 +478,7 @@ } function resolveFailedDiff( $origText, $diff ) { - $context = array(); + $context = []; $diffLines = explode( "\n", $diff ); for ( $i = 0; $i < count( $diffLines ); $i++ ) { $diffLine = $diffLines[$i]; @@ -497,7 +496,7 @@ $i--; } - $changedLinks = array(); + $changedLinks = []; $origLines = explode( "\n", $origText ); foreach ( $context as $i => $contextLine ) { $origLine = isset( $origLines[$i] ) ? $origLines[$i] : ''; @@ -517,7 +516,7 @@ } function resolveTextChange( $source, $dest ) { - $changedLinks = array(); + $changedLinks = []; $sourceLinks = $this->getLinkList( $source ); $destLinks = $this->getLinkList( $dest ); $newLinks = array_diff( $destLinks, $sourceLinks ); @@ -536,8 +535,8 @@ } if ( $bestRemovedLink !== false ) { $changedLinks[$bestRemovedLink] = $newLink; - $newLinks = array_diff( $newLinks, array( $newLink ) ); - $removedLinks = array_diff( $removedLinks, array( $bestRemovedLink ) ); + $newLinks = array_diff( $newLinks, [ $newLink ] ); + $removedLinks = array_diff( $removedLinks, [ $bestRemovedLink ] ); } } @@ -735,85 +734,84 @@ foreach ( $this->textCache as $title => $oldText ) { if ( $newWithUnderscores === $title - && in_array( $title, $this->skipSelfSubstitution ) ) - { + && in_array( $title, $this->skipSelfSubstitution ) ) { // Hack to make Pythagorean_Theorem etc. work continue; } $newText = $this->substituteTextLinks( $old, $new, $oldText ); if ( $oldText !== $newText ) { - $this->saveRevision( array( + $this->saveRevision( [ 'rctitle' => $title, 'timestamp' => $timestamp, 'text' => $newText, - 'extra' => array( 'name' => 'Page move link fixup script' ), + 'extra' => [ 'name' => 'Page move link fixup script' ], 'summary' => '', 'minor' => true - ) ); + ] ); } } } function substituteTextLinks( $old, $new, $text ) { - $this->saveUrl = array(); + $this->saveUrl = []; $this->old = $old; $this->new = $new; $text = str_replace( $this->FS, '', $text ); # Remove separators (paranoia) $text = preg_replace_callback( '/(<pre>(.*?)<\/pre>)/is', - array( $this, 'storeRaw' ), $text ); + [ $this, 'storeRaw' ], $text ); $text = preg_replace_callback( '/(<code>(.*?)<\/code>)/is', - array( $this, 'storeRaw' ), $text ); + [ $this, 'storeRaw' ], $text ); $text = preg_replace_callback( '/(<nowiki>(.*?)<\/nowiki>)/s', - array( $this, 'storeRaw' ), $text ); + [ $this, 'storeRaw' ], $text ); $text = preg_replace_callback( "/\[\[{$this->FreeLinkPattern}\|([^\]]+)\]\]/", - array( $this, 'subFreeLink' ), $text ); + [ $this, 'subFreeLink' ], $text ); $text = preg_replace_callback( "/\[\[{$this->FreeLinkPattern}\]\]/", - array( $this, 'subFreeLink' ), $text ); + [ $this, 'subFreeLink' ], $text ); $text = preg_replace_callback( "/(\[{$this->UrlPattern}\s+([^\]]+?)\])/", - array( $this, 'storeRaw' ), $text ); + [ $this, 'storeRaw' ], $text ); $text = preg_replace_callback( "/(\[{$this->InterLinkPattern}\s+([^\]]+?)\])/", - array( $this, 'storeRaw' ), $text ); + [ $this, 'storeRaw' ], $text ); $text = preg_replace_callback( "/(\[?{$this->UrlPattern}\]?)/", - array( $this, 'storeRaw' ), $text ); + [ $this, 'storeRaw' ], $text ); $text = preg_replace_callback( "/(\[?{$this->InterLinkPattern}\]?)/", - array( $this, 'storeRaw' ), $text ); + [ $this, 'storeRaw' ], $text ); $text = preg_replace_callback( "/{$this->LinkPattern}/", - array( $this, 'subWikiLink' ), $text ); + [ $this, 'subWikiLink' ], $text ); $text = preg_replace_callback( "/{$this->FS}(\d+){$this->FS}/", - array( $this, 'restoreRaw' ), $text ); # Restore saved text + [ $this, 'restoreRaw' ], $text ); # Restore saved text return $text; } function getLinkList( $text ) { - $this->saveUrl = array(); - $this->linkList = array(); + $this->saveUrl = []; + $this->linkList = []; $text = str_replace( $this->FS, '', $text ); # Remove separators (paranoia) $text = preg_replace_callback( '/(<pre>(.*?)<\/pre>)/is', - array( $this, 'storeRaw' ), $text ); + [ $this, 'storeRaw' ], $text ); $text = preg_replace_callback( '/(<code>(.*?)<\/code>)/is', - array( $this, 'storeRaw' ), $text ); + [ $this, 'storeRaw' ], $text ); $text = preg_replace_callback( '/(<nowiki>(.*?)<\/nowiki>)/s', - array( $this, 'storeRaw' ), $text ); + [ $this, 'storeRaw' ], $text ); $text = preg_replace_callback( "/\[\[{$this->FreeLinkPattern}\|([^\]]+)\]\]/", - array( $this, 'storeLink' ), $text ); + [ $this, 'storeLink' ], $text ); $text = preg_replace_callback( "/\[\[{$this->FreeLinkPattern}\]\]/", - array( $this, 'storeLink' ), $text ); + [ $this, 'storeLink' ], $text ); $text = preg_replace_callback( "/(\[{$this->UrlPattern}\s+([^\]]+?)\])/", - array( $this, 'storeRaw' ), $text ); + [ $this, 'storeRaw' ], $text ); $text = preg_replace_callback( "/(\[{$this->InterLinkPattern}\s+([^\]]+?)\])/", - array( $this, 'storeRaw' ), $text ); + [ $this, 'storeRaw' ], $text ); $text = preg_replace_callback( "/(\[?{$this->UrlPattern}\]?)/", - array( $this, 'storeRaw' ), $text ); + [ $this, 'storeRaw' ], $text ); $text = preg_replace_callback( "/(\[?{$this->InterLinkPattern}\]?)/", - array( $this, 'storeRaw' ), $text ); + [ $this, 'storeRaw' ], $text ); $text = preg_replace_callback( "/{$this->LinkPattern}/", - array( $this, 'storeLink' ), $text ); + [ $this, 'storeLink' ], $text ); return $this->linkList; } @@ -843,7 +841,7 @@ $link .= "|$name"; } $link .= "]]"; - return $this->storeRaw( array( 1 => $link ) ); + return $this->storeRaw( [ 1 => $link ] ); } function subWikiLink( $m ) { @@ -854,7 +852,7 @@ $link = "[[$link]]"; } } - return $this->storeRaw( array( 1 => $link ) ); + return $this->storeRaw( [ 1 => $link ] ); } function restoreRaw( $m ) { @@ -880,7 +878,7 @@ function unserializeUseMod( $s, $sep ) { $parts = explode( $sep, $s ); - $result = array(); + $result = []; for ( $i = 0; $i < count( $parts ); $i += 2 ) { $result[$parts[$i]] = $parts[$i + 1]; } @@ -889,4 +887,4 @@ } $maintClass = 'ImportUseModWikipedia'; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/makeDumpList.php b/makeDumpList.php index 89e67f5..c375e04 100644 --- a/makeDumpList.php +++ b/makeDumpList.php @@ -1,6 +1,6 @@ <?php -require_once( __DIR__ . '/WikimediaMaintenance.php' ); +require_once __DIR__ . '/WikimediaMaintenance.php'; class MakeDumpList extends Maintenance { public function __construct() { @@ -45,8 +45,8 @@ 'page_id=tl_from' ]; $res = $dbr->select( - ['page', 'templatelinks'], - ['tl_namespace', 'tl_title'], + [ 'page', 'templatelinks' ], + [ 'tl_namespace', 'tl_title' ], $conds, __METHOD__ ); foreach ( $res as $row ) { @@ -57,4 +57,4 @@ } $maintClass = "MakeDumpList"; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/makeSizeDBLists.php b/makeSizeDBLists.php index e168c2d..353554f 100644 --- a/makeSizeDBLists.php +++ b/makeSizeDBLists.php @@ -18,13 +18,13 @@ function execute() { global $wgConf; - $small = array(); - $medium = array(); - $large = array(); + $small = []; + $medium = []; + $large = []; foreach ( $wgConf->getLocalDatabases() as $wiki ) { try { $lb = wfGetLB( $wiki ); - $db = $lb->getConnection( DB_MASTER, array(), $wiki ); + $db = $lb->getConnection( DB_MASTER, [], $wiki ); } catch ( Exception $e ) { // Probably just wikitech etc, skip! continue; @@ -60,4 +60,4 @@ } $maintClass = 'MakeSizeDBLists'; -require_once( DO_MAINTENANCE ); +require_once DO_MAINTENANCE; diff --git a/migrateWlmUploads.php b/migrateWlmUploads.php index 36b2507..0a1e51c 100644 --- a/migrateWlmUploads.php +++ b/migrateWlmUploads.php @@ -29,15 +29,15 @@ class MigrateWlmUploads extends Maintenance { private $dryRun, - $testerUsernames = array( + $testerUsernames = [ 'Jdlrobson', 'Tfinc', 'Brion VIBBER', 'Awjrichards', 'Philinje', - ), + ], $home, - $logFiles = array( 'found', 'done', 'exists', 'nouser' ), + $logFiles = [ 'found', 'done', 'exists', 'nouser' ], $tmpDir, $deletingUser; @@ -67,25 +67,24 @@ } wfRestoreWarnings(); - $this->home = getenv( 'HOME' ); $this->dryRun = !$this->hasOption( 'do-it' ); $dbw = $this->getDB( DB_MASTER ); - $this->commonsDbw = $this->getDB( DB_MASTER, array(), 'commonswiki' ); + $this->commonsDbw = $this->getDB( DB_MASTER, [], 'commonswiki' ); $wlmTemplate = Title::newFromText( 'Template:Uploaded with WLM Mobile' ); $this->deletingUser = User::newFromName( 'Maintenance script' ); $res = $dbw->select( - array( 'templatelinks', 'page', 'image' ), - array( 'page_title', 'img_user_text', 'img_timestamp' ), - array( + [ 'templatelinks', 'page', 'image' ], + [ 'page_title', 'img_user_text', 'img_timestamp' ], + [ 'tl_namespace' => $wlmTemplate->getNamespace(), 'tl_title' => $wlmTemplate->getDBkey(), 'tl_from = page_id', 'page_namespace' => NS_FILE, 'page_title = img_name', - ), + ], __METHOD__ ); @@ -94,7 +93,7 @@ $user = $row->img_user_text; $timestamp = $row->img_timestamp; - $this->logToFile( 'found', array( $title, $user ) ); + $this->logToFile( 'found', [ $title, $user ] ); $this->output( "$title by $user uploaded at $timestamp\n" ); if ( in_array( $user, $this->testerUsernames ) ) { $this->output( " ...this user is an app tester, rejecting\n" ); @@ -135,15 +134,15 @@ } private function migrateFile( $fileName, $user, $timestamp ) { - if ( !$this->commonsDbw->selectField( 'user', 'user_id', array( 'user_name' => $user ) ) ) { - $this->logToFile( 'nouser', array( $fileName, $user ) ); + if ( !$this->commonsDbw->selectField( 'user', 'user_id', [ 'user_name' => $user ] ) ) { + $this->logToFile( 'nouser', [ $fileName, $user ] ); $this->output( " ...No such user found on destination wiki\n" ); return; } $localFile = wfLocalFile( $fileName ); - $remoteFileName = $this->commonsDbw->selectField( 'image', 'img_name', array( 'img_sha1' => $localFile->getSha1() ) ); + $remoteFileName = $this->commonsDbw->selectField( 'image', 'img_name', [ 'img_sha1' => $localFile->getSha1() ] ); if ( $remoteFileName ) { - $this->logToFile( 'exists', array( $fileName, $user, $remoteFileName ) ); + $this->logToFile( 'exists', [ $fileName, $user, $remoteFileName ] ); $this->output( " ...File already exists on destination wiki as $remoteFileName\n" ); return; } @@ -158,14 +157,14 @@ // we just call upload script instead $tempFile = "{$this->tmpDir}/{$fileName}"; $cmd = 'sudo -u apache mwscript importImages.php --wiki=commonswiki' - . ' --user=' . wfEscapeShellArg( $user ) + . ' --user=' . wfEscapeShellArg( $user ) . ' --comment-file=' . wfEscapeShellArg( $descFile ) . ' --summary=' . wfEscapeShellArg( 'WLM image automatically imported from testwiki' ) . ' --timestamp=' . wfEscapeShellArg( $timestamp ) . ' ' . wfEscapeShellArg( $this->tmpDir ); $this->output( " ...Executing $cmd\n" ); if ( $this->dryRun ) { - $this->logToFile( 'done', array( $fileName, $user ) ); + $this->logToFile( 'done', [ $fileName, $user ] ); return; } @@ -174,14 +173,14 @@ copy( $localCopy->getPath(), $tempFile ); $retval = 0; - $output = wfShellExec( $cmd, $retval, array(), array( 'memory' => 1024 * 512 ) ); + $output = wfShellExec( $cmd, $retval, [], [ 'memory' => 1024 * 512 ] ); if ( $output ) { $this->output( $output . "\n" ); } if ( $retval ) { $this->error( '*** Upload error, aborting ***', 1 ); } - $this->logToFile( 'done', array( $fileName, $user ) ); + $this->logToFile( 'done', [ $fileName, $user ] ); wfSuppressWarnings(); unlink( $tempFile ); @@ -198,4 +197,4 @@ } $maintClass = 'MigrateWlmUploads'; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/ourUsers.php b/ourUsers.php index c8578e2..6f95c14 100644 --- a/ourUsers.php +++ b/ourUsers.php @@ -32,17 +32,17 @@ $wikiadmin_pass = `wikiadmin_pass`; $nagios_pass = `nagios_sql_pass`; -$hosts = array( +$hosts = [ 'localhost', '10.0.%', '66.230.200.%', '208.80.152.%', -); +]; -$databases = array( +$databases = [ '%wik%', 'centralauth', -); +]; print "/*!40100 set old_passwords=1 */;\n"; print "/*!40100 set global old_passwords=1 */;\n"; @@ -67,4 +67,3 @@ print "\n"; } - diff --git a/passwordAudit.php b/passwordAudit.php index 4c8ebad..4656802 100644 --- a/passwordAudit.php +++ b/passwordAudit.php @@ -48,7 +48,7 @@ $hash = $dbr->selectField( 'globaluser', 'gu_password', - array( 'gu_name' => $username ), + [ 'gu_name' => $username ], __METHOD__ ); @@ -56,7 +56,7 @@ $hash = $dbr->selectField( 'user', 'user_password', - array( 'user_name' => $username ), + [ 'user_name' => $username ], __METHOD__ ); } @@ -101,7 +101,7 @@ $pieces = explode( ':', $hash ); $salt = base64_decode( $pieces[5] ); $roundTotal = $lastRound = hash_hmac( 'sha256', $salt . pack( 'N', 1 ), $test, true ); - for ( $j = 1; $j < (int) $pieces[3]; ++$j ) { + for ( $j = 1; $j < (int)$pieces[3]; ++$j ) { $lastRound = hash_hmac( 'sha256', $lastRound, $test, true ); $roundTotal ^= $lastRound; } @@ -111,4 +111,4 @@ } $maintClass = 'passwordAudit'; -require_once RUN_MAINTENANCE_IF_MAIN; \ No newline at end of file +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..41bf1f4 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,34 @@ +<?xml version="1.0"?> +<ruleset> + <rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"> + <exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationProtected" /> + <exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic" /> + <exclude name="MediaWiki.Commenting.FunctionComment.MissingParamComment" /> + <exclude name="MediaWiki.Commenting.FunctionComment.MissingParamName" /> + <exclude name="MediaWiki.Commenting.FunctionComment.MissingParamTag" /> + <exclude name="MediaWiki.Commenting.FunctionComment.MissingReturn" /> + <exclude name="MediaWiki.ControlStructures.AssignmentInControlStructures.AssignmentInControlStructures" /> + <exclude name="MediaWiki.NamingConventions.PrefixedGlobalFunctions.wfPrefix" /> + <exclude name="MediaWiki.NamingConventions.ValidGlobalName.wgPrefix" /> + <exclude name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment" /> + </rule> + <file>.</file> + <arg name="encoding" value="utf8"/> + <arg name="extensions" value="php,php5,inc,sample"/> + + <rule ref="Generic.Classes.DuplicateClassName.Found"> + <severity>0</severity> + </rule> + <rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed"> + <severity>0</severity> + </rule> + <rule ref="Generic.Files.LineLength.TooLong"> + <severity>0</severity> + </rule> + <rule ref="Generic.PHP.BacktickOperator.Found"> + <severity>0</severity> + </rule> + <rule ref="Squiz.Classes.ValidClassName.NotCamelCaps"> + <severity>0</severity> + </rule> +</ruleset> diff --git a/purgeStaleMemcachedText.php b/purgeStaleMemcachedText.php index 4fa7a2e..941c7e0 100644 --- a/purgeStaleMemcachedText.php +++ b/purgeStaleMemcachedText.php @@ -6,9 +6,9 @@ global $wgMemc, $wgDBname; $db = wfGetDB( DB_MASTER ); $maxTextId = $db->selectField( 'text', 'max(old_id)' ); - $latestReplicatedTextId = $db->selectField( array( 'recentchanges', 'revision' ), 'rev_text_id', - array( 'rev_id = rc_this_oldid', "rc_timestamp < '20101225183000'" ), 'purgeStaleMemcachedText', - array( 'ORDER BY' => 'rc_timestamp DESC' ) ); + $latestReplicatedTextId = $db->selectField( [ 'recentchanges', 'revision' ], 'rev_text_id', + [ 'rev_id = rc_this_oldid', "rc_timestamp < '20101225183000'" ], 'purgeStaleMemcachedText', + [ 'ORDER BY' => 'rc_timestamp DESC' ] ); $latestReplicatedTextId -= 100; # A bit of paranoia echo "Going to purge text entries from $latestReplicatedTextId to $maxTextId in $wgDBname\n"; @@ -31,4 +31,3 @@ } purgeStaleMemcachedText(); - diff --git a/purgeUrls.php b/purgeUrls.php index ac1ead9..a236ca3 100644 --- a/purgeUrls.php +++ b/purgeUrls.php @@ -57,7 +57,7 @@ $url = trim( fgets( $stdin ) ); if ( preg_match( '%^https?://%', $url ) ) { $urls[] = $url; - } else if ( $url !== '' ) { + } elseif ( $url !== '' ) { $this->output( "Invalid url (skipped): $url\n" ); } } diff --git a/rcParamsTypeCheck.php b/rcParamsTypeCheck.php index f316f82..93941ef 100644 --- a/rcParamsTypeCheck.php +++ b/rcParamsTypeCheck.php @@ -17,7 +17,7 @@ $count = 0; foreach ( $wgConf->getLocalDatabases() as $wiki ) { $lb = wfGetLB( $wiki ); - $db = $lb->getConnection( DB_MASTER, array(), $wiki ); + $db = $lb->getConnection( DB_MASTER, [], $wiki ); $field = $db->fieldInfo( 'recentchanges', 'rc_params' ); if ( $field->type() !== "blob" ) { echo $wiki . "\n"; @@ -30,4 +30,4 @@ } $maintClass = 'GetJobQueueLengths'; -require_once( DO_MAINTENANCE ); +require_once DO_MAINTENANCE; diff --git a/removeDeletedWikis.php b/removeDeletedWikis.php index 7b83660..aafecf9 100644 --- a/removeDeletedWikis.php +++ b/removeDeletedWikis.php @@ -65,10 +65,10 @@ do { // https://bugzilla.wikimedia.org/show_bug.cgi?id=52868 // $dbw->delete( - // $table, - // array( $column => $wiki ), - // __METHOD__, - // array( 'LIMIT' => 500 ), + // $table, + // array( $column => $wiki ), + // __METHOD__, + // array( 'LIMIT' => 500 ), // ); $wikiQuoted = $dbw->addQuotes( $wiki ); $dbw->query( @@ -85,4 +85,4 @@ } $maintClass = 'RemoveDeletedWikis'; -require_once( DO_MAINTENANCE ); +require_once DO_MAINTENANCE; diff --git a/renameInvalidUsernames.php b/renameInvalidUsernames.php index a6a59e0..9af4d09 100644 --- a/renameInvalidUsernames.php +++ b/renameInvalidUsernames.php @@ -50,30 +50,29 @@ } } fclose( $file ); - } protected function rename( $userId, $wiki ) { - $dbw = wfGetDB( DB_MASTER, array(), $wiki ); - $row = $dbw->selectRow( 'user', User::selectFields(), array( 'user_id' => $userId ), __METHOD__ ); + $dbw = wfGetDB( DB_MASTER, [], $wiki ); + $row = $dbw->selectRow( 'user', User::selectFields(), [ 'user_id' => $userId ], __METHOD__ ); $oldUser = User::newFromRow( $row ); $reason = '[[m:Special:MyLanguage/Single User Login finalisation announcement|SUL finalization]] - [[phab:T5507]]'; $caUser = new CentralAuthUser( $oldUser->getName(), CentralAuthUser::READ_LATEST ); $maintScript = User::newFromName( 'Maintenance script' ); - $session = array( + $session = [ 'userId' => $maintScript->getId(), 'ip' => '127.0.0.1', 'sessionId' => '0', - 'headers' => array(), - ); - $data = array( + 'headers' => [], + ]; + $data = [ 'movepages' => true, 'suppressredirects' => true, 'reason' => $reason, 'force' => true, - ); + ]; if ( $caUser->exists() && $caUser->isAttached() ) { $newUser = User::newFromName( 'Invalid username ' . (string)$caUser->getId(), 'usable' ); @@ -107,12 +106,12 @@ return; } $statuses = new GlobalRenameUserStatus( $oldUser->getName() ); - $success = $statuses->setStatuses( array( array( + $success = $statuses->setStatuses( [ [ 'ru_wiki' => $wiki, 'ru_oldname' => $oldUser->getName(), 'ru_newname' => $newCAUser->getName(), 'ru_status' => 'queued' - ) ) ); + ] ] ); if ( !$success ) { $this->output( "WARNING: Race condition, renameuser_status already set for {$newCAUser->getName()}. Skipping.\n" ); @@ -123,7 +122,7 @@ $job = new LocalRenameUserJob( Title::newFromText( 'Global rename job' ), - array( + [ 'from' => $oldUser->getName(), 'to' => $newCAUser->getName(), 'renamer' => 'Maintenance script', @@ -132,7 +131,7 @@ 'promotetoglobal' => true, 'reason' => $reason, 'force' => true, - ) + ] ); JobQueueGroup::singleton( $wiki )->push( $job ); @@ -144,9 +143,9 @@ protected function getCurrentRenameCount() { $row = CentralAuthUser::getCentralDB()->selectRow( - array( 'renameuser_status' ), - array( 'COUNT(*) as count' ), - array(), + [ 'renameuser_status' ], + [ 'COUNT(*) as count' ], + [], __METHOD__ ); return (int)$row->count; diff --git a/renameWiki.php b/renameWiki.php index 76d4ea8..da77293 100644 --- a/renameWiki.php +++ b/renameWiki.php @@ -66,16 +66,16 @@ if ( is_array( $wgDefaultExternalStore ) ) { $stores = $wgDefaultExternalStore; } elseif ( $wgDefaultExternalStore ) { - $stores = array( $wgDefaultExternalStore ); + $stores = [ $wgDefaultExternalStore ]; } else { - $stores = array(); + $stores = []; } if ( count( $stores ) ) { $this->output( "Initialising external storage...\n" ); global $wgDBuser, $wgDBpassword, $wgExternalServers; foreach ( $stores as $storeURL ) { - $m = array(); + $m = []; if ( !preg_match( '!^DB://(.*)$!', $storeURL, $m ) ) { continue; } @@ -101,4 +101,4 @@ } $maintClass = "RenameWiki"; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN; diff --git a/sanityCheck.php b/sanityCheck.php index d2d122e..1fb5a14 100644 --- a/sanityCheck.php +++ b/sanityCheck.php @@ -16,9 +16,9 @@ function __construct() { $this->title = Title::newMainPage(); - parent::__construct( array( + parent::__construct( [ 'title' => $this->title->getPrefixedDBkey() - ) ); + ] ); } function getRequestURL() { diff --git a/socket-test.php b/socket-test.php index ff5ad34..386414e 100644 --- a/socket-test.php +++ b/socket-test.php @@ -1,10 +1,8 @@ <?php -require( __DIR__ . '/commandLine.inc' ); +require __DIR__ . '/commandLine.inc'; $msg = 'test ' . str_repeat( 'TTTT ', 10000 ); # wfErrorLog( $msg, 'udp://10.0.6.30:8420/test' ); $sock = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP ); socket_sendto( $sock, $msg, strlen( $msg ), 0, '10.0.6.30', 8420 ); - - diff --git a/storage/testRctComplete.php b/storage/testRctComplete.php index 2498197..825ea8d 100644 --- a/storage/testRctComplete.php +++ b/storage/testRctComplete.php @@ -5,10 +5,10 @@ $good = 0; foreach ( $wgLocalDatabases as $wiki ) { $lb = wfGetLB( $wiki ); - $db = $lb->getConnection( DB_SLAVE, array(), $wiki ); + $db = $lb->getConnection( DB_SLAVE, [], $wiki ); if ( $db->tableExists( 'blob_tracking' ) ) { $notDone = $db->selectField( 'blob_tracking', '1', - array( 'bt_moved' => 0 ) ); + [ 'bt_moved' => 0 ] ); if ( $notDone ) { $bad++; echo "$wiki\n"; diff --git a/unsuppressCrossWiki.php b/unsuppressCrossWiki.php index 8112432..c4ee000 100644 --- a/unsuppressCrossWiki.php +++ b/unsuppressCrossWiki.php @@ -20,14 +20,14 @@ $wikis = $user->listAttached(); // wikis with attached accounts foreach ( $wikis as $wiki ) { $lb = wfGetLB( $wiki ); - $dbw = $lb->getConnection( DB_MASTER, array(), $wiki ); + $dbw = $lb->getConnection( DB_MASTER, [], $wiki ); # Get local ID like $user->localUserData( $wiki ) does $localUserId = $dbw->selectField( 'user', 'user_id', - array( 'user_name' => $userName ), __METHOD__ ); + [ 'user_name' => $userName ], __METHOD__ ); $delUserBit = Revision::DELETED_USER; $hiddenCount = $dbw->selectField( 'revision', 'COUNT(*)', - array( 'rev_user' => $localUserId, "rev_deleted & $delUserBit != 0" ), __METHOD__ ); + [ 'rev_user' => $localUserId, "rev_deleted & $delUserBit != 0" ], __METHOD__ ); echo "$hiddenCount edits have the username hidden on \"$wiki\"\n"; # Unsuppress username on edits if ( $hiddenCount > 0 ) { -- To view, visit https://gerrit.wikimedia.org/r/368119 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I26914255fe19b6723778b6442d0a9b29bfa931fb Gerrit-PatchSet: 6 Gerrit-Project: mediawiki/extensions/WikimediaMaintenance Gerrit-Branch: master Gerrit-Owner: Reedy <re...@wikimedia.org> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits