mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
Allow Blockautopromote duration to be configured for wikis.
Rather than always using 5 days, the length (in days) can be configured by setting `AbuseFilterBlockAutopromoteDuration` to the desired length. Bug: T231756 Change-Id: I996e08a9099ab59657fe511ec2934d26edfa5c7b
This commit is contained in:
parent
2af86fbb0c
commit
bf74fd0c23
|
@ -366,6 +366,10 @@
|
|||
"value": null,
|
||||
"description": "Old standard block duration for anonymous users, $wgAbuseFilterBlockDuration will be used if null. Kept for backward compatibility after T32024."
|
||||
},
|
||||
"AbuseFilterBlockAutopromoteDuration": {
|
||||
"value": 5,
|
||||
"description": "Duration, in days, for which users' autopromotion is blocked by filters."
|
||||
},
|
||||
"AbuseFilterCustomActionsHandlers": {
|
||||
"value": [],
|
||||
"description": "Callback functions for custom actions"
|
||||
|
|
|
@ -38,13 +38,6 @@ class AbuseFilter {
|
|||
*/
|
||||
public static $logIds = [];
|
||||
|
||||
/**
|
||||
* Duration for the blockautopromote action.
|
||||
* A future improvement could be to make this customizable on a per-filter basis.
|
||||
* @var int
|
||||
*/
|
||||
private const BLOCKAUTOPROMOTE_DURATION = 5 * 86400;
|
||||
|
||||
/**
|
||||
* @var string[] The FULL list of fields in the abuse_filter table
|
||||
* @internal
|
||||
|
@ -873,14 +866,15 @@ class AbuseFilter {
|
|||
*
|
||||
* @param User $target
|
||||
* @param string $msg The message to show in the log
|
||||
* @param int $duration Duration for which autopromotion is blocked, in seconds
|
||||
* @return bool True on success, false on failure
|
||||
*/
|
||||
public static function blockAutoPromote( User $target, $msg ) {
|
||||
public static function blockAutoPromote( User $target, $msg, int $duration ) {
|
||||
$store = ObjectCache::getInstance( 'db-replicated' );
|
||||
if ( !$store->set(
|
||||
self::autoPromoteBlockKey( $store, $target ),
|
||||
1,
|
||||
self::BLOCKAUTOPROMOTE_DURATION
|
||||
$duration
|
||||
) ) {
|
||||
// Failed to set key
|
||||
$logger = LoggerFactory::getInstance( 'AbuseFilter' );
|
||||
|
@ -896,7 +890,7 @@ class AbuseFilter {
|
|||
$logEntry->setTarget( $target->getUserPage() );
|
||||
|
||||
$logEntry->setParameters( [
|
||||
'7::duration' => self::BLOCKAUTOPROMOTE_DURATION,
|
||||
'7::duration' => $duration,
|
||||
// These parameters are unused in our message, but some parts of the code check for them
|
||||
'4::oldgroups' => [],
|
||||
'5::newgroups' => []
|
||||
|
|
|
@ -912,7 +912,7 @@ class AbuseFilterRunner {
|
|||
* containing the message key followed by any message parameters.
|
||||
*/
|
||||
protected function takeConsequenceAction( $action, $parameters, $ruleDescription, $ruleNumber ) {
|
||||
global $wgAbuseFilterCustomActionsHandlers;
|
||||
global $wgAbuseFilterCustomActionsHandlers, $wgAbuseFilterBlockAutopromoteDuration;
|
||||
|
||||
$message = null;
|
||||
|
||||
|
@ -995,21 +995,23 @@ class AbuseFilterRunner {
|
|||
break;
|
||||
case 'blockautopromote':
|
||||
if ( !$this->user->isAnon() ) {
|
||||
// Block for 5 days
|
||||
$duration = $wgAbuseFilterBlockAutopromoteDuration * 86400;
|
||||
$blocked = AbuseFilter::blockAutoPromote(
|
||||
$this->user,
|
||||
wfMessage(
|
||||
'abusefilter-blockautopromotereason',
|
||||
$ruleDescription,
|
||||
$ruleNumber
|
||||
)->inContentLanguage()->text()
|
||||
)->inContentLanguage()->text(),
|
||||
$duration
|
||||
);
|
||||
|
||||
if ( $blocked ) {
|
||||
$message = [
|
||||
'abusefilter-autopromote-blocked',
|
||||
$ruleDescription,
|
||||
$ruleNumber
|
||||
$ruleNumber,
|
||||
$duration
|
||||
];
|
||||
} else {
|
||||
$logger = LoggerFactory::getInstance( 'AbuseFilter' );
|
||||
|
|
Loading…
Reference in a new issue