From c2da0d4857abc9b5d47f3f8aa8c076f76c7346e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= Date: Thu, 6 Jun 2024 10:03:15 +0200 Subject: [PATCH] Drop $wgAbuseFilterActorTableSchemaMigrationStage First patch in a series of dropping the old columns. Wikis now need to run the maintenance script (e.g., via update.php) prior to serving this commit. Wikimedia wikis are already on SCHEMA_COMPAT_NEW stage. Bug: T188180 Change-Id: I86ec2b816eed17b62bf02bfd085570f132011b3e --- extension.json | 13 +------- .../Hooks/Handlers/RegistrationCallback.php | 19 +---------- .../Hooks/Handlers/SchemaChangesHandler.php | 21 ++++-------- includes/Hooks/Handlers/UserMergeHandler.php | 16 ++-------- includes/Hooks/Handlers/UserRenameHandler.php | 32 ------------------- includes/ServiceWiring.php | 2 +- maintenance/MigrateActorsAF.php | 9 ------ tests/phpunit/integration/FilterStoreTest.php | 15 +-------- 8 files changed, 13 insertions(+), 114 deletions(-) delete mode 100644 includes/Hooks/Handlers/UserRenameHandler.php diff --git a/extension.json b/extension.json index 5afe33c03..4b3c6797f 100644 --- a/extension.json +++ b/extension.json @@ -356,9 +356,6 @@ "class": "MediaWiki\\Extension\\AbuseFilter\\Hooks\\Handlers\\SchemaChangesHandler", "factory": "MediaWiki\\Extension\\AbuseFilter\\Hooks\\Handlers\\SchemaChangesHandler::newFromGlobalState" }, - "UserRename": { - "class": "MediaWiki\\Extension\\AbuseFilter\\Hooks\\Handlers\\UserRenameHandler" - }, "EditPermission": { "class": "MediaWiki\\Extension\\AbuseFilter\\Hooks\\Handlers\\EditPermissionHandler" }, @@ -399,10 +396,7 @@ "class": "MediaWiki\\Extension\\AbuseFilter\\Hooks\\Handlers\\EchoHandler" }, "UserMerge": { - "class": "MediaWiki\\Extension\\AbuseFilter\\Hooks\\Handlers\\UserMergeHandler", - "services": [ - "MainConfig" - ] + "class": "MediaWiki\\Extension\\AbuseFilter\\Hooks\\Handlers\\UserMergeHandler" } }, "Hooks": { @@ -420,7 +414,6 @@ "UploadVerifyUpload": "FilteredActions", "UploadStashFile": "FilteredActions", "PageSaveComplete": "PageSave", - "RenameUserSQL": "UserRename", "getUserPermissionsErrors": "EditPermission", "CheckUserInsertChangesRow": "CheckUser", "CheckUserInsertPrivateEventRow": "CheckUser", @@ -569,10 +562,6 @@ "value": true, "description": "Whether to include IP in the abuse_filter_log" }, - "AbuseFilterActorTableSchemaMigrationStage": { - "value": 769, - "description": "Stage of the migration of af_user/af_user_text to af_actor and afh_user/afh_user_text to afh_actor. Should be one of the following (combinations of) constants: SCHEMA_COMPAT_OLD, SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, SCHEMA_COMPAT_NEW. See also \"Schema compatibility flags\" in includes/Defines.php in core. Note: When changing the default here, change it also in unit tests." - }, "AbuseFilterEnableBlockedExternalDomain": { "value": false, "description": "Temporary config value to disable Special:BlockedExternalDomains" diff --git a/includes/Hooks/Handlers/RegistrationCallback.php b/includes/Hooks/Handlers/RegistrationCallback.php index 9c872824d..216081c6f 100644 --- a/includes/Hooks/Handlers/RegistrationCallback.php +++ b/includes/Hooks/Handlers/RegistrationCallback.php @@ -2,8 +2,6 @@ namespace MediaWiki\Extension\AbuseFilter\Hooks\Handlers; -use InvalidArgumentException; - /** * This class runs a callback when the extension is registered, right after configuration has been * loaded (not really a hook, but almost). @@ -15,8 +13,7 @@ class RegistrationCallback { global $wgAbuseFilterProfile, $wgAbuseFilterProfiling, $wgAbuseFilterPrivateLog, $wgAbuseFilterForceSummary, $wgGroupPermissions, $wgAbuseFilterRestrictions, $wgAbuseFilterDisallowGlobalLocalBlocks, - $wgAbuseFilterActionRestrictions, $wgAbuseFilterLocallyDisabledGlobalActions, - $wgAbuseFilterActorTableSchemaMigrationStage; + $wgAbuseFilterActionRestrictions, $wgAbuseFilterLocallyDisabledGlobalActions; // @todo Remove this in a future release (added in 1.33) if ( isset( $wgAbuseFilterProfile ) || isset( $wgAbuseFilterProfiling ) ) { @@ -90,20 +87,6 @@ class RegistrationCallback { wfWarn( '$wgAbuseFilterRestrictions has been renamed to $wgAbuseFilterActionRestrictions.' ); $wgAbuseFilterActionRestrictions = $wgAbuseFilterRestrictions; } - - // in order - $allowedStages = [ - SCHEMA_COMPAT_OLD, - SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD, - SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW, - SCHEMA_COMPAT_NEW, - ]; - if ( !in_array( $wgAbuseFilterActorTableSchemaMigrationStage, $allowedStages ) ) { - throw new InvalidArgumentException( - '$wgAbuseFilterActorTableSchemaMigrationStage must specify a supported ' . - 'combination of schema compatibility flags' - ); - } } } diff --git a/includes/Hooks/Handlers/SchemaChangesHandler.php b/includes/Hooks/Handlers/SchemaChangesHandler.php index 62aab7ae3..e528fdf61 100644 --- a/includes/Hooks/Handlers/SchemaChangesHandler.php +++ b/includes/Hooks/Handlers/SchemaChangesHandler.php @@ -55,8 +55,6 @@ class SchemaChangesHandler implements LoadExtensionSchemaUpdatesHook { * @param DatabaseUpdater $updater */ public function onLoadExtensionSchemaUpdates( $updater ) { - global $wgAbuseFilterActorTableSchemaMigrationStage; - $dbType = $updater->getDB()->getType(); $dir = __DIR__ . "/../../../db_patches"; @@ -178,21 +176,16 @@ class SchemaChangesHandler implements LoadExtensionSchemaUpdatesHook { "$dir/$dbType/patch-add-afh_actor.sql", true ] ); + // 1.43 + $updater->addExtensionUpdate( [ + 'runMaintenance', + MigrateActorsAF::class, + __DIR__ . '/../../../maintenance/MigrateActorsAF.php', + ] ); + $updater->addExtensionUpdate( [ [ $this, 'createAbuseFilterUser' ] ] ); // 1.35 $updater->addPostDatabaseUpdateMaintenance( UpdateVarDumps::class ); - - // Don't launch the script on update.php if the migration stage is not high enough. - // This would throw an exception. - // Also check if the global is set. - // If globals aren't loaded, it's install.php, and not update.php. This is intentional, - // see for instance, T193855 or T198331. - if ( isset( $wgAbuseFilterActorTableSchemaMigrationStage ) && - ( $wgAbuseFilterActorTableSchemaMigrationStage & SCHEMA_COMPAT_WRITE_NEW ) - ) { - // 1.41 - $updater->addPostDatabaseUpdateMaintenance( MigrateActorsAF::class ); - } } /** diff --git a/includes/Hooks/Handlers/UserMergeHandler.php b/includes/Hooks/Handlers/UserMergeHandler.php index 6b1835607..36fe3bec6 100644 --- a/includes/Hooks/Handlers/UserMergeHandler.php +++ b/includes/Hooks/Handlers/UserMergeHandler.php @@ -2,31 +2,21 @@ namespace MediaWiki\Extension\AbuseFilter\Hooks\Handlers; -use MediaWiki\Config\Config; use MediaWiki\Extension\UserMerge\Hooks\AccountFieldsHook; class UserMergeHandler implements AccountFieldsHook { - private Config $config; - - public function __construct( Config $config ) { - $this->config = $config; - } - /** * Tables that Extension:UserMerge needs to update * * @param array[] &$updateFields */ public function onUserMergeAccountFields( array &$updateFields ) { - $actorStage = $this->config->get( 'AbuseFilterActorTableSchemaMigrationStage' ); $updateFields[] = [ 'abuse_filter', - 'af_user', - 'af_user_text', 'batchKey' => 'af_id', 'actorId' => 'af_actor', - 'actorStage' => $actorStage, + 'actorStage' => SCHEMA_COMPAT_NEW, ]; $updateFields[] = [ 'abuse_filter_log', @@ -36,11 +26,9 @@ class UserMergeHandler implements AccountFieldsHook { ]; $updateFields[] = [ 'abuse_filter_history', - 'afh_user', - 'afh_user_text', 'batchKey' => 'afh_id', 'actorId' => 'afh_actor', - 'actorStage' => $actorStage, + 'actorStage' => SCHEMA_COMPAT_NEW, ]; } diff --git a/includes/Hooks/Handlers/UserRenameHandler.php b/includes/Hooks/Handlers/UserRenameHandler.php deleted file mode 100644 index 00d7fd4cb..000000000 --- a/includes/Hooks/Handlers/UserRenameHandler.php +++ /dev/null @@ -1,32 +0,0 @@ -tablesJob['abuse_filter'] = [ - RenameuserSQL::NAME_COL => 'af_user_text', - RenameuserSQL::UID_COL => 'af_user', - RenameuserSQL::TIME_COL => 'af_timestamp', - 'uniqueKey' => 'af_id' - ]; - $renameUserSql->tablesJob['abuse_filter_history'] = [ - RenameuserSQL::NAME_COL => 'afh_user_text', - RenameuserSQL::UID_COL => 'afh_user', - RenameuserSQL::TIME_COL => 'afh_timestamp', - 'uniqueKey' => 'afh_id' - ]; - } - -} diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 37ff8cb9f..3f3b95efa 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -379,7 +379,7 @@ return [ MediaWikiServices $services ): AbuseFilterActorMigration { return new AbuseFilterActorMigration( - $services->getMainConfig()->get( 'AbuseFilterActorTableSchemaMigrationStage' ), + SCHEMA_COMPAT_NEW, $services->getActorStoreFactory(), ); }, diff --git a/maintenance/MigrateActorsAF.php b/maintenance/MigrateActorsAF.php index c52e54715..8f1f68d14 100644 --- a/maintenance/MigrateActorsAF.php +++ b/maintenance/MigrateActorsAF.php @@ -52,15 +52,6 @@ class MigrateActorsAF extends LoggedUpdateMaintenance { $this->tables = explode( ',', $tables ); } - $stage = $this->getConfig()->get( 'AbuseFilterActorTableSchemaMigrationStage' ); - if ( !( $stage & SCHEMA_COMPAT_WRITE_NEW ) ) { - $this->output( - '...cannot update while $wgAbuseFilterActorTableSchemaMigrationStage ' . - "lacks SCHEMA_COMPAT_WRITE_NEW\n" - ); - return false; - } - $errors = 0; $errors += $this->migrate( 'abuse_filter', 'af_id', 'af_user', 'af_user_text', 'af_actor' ); $errors += $this->migrate( diff --git a/tests/phpunit/integration/FilterStoreTest.php b/tests/phpunit/integration/FilterStoreTest.php index ca3d1bec9..776d35852 100644 --- a/tests/phpunit/integration/FilterStoreTest.php +++ b/tests/phpunit/integration/FilterStoreTest.php @@ -94,20 +94,7 @@ class FilterStoreTest extends MediaWikiIntegrationTestCase { ); } - public static function provideSaveFilter_valid(): array { - return [ - [ SCHEMA_COMPAT_OLD ], - [ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_OLD ], - [ SCHEMA_COMPAT_WRITE_BOTH | SCHEMA_COMPAT_READ_NEW ], - [ SCHEMA_COMPAT_NEW ], - ]; - } - - /** - * @dataProvider provideSaveFilter_valid - */ - public function testSaveFilter_valid( int $stage ) { - $this->overrideConfigValue( 'AbuseFilterActorTableSchemaMigrationStage', $stage ); + public function testSaveFilter_valid() { $row = [ 'id' => null, 'rules' => '/* My rules */',