Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 415
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3use Flow\Data\FlowObjectCache;
4use Flow\Data\Index\TopKIndex;
5use Flow\Data\Index\UniqueFeatureIndex;
6use Flow\Data\Listener\EditCountListener;
7use Flow\Data\Mapper\BasicObjectMapper;
8use Flow\Data\Mapper\CachingObjectMapper;
9use Flow\Data\ObjectManager;
10use Flow\Data\Storage\BasicDbStorage;
11use Flow\Data\Storage\PostRevisionStorage;
12use Flow\Data\Storage\PostRevisionTopicHistoryStorage;
13use Flow\Data\Storage\TopicListStorage;
14use Flow\DbFactory;
15use Flow\FlowActions;
16use Flow\Formatter\CategoryViewerFormatter;
17use Flow\Formatter\ChangesListFormatter;
18use Flow\Formatter\CheckUserFormatter;
19use Flow\Formatter\ContributionsFormatter;
20use Flow\Formatter\FeedItemFormatter;
21use Flow\Formatter\IRCLineUrlFormatter;
22use Flow\Formatter\RevisionDiffViewFormatter;
23use Flow\Formatter\RevisionFormatterFactory;
24use Flow\Formatter\RevisionUndoViewFormatter;
25use Flow\Formatter\RevisionViewFormatter;
26use Flow\Formatter\TocTopicListFormatter;
27use Flow\Formatter\TopicFormatter;
28use Flow\Formatter\TopicListFormatter;
29use Flow\Import\ArchiveNameHelper;
30use Flow\Import\OptInController;
31use Flow\Model\TopicListEntry;
32use Flow\Model\URLReference;
33use Flow\Model\WikiReference;
34use Flow\Model\Workflow;
35use Flow\Notifications\Controller as NotificationsController;
36use Flow\OccupationController;
37use Flow\Parsoid\ContentFixer;
38use Flow\Parsoid\Fixer\BadImageRemover;
39use Flow\Parsoid\Fixer\BaseHrefFixer;
40use Flow\Parsoid\Fixer\ExtLinkFixer;
41use Flow\Parsoid\Fixer\WikiLinkFixer;
42use Flow\Repository\TreeRepository;
43use Flow\Repository\UserName\OneStepUserNameQuery;
44use Flow\Repository\UserNameBatch;
45use Flow\RevisionActionPermissions;
46use Flow\TalkpageManager;
47use Flow\TemplateHelper;
48use Flow\Templating;
49use Flow\UrlGenerator;
50use Flow\WatchedTopicItems;
51use MediaWiki\Config\ServiceOptions;
52use MediaWiki\Context\RequestContext;
53use MediaWiki\Logger\LoggerFactory;
54use MediaWiki\MediaWikiServices;
55use MediaWiki\User\User;
56use Psr\Log\LoggerInterface;
57
58/**
59 * Service wiring for Flow services
60 *
61 * Currently most services are defined in and retrieved
62 * from the flow container, but they should be moved
63 * here, see T170330.
64 *
65 * PHPUnit doesn't understand code coverage for code outside of classes/functions,
66 * like service wiring files.
67 * @codeCoverageIgnore
68 *
69 * @author DannyS712
70 *
71 * @phpcs-require-sorted-array
72 */
73return [
74    'FlowActions' => static function ( MediaWikiServices $services ): FlowActions {
75        // Flow configuration
76        return new FlowActions(
77            require __DIR__ . '/../FlowActions.php'
78        );
79    },
80
81    'FlowCache' => static function ( MediaWikiServices $services ): FlowObjectCache {
82        // New storage implementation
83        return new FlowObjectCache(
84            $services->getMainWANObjectCache(),
85            $services->getMainConfig()->get( 'FlowCacheTime' )
86        );
87    },
88
89    'FlowCategoryViewerFormatter' => static function (
90        MediaWikiServices $services
91    ): CategoryViewerFormatter {
92        return new CategoryViewerFormatter(
93            $services->getService( 'FlowPermissions' )
94        );
95    },
96
97    'FlowChangesListFormatter' => static function (
98        MediaWikiServices $services
99    ): ChangesListFormatter {
100        return new ChangesListFormatter(
101            $services->getService( 'FlowPermissions' ),
102            $services->getService( 'FlowRevisionFormatterFactory' )->create()
103        );
104    },
105
106    'FlowCheckUserFormatter' => static function (
107        MediaWikiServices $services
108    ): CheckUserFormatter {
109        return new CheckUserFormatter(
110            $services->getService( 'FlowPermissions' ),
111            $services->getService( 'FlowRevisionFormatterFactory' )->create()
112        );
113    },
114
115    'FlowContributionsFormatter' => static function (
116        MediaWikiServices $services
117    ): ContributionsFormatter {
118        return new ContributionsFormatter(
119            $services->getService( 'FlowPermissions' ),
120            $services->getService( 'FlowRevisionFormatterFactory' )->create()
121        );
122    },
123
124    'FlowDbFactory' => static function ( MediaWikiServices $services ): DbFactory {
125        // Always returns the correct database for flow storage
126        $config = $services->getMainConfig();
127        return new DbFactory(
128            $services->getDBLoadBalancerFactory(),
129            $config->get( 'FlowDefaultWikiDb' ),
130            $config->get( 'FlowCluster' )
131        );
132    },
133
134    'FlowDefaultLogger' => static function ( MediaWikiServices $services ): LoggerInterface {
135        return LoggerFactory::getInstance( 'Flow' );
136    },
137
138    'FlowDeferredQueue' => static function ( MediaWikiServices $services ): SplQueue {
139        // Queue of callbacks to run by DeferredUpdates, but only
140        // on successful commit
141        return new SplQueue;
142    },
143
144    'FlowEditCountListener' => static function ( MediaWikiServices $services ): EditCountListener {
145        return new EditCountListener(
146            $services->getService( 'FlowActions' )
147        );
148    },
149
150    'FlowFeedItemFormatter' => static function (
151        MediaWikiServices $services
152    ): FeedItemFormatter {
153        return new FeedItemFormatter(
154            $services->getService( 'FlowPermissions' ),
155            $services->getService( 'FlowRevisionFormatterFactory' )->create()
156        );
157    },
158
159    'FlowIRCLineUrlFormatter' => static function (
160        MediaWikiServices $services
161    ): IRCLineUrlFormatter {
162        return new IRCLineUrlFormatter(
163            $services->getService( 'FlowPermissions' ),
164            $services->getService( 'FlowRevisionFormatterFactory' )->create()
165        );
166    },
167
168    'FlowNotificationsController' => static function (
169        MediaWikiServices $services
170    ): NotificationsController {
171        return new NotificationsController(
172            new ServiceOptions( NotificationsController::CONSTRUCTOR_OPTIONS, $services->getMainConfig() ),
173            $services->getContentLanguage(),
174            $services->getService( 'FlowTreeRepository' )
175        );
176    },
177
178    'FlowOptInController' => static function (
179        MediaWikiServices $services
180    ): OptInController {
181        /** @var OccupationController $occupationController */
182        $occupationController = $services->getService( 'FlowTalkpageManager' );
183        $archiveNameHelper = new ArchiveNameHelper();
184        return new OptInController(
185            $occupationController,
186            $services->getService( 'FlowNotificationsController' ),
187            $archiveNameHelper,
188            $services->getService( 'FlowDefaultLogger' ),
189            $occupationController->getTalkpageManager()
190        );
191    },
192
193    'FlowPermissions' => static function ( MediaWikiServices $services ): RevisionActionPermissions {
194        return new RevisionActionPermissions(
195            $services->getService( 'FlowActions' ),
196            $services->getService( 'FlowUser' )
197        );
198    },
199
200    'FlowPostRevisionStorage' => static function ( MediaWikiServices $services ): PostRevisionStorage {
201        return new PostRevisionStorage(
202            $services->getService( 'FlowDbFactory' ),
203            $services->getMainConfig()->get( 'FlowExternalStore' ),
204            $services->getService( 'FlowTreeRepository' )
205        );
206    },
207
208    'FlowPostRevisionTopicHistoryStorage' => static function (
209        MediaWikiServices $services
210    ): PostRevisionTopicHistoryStorage {
211        return new PostRevisionTopicHistoryStorage(
212            $services->getService( 'FlowPostRevisionStorage' ),
213            $services->getService( 'FlowTreeRepository' )
214        );
215    },
216
217    'FlowRevisionDiffViewFormatter' => static function (
218        MediaWikiServices $services
219    ): RevisionDiffViewFormatter {
220        return new RevisionDiffViewFormatter(
221            $services->getService( 'FlowRevisionViewFormatter' ),
222            $services->getService( 'FlowUrlGenerator' )
223        );
224    },
225
226    'FlowRevisionFormatterFactory' => static function (
227        MediaWikiServices $services
228    ): RevisionFormatterFactory {
229        global $wgFlowMaxThreadingDepth;
230
231        return new RevisionFormatterFactory(
232            $services->getService( 'FlowPermissions' ),
233            $services->getService( 'FlowTemplating' ),
234            $services->getService( 'FlowUrlGenerator' ),
235            $services->getService( 'FlowUserNameRepository' ),
236            $wgFlowMaxThreadingDepth
237        );
238    },
239
240    'FlowRevisionUndoViewFormatter' => static function (
241        MediaWikiServices $services
242    ): RevisionUndoViewFormatter {
243        return new RevisionUndoViewFormatter(
244            $services->getService( 'FlowRevisionViewFormatter' )
245        );
246    },
247
248    'FlowRevisionViewFormatter' => static function (
249        MediaWikiServices $services
250    ): RevisionViewFormatter {
251        return new RevisionViewFormatter(
252            $services->getService( 'FlowUrlGenerator' ),
253            $services->getService( 'FlowRevisionFormatterFactory' )->create()
254        );
255    },
256
257    'FlowStorage.TopicList' => static function ( MediaWikiServices $services ): ObjectManager {
258        // Lookup from topic_id to its owning board id
259        $topicListPrimaryIndex = new UniqueFeatureIndex(
260            $services->getService( 'FlowCache' ),
261            $services->getService( 'FlowStorage.TopicList.Backend' ),
262            $services->getService( 'FlowStorage.TopicList.Mapper' ),
263            'flow_topic_list:topic',
264            [ 'topic_id' ]
265        );
266        // Lookup from board to contained topics
267        // In reverse order by topic_id
268        $topicListReverseLookupIndex = new TopKIndex(
269            $services->getService( 'FlowCache' ),
270            $services->getService( 'FlowStorage.TopicList.Backend' ),
271            $services->getService( 'FlowStorage.TopicList.Mapper' ),
272            'flow_topic_list:list',
273            [ 'topic_list_id' ],
274            [ 'sort' => 'topic_id' ]
275        );
276        $indexes = [
277            $topicListPrimaryIndex,
278            $topicListReverseLookupIndex,
279            $services->getService( 'FlowStorage.TopicList.LastUpdatedIndex' )
280        ];
281        return new ObjectManager(
282            $services->getService( 'FlowStorage.TopicList.Mapper' ),
283            $services->getService( 'FlowStorage.TopicList.Backend' ),
284            $services->getService( 'FlowDbFactory' ),
285            $indexes
286        );
287    },
288
289    'FlowStorage.TopicList.Backend' => static function ( MediaWikiServices $services ): TopicListStorage {
290        return new TopicListStorage(
291            // factory and table
292            $services->getService( 'FlowDbFactory' ),
293            'flow_topic_list',
294            [ 'topic_list_id', 'topic_id' ]
295        );
296    },
297
298    'FlowStorage.TopicList.LastUpdatedIndex' => static function ( MediaWikiServices $services ): TopKIndex {
299        // In reverse order by topic last_updated
300        return new TopKIndex(
301            $services->getService( 'FlowCache' ),
302            $services->getService( 'FlowStorage.TopicList.Backend' ),
303            $services->getService( 'FlowStorage.TopicList.Mapper' ),
304            'flow_topic_list_last_updated:list',
305            [ 'topic_list_id' ],
306            [
307                'sort' => 'workflow_last_update_timestamp',
308                'order' => 'desc'
309            ]
310        );
311    },
312
313    'FlowStorage.TopicList.Mapper' => static function ( MediaWikiServices $services ): BasicObjectMapper {
314        // Must be BasicObjectMapper, due to variance in when
315        // we have workflow_last_update_timestamp
316        return BasicObjectMapper::model(
317            TopicListEntry::class
318        );
319    },
320
321    'FlowStorage.UrlReference' => static function ( MediaWikiServices $services ): ObjectManager {
322        $urlReferenceMapper = BasicObjectMapper::model(
323            URLReference::class
324        );
325        $urlReferenceBackend = new BasicDbStorage(
326            // factory and table
327            $services->getService( 'FlowDbFactory' ),
328            'flow_ext_ref',
329            [
330                'ref_src_wiki',
331                'ref_src_namespace',
332                'ref_src_title',
333                'ref_src_object_id',
334                'ref_type',
335                'ref_target',
336            ]
337        );
338        $urlReferenceSourceLookupIndex = new TopKIndex(
339            $services->getService( 'FlowCache' ),
340            $urlReferenceBackend,
341            $urlReferenceMapper,
342            'flow_ref:url:by-source:v3',
343            [
344                'ref_src_wiki',
345                'ref_src_namespace',
346                'ref_src_title',
347            ],
348            [
349                'order' => 'ASC',
350                'sort' => 'ref_src_object_id',
351            ]
352        );
353        $urlReferenceRevisionLookupIndex = new TopKIndex(
354            $services->getService( 'FlowCache' ),
355            $urlReferenceBackend,
356            $urlReferenceMapper,
357            'flow_ref:url:by-revision:v3',
358            [
359                'ref_src_wiki',
360                'ref_src_object_type',
361                'ref_src_object_id',
362            ],
363            [
364                'order' => 'ASC',
365                'sort' => [ 'ref_target' ],
366            ]
367        );
368        $indexes = [
369            $urlReferenceSourceLookupIndex,
370            $urlReferenceRevisionLookupIndex,
371        ];
372        return new ObjectManager(
373            $urlReferenceMapper,
374            $urlReferenceBackend,
375            $services->getService( 'FlowDbFactory' ),
376            $indexes,
377            []
378        );
379    },
380
381    'FlowStorage.WikiReference' => static function ( MediaWikiServices $services ): ObjectManager {
382        $wikiReferenceMapper = BasicObjectMapper::model(
383            WikiReference::class
384        );
385        $wikiReferenceBackend = new BasicDbStorage(
386            $services->getService( 'FlowDbFactory' ),
387            'flow_wiki_ref',
388            [
389                'ref_src_wiki',
390                'ref_src_namespace',
391                'ref_src_title',
392                'ref_src_object_id',
393                'ref_type',
394                'ref_target_namespace',
395                'ref_target_title'
396            ]
397        );
398        $wikiReferenceSourceLookupIndex = new TopKIndex(
399            $services->getService( 'FlowCache' ),
400            $wikiReferenceBackend,
401            $wikiReferenceMapper,
402            'flow_ref:wiki:by-source:v3',
403            [
404                'ref_src_wiki',
405                'ref_src_namespace',
406                'ref_src_title',
407            ],
408            [
409                'order' => 'ASC',
410                'sort' => 'ref_src_object_id',
411            ]
412        );
413        $wikiReferenceRevisionLookupIndex = new TopKIndex(
414            $services->getService( 'FlowCache' ),
415            $wikiReferenceBackend,
416            $wikiReferenceMapper,
417            'flow_ref:wiki:by-revision:v3',
418            [
419                'ref_src_wiki',
420                'ref_src_object_type',
421                'ref_src_object_id',
422            ],
423            [
424                'order' => 'ASC',
425                'sort' => [ 'ref_target_namespace', 'ref_target_title' ],
426            ]
427        );
428        $indexes = [
429            $wikiReferenceSourceLookupIndex,
430            $wikiReferenceRevisionLookupIndex,
431        ];
432        return new ObjectManager(
433            $wikiReferenceMapper,
434            $wikiReferenceBackend,
435            $services->getService( 'FlowDbFactory' ),
436            $indexes,
437            []
438        );
439    },
440
441    'FlowStorage.WorkflowMapper' => static function (
442        MediaWikiServices $services
443    ): CachingObjectMapper {
444        return CachingObjectMapper::model(
445            Workflow::class,
446            [ 'workflow_id' ]
447        );
448    },
449
450    'FlowTalkpageManager' => static function ( MediaWikiServices $services ): OccupationController {
451        return new TalkpageManager( $services->getUserGroupManager() );
452    },
453
454    'FlowTemplateHandler' => static function ( MediaWikiServices $services ): TemplateHelper {
455        return new TemplateHelper(
456            __DIR__ . '/../handlebars',
457            $services->getMainConfig()->get( 'FlowServerCompileTemplates' )
458        );
459    },
460
461    'FlowTemplating' => static function ( MediaWikiServices $services ): Templating {
462        global $wgArticlePath;
463
464        $wikiLinkFixer = new WikiLinkFixer(
465            $services->getLinkBatchFactory()->newLinkBatch()
466        );
467        $badImageRemover = new BadImageRemover(
468            [ $services->getBadFileLookup(), 'isBadFile' ]
469        );
470        $contextFixer = new ContentFixer(
471            $wikiLinkFixer,
472            $badImageRemover,
473            new BaseHrefFixer( $wgArticlePath, $services->getUrlUtils() ),
474            new ExtLinkFixer( $services->getUrlUtils() )
475        );
476
477        return new Templating(
478            $services->getService( 'FlowUserNameRepository' ),
479            $contextFixer,
480            $services->getService( 'FlowPermissions' )
481        );
482    },
483
484    'FlowTocTopicListFormatter' => static function (
485        MediaWikiServices $services
486    ): TocTopicListFormatter {
487        return new TocTopicListFormatter(
488            $services->getService( 'FlowTemplating' )
489        );
490    },
491
492    'FlowTopicFormatter' => static function (
493        MediaWikiServices $services
494    ): TopicFormatter {
495        return new TopicFormatter(
496            $services->getService( 'FlowUrlGenerator' ),
497            $services->getService( 'FlowRevisionFormatterFactory' )->create()
498        );
499    },
500
501    'FlowTopicListFormatter' => static function (
502        MediaWikiServices $services
503    ): TopicListFormatter {
504        return new TopicListFormatter(
505            $services->getService( 'FlowUrlGenerator' ),
506            $services->getService( 'FlowRevisionFormatterFactory' )->create()
507        );
508    },
509
510    'FlowTreeRepository' => static function ( MediaWikiServices $services ): TreeRepository {
511        // Database Access Layer external from main implementation
512        return new TreeRepository(
513            $services->getService( 'FlowDbFactory' ),
514            $services->getService( 'FlowCache' )
515        );
516    },
517
518    'FlowUrlGenerator' => static function ( MediaWikiServices $services ): UrlGenerator {
519        return new UrlGenerator(
520            $services->getService( 'FlowStorage.WorkflowMapper' )
521        );
522    },
523
524    'FlowUser' => static function ( MediaWikiServices $services ): User {
525        if ( defined( 'RUN_MAINTENANCE_IF_MAIN' ) ) {
526            return new User;
527        } else {
528            return RequestContext::getMain()->getUser();
529        }
530    },
531
532    'FlowUserNameRepository' => static function ( MediaWikiServices $services ): UserNameBatch {
533        return new UserNameBatch(
534            new OneStepUserNameQuery(
535                $services->getService( 'FlowDbFactory' ),
536                $services->getHideUserUtils()
537            )
538        );
539    },
540
541    'FlowWatchedTopicItems' => static function ( MediaWikiServices $services ): WatchedTopicItems {
542        return new WatchedTopicItems(
543            $services->getService( 'FlowUser' ),
544            $services->getConnectionProvider()->getReplicaDatabase()
545        );
546    },
547
548];