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