mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
Add a hook to determine whether the current action should be filtered
Bug: T229252 Change-Id: I126013b6c516eebe7273fb85f2c5681844e757be
This commit is contained in:
parent
e82e455ce3
commit
7edf12dbc6
|
@ -61,3 +61,10 @@ $method: Method to generate the variable
|
|||
$vars: AbuseFilterVariableHolder
|
||||
$parameters: Parameters with data to compute the value
|
||||
&$result: Result of the computation
|
||||
|
||||
'AbuseFilterShouldFilterAction': Called before filtering an action. If the current action should not be filtered,
|
||||
return false and add a useful reason to $skipReasons.
|
||||
$vars: AbuseFilterVariableHolder
|
||||
$title: Title object target of the action
|
||||
$user: User object performer of the action
|
||||
&$skipReasons: Array of reasons why the action should be skipped
|
||||
|
|
|
@ -107,7 +107,20 @@ class AbuseFilterRunner {
|
|||
$this->executeMode = true;
|
||||
$this->init();
|
||||
|
||||
$useStash = $allowStash && $this->vars->getVar( 'action' )->toString() === 'edit';
|
||||
$action = $this->vars->getVar( 'action' )->toString();
|
||||
|
||||
$skipReasons = [];
|
||||
$shouldFilter = Hooks::run(
|
||||
'AbuseFilterShouldFilterAction',
|
||||
[ $this->vars, $this->title, $this->user, &$skipReasons ]
|
||||
);
|
||||
if ( !$shouldFilter ) {
|
||||
$logger = LoggerFactory::getInstance( 'AbuseFilter' );
|
||||
$logger->info( "Skipping action $action. Reasons provided: " . implode( ', ', $skipReasons ) );
|
||||
return Status::newGood();
|
||||
}
|
||||
|
||||
$useStash = $allowStash && $action === 'edit';
|
||||
|
||||
$startTime = microtime( true );
|
||||
|
||||
|
@ -195,6 +208,16 @@ class AbuseFilterRunner {
|
|||
$this->executeMode = false;
|
||||
$this->init();
|
||||
|
||||
$skipReasons = [];
|
||||
$shouldFilter = Hooks::run(
|
||||
'AbuseFilterShouldFilterAction',
|
||||
[ $this->vars, $this->title, $this->user, &$skipReasons ]
|
||||
);
|
||||
if ( !$shouldFilter ) {
|
||||
// Don't log it yet
|
||||
return Status::newGood();
|
||||
}
|
||||
|
||||
$cache = ObjectCache::getLocalClusterInstance();
|
||||
$stashKey = $this->getStashKey( $cache );
|
||||
|
||||
|
|
Loading…
Reference in a new issue