2020-11-27 14:49:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\AbuseFilter;
|
|
|
|
|
2021-01-06 15:40:23 +00:00
|
|
|
use MediaWiki\Config\ServiceOptions;
|
2020-11-27 14:49:41 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\ChangeTags\ChangeTagger;
|
2020-12-18 14:05:33 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Consequences\ConsequencesExecutorFactory;
|
2020-11-27 14:49:41 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Hooks\AbuseFilterHookRunner;
|
2021-09-01 11:53:38 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Parser\RuleCheckerFactory;
|
2021-01-03 13:10:20 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\VariableGenerator\VariableGeneratorFactory;
|
2021-01-02 14:01:00 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Variables\VariableHolder;
|
2021-01-02 13:41:31 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Variables\VariablesManager;
|
2020-11-27 14:49:41 +00:00
|
|
|
use MediaWiki\Extension\AbuseFilter\Watcher\EmergencyWatcher;
|
|
|
|
use MediaWiki\Extension\AbuseFilter\Watcher\UpdateHitCountWatcher;
|
2023-08-19 17:49:36 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-12-10 19:03:19 +00:00
|
|
|
use MediaWiki\User\User;
|
2020-11-27 14:49:41 +00:00
|
|
|
use Psr\Log\LoggerInterface;
|
2024-10-19 19:55:40 +00:00
|
|
|
use Wikimedia\ObjectCache\BagOStuff;
|
|
|
|
use Wikimedia\Stats\IBufferingStatsdDataFactory;
|
|
|
|
use Wikimedia\Stats\NullStatsdDataFactory;
|
2020-11-27 14:49:41 +00:00
|
|
|
|
|
|
|
class FilterRunnerFactory {
|
2023-03-27 16:43:06 +00:00
|
|
|
public const SERVICE_NAME = 'AbuseFilterFilterRunnerFactory';
|
2020-11-27 14:49:41 +00:00
|
|
|
|
|
|
|
/** @var AbuseFilterHookRunner */
|
|
|
|
private $hookRunner;
|
|
|
|
/** @var FilterProfiler */
|
|
|
|
private $filterProfiler;
|
|
|
|
/** @var ChangeTagger */
|
|
|
|
private $changeTagger;
|
|
|
|
/** @var FilterLookup */
|
|
|
|
private $filterLookup;
|
2021-09-01 11:53:38 +00:00
|
|
|
/** @var RuleCheckerFactory */
|
|
|
|
private $ruleCheckerFactory;
|
2020-11-27 14:49:41 +00:00
|
|
|
/** @var ConsequencesExecutorFactory */
|
|
|
|
private $consExecutorFactory;
|
|
|
|
/** @var AbuseLoggerFactory */
|
|
|
|
private $abuseLoggerFactory;
|
2020-10-18 22:25:05 +00:00
|
|
|
/** @var VariablesManager */
|
|
|
|
private $varManager;
|
2021-01-03 13:10:20 +00:00
|
|
|
/** @var VariableGeneratorFactory */
|
|
|
|
private $varGeneratorFactory;
|
2021-02-10 13:13:03 +00:00
|
|
|
/** @var EmergencyCache */
|
|
|
|
private $emergencyCache;
|
2020-11-27 14:49:41 +00:00
|
|
|
/** @var UpdateHitCountWatcher */
|
|
|
|
private $updateHitCountWatcher;
|
|
|
|
/** @var EmergencyWatcher */
|
|
|
|
private $emergencyWatcher;
|
2020-12-21 14:51:31 +00:00
|
|
|
/** @var BagOStuff */
|
|
|
|
private $localCache;
|
2020-11-27 14:49:41 +00:00
|
|
|
/** @var LoggerInterface */
|
|
|
|
private $logger;
|
2020-12-21 14:51:31 +00:00
|
|
|
/** @var LoggerInterface */
|
|
|
|
private $editStashLogger;
|
2020-11-27 14:49:41 +00:00
|
|
|
/** @var IBufferingStatsdDataFactory */
|
|
|
|
private $statsdDataFactory;
|
2021-01-06 15:40:23 +00:00
|
|
|
/** @var ServiceOptions */
|
|
|
|
private $options;
|
2020-11-27 14:49:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param AbuseFilterHookRunner $hookRunner
|
|
|
|
* @param FilterProfiler $filterProfiler
|
|
|
|
* @param ChangeTagger $changeTagger
|
|
|
|
* @param FilterLookup $filterLookup
|
2021-09-01 11:53:38 +00:00
|
|
|
* @param RuleCheckerFactory $ruleCheckerFactory
|
2020-11-27 14:49:41 +00:00
|
|
|
* @param ConsequencesExecutorFactory $consExecutorFactory
|
|
|
|
* @param AbuseLoggerFactory $abuseLoggerFactory
|
2020-10-18 22:25:05 +00:00
|
|
|
* @param VariablesManager $varManager
|
2021-01-03 13:10:20 +00:00
|
|
|
* @param VariableGeneratorFactory $varGeneratorFactory
|
2021-02-10 13:13:03 +00:00
|
|
|
* @param EmergencyCache $emergencyCache
|
2020-11-27 14:49:41 +00:00
|
|
|
* @param UpdateHitCountWatcher $updateHitCountWatcher
|
|
|
|
* @param EmergencyWatcher $emergencyWatcher
|
2020-12-21 14:51:31 +00:00
|
|
|
* @param BagOStuff $localCache
|
2020-11-27 14:49:41 +00:00
|
|
|
* @param LoggerInterface $logger
|
2020-12-21 14:51:31 +00:00
|
|
|
* @param LoggerInterface $editStashLogger
|
2020-11-27 14:49:41 +00:00
|
|
|
* @param IBufferingStatsdDataFactory $statsdDataFactory
|
2021-01-06 15:40:23 +00:00
|
|
|
* @param ServiceOptions $options
|
2020-11-27 14:49:41 +00:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
AbuseFilterHookRunner $hookRunner,
|
|
|
|
FilterProfiler $filterProfiler,
|
|
|
|
ChangeTagger $changeTagger,
|
|
|
|
FilterLookup $filterLookup,
|
2021-09-01 11:53:38 +00:00
|
|
|
RuleCheckerFactory $ruleCheckerFactory,
|
2020-11-27 14:49:41 +00:00
|
|
|
ConsequencesExecutorFactory $consExecutorFactory,
|
|
|
|
AbuseLoggerFactory $abuseLoggerFactory,
|
2020-10-18 22:25:05 +00:00
|
|
|
VariablesManager $varManager,
|
2021-01-03 13:10:20 +00:00
|
|
|
VariableGeneratorFactory $varGeneratorFactory,
|
2021-02-10 13:13:03 +00:00
|
|
|
EmergencyCache $emergencyCache,
|
2020-11-27 14:49:41 +00:00
|
|
|
UpdateHitCountWatcher $updateHitCountWatcher,
|
|
|
|
EmergencyWatcher $emergencyWatcher,
|
2020-12-21 14:51:31 +00:00
|
|
|
BagOStuff $localCache,
|
2020-11-27 14:49:41 +00:00
|
|
|
LoggerInterface $logger,
|
2020-12-21 14:51:31 +00:00
|
|
|
LoggerInterface $editStashLogger,
|
2020-11-27 14:49:41 +00:00
|
|
|
IBufferingStatsdDataFactory $statsdDataFactory,
|
2023-08-18 20:47:19 +00:00
|
|
|
ServiceOptions $options
|
2020-11-27 14:49:41 +00:00
|
|
|
) {
|
|
|
|
$this->hookRunner = $hookRunner;
|
|
|
|
$this->filterProfiler = $filterProfiler;
|
|
|
|
$this->changeTagger = $changeTagger;
|
|
|
|
$this->filterLookup = $filterLookup;
|
2021-09-01 11:53:38 +00:00
|
|
|
$this->ruleCheckerFactory = $ruleCheckerFactory;
|
2020-11-27 14:49:41 +00:00
|
|
|
$this->consExecutorFactory = $consExecutorFactory;
|
|
|
|
$this->abuseLoggerFactory = $abuseLoggerFactory;
|
2020-10-18 22:25:05 +00:00
|
|
|
$this->varManager = $varManager;
|
2021-01-03 13:10:20 +00:00
|
|
|
$this->varGeneratorFactory = $varGeneratorFactory;
|
2021-02-10 13:13:03 +00:00
|
|
|
$this->emergencyCache = $emergencyCache;
|
2020-11-27 14:49:41 +00:00
|
|
|
$this->updateHitCountWatcher = $updateHitCountWatcher;
|
|
|
|
$this->emergencyWatcher = $emergencyWatcher;
|
2020-12-21 14:51:31 +00:00
|
|
|
$this->localCache = $localCache;
|
2020-11-27 14:49:41 +00:00
|
|
|
$this->logger = $logger;
|
2020-12-21 14:51:31 +00:00
|
|
|
$this->editStashLogger = $editStashLogger;
|
2020-11-27 14:49:41 +00:00
|
|
|
$this->statsdDataFactory = $statsdDataFactory;
|
2021-01-06 15:40:23 +00:00
|
|
|
$this->options = $options;
|
2020-11-27 14:49:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param User $user
|
|
|
|
* @param Title $title
|
2021-01-02 14:01:00 +00:00
|
|
|
* @param VariableHolder $vars
|
2020-11-27 14:49:41 +00:00
|
|
|
* @param string $group
|
|
|
|
* @return FilterRunner
|
|
|
|
*/
|
|
|
|
public function newRunner(
|
|
|
|
User $user,
|
|
|
|
Title $title,
|
2021-01-02 14:01:00 +00:00
|
|
|
VariableHolder $vars,
|
2020-11-27 14:49:41 +00:00
|
|
|
string $group
|
2021-07-21 18:51:12 +00:00
|
|
|
): FilterRunner {
|
2020-11-27 14:49:41 +00:00
|
|
|
// TODO Add a method to this class taking these as params? Add a hook for custom watchers
|
|
|
|
$watchers = [ $this->updateHitCountWatcher, $this->emergencyWatcher ];
|
|
|
|
return new FilterRunner(
|
|
|
|
$this->hookRunner,
|
|
|
|
$this->filterProfiler,
|
|
|
|
$this->changeTagger,
|
|
|
|
$this->filterLookup,
|
2021-09-01 11:53:38 +00:00
|
|
|
$this->ruleCheckerFactory,
|
2020-11-27 14:49:41 +00:00
|
|
|
$this->consExecutorFactory,
|
|
|
|
$this->abuseLoggerFactory,
|
2020-10-18 22:25:05 +00:00
|
|
|
$this->varManager,
|
2021-01-03 13:10:20 +00:00
|
|
|
$this->varGeneratorFactory,
|
2021-02-10 13:13:03 +00:00
|
|
|
$this->emergencyCache,
|
2020-11-27 14:49:41 +00:00
|
|
|
$watchers,
|
2020-12-21 14:51:31 +00:00
|
|
|
new EditStashCache(
|
|
|
|
$this->localCache,
|
|
|
|
// Bots do not use edit stashing, so avoid distorting the stats
|
2021-02-22 11:08:50 +00:00
|
|
|
$user->isBot() ? new NullStatsdDataFactory() : $this->statsdDataFactory,
|
2020-12-21 14:51:31 +00:00
|
|
|
$this->varManager,
|
|
|
|
$this->editStashLogger,
|
|
|
|
$title,
|
|
|
|
$group
|
|
|
|
),
|
2020-11-27 14:49:41 +00:00
|
|
|
$this->logger,
|
2021-01-06 15:40:23 +00:00
|
|
|
$this->options,
|
2020-11-27 14:49:41 +00:00
|
|
|
$user,
|
|
|
|
$title,
|
|
|
|
$vars,
|
|
|
|
$group
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|