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