Merge "Drop $wgAbuseFilterActorTableSchemaMigrationStage"

This commit is contained in:
jenkins-bot 2024-06-10 13:27:07 +00:00 committed by Gerrit Code Review
commit a5afeff49c
8 changed files with 13 additions and 114 deletions

View file

@ -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"

View file

@ -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'
);
}
}
}

View file

@ -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 );
}
}
/**

View file

@ -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,
];
}

View file

@ -1,32 +0,0 @@
<?php
namespace MediaWiki\Extension\AbuseFilter\Hooks\Handlers;
use MediaWiki\RenameUser\Hook\RenameUserSQLHook;
use MediaWiki\RenameUser\RenameuserSQL;
class UserRenameHandler implements RenameUserSQLHook {
/**
* @inheritDoc
*/
public function onRenameUserSQL( RenameuserSQL $renameUserSql ): void {
global $wgAbuseFilterActorTableSchemaMigrationStage;
if ( !( $wgAbuseFilterActorTableSchemaMigrationStage & SCHEMA_COMPAT_OLD ) ) {
return;
}
$renameUserSql->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'
];
}
}

View file

@ -379,7 +379,7 @@ return [
MediaWikiServices $services
): AbuseFilterActorMigration {
return new AbuseFilterActorMigration(
$services->getMainConfig()->get( 'AbuseFilterActorTableSchemaMigrationStage' ),
SCHEMA_COMPAT_NEW,
$services->getActorStoreFactory(),
);
},

View file

@ -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(

View file

@ -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 */',