diff --git a/extension.json b/extension.json index cd8ed69d2..74b982b0d 100644 --- a/extension.json +++ b/extension.json @@ -94,6 +94,9 @@ "services": [ "MainWANObjectCache" ] + }, + "AbuseFilterHooks": { + "class": "MediaWiki\\Extension\\ConfirmEdit\\AbuseFilterHooks" } }, "Hooks": { @@ -107,7 +110,8 @@ "EditPage::showEditForm:fields": "ConfirmEditHooks", "EditFilterMergedContent": "ConfirmEditHooks", "APIGetAllowedParams": "ConfirmEditHooks", - "AuthChangeFormFields": "ConfirmEditHooks" + "AuthChangeFormFields": "ConfirmEditHooks", + "AbuseFilterCustomActions": "AbuseFilterHooks" }, "AuthManagerAutoConfig": { "preauth": { diff --git a/i18n/en.json b/i18n/en.json index 60231935b..29b2e269f 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -31,5 +31,6 @@ "confirmedit-preview-validity": "Validity", "confirmedit-preview-valid": "valid", "confirmedit-preview-invalid": "invalid", - "confirmedit-preview-description": "The following table shows the list of lines on this page and whether it's a valid IP address or IP address range. If the line is a valid IP address or IP address range, it will be excluded from CAPTCHA checks but invalid lines will be ignored. An example of a valid IP address range would be: 69.208.0.0/16 which goes from 69.208.0.0 to 69.208.255.255. [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Range_blocks#Calculating_the_CIDR_suffix More information] about calculating an IP address range." + "confirmedit-preview-description": "The following table shows the list of lines on this page and whether it's a valid IP address or IP address range. If the line is a valid IP address or IP address range, it will be excluded from CAPTCHA checks but invalid lines will be ignored. An example of a valid IP address range would be: 69.208.0.0/16 which goes from 69.208.0.0 to 69.208.255.255. [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Range_blocks#Calculating_the_CIDR_suffix More information] about calculating an IP address range.", + "abusefilter-edit-action-showcaptcha": "Require the user to complete a CAPTCHA in order to proceed with the action. Users with permission to skip a CAPTCHA are exempt." } diff --git a/i18n/qqq.json b/i18n/qqq.json index 3b7ed0706..40bdc90ee 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -47,5 +47,6 @@ "confirmedit-preview-validity": "Used as a table heading for the edit preview of [[MediaWiki:Captcha-ip-whitelist]] to indicate the validity of a content of a line (if it's an IP address or not).\n{{Identical|Validity}}", "confirmedit-preview-valid": "Used to indicate a valid IP address in the edit preview of [[MediaWiki:Captcha-ip-whitelist]].\n{{Identical|Valid}}", "confirmedit-preview-invalid": "Used to indicate an invalid IP address in the edit preview of [[MediaWiki:Captcha-ip-whitelist]].\n{{Identical|Invalid}}", - "confirmedit-preview-description": "Explains the edit preview of [[MediaWiki:Captcha-ip-whitelist]]." + "confirmedit-preview-description": "Explains the edit preview of [[MediaWiki:Captcha-ip-whitelist]].", + "abusefilter-edit-action-showcaptcha": "Label shown in [[Special:AbuseFilter]] for the show CAPTCHA consequence." } diff --git a/includes/AbuseFilter/CaptchaConsequence.php b/includes/AbuseFilter/CaptchaConsequence.php new file mode 100644 index 000000000..f08239c40 --- /dev/null +++ b/includes/AbuseFilter/CaptchaConsequence.php @@ -0,0 +1,22 @@ +getRequest()->setVal( self::FLAG, true ); + return true; + } +} diff --git a/includes/AbuseFilterHooks.php b/includes/AbuseFilterHooks.php new file mode 100644 index 000000000..6326d2b4c --- /dev/null +++ b/includes/AbuseFilterHooks.php @@ -0,0 +1,18 @@ +createMock( Parameters::class ); + $parameters->method( 'getAction' )->willReturn( 'edit' ); + $captchaConsequence = new CaptchaConsequence( $parameters ); + $request = RequestContext::getMain(); + $this->assertNull( $request->getRequest()->getVal( + CaptchaConsequence::FLAG + ) ); + $captchaConsequence->execute(); + $this->assertTrue( + $request->getRequest()->getBool( + CaptchaConsequence::FLAG + ) + ); + } + +} diff --git a/tests/phpunit/unit/AbuseFilterHooksTest.php b/tests/phpunit/unit/AbuseFilterHooksTest.php new file mode 100644 index 000000000..6bd6a68f4 --- /dev/null +++ b/tests/phpunit/unit/AbuseFilterHooksTest.php @@ -0,0 +1,19 @@ +onAbuseFilterCustomActions( $actions ); + $this->assertArrayHasKey( 'showcaptcha', $actions ); + } +}