diff --git a/extension.json b/extension.json index 7980fcd4d..a5a2bb0c2 100644 --- a/extension.json +++ b/extension.json @@ -12,7 +12,7 @@ "license-name": "GPL-2.0-or-later", "type": "antispam", "requires": { - "MediaWiki": ">= 1.35.0" + "MediaWiki": ">= 1.36.0" }, "AvailableRights": [ "abusefilter-modify", diff --git a/includes/AFComputedVariable.php b/includes/AFComputedVariable.php index 4a3a5c55e..34f48f39d 100644 --- a/includes/AFComputedVariable.php +++ b/includes/AFComputedVariable.php @@ -164,7 +164,7 @@ class AFComputedVariable { * @throws AFPException */ public function compute( AbuseFilterVariableHolder $vars ) { - // TODO: find a way to inject the User object from hook parameters. + // phpcs:ignore MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgUser global $wgUser; // Used for parsing wikitext from saved revisions and checking for diff --git a/includes/AbuseFilterRunner.php b/includes/AbuseFilterRunner.php index f0148c275..9902ea06f 100644 --- a/includes/AbuseFilterRunner.php +++ b/includes/AbuseFilterRunner.php @@ -1,6 +1,5 @@ user->isAnon() ) { + $userGroupsManager = MediaWikiServices::getInstance()->getUserGroupManager(); // Pull the groups from the VariableHolder, so that they will always be computed. // This allow us to pull the groups from the VariableHolder to undo the degroup // via Special:AbuseFilter/revert. $groups = $this->vars->getVar( 'user_groups', AbuseFilterVariableHolder::GET_LAX ); if ( $groups->type !== AFPData::DARRAY ) { // Somehow, the variable wasn't set - $groups = $this->user->getEffectiveGroups(); + $groups = $userGroupsManager->getUserEffectiveGroups( $this->user ); $this->vars->setVar( 'user_groups', $groups ); } else { $groups = $groups->toNative(); @@ -787,7 +787,7 @@ class AbuseFilterRunner { $this->vars->setVar( 'user_groups', $groups ); foreach ( $groups as $group ) { - $this->user->removeGroup( $group ); + $userGroupsManager->removeUserFromGroup( $this->user, $group ); } $message = [ @@ -931,49 +931,25 @@ class AbuseFilterRunner { $isAutoBlock, $preventEditOwnUserTalk ) { + $blockUserFactory = MediaWikiServices::getInstance()->getBlockUserFactory(); $filterUser = AbuseFilter::getFilterUser(); $reason = wfMessage( 'abusefilter-blockreason', $ruleDesc, $ruleNumber )->inContentLanguage()->text(); - $block = new DatabaseBlock(); - $block->setTarget( $target ); - $block->setBlocker( $filterUser ); - $block->setReason( $reason ); - $block->isHardblock( false ); - $block->isAutoblocking( $isAutoBlock ); - $block->isCreateAccountBlocked( true ); - $block->isUsertalkEditAllowed( !$preventEditOwnUserTalk ); - $block->setExpiry( SpecialBlock::parseExpiryInput( $expiry ) ); - - $success = $block->insert(); - - if ( $success ) { - // Log it only if the block was successful - $logParams = []; - $logParams['5::duration'] = ( $block->getExpiry() === 'infinity' ) - ? 'indefinite' - : $expiry; - $flags = [ 'nocreate' ]; - if ( !$block->isAutoblocking() && !IPUtils::isIPAddress( $target ) ) { - // Conditionally added same as SpecialBlock - $flags[] = 'noautoblock'; - } - if ( $preventEditOwnUserTalk === true ) { - $flags[] = 'nousertalk'; - } - $logParams['6::flags'] = implode( ',', $flags ); - - $logEntry = new ManualLogEntry( 'block', 'block' ); - $logEntry->setTarget( Title::makeTitle( NS_USER, $target ) ); - $logEntry->setComment( $reason ); - $logEntry->setPerformer( $filterUser ); - $logEntry->setParameters( $logParams ); - $blockIds = array_merge( [ $success['id'] ], $success['autoIds'] ); - $logEntry->setRelations( [ 'ipb_id' => $blockIds ] ); - $logEntry->publish( $logEntry->insert() ); - } + $blockUserFactory->newBlockUser( + $target, + $filterUser, + $expiry, + $reason, + [ + 'isHardBlock' => false, + 'isAutoblocking' => $isAutoBlock, + 'isCreateAccountBlocked' => true, + 'isUserTalkEditBlocked' => $preventEditOwnUserTalk + ] + )->placeBlockUnsafe(); } /**