From b7cd670cb7b2bf58ff4ab9db845d0bee0301b6cc Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Thu, 28 Feb 2019 12:04:31 +0100 Subject: [PATCH] maintenance: Remove unused code from several maintenance scripts The most notable removal is done in the orphans script. This code was really never used. Brion introduced it in 2005, already disabled. I have all the respect for what Brion did. I just think it does not make much sense to keep code around for so long if it does not work anyway, and must be rewritten from scratch anyway now that we have multi-content revisions and such. Change-Id: I4e8050929f90e44a6e6051bf938993a8b0cdf649 --- maintenance/cleanupPreferences.php | 1 - maintenance/deleteBatch.php | 2 - maintenance/includes/BackupDumper.php | 3 -- maintenance/includes/MigrateActors.php | 1 - maintenance/mergeMessageFileList.php | 1 - maintenance/mysql.php | 2 - maintenance/orphans.php | 52 +---------------------- maintenance/pageExists.php | 1 - maintenance/populateBacklinkNamespace.php | 2 - maintenance/protect.php | 3 -- maintenance/updateCollation.php | 1 - maintenance/updateSpecialPages.php | 2 +- 12 files changed, 2 insertions(+), 69 deletions(-) diff --git a/maintenance/cleanupPreferences.php b/maintenance/cleanupPreferences.php index a52ce17565..a6399f66e6 100644 --- a/maintenance/cleanupPreferences.php +++ b/maintenance/cleanupPreferences.php @@ -60,7 +60,6 @@ class CleanupPreferences extends Maintenance { global $wgHiddenPrefs, $wgDefaultUserOptions; $dbw = $this->getDB( DB_MASTER ); - $didWork = false; $hidden = $this->hasOption( 'hidden' ); $unknown = $this->hasOption( 'unknown' ); $bogus = $this->hasOption( 'bogus' ); diff --git a/maintenance/deleteBatch.php b/maintenance/deleteBatch.php index 09e82118f0..fe3bea05de 100644 --- a/maintenance/deleteBatch.php +++ b/maintenance/deleteBatch.php @@ -80,8 +80,6 @@ class DeleteBatch extends Maintenance { $this->fatalError( "Unable to read file, exiting" ); } - $dbw = $this->getDB( DB_MASTER ); - # Handle each entry for ( $linenum = 1; !feof( $file ); $linenum++ ) { $line = trim( fgets( $file ) ); diff --git a/maintenance/includes/BackupDumper.php b/maintenance/includes/BackupDumper.php index 673ea7f864..45786d8da0 100644 --- a/maintenance/includes/BackupDumper.php +++ b/maintenance/includes/BackupDumper.php @@ -74,9 +74,6 @@ abstract class BackupDumper extends Maintenance { /** @var LoadBalancer */ protected $lb; - // @todo Unused? - private $stubText = false; // include rev_text_id instead of text; for 2-pass dump - /** * @param array|null $args For backward compatibility */ diff --git a/maintenance/includes/MigrateActors.php b/maintenance/includes/MigrateActors.php index 813f88e965..ba6c375aa7 100644 --- a/maintenance/includes/MigrateActors.php +++ b/maintenance/includes/MigrateActors.php @@ -414,7 +414,6 @@ class MigrateActors extends LoggedUpdateMaintenance { $complainedAboutUsers = []; $primaryKey = [ 'ls_value', 'ls_log_id' ]; - $pkFilter = array_flip( $primaryKey ); $this->output( "Beginning migration of log_search\n" ); wfWaitForSlaves(); diff --git a/maintenance/mergeMessageFileList.php b/maintenance/mergeMessageFileList.php index 6ae506fcf2..80e72fb8b4 100644 --- a/maintenance/mergeMessageFileList.php +++ b/maintenance/mergeMessageFileList.php @@ -77,7 +77,6 @@ class MergeMessageFileList extends Maintenance { $extdir = $this->getOption( 'extensions-dir' ); # Allow multiple directories to be passed with ":" as delimiter $extdirs = explode( ':', $extdir ); - $entries = []; foreach ( $extdirs as $extdir ) { $entries = scandir( $extdir ); foreach ( $entries as $extname ) { diff --git a/maintenance/mysql.php b/maintenance/mysql.php index 9424402cdf..34a6cb6951 100644 --- a/maintenance/mysql.php +++ b/maintenance/mysql.php @@ -72,8 +72,6 @@ class MysqlMaintenance extends Maintenance { $host = $this->getOption( 'host' ); $serverCount = $lb->getServerCount(); for ( $index = 0; $index < $serverCount; ++$index ) { - $serverInfo = $lb->getServerInfo( $index ); - if ( $lb->getServerName( $index ) === $host ) { break; } diff --git a/maintenance/orphans.php b/maintenance/orphans.php index d47ca43f0b..bfae4b71ed 100644 --- a/maintenance/orphans.php +++ b/maintenance/orphans.php @@ -53,8 +53,6 @@ class Orphans extends Maintenance { public function execute() { $this->checkOrphans( $this->hasOption( 'fix' ) ); $this->checkSeparation( $this->hasOption( 'fix' ) ); - # Does not work yet, do not use - # $this->checkWidows( $this->hasOption( 'fix' ) ); } /** @@ -67,7 +65,7 @@ class Orphans extends Maintenance { if ( $extraTable ) { $tbls = array_merge( $tbls, $extraTable ); } - $db->lockTables( [], $tbls, __METHOD__, false ); + $db->lockTables( [], $tbls, __METHOD__ ); } /** @@ -139,54 +137,6 @@ class Orphans extends Maintenance { } } - /** - * @param bool $fix - * @todo DON'T USE THIS YET! It will remove entries which have children, - * but which aren't properly attached (eg if page_latest is bogus - * but valid revisions do exist) - */ - private function checkWidows( $fix ) { - $dbw = $this->getDB( DB_MASTER ); - $page = $dbw->tableName( 'page' ); - $revision = $dbw->tableName( 'revision' ); - - if ( $fix ) { - $this->lockTables( $dbw ); - } - - $this->output( "\nChecking for childless page table entries... " - . "(this may take a while on a large wiki)\n" ); - $result = $dbw->query( " - SELECT * - FROM $page LEFT OUTER JOIN $revision ON page_latest=rev_id - WHERE rev_id IS NULL - " ); - $widows = $result->numRows(); - if ( $widows > 0 ) { - $this->output( "$widows childless pages...\n" ); - $this->output( sprintf( "%10s %11s %2s %s\n", 'page_id', 'page_latest', 'ns', 'page_title' ) ); - foreach ( $result as $row ) { - printf( "%10d %11d %2d %s\n", - $row->page_id, - $row->page_latest, - $row->page_namespace, - $row->page_title ); - if ( $fix ) { - $dbw->delete( 'page', [ 'page_id' => $row->page_id ] ); - } - } - if ( !$fix ) { - $this->output( "Run again with --fix to remove these entries automatically.\n" ); - } - } else { - $this->output( "No childless pages! Yay!\n" ); - } - - if ( $fix ) { - $dbw->unlockTables( __METHOD__ ); - } - } - /** * Check for pages where page_latest is wrong * @param bool $fix Whether to fix broken entries diff --git a/maintenance/pageExists.php b/maintenance/pageExists.php index dc9bbdacab..10d37de48c 100644 --- a/maintenance/pageExists.php +++ b/maintenance/pageExists.php @@ -36,7 +36,6 @@ class PageExists extends Maintenance { $title = Title::newFromText( $titleArg ); $pageExists = $title && $title->exists(); - $text = ''; $code = 0; if ( $pageExists ) { $text = "{$title} exists."; diff --git a/maintenance/populateBacklinkNamespace.php b/maintenance/populateBacklinkNamespace.php index e2fd8b5a58..ac527213c8 100644 --- a/maintenance/populateBacklinkNamespace.php +++ b/maintenance/populateBacklinkNamespace.php @@ -44,8 +44,6 @@ class PopulateBacklinkNamespace extends LoggedUpdateMaintenance { } public function doDBUpdates() { - $force = $this->getOption( 'force' ); - $db = $this->getDB( DB_MASTER ); $this->output( "Updating *_from_namespace fields in links tables.\n" ); diff --git a/maintenance/protect.php b/maintenance/protect.php index b47476a58c..e2c1a8b340 100644 --- a/maintenance/protect.php +++ b/maintenance/protect.php @@ -62,9 +62,6 @@ class Protect extends Maintenance { $this->fatalError( "Invalid username" ); } - // @todo FIXME: This is reset 7 lines down. - $restrictions = [ 'edit' => $protection, 'move' => $protection ]; - $t = Title::newFromText( $this->getArg() ); if ( !$t ) { $this->fatalError( "Invalid title" ); diff --git a/maintenance/updateCollation.php b/maintenance/updateCollation.php index 12b33b47bb..ab40e4863e 100644 --- a/maintenance/updateCollation.php +++ b/maintenance/updateCollation.php @@ -142,7 +142,6 @@ TEXT wfWaitForSlaves(); } $count = 0; - $batchCount = 0; $batchConds = []; do { $this->output( "Selecting next " . self::BATCH_SIZE . " rows..." ); diff --git a/maintenance/updateSpecialPages.php b/maintenance/updateSpecialPages.php index 3b28b657c5..5d756e87a5 100644 --- a/maintenance/updateSpecialPages.php +++ b/maintenance/updateSpecialPages.php @@ -49,7 +49,7 @@ class UpdateSpecialPages extends Maintenance { $this->doSpecialPageCacheUpdates( $dbw ); foreach ( QueryPage::getPages() as $page ) { - list( $class, $special ) = $page; + list( , $special ) = $page; $limit = $page[2] ?? null; # --list : just show the name of pages -- 2.20.1