Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 347
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3declare( strict_types=1 );
4
5use MediaWiki\Config\ServiceOptions;
6use MediaWiki\Context\RequestContext;
7use MediaWiki\Extension\CampaignEvents\Address\AddressStore;
8use MediaWiki\Extension\CampaignEvents\Database\CampaignsDatabaseHelper;
9use MediaWiki\Extension\CampaignEvents\Event\DeleteEventCommand;
10use MediaWiki\Extension\CampaignEvents\Event\EditEventCommand;
11use MediaWiki\Extension\CampaignEvents\Event\EventFactory;
12use MediaWiki\Extension\CampaignEvents\Event\PageEventLookup;
13use MediaWiki\Extension\CampaignEvents\Event\Store\EventStore;
14use MediaWiki\Extension\CampaignEvents\Event\Store\EventTopicsStore;
15use MediaWiki\Extension\CampaignEvents\Event\Store\EventWikisStore;
16use MediaWiki\Extension\CampaignEvents\Event\Store\IEventLookup;
17use MediaWiki\Extension\CampaignEvents\Event\Store\IEventStore;
18use MediaWiki\Extension\CampaignEvents\EventPage\EventPageCacheUpdater;
19use MediaWiki\Extension\CampaignEvents\EventPage\EventPageDecoratorFactory;
20use MediaWiki\Extension\CampaignEvents\FrontendModules\FrontendModulesFactory;
21use MediaWiki\Extension\CampaignEvents\Hooks\CampaignEventsHookRunner;
22use MediaWiki\Extension\CampaignEvents\Invitation\InvitationListGenerator;
23use MediaWiki\Extension\CampaignEvents\Invitation\InvitationListStore;
24use MediaWiki\Extension\CampaignEvents\Invitation\PotentialInviteesFinder;
25use MediaWiki\Extension\CampaignEvents\Invitation\WorklistParser;
26use MediaWiki\Extension\CampaignEvents\Messaging\CampaignsUserMailer;
27use MediaWiki\Extension\CampaignEvents\MWEntity\CampaignsCentralUserLookup;
28use MediaWiki\Extension\CampaignEvents\MWEntity\CampaignsPageFactory;
29use MediaWiki\Extension\CampaignEvents\MWEntity\CampaignsPageFormatter;
30use MediaWiki\Extension\CampaignEvents\MWEntity\MWPermissionsLookup;
31use MediaWiki\Extension\CampaignEvents\MWEntity\PageAuthorLookup;
32use MediaWiki\Extension\CampaignEvents\MWEntity\PageURLResolver;
33use MediaWiki\Extension\CampaignEvents\MWEntity\UserLinker;
34use MediaWiki\Extension\CampaignEvents\MWEntity\WikiLookup;
35use MediaWiki\Extension\CampaignEvents\Notifications\UserNotifier;
36use MediaWiki\Extension\CampaignEvents\Organizers\OrganizersStore;
37use MediaWiki\Extension\CampaignEvents\Organizers\RoleFormatter;
38use MediaWiki\Extension\CampaignEvents\Pager\EventsPagerFactory;
39use MediaWiki\Extension\CampaignEvents\Participants\ParticipantsStore;
40use MediaWiki\Extension\CampaignEvents\Participants\RegisterParticipantCommand;
41use MediaWiki\Extension\CampaignEvents\Participants\UnregisterParticipantCommand;
42use MediaWiki\Extension\CampaignEvents\Permissions\PermissionChecker;
43use MediaWiki\Extension\CampaignEvents\PolicyMessagesLookup;
44use MediaWiki\Extension\CampaignEvents\Questions\EventAggregatedAnswersStore;
45use MediaWiki\Extension\CampaignEvents\Questions\EventQuestionsRegistry;
46use MediaWiki\Extension\CampaignEvents\Questions\EventQuestionsStore;
47use MediaWiki\Extension\CampaignEvents\Questions\ParticipantAnswersStore;
48use MediaWiki\Extension\CampaignEvents\Time\EventTimeFormatter;
49use MediaWiki\Extension\CampaignEvents\Topics\EmptyTopicRegistry;
50use MediaWiki\Extension\CampaignEvents\Topics\ITopicRegistry;
51use MediaWiki\Extension\CampaignEvents\TrackingTool\TrackingToolEventWatcher;
52use MediaWiki\Extension\CampaignEvents\TrackingTool\TrackingToolRegistry;
53use MediaWiki\Extension\CampaignEvents\TrackingTool\TrackingToolUpdater;
54use MediaWiki\Logger\LoggerFactory;
55use MediaWiki\MainConfigNames;
56use MediaWiki\MediaWikiServices;
57use MediaWiki\Registration\ExtensionRegistry;
58
59// This file is actually covered by CampaignEventsServicesTest, but it's not possible to specify a path
60// in @covers annotations (https://github.com/sebastianbergmann/phpunit/issues/3794)
61// @codeCoverageIgnoreStart
62return [
63    CampaignsDatabaseHelper::SERVICE_NAME => static function ( MediaWikiServices $services ): CampaignsDatabaseHelper {
64        return new CampaignsDatabaseHelper(
65            $services->getDBLoadBalancerFactory()
66        );
67    },
68    CampaignsPageFactory::SERVICE_NAME => static function ( MediaWikiServices $services ): CampaignsPageFactory {
69        return new CampaignsPageFactory(
70            $services->getPageStoreFactory(),
71            $services->getTitleParser(),
72            $services->getTitleFormatter()
73        );
74    },
75    CampaignsCentralUserLookup::SERVICE_NAME =>
76        static function ( MediaWikiServices $services ): CampaignsCentralUserLookup {
77            return new CampaignsCentralUserLookup(
78                $services->getCentralIdLookup(),
79                $services->getUserFactory(),
80                $services->getUserNameUtils()
81            );
82        },
83    IEventStore::STORE_SERVICE_NAME => static function ( MediaWikiServices $services ): IEventStore {
84        return new EventStore(
85            $services->get( CampaignsDatabaseHelper::SERVICE_NAME ),
86            $services->get( CampaignsPageFactory::SERVICE_NAME ),
87            $services->get( AddressStore::SERVICE_NAME ),
88            $services->get( TrackingToolUpdater::SERVICE_NAME ),
89            $services->get( EventQuestionsStore::SERVICE_NAME ),
90            $services->get( EventWikisStore::SERVICE_NAME ),
91            $services->get( EventTopicsStore::SERVICE_NAME ),
92        );
93    },
94    IEventLookup::LOOKUP_SERVICE_NAME => static function ( MediaWikiServices $services ): IEventLookup {
95        return $services->get( IEventStore::STORE_SERVICE_NAME );
96    },
97    PermissionChecker::SERVICE_NAME => static function ( MediaWikiServices $services ): PermissionChecker {
98        return new PermissionChecker(
99            $services->get( OrganizersStore::SERVICE_NAME ),
100            $services->get( PageAuthorLookup::SERVICE_NAME ),
101            $services->get( CampaignsCentralUserLookup::SERVICE_NAME ),
102            $services->get( MWPermissionsLookup::SERVICE_NAME )
103        );
104    },
105    CampaignsUserMailer::SERVICE_NAME => static function ( MediaWikiServices $services ): CampaignsUserMailer {
106        return new CampaignsUserMailer(
107            $services->getUserFactory(),
108            $services->getJobQueueGroup(),
109            new ServiceOptions(
110                CampaignsUserMailer::CONSTRUCTOR_OPTIONS,
111                $services->getMainConfig()
112            ),
113            $services->getCentralIdLookup(),
114            $services->get( CampaignsCentralUserLookup::SERVICE_NAME ),
115            $services->getUserOptionsLookup(),
116            $services->getMessageFormatterFactory()->getTextFormatter( $services->getContentLanguage()->getCode() ),
117            $services->get( PageURLResolver::SERVICE_NAME ),
118            $services->getEmailUserFactory(),
119        );
120    },
121    EventFactory::SERVICE_NAME => static function ( MediaWikiServices $services ): EventFactory {
122        return new EventFactory(
123            $services->get( CampaignsPageFactory::SERVICE_NAME ),
124            $services->get( CampaignsPageFormatter::SERVICE_NAME ),
125            $services->get( TrackingToolRegistry::SERVICE_NAME ),
126            $services->get( EventQuestionsRegistry::SERVICE_NAME ),
127            $services->get( WikiLookup::SERVICE_NAME )
128        );
129    },
130    CampaignsPageFormatter::SERVICE_NAME => static function ( MediaWikiServices $services ): CampaignsPageFormatter {
131        return new CampaignsPageFormatter(
132            $services->getTitleFormatter()
133        );
134    },
135    ParticipantsStore::SERVICE_NAME => static function ( MediaWikiServices $services ): ParticipantsStore {
136        return new ParticipantsStore(
137            $services->get( CampaignsDatabaseHelper::SERVICE_NAME ),
138            $services->get( CampaignsCentralUserLookup::SERVICE_NAME ),
139            $services->get( ParticipantAnswersStore::SERVICE_NAME )
140        );
141    },
142    OrganizersStore::SERVICE_NAME => static function ( MediaWikiServices $services ): OrganizersStore {
143        return new OrganizersStore(
144            $services->get( CampaignsDatabaseHelper::SERVICE_NAME )
145        );
146    },
147    EditEventCommand::SERVICE_NAME => static function ( MediaWikiServices $services ): EditEventCommand {
148        return new EditEventCommand(
149            $services->get( IEventStore::STORE_SERVICE_NAME ),
150            $services->get( IEventLookup::LOOKUP_SERVICE_NAME ),
151            $services->get( OrganizersStore::SERVICE_NAME ),
152            $services->get( PermissionChecker::SERVICE_NAME ),
153            $services->get( CampaignsCentralUserLookup::SERVICE_NAME ),
154            $services->get( EventPageCacheUpdater::SERVICE_NAME ),
155            $services->get( TrackingToolEventWatcher::SERVICE_NAME ),
156            $services->get( TrackingToolUpdater::SERVICE_NAME ),
157            LoggerFactory::getInstance( 'CampaignEvents' ),
158            $services->get( ParticipantAnswersStore::SERVICE_NAME ),
159            $services->get( EventAggregatedAnswersStore::SERVICE_NAME ),
160            $services->get( PageEventLookup::SERVICE_NAME )
161        );
162    },
163    DeleteEventCommand::SERVICE_NAME => static function ( MediaWikiServices $services ): DeleteEventCommand {
164        return new DeleteEventCommand(
165            $services->get( IEventStore::STORE_SERVICE_NAME ),
166            $services->get( PermissionChecker::SERVICE_NAME ),
167            $services->get( TrackingToolEventWatcher::SERVICE_NAME ),
168            $services->get( EventPageCacheUpdater::SERVICE_NAME )
169        );
170    },
171    RoleFormatter::SERVICE_NAME => static function ( MediaWikiServices $services ): RoleFormatter {
172        return new RoleFormatter(
173            $services->getMessageFormatterFactory()
174        );
175    },
176    RegisterParticipantCommand::SERVICE_NAME =>
177        static function ( MediaWikiServices $services ): RegisterParticipantCommand {
178            return new RegisterParticipantCommand(
179                $services->get( ParticipantsStore::SERVICE_NAME ),
180                $services->get( PermissionChecker::SERVICE_NAME ),
181                $services->get( CampaignsCentralUserLookup::SERVICE_NAME ),
182                $services->get( UserNotifier::SERVICE_NAME ),
183                $services->get( EventPageCacheUpdater::SERVICE_NAME ),
184                $services->get( TrackingToolEventWatcher::SERVICE_NAME )
185            );
186        },
187    UnregisterParticipantCommand::SERVICE_NAME =>
188        static function ( MediaWikiServices $services ): UnregisterParticipantCommand {
189            return new UnregisterParticipantCommand(
190                $services->get( ParticipantsStore::SERVICE_NAME ),
191                $services->get( PermissionChecker::SERVICE_NAME ),
192                $services->get( CampaignsCentralUserLookup::SERVICE_NAME ),
193                $services->get( EventPageCacheUpdater::SERVICE_NAME ),
194                $services->get( TrackingToolEventWatcher::SERVICE_NAME )
195            );
196        },
197    EventsPagerFactory::SERVICE_NAME => static function ( MediaWikiServices $services ): EventsPagerFactory {
198        return new EventsPagerFactory(
199            $services->get( CampaignsDatabaseHelper::SERVICE_NAME ),
200            $services->get( CampaignsPageFactory::SERVICE_NAME ),
201            $services->get( PageURLResolver::SERVICE_NAME ),
202            $services->getLinkBatchFactory(),
203            $services->get( UserLinker::SERVICE_NAME ),
204            $services->get( OrganizersStore::SERVICE_NAME ),
205            $services->getUserOptionsLookup(),
206            $services->get( CampaignsCentralUserLookup::SERVICE_NAME ),
207            $services->get( WikiLookup::SERVICE_NAME ),
208            $services->get( EventWikisStore::SERVICE_NAME )
209        );
210    },
211    EventPageDecoratorFactory::SERVICE_NAME =>
212        static function ( MediaWikiServices $services ): EventPageDecoratorFactory {
213            return new EventPageDecoratorFactory(
214                $services->get( PageEventLookup::SERVICE_NAME ),
215                $services->get( ParticipantsStore::SERVICE_NAME ),
216                $services->get( OrganizersStore::SERVICE_NAME ),
217                $services->get( PermissionChecker::SERVICE_NAME ),
218                $services->getMessageFormatterFactory(),
219                $services->getLinkRenderer(),
220                $services->get( CampaignsPageFactory::SERVICE_NAME ),
221                $services->get( CampaignsCentralUserLookup::SERVICE_NAME ),
222                $services->get( UserLinker::SERVICE_NAME ),
223                $services->get( EventTimeFormatter::SERVICE_NAME ),
224                $services->get( EventPageCacheUpdater::SERVICE_NAME ),
225                $services->get( EventQuestionsRegistry::SERVICE_NAME ),
226                $services->get( WikiLookup::SERVICE_NAME )
227            );
228        },
229    CampaignEventsHookRunner::SERVICE_NAME =>
230        static function ( MediaWikiServices $services ): CampaignEventsHookRunner {
231            return new CampaignEventsHookRunner( $services->getHookContainer() );
232        },
233    PolicyMessagesLookup::SERVICE_NAME => static function ( MediaWikiServices $services ): PolicyMessagesLookup {
234        return new PolicyMessagesLookup(
235            $services->get( CampaignEventsHookRunner::SERVICE_NAME )
236        );
237    },
238    PageURLResolver::SERVICE_NAME => static function ( MediaWikiServices $services ): PageURLResolver {
239        return new PageURLResolver(
240            $services->getTitleFactory()
241        );
242    },
243    PageEventLookup::SERVICE_NAME => static function ( MediaWikiServices $services ): PageEventLookup {
244        return new PageEventLookup(
245            $services->get( IEventLookup::LOOKUP_SERVICE_NAME ),
246            $services->get( CampaignsPageFactory::SERVICE_NAME ),
247            $services->getTitleFactory(),
248            ExtensionRegistry::getInstance()->isLoaded( 'Translate' )
249        );
250    },
251    PageAuthorLookup::SERVICE_NAME => static function ( MediaWikiServices $services ): PageAuthorLookup {
252        return new PageAuthorLookup(
253            $services->getRevisionStoreFactory(),
254            $services->get( CampaignsCentralUserLookup::SERVICE_NAME )
255        );
256    },
257    UserLinker::SERVICE_NAME => static function ( MediaWikiServices $services ): UserLinker {
258        return new UserLinker(
259            $services->get( CampaignsCentralUserLookup::SERVICE_NAME ),
260            $services->getMessageFormatterFactory(),
261            $services->getLinkBatchFactory()
262        );
263    },
264    FrontendModulesFactory::SERVICE_NAME => static function ( MediaWikiServices $services ): FrontendModulesFactory {
265        return new FrontendModulesFactory(
266            $services->getMessageFormatterFactory(),
267            $services->get( OrganizersStore::SERVICE_NAME ),
268            $services->get( ParticipantsStore::SERVICE_NAME ),
269            $services->get( PageURLResolver::SERVICE_NAME ),
270            $services->get( UserLinker::SERVICE_NAME ),
271            $services->get( CampaignsCentralUserLookup::SERVICE_NAME ),
272            $services->get( PermissionChecker::SERVICE_NAME ),
273            $services->get( EventTimeFormatter::SERVICE_NAME ),
274            $services->getUserFactory(),
275            $services->get( TrackingToolRegistry::SERVICE_NAME ),
276            $services->get( CampaignsUserMailer::SERVICE_NAME ),
277            $services->get( ParticipantAnswersStore::SERVICE_NAME ),
278            $services->get( EventAggregatedAnswersStore::SERVICE_NAME ),
279            $services->get( EventQuestionsRegistry::SERVICE_NAME ),
280            $services->get( CampaignEventsHookRunner::SERVICE_NAME ),
281            $services->get( WikiLookup::SERVICE_NAME )
282        );
283    },
284    AddressStore::SERVICE_NAME => static function ( MediaWikiServices $services ): AddressStore {
285        return new AddressStore(
286            $services->get( CampaignsDatabaseHelper::SERVICE_NAME )
287        );
288    },
289    TrackingToolRegistry::SERVICE_NAME => static function ( MediaWikiServices $services ): TrackingToolRegistry {
290        return new TrackingToolRegistry(
291            $services->getObjectFactory(),
292            new ServiceOptions(
293                TrackingToolRegistry::CONSTRUCTOR_OPTIONS,
294                $services->getMainConfig()
295            )
296        );
297    },
298    EventTimeFormatter::SERVICE_NAME => static function ( MediaWikiServices $services ): EventTimeFormatter {
299        return new EventTimeFormatter(
300            $services->getUserOptionsLookup()
301        );
302    },
303    UserNotifier::SERVICE_NAME => static function ( MediaWikiServices $services ): UserNotifier {
304        return new UserNotifier(
305            ExtensionRegistry::getInstance()->isLoaded( 'Echo' )
306        );
307    },
308    MWPermissionsLookup::SERVICE_NAME => static function ( MediaWikiServices $services ): MWPermissionsLookup {
309        return new MWPermissionsLookup(
310            $services->getUserFactory(),
311            $services->getUserNameUtils()
312        );
313    },
314    EventPageCacheUpdater::SERVICE_NAME => static function ( MediaWikiServices $services ): EventPageCacheUpdater {
315        return new EventPageCacheUpdater(
316            $services->getHtmlCacheUpdater()
317        );
318    },
319    TrackingToolEventWatcher::SERVICE_NAME =>
320        static function ( MediaWikiServices $services ): TrackingToolEventWatcher {
321            return new TrackingToolEventWatcher(
322                $services->get( TrackingToolRegistry::SERVICE_NAME ),
323                $services->get( TrackingToolUpdater::SERVICE_NAME ),
324                LoggerFactory::getInstance( 'CampaignEvents' )
325            );
326        },
327    TrackingToolUpdater::SERVICE_NAME => static function ( MediaWikiServices $services ): TrackingToolUpdater {
328        return new TrackingToolUpdater(
329            $services->get( CampaignsDatabaseHelper::SERVICE_NAME )
330        );
331    },
332    EventQuestionsRegistry::SERVICE_NAME => static function ( MediaWikiServices $services ): EventQuestionsRegistry {
333        return new EventQuestionsRegistry(
334            $services->getMainConfig()->get( 'CampaignEventsEnableWikimediaParticipantQuestions' )
335        );
336    },
337    EventQuestionsStore::SERVICE_NAME => static function ( MediaWikiServices $services ): EventQuestionsStore {
338        return new EventQuestionsStore(
339            $services->get( CampaignsDatabaseHelper::SERVICE_NAME )
340        );
341    },
342    ParticipantAnswersStore::SERVICE_NAME => static function ( MediaWikiServices $services ): ParticipantAnswersStore {
343        return new ParticipantAnswersStore(
344            $services->get( CampaignsDatabaseHelper::SERVICE_NAME )
345        );
346    },
347    EventAggregatedAnswersStore::SERVICE_NAME => static function (
348        MediaWikiServices $services
349    ): EventAggregatedAnswersStore {
350        return new EventAggregatedAnswersStore(
351            $services->get( CampaignsDatabaseHelper::SERVICE_NAME )
352        );
353    },
354    PotentialInviteesFinder::SERVICE_NAME => static function ( MediaWikiServices $services ): PotentialInviteesFinder {
355        return new PotentialInviteesFinder(
356            $services->getRevisionStoreFactory(),
357            $services->getConnectionProvider(),
358            $services->getNameTableStoreFactory(),
359            $services->getMainConfig()->get( MainConfigNames::BlockTargetMigrationStage ),
360            $services->getUserOptionsLookup()
361        );
362    },
363    WorklistParser::SERVICE_NAME => static function ( MediaWikiServices $services ): WorklistParser {
364        return new WorklistParser(
365            $services->getPageStoreFactory()
366        );
367    },
368    InvitationListGenerator::SERVICE_NAME => static function ( MediaWikiServices $services ): InvitationListGenerator {
369        return new InvitationListGenerator(
370            $services->get( PermissionChecker::SERVICE_NAME ),
371            $services->get( CampaignsPageFactory::SERVICE_NAME ),
372            $services->get( PageEventLookup::SERVICE_NAME ),
373            $services->get( OrganizersStore::SERVICE_NAME ),
374            $services->get( CampaignsCentralUserLookup::SERVICE_NAME ),
375            $services->get( InvitationListStore::SERVICE_NAME ),
376            $services->getJobQueueGroup()
377        );
378    },
379    InvitationListStore::SERVICE_NAME => static function ( MediaWikiServices $services ): InvitationListStore {
380        return new InvitationListStore(
381            $services->get( CampaignsDatabaseHelper::SERVICE_NAME ),
382            $services->getPageStoreFactory()
383        );
384    },
385    WikiLookup::SERVICE_NAME => static function ( MediaWikiServices $services ): WikiLookup {
386        global $wgConf;
387        return new WikiLookup(
388            $wgConf,
389            $services->getMainWANObjectCache(),
390            RequestContext::getMain(),
391            RequestContext::getMain()->getLanguage()->getCode()
392        );
393    },
394    EventWikisStore::SERVICE_NAME => static function ( MediaWikiServices $services ): EventWikisStore {
395        return new EventWikisStore(
396            $services->get( CampaignsDatabaseHelper::SERVICE_NAME ),
397            $services->getMainConfig()->get( 'CampaignEventsEnableEventWikis' )
398        );
399    },
400    ITopicRegistry::SERVICE_NAME => static function (): ITopicRegistry {
401        return new EmptyTopicRegistry();
402    },
403    EventTopicsStore::SERVICE_NAME => static function ( MediaWikiServices $services ): EventTopicsStore {
404        return new EventTopicsStore(
405            $services->get( CampaignsDatabaseHelper::SERVICE_NAME ),
406            $services->getMainConfig()->get( 'CampaignEventsEnableEventTopics' )
407        );
408    },
409];