mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-24 06:03:49 +00:00
Merge "Allow Blockautopromote duration to be configured for wikis."
This commit is contained in:
commit
3f8e61b42f
|
@ -367,6 +367,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"
|
||||
|
|
|
@ -39,13 +39,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
|
||||
|
@ -877,14 +870,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' );
|
||||
|
@ -900,7 +894,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' => []
|
||||
|
|
|
@ -920,7 +920,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;
|
||||
|
||||
|
@ -988,21 +988,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