Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3use MediaWiki\Config\ServiceOptions;
4use MediaWiki\Extension\AbuseFilter\AbuseFilterActorMigration;
5use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager as PermManager;
6use MediaWiki\Extension\AbuseFilter\AbuseLogger;
7use MediaWiki\Extension\AbuseFilter\AbuseLoggerFactory;
8use MediaWiki\Extension\AbuseFilter\BlockAutopromoteStore;
9use MediaWiki\Extension\AbuseFilter\BlockedDomainFilter;
10use MediaWiki\Extension\AbuseFilter\BlockedDomainStorage;
11use MediaWiki\Extension\AbuseFilter\CentralDBManager;
12use MediaWiki\Extension\AbuseFilter\ChangeTags\ChangeTagger;
13use MediaWiki\Extension\AbuseFilter\ChangeTags\ChangeTagsManager;
14use MediaWiki\Extension\AbuseFilter\ChangeTags\ChangeTagValidator;
15use MediaWiki\Extension\AbuseFilter\Consequences\ConsequencesExecutor;
16use MediaWiki\Extension\AbuseFilter\Consequences\ConsequencesExecutorFactory as ConsExecutorFactory;
17use MediaWiki\Extension\AbuseFilter\Consequences\ConsequencesFactory;
18use MediaWiki\Extension\AbuseFilter\Consequences\ConsequencesLookup;
19use MediaWiki\Extension\AbuseFilter\Consequences\ConsequencesRegistry;
20use MediaWiki\Extension\AbuseFilter\EchoNotifier;
21use MediaWiki\Extension\AbuseFilter\EditBox\EditBoxBuilderFactory;
22use MediaWiki\Extension\AbuseFilter\EditRevUpdater;
23use MediaWiki\Extension\AbuseFilter\EmergencyCache;
24use MediaWiki\Extension\AbuseFilter\FilterCompare;
25use MediaWiki\Extension\AbuseFilter\FilterImporter;
26use MediaWiki\Extension\AbuseFilter\FilterLookup;
27use MediaWiki\Extension\AbuseFilter\FilterProfiler;
28use MediaWiki\Extension\AbuseFilter\FilterRunner;
29use MediaWiki\Extension\AbuseFilter\FilterRunnerFactory;
30use MediaWiki\Extension\AbuseFilter\FilterStore;
31use MediaWiki\Extension\AbuseFilter\FilterUser;
32use MediaWiki\Extension\AbuseFilter\FilterValidator;
33use MediaWiki\Extension\AbuseFilter\Hooks\AbuseFilterHookRunner;
34use MediaWiki\Extension\AbuseFilter\KeywordsManager;
35use MediaWiki\Extension\AbuseFilter\Parser\RuleCheckerFactory;
36use MediaWiki\Extension\AbuseFilter\SpecsFormatter;
37use MediaWiki\Extension\AbuseFilter\TextExtractor;
38use MediaWiki\Extension\AbuseFilter\VariableGenerator\VariableGeneratorFactory;
39use MediaWiki\Extension\AbuseFilter\Variables\LazyVariableComputer;
40use MediaWiki\Extension\AbuseFilter\Variables\VariablesBlobStore;
41use MediaWiki\Extension\AbuseFilter\Variables\VariablesFormatter;
42use MediaWiki\Extension\AbuseFilter\Variables\VariablesManager;
43use MediaWiki\Extension\AbuseFilter\Watcher\EmergencyWatcher;
44use MediaWiki\Extension\AbuseFilter\Watcher\UpdateHitCountWatcher;
45use MediaWiki\Logger\LoggerFactory;
46use MediaWiki\MediaWikiServices;
47use MediaWiki\WikiMap\WikiMap;
48use Wikimedia\Equivset\Equivset;
49
50// This file is actually covered by AbuseFilterServicesTest, but it's not possible to specify a path
51// in @covers annotations (https://github.com/sebastianbergmann/phpunit/issues/3794)
52// @codeCoverageIgnoreStart
53
54return [
55    AbuseFilterHookRunner::SERVICE_NAME => static function ( MediaWikiServices $services ): AbuseFilterHookRunner {
56        return new AbuseFilterHookRunner( $services->getHookContainer() );
57    },
58    KeywordsManager::SERVICE_NAME => static function ( MediaWikiServices $services ): KeywordsManager {
59        return new KeywordsManager( $services->get( AbuseFilterHookRunner::SERVICE_NAME ) );
60    },
61    FilterProfiler::SERVICE_NAME => static function ( MediaWikiServices $services ): FilterProfiler {
62        return new FilterProfiler(
63            $services->getWRStatsFactory(),
64            new ServiceOptions(
65                FilterProfiler::CONSTRUCTOR_OPTIONS,
66                $services->getMainConfig()
67            ),
68            WikiMap::getCurrentWikiDbDomain()->getId(),
69            $services->getStatsdDataFactory(),
70            LoggerFactory::getInstance( 'AbuseFilter' )
71        );
72    },
73    PermManager::SERVICE_NAME => static function ( MediaWikiServices $services ): PermManager {
74        // No longer has any dependencies
75        return new PermManager();
76    },
77    ChangeTagger::SERVICE_NAME => static function ( MediaWikiServices $services ): ChangeTagger {
78        return new ChangeTagger(
79            $services->getService( ChangeTagsManager::SERVICE_NAME )
80        );
81    },
82    ChangeTagsManager::SERVICE_NAME => static function ( MediaWikiServices $services ): ChangeTagsManager {
83        return new ChangeTagsManager(
84            $services->getDBLoadBalancerFactory(),
85            $services->getMainWANObjectCache(),
86            $services->get( CentralDBManager::SERVICE_NAME )
87        );
88    },
89    ChangeTagValidator::SERVICE_NAME => static function ( MediaWikiServices $services ): ChangeTagValidator {
90        return new ChangeTagValidator(
91            $services->getService( ChangeTagsManager::SERVICE_NAME )
92        );
93    },
94    CentralDBManager::SERVICE_NAME => static function ( MediaWikiServices $services ): CentralDBManager {
95        return new CentralDBManager(
96            $services->getDBLoadBalancerFactory(),
97            $services->getMainConfig()->get( 'AbuseFilterCentralDB' ),
98            $services->getMainConfig()->get( 'AbuseFilterIsCentral' )
99        );
100    },
101    BlockAutopromoteStore::SERVICE_NAME => static function ( MediaWikiServices $services ): BlockAutopromoteStore {
102        return new BlockAutopromoteStore(
103            $services->getMainObjectStash(),
104            LoggerFactory::getInstance( 'AbuseFilter' ),
105            $services->get( FilterUser::SERVICE_NAME )
106        );
107    },
108    FilterUser::SERVICE_NAME => static function ( MediaWikiServices $services ): FilterUser {
109        return new FilterUser(
110            // TODO We need a proper MessageLocalizer, see T247127
111            RequestContext::getMain(),
112            $services->getUserGroupManager(),
113            LoggerFactory::getInstance( 'AbuseFilter' )
114        );
115    },
116    RuleCheckerFactory::SERVICE_NAME => static function ( MediaWikiServices $services ): RuleCheckerFactory {
117        return new RuleCheckerFactory(
118            $services->getContentLanguage(),
119            // We could use $services here, but we need the fallback
120            ObjectCache::getLocalServerInstance( 'hash' ),
121            LoggerFactory::getInstance( 'AbuseFilter' ),
122            $services->getService( KeywordsManager::SERVICE_NAME ),
123            $services->get( VariablesManager::SERVICE_NAME ),
124            $services->getStatsdDataFactory(),
125            new Equivset(),
126            $services->getMainConfig()->get( 'AbuseFilterConditionLimit' )
127        );
128    },
129    FilterLookup::SERVICE_NAME => static function ( MediaWikiServices $services ): FilterLookup {
130        return new FilterLookup(
131            $services->getDBLoadBalancer(),
132            $services->getMainWANObjectCache(),
133            $services->get( CentralDBManager::SERVICE_NAME ),
134            $services->get( AbuseFilterActorMigration::SERVICE_NAME )
135        );
136    },
137    EmergencyCache::SERVICE_NAME => static function ( MediaWikiServices $services ): EmergencyCache {
138        return new EmergencyCache(
139            $services->getMainObjectStash(),
140            $services->getMainConfig()->get( 'AbuseFilterEmergencyDisableAge' )
141        );
142    },
143    EmergencyWatcher::SERVICE_NAME => static function ( MediaWikiServices $services ): EmergencyWatcher {
144        return new EmergencyWatcher(
145            $services->getService( EmergencyCache::SERVICE_NAME ),
146            $services->getDBLoadBalancerFactory(),
147            $services->getService( FilterLookup::SERVICE_NAME ),
148            $services->getService( EchoNotifier::SERVICE_NAME ),
149            new ServiceOptions(
150                EmergencyWatcher::CONSTRUCTOR_OPTIONS,
151                $services->getMainConfig()
152            )
153        );
154    },
155    EchoNotifier::SERVICE_NAME => static function ( MediaWikiServices $services ): EchoNotifier {
156        return new EchoNotifier(
157            $services->getService( FilterLookup::SERVICE_NAME ),
158            $services->getService( ConsequencesRegistry::SERVICE_NAME ),
159            ExtensionRegistry::getInstance()->isLoaded( 'Echo' )
160        );
161    },
162    FilterValidator::SERVICE_NAME => static function ( MediaWikiServices $services ): FilterValidator {
163        return new FilterValidator(
164            $services->get( ChangeTagValidator::SERVICE_NAME ),
165            $services->get( RuleCheckerFactory::SERVICE_NAME ),
166            $services->get( PermManager::SERVICE_NAME ),
167            new ServiceOptions(
168                FilterValidator::CONSTRUCTOR_OPTIONS,
169                $services->getMainConfig()
170            )
171        );
172    },
173    FilterCompare::SERVICE_NAME => static function ( MediaWikiServices $services ): FilterCompare {
174        return new FilterCompare(
175            $services->get( ConsequencesRegistry::SERVICE_NAME )
176        );
177    },
178    FilterImporter::SERVICE_NAME => static function ( MediaWikiServices $services ): FilterImporter {
179        return new FilterImporter(
180            new ServiceOptions(
181                FilterImporter::CONSTRUCTOR_OPTIONS,
182                $services->getMainConfig()
183            ),
184            $services->get( ConsequencesRegistry::SERVICE_NAME )
185        );
186    },
187    FilterStore::SERVICE_NAME => static function ( MediaWikiServices $services ): FilterStore {
188        return new FilterStore(
189            $services->get( ConsequencesRegistry::SERVICE_NAME ),
190            $services->getDBLoadBalancerFactory(),
191            $services->get( FilterProfiler::SERVICE_NAME ),
192            $services->get( FilterLookup::SERVICE_NAME ),
193            $services->get( ChangeTagsManager::SERVICE_NAME ),
194            $services->get( FilterValidator::SERVICE_NAME ),
195            $services->get( FilterCompare::SERVICE_NAME ),
196            $services->get( EmergencyCache::SERVICE_NAME ),
197            $services->get( AbuseFilterActorMigration::SERVICE_NAME )
198        );
199    },
200    ConsequencesFactory::SERVICE_NAME => static function ( MediaWikiServices $services ): ConsequencesFactory {
201        return new ConsequencesFactory(
202            new ServiceOptions(
203                ConsequencesFactory::CONSTRUCTOR_OPTIONS,
204                $services->getMainConfig()
205            ),
206            LoggerFactory::getInstance( 'AbuseFilter' ),
207            $services->getBlockUserFactory(),
208            $services->getDatabaseBlockStore(),
209            $services->getUserGroupManager(),
210            $services->getMainObjectStash(),
211            $services->get( ChangeTagger::SERVICE_NAME ),
212            $services->get( BlockAutopromoteStore::SERVICE_NAME ),
213            $services->get( FilterUser::SERVICE_NAME ),
214            // TODO: Use a proper MessageLocalizer once available (T247127)
215            RequestContext::getMain(),
216            $services->getUserEditTracker(),
217            $services->getUserFactory(),
218            $services->getUserIdentityUtils()
219        );
220    },
221    EditBoxBuilderFactory::SERVICE_NAME => static function ( MediaWikiServices $services ): EditBoxBuilderFactory {
222        return new EditBoxBuilderFactory(
223            $services->get( PermManager::SERVICE_NAME ),
224            $services->get( KeywordsManager::SERVICE_NAME ),
225            ExtensionRegistry::getInstance()->isLoaded( 'CodeEditor' )
226        );
227    },
228    ConsequencesLookup::SERVICE_NAME => static function ( MediaWikiServices $services ): ConsequencesLookup {
229        return new ConsequencesLookup(
230            $services->getDBLoadBalancerFactory(),
231            $services->get( CentralDBManager::SERVICE_NAME ),
232            $services->get( ConsequencesRegistry::SERVICE_NAME ),
233            LoggerFactory::getInstance( 'AbuseFilter' )
234        );
235    },
236    ConsequencesRegistry::SERVICE_NAME => static function ( MediaWikiServices $services ): ConsequencesRegistry {
237        return new ConsequencesRegistry(
238            $services->get( AbuseFilterHookRunner::SERVICE_NAME ),
239            $services->getMainConfig()->get( 'AbuseFilterActions' )
240        );
241    },
242    AbuseLoggerFactory::SERVICE_NAME => static function ( MediaWikiServices $services ): AbuseLoggerFactory {
243        return new AbuseLoggerFactory(
244            $services->get( CentralDBManager::SERVICE_NAME ),
245            $services->get( FilterLookup::SERVICE_NAME ),
246            $services->get( VariablesBlobStore::SERVICE_NAME ),
247            $services->get( VariablesManager::SERVICE_NAME ),
248            $services->get( EditRevUpdater::SERVICE_NAME ),
249            $services->getDBLoadBalancerFactory(),
250            new ServiceOptions(
251                AbuseLogger::CONSTRUCTOR_OPTIONS,
252                $services->getMainConfig()
253            ),
254            WikiMap::getCurrentWikiDbDomain()->getId(),
255            RequestContext::getMain()->getRequest()->getIP()
256        );
257    },
258    UpdateHitCountWatcher::SERVICE_NAME => static function ( MediaWikiServices $services ): UpdateHitCountWatcher {
259        return new UpdateHitCountWatcher(
260            $services->getDBLoadBalancerFactory(),
261            $services->get( CentralDBManager::SERVICE_NAME )
262        );
263    },
264    VariablesBlobStore::SERVICE_NAME => static function ( MediaWikiServices $services ): VariablesBlobStore {
265        return new VariablesBlobStore(
266            $services->get( VariablesManager::SERVICE_NAME ),
267            $services->getBlobStoreFactory(),
268            $services->getBlobStore(),
269            $services->getMainConfig()->get( 'AbuseFilterCentralDB' )
270        );
271    },
272    ConsExecutorFactory::SERVICE_NAME => static function ( MediaWikiServices $services ): ConsExecutorFactory {
273        return new ConsExecutorFactory(
274            $services->get( ConsequencesLookup::SERVICE_NAME ),
275            $services->get( ConsequencesFactory::SERVICE_NAME ),
276            $services->get( ConsequencesRegistry::SERVICE_NAME ),
277            $services->get( FilterLookup::SERVICE_NAME ),
278            LoggerFactory::getInstance( 'AbuseFilter' ),
279            $services->getUserIdentityUtils(),
280            new ServiceOptions(
281                ConsequencesExecutor::CONSTRUCTOR_OPTIONS,
282                $services->getMainConfig()
283            )
284        );
285    },
286    FilterRunnerFactory::SERVICE_NAME => static function ( MediaWikiServices $services ): FilterRunnerFactory {
287        return new FilterRunnerFactory(
288            $services->get( AbuseFilterHookRunner::SERVICE_NAME ),
289            $services->get( FilterProfiler::SERVICE_NAME ),
290            $services->get( ChangeTagger::SERVICE_NAME ),
291            $services->get( FilterLookup::SERVICE_NAME ),
292            $services->get( RuleCheckerFactory::SERVICE_NAME ),
293            $services->get( ConsExecutorFactory::SERVICE_NAME ),
294            $services->get( AbuseLoggerFactory::SERVICE_NAME ),
295            $services->get( VariablesManager::SERVICE_NAME ),
296            $services->get( VariableGeneratorFactory::SERVICE_NAME ),
297            $services->get( EmergencyCache::SERVICE_NAME ),
298            $services->get( UpdateHitCountWatcher::SERVICE_NAME ),
299            $services->get( EmergencyWatcher::SERVICE_NAME ),
300            ObjectCache::getLocalClusterInstance(),
301            LoggerFactory::getInstance( 'AbuseFilter' ),
302            LoggerFactory::getInstance( 'StashEdit' ),
303            $services->getStatsdDataFactory(),
304            new ServiceOptions(
305                FilterRunner::CONSTRUCTOR_OPTIONS,
306                $services->getMainConfig()
307            )
308        );
309    },
310    VariablesFormatter::SERVICE_NAME => static function ( MediaWikiServices $services ): VariablesFormatter {
311        return new VariablesFormatter(
312            $services->get( KeywordsManager::SERVICE_NAME ),
313            $services->get( VariablesManager::SERVICE_NAME ),
314            // TODO: Use a proper MessageLocalizer once available (T247127)
315            RequestContext::getMain()
316        );
317    },
318    SpecsFormatter::SERVICE_NAME => static function ( MediaWikiServices $services ): SpecsFormatter {
319        return new SpecsFormatter(
320            // TODO: Use a proper MessageLocalizer once available (T247127)
321            RequestContext::getMain()
322        );
323    },
324    LazyVariableComputer::SERVICE_NAME => static function ( MediaWikiServices $services ): LazyVariableComputer {
325        return new LazyVariableComputer(
326            $services->get( TextExtractor::SERVICE_NAME ),
327            $services->get( AbuseFilterHookRunner::SERVICE_NAME ),
328            LoggerFactory::getInstance( 'AbuseFilter' ),
329            $services->getDBLoadBalancerFactory(),
330            $services->getMainWANObjectCache(),
331            $services->getRevisionLookup(),
332            $services->getRevisionStore(),
333            $services->getContentLanguage(),
334            $services->getParserFactory(),
335            $services->getUserEditTracker(),
336            $services->getUserGroupManager(),
337            $services->getPermissionManager(),
338            $services->getRestrictionStore(),
339            WikiMap::getCurrentWikiDbDomain()->getId()
340        );
341    },
342    TextExtractor::SERVICE_NAME => static function ( MediaWikiServices $services ): TextExtractor {
343        return new TextExtractor( $services->get( AbuseFilterHookRunner::SERVICE_NAME ) );
344    },
345    VariablesManager::SERVICE_NAME => static function ( MediaWikiServices $services ): VariablesManager {
346        return new VariablesManager(
347            $services->get( KeywordsManager::SERVICE_NAME ),
348            $services->get( LazyVariableComputer::SERVICE_NAME )
349        );
350    },
351    VariableGeneratorFactory::SERVICE_NAME => static function (
352        MediaWikiServices $services
353    ): VariableGeneratorFactory {
354        return new VariableGeneratorFactory(
355            $services->get( AbuseFilterHookRunner::SERVICE_NAME ),
356            $services->get( TextExtractor::SERVICE_NAME ),
357            $services->getMimeAnalyzer(),
358            $services->getRepoGroup(),
359            $services->getWikiPageFactory()
360        );
361    },
362    EditRevUpdater::SERVICE_NAME => static function ( MediaWikiServices $services ): EditRevUpdater {
363        return new EditRevUpdater(
364            $services->get( CentralDBManager::SERVICE_NAME ),
365            $services->getRevisionLookup(),
366            $services->getDBLoadBalancerFactory(),
367            WikiMap::getCurrentWikiDbDomain()->getId()
368        );
369    },
370    AbuseFilterActorMigration::SERVICE_NAME => static function (
371        MediaWikiServices $services
372    ): AbuseFilterActorMigration {
373        return new AbuseFilterActorMigration(
374            $services->getMainConfig()->get( 'AbuseFilterActorTableSchemaMigrationStage' ),
375            $services->getActorStoreFactory(),
376        );
377    },
378    BlockedDomainStorage::SERVICE_NAME => static function (
379        MediaWikiServices $services
380    ): BlockedDomainStorage {
381        return new BlockedDomainStorage(
382            $services->getLocalServerObjectCache(),
383            $services->getRevisionLookup(),
384            $services->getUserFactory(),
385            $services->getWikiPageFactory(),
386            $services->getUrlUtils()
387        );
388    },
389    BlockedDomainFilter::SERVICE_NAME => static function (
390        MediaWikiServices $services
391    ): BlockedDomainFilter {
392        return new BlockedDomainFilter(
393            $services->get( VariablesManager::SERVICE_NAME ),
394            $services->get( BlockedDomainStorage::SERVICE_NAME )
395        );
396    },
397    // b/c for extensions
398    'AbuseFilterRunnerFactory' => static function ( MediaWikiServices $services ): FilterRunnerFactory {
399        return $services->get( FilterRunnerFactory::SERVICE_NAME );
400    },
401];
402
403// @codeCoverageIgnoreEnd