Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
25 / 25 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| AbuseLoggerFactory | |
100.00% |
25 / 25 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getProtectedVarsAccessLogger | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| newLogger | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace MediaWiki\Extension\AbuseFilter; |
| 4 | |
| 5 | use MediaWiki\Config\ServiceOptions; |
| 6 | use MediaWiki\Extension\AbuseFilter\Hooks\AbuseFilterHookRunner; |
| 7 | use MediaWiki\Extension\AbuseFilter\Parser\RuleCheckerFactory; |
| 8 | use MediaWiki\Extension\AbuseFilter\Variables\VariableHolder; |
| 9 | use MediaWiki\Extension\AbuseFilter\Variables\VariablesBlobStore; |
| 10 | use MediaWiki\Extension\AbuseFilter\Variables\VariablesManager; |
| 11 | use MediaWiki\Title\Title; |
| 12 | use MediaWiki\Title\TitleFactory; |
| 13 | use MediaWiki\User\ActorStore; |
| 14 | use MediaWiki\User\User; |
| 15 | use Psr\Log\LoggerInterface; |
| 16 | use Wikimedia\Rdbms\LBFactory; |
| 17 | |
| 18 | class AbuseLoggerFactory { |
| 19 | public const SERVICE_NAME = 'AbuseFilterAbuseLoggerFactory'; |
| 20 | |
| 21 | public const CONSTRUCTOR_OPTIONS = [ |
| 22 | 'AbuseFilterLogIP', |
| 23 | 'AbuseFilterNotifications', |
| 24 | 'AbuseFilterNotificationsPrivate', |
| 25 | ]; |
| 26 | |
| 27 | /** |
| 28 | * The default amount of time after which a duplicate log entry can be inserted. 24 hours (in |
| 29 | * seconds). |
| 30 | * |
| 31 | * @var int |
| 32 | */ |
| 33 | private const DEFAULT_DEBOUNCE_DELAY = 24 * 60 * 60; |
| 34 | |
| 35 | public function __construct( |
| 36 | private readonly CentralDBManager $centralDBManager, |
| 37 | private readonly FilterLookup $filterLookup, |
| 38 | private readonly VariablesBlobStore $varBlobStore, |
| 39 | private readonly VariablesManager $varManager, |
| 40 | private readonly EditRevUpdater $editRevUpdater, |
| 41 | private readonly AbuseFilterPermissionManager $afPermissionManager, |
| 42 | private readonly RuleCheckerFactory $ruleCheckerFactory, |
| 43 | private readonly LBFactory $lbFactory, |
| 44 | private readonly ActorStore $actorStore, |
| 45 | private readonly TitleFactory $titleFactory, |
| 46 | private readonly ServiceOptions $options, |
| 47 | private readonly string $wikiID, |
| 48 | private readonly string $requestIP, |
| 49 | private readonly LoggerInterface $logger, |
| 50 | private readonly AbuseFilterHookRunner $hookRunner |
| 51 | ) { |
| 52 | $options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @param int $delay |
| 57 | * @return ProtectedVarsAccessLogger |
| 58 | */ |
| 59 | public function getProtectedVarsAccessLogger( |
| 60 | int $delay = self::DEFAULT_DEBOUNCE_DELAY |
| 61 | ): ProtectedVarsAccessLogger { |
| 62 | return new ProtectedVarsAccessLogger( |
| 63 | $this->logger, |
| 64 | $this->lbFactory, |
| 65 | $this->actorStore, |
| 66 | $this->hookRunner, |
| 67 | $this->titleFactory, |
| 68 | $delay |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @param Title $title |
| 74 | * @param User $user |
| 75 | * @param VariableHolder $vars |
| 76 | * @return AbuseLogger |
| 77 | */ |
| 78 | public function newLogger( |
| 79 | Title $title, |
| 80 | User $user, |
| 81 | VariableHolder $vars |
| 82 | ): AbuseLogger { |
| 83 | return new AbuseLogger( |
| 84 | $this->centralDBManager, |
| 85 | $this->filterLookup, |
| 86 | $this->varBlobStore, |
| 87 | $this->varManager, |
| 88 | $this->editRevUpdater, |
| 89 | $this->lbFactory, |
| 90 | $this->ruleCheckerFactory, |
| 91 | $this->afPermissionManager, |
| 92 | $this->options, |
| 93 | $this->wikiID, |
| 94 | $this->requestIP, |
| 95 | $title, |
| 96 | $user, |
| 97 | $vars |
| 98 | ); |
| 99 | } |
| 100 | } |