Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
83.33% covered (warning)
83.33%
5 / 6
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
AbuseFilterHooks
83.33% covered (warning)
83.33%
5 / 6
50.00% covered (danger)
50.00%
1 / 2
3.04
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 onAbuseFilterCustomActions
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
2.03
1<?php
2
3namespace MediaWiki\Extension\ConfirmEdit;
4
5use MediaWiki\Config\Config;
6use MediaWiki\Extension\AbuseFilter\Consequences\Parameters;
7use MediaWiki\Extension\AbuseFilter\Hooks\AbuseFilterCustomActionsHook;
8use MediaWiki\Extension\ConfirmEdit\AbuseFilter\CaptchaConsequence;
9
10class AbuseFilterHooks implements AbuseFilterCustomActionsHook {
11
12    public function __construct(
13        private readonly Config $config,
14    ) {
15    }
16
17    /** @inheritDoc */
18    public function onAbuseFilterCustomActions( array &$actions ): void {
19        $enabledActions = $this->config->get( 'ConfirmEditEnabledAbuseFilterCustomActions' );
20        if ( in_array( 'showcaptcha', $enabledActions ) ) {
21            // Messages used: abusefilter-edit-action-showcaptcha, abusefilter-edit-action-showcaptcha-help
22            $actions['showcaptcha'] = static function ( Parameters $params ): CaptchaConsequence {
23                return new CaptchaConsequence( $params );
24            };
25        }
26    }
27
28}