diff --git a/.phan/config.php b/.phan/config.php index 5acdba32f..adff6a16b 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -7,6 +7,7 @@ $cfg['directory_list'] = array_merge( [ '../../extensions/CheckUser', '../../extensions/Echo', + '../../extensions/UserMerge', ] ); @@ -15,6 +16,7 @@ $cfg['exclude_analysis_directory_list'] = array_merge( [ '../../extensions/CheckUser', '../../extensions/Echo', + '../../extensions/UserMerge', ] ); diff --git a/extension.json b/extension.json index f704f9ff2..e574ba5b0 100644 --- a/extension.json +++ b/extension.json @@ -396,6 +396,12 @@ }, "Echo": { "class": "MediaWiki\\Extension\\AbuseFilter\\Hooks\\Handlers\\EchoHandler" + }, + "UserMerge": { + "class": "MediaWiki\\Extension\\AbuseFilter\\Hooks\\Handlers\\UserMergeHandler", + "services": [ + "MainConfig" + ] } }, "Hooks": { @@ -418,7 +424,7 @@ "CheckUserInsertChangesRow": "CheckUser", "CheckUserInsertPrivateEventRow": "CheckUser", "CheckUserInsertLogEventRow": "CheckUser", - "UserMergeAccountFields": "MediaWiki\\Extension\\AbuseFilter\\Hooks\\Handlers\\UserMergeHandler::onUserMergeAccountFields", + "UserMergeAccountFields": "UserMerge", "BeforeCreateEchoEvent": "Echo", "ParserOutputStashForEdit": "FilteredActions", "UnitTestsAfterDatabaseSetup": "Tests", diff --git a/includes/Hooks/Handlers/UserMergeHandler.php b/includes/Hooks/Handlers/UserMergeHandler.php index 2511730ee..e57b1eba1 100644 --- a/includes/Hooks/Handlers/UserMergeHandler.php +++ b/includes/Hooks/Handlers/UserMergeHandler.php @@ -2,23 +2,31 @@ namespace MediaWiki\Extension\AbuseFilter\Hooks\Handlers; -class UserMergeHandler { +use 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 - * @todo Use new hook system once UserMerge is updated * - * @param array &$updateFields + * @param array[] &$updateFields */ - public static function onUserMergeAccountFields( array &$updateFields ) { - global $wgAbuseFilterActorTableSchemaMigrationStage; + 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' => $wgAbuseFilterActorTableSchemaMigrationStage, + 'actorStage' => $actorStage, ]; $updateFields[] = [ 'abuse_filter_log', @@ -32,7 +40,7 @@ class UserMergeHandler { 'afh_user_text', 'batchKey' => 'afh_id', 'actorId' => 'afh_actor', - 'actorStage' => $wgAbuseFilterActorTableSchemaMigrationStage, + 'actorStage' => $actorStage, ]; } diff --git a/tests/phpunit/integration/AbuseFilterExtensionJsonTest.php b/tests/phpunit/integration/AbuseFilterExtensionJsonTest.php index 7fdd99815..d2f80fb5f 100644 --- a/tests/phpunit/integration/AbuseFilterExtensionJsonTest.php +++ b/tests/phpunit/integration/AbuseFilterExtensionJsonTest.php @@ -2,6 +2,7 @@ namespace MediaWiki\Extension\AbuseFilter\Tests\Integration; +use ExtensionRegistry; use MediaWiki\Tests\ExtensionJsonTestBase; /** @@ -14,4 +15,12 @@ class AbuseFilterExtensionJsonTest extends ExtensionJsonTestBase { /** @inheritDoc */ protected string $extensionJsonPath = __DIR__ . '/../../../extension.json'; + public function provideHookHandlerNames(): iterable { + foreach ( $this->getExtensionJson()['HookHandlers'] ?? [] as $hookHandlerName => $specification ) { + if ( $hookHandlerName === 'UserMerge' && !ExtensionRegistry::getInstance()->isLoaded( 'UserMerge' ) ) { + continue; + } + yield [ $hookHandlerName ]; + } + } }