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/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21namespace MediaWiki\Extension\MediaModeration;
22
23use MediaWiki\Config\ServiceOptions;
24use MediaWiki\Context\DerivativeContext;
25use MediaWiki\Context\RequestContext;
26use MediaWiki\Extension\MediaModeration\PeriodicMetrics\MediaModerationMetricsFactory;
27use MediaWiki\Extension\MediaModeration\PhotoDNA\IMediaModerationPhotoDNAServiceProvider;
28use MediaWiki\Extension\MediaModeration\Services\MediaModerationDatabaseLookup;
29use MediaWiki\Extension\MediaModeration\Services\MediaModerationDatabaseManager;
30use MediaWiki\Extension\MediaModeration\Services\MediaModerationEmailer;
31use MediaWiki\Extension\MediaModeration\Services\MediaModerationFileFactory;
32use MediaWiki\Extension\MediaModeration\Services\MediaModerationFileLookup;
33use MediaWiki\Extension\MediaModeration\Services\MediaModerationFileProcessor;
34use MediaWiki\Extension\MediaModeration\Services\MediaModerationFileScanner;
35use MediaWiki\Extension\MediaModeration\Services\MediaModerationImageContentsLookup;
36use MediaWiki\Extension\MediaModeration\Services\MediaModerationMockPhotoDNAServiceProvider;
37use MediaWiki\Extension\MediaModeration\Services\MediaModerationPhotoDNAServiceProvider;
38use MediaWiki\Logger\LoggerFactory;
39use MediaWiki\MediaWikiServices;
40
41// PHP unit does not understand code coverage for this file
42// as the @covers annotation cannot cover a specific file
43// This is fully tested in ServiceWiringTest.php
44// @codeCoverageIgnoreStart
45
46return [
47    'MediaModerationDatabaseLookup' => static function (
48        MediaWikiServices $services
49    ): MediaModerationDatabaseLookup {
50        return new MediaModerationDatabaseLookup(
51            $services->getDBLoadBalancerFactory()
52        );
53    },
54    'MediaModerationDatabaseManager' => static function (
55        MediaWikiServices $services
56    ): MediaModerationDatabaseManager {
57        return new MediaModerationDatabaseManager(
58            $services->getDBLoadBalancerFactory()->getPrimaryDatabase( 'virtual-mediamoderation' ),
59            $services->getService( 'MediaModerationDatabaseLookup' )
60        );
61    },
62    'MediaModerationFileProcessor' => static function (
63        MediaWikiServices $services
64    ): MediaModerationFileProcessor {
65        return new MediaModerationFileProcessor(
66            $services->getService( 'MediaModerationDatabaseManager' ),
67            $services->getMediaHandlerFactory(),
68            LoggerFactory::getInstance( 'mediamoderation' )
69        );
70    },
71    'MediaModerationFileFactory' => static function (
72        MediaWikiServices $services
73    ): MediaModerationFileFactory {
74        return new MediaModerationFileFactory(
75            $services->getRepoGroup()->getLocalRepo()
76        );
77    },
78    'MediaModerationFileLookup' => static function (
79        MediaWikiServices $services
80    ): MediaModerationFileLookup {
81        return new MediaModerationFileLookup(
82            $services->getRepoGroup()->getLocalRepo(),
83            $services->get( 'MediaModerationFileFactory' )
84        );
85    },
86    'MediaModerationMetricsFactory' => static function (
87        MediaWikiServices $services
88    ): MediaModerationMetricsFactory {
89        return new MediaModerationMetricsFactory(
90            $services->getDBLoadBalancerFactory()->getReplicaDatabase( 'virtual-mediamoderation' ),
91        );
92    },
93    'MediaModerationPhotoDNAServiceProvider' => static function (
94        MediaWikiServices $services
95    ): IMediaModerationPhotoDNAServiceProvider {
96        $config = $services->getConfigFactory()->makeConfig( 'MediaModeration' );
97        // If we are in developer mode, and the subscription key or the URL are not
98        // configured, then use the mock API.
99        if ( $config->get( 'MediaModerationDeveloperMode' ) &&
100            (
101                !$config->get( 'MediaModerationPhotoDNASubscriptionKey' ) ||
102                !$config->get( 'MediaModerationPhotoDNAUrl' )
103            )
104        ) {
105            return $services->get( '_MediaModerationMockPhotoDNAServiceProvider' );
106        }
107        return $services->get( '_MediaModerationPhotoDNAServiceProviderProduction' );
108    },
109    '_MediaModerationMockPhotoDNAServiceProvider' => static function (
110        MediaWikiServices $services
111    ): MediaModerationMockPhotoDNAServiceProvider {
112        $mockFiles = $services->getMainConfig()->get( 'MediaModerationPhotoDNAMockServiceFiles' );
113        return new MediaModerationMockPhotoDNAServiceProvider(
114            $mockFiles['FilesToIsMatchMap'] ?? [],
115            $mockFiles['FilesToStatusCodeMap'] ?? []
116        );
117    },
118    '_MediaModerationPhotoDNAServiceProviderProduction' => static function (
119        MediaWikiServices $services
120    ): MediaModerationPhotoDNAServiceProvider {
121        return new MediaModerationPhotoDNAServiceProvider(
122            new ServiceOptions(
123                MediaModerationPhotoDNAServiceProvider::CONSTRUCTOR_OPTIONS,
124                $services->getMainConfig(),
125            ),
126            $services->getHttpRequestFactory(),
127            $services->getStatsFactory(),
128            $services->get( 'MediaModerationImageContentsLookup' ),
129            $services->getFormatterFactory()->getStatusFormatter( RequestContext::getMain() )
130        );
131    },
132    'MediaModerationImageContentsLookup' => static function (
133        MediaWikiServices $services
134    ): MediaModerationImageContentsLookup {
135        return new MediaModerationImageContentsLookup(
136            new ServiceOptions(
137                MediaModerationImageContentsLookup::CONSTRUCTOR_OPTIONS,
138                $services->getMainConfig(),
139            ),
140            $services->getRepoGroup()->getLocalRepo()->getBackend(),
141            $services->getStatsFactory(),
142            $services->getMimeAnalyzer(),
143            $services->getRepoGroup()->getLocalRepo(),
144            $services->getHttpRequestFactory()
145        );
146    },
147    'MediaModerationFileScanner' => static function (
148        MediaWikiServices $services
149    ): MediaModerationFileScanner {
150        return new MediaModerationFileScanner(
151            $services->get( 'MediaModerationDatabaseLookup' ),
152            $services->get( 'MediaModerationDatabaseManager' ),
153            $services->get( 'MediaModerationFileLookup' ),
154            $services->get( 'MediaModerationFileProcessor' ),
155            $services->get( 'MediaModerationPhotoDNAServiceProvider' ),
156            $services->get( 'MediaModerationEmailer' ),
157            $services->getFormatterFactory()->getStatusFormatter( RequestContext::getMain() ),
158            $services->getStatsFactory(),
159            LoggerFactory::getInstance( 'mediamoderation' )
160        );
161    },
162    'MediaModerationEmailer' => static function (
163        MediaWikiServices $services
164    ): MediaModerationEmailer {
165        // The emails sent by this service should be in English.
166        $messageLocalizer = new DerivativeContext( RequestContext::getMain() );
167        $messageLocalizer->setLanguage( 'en' );
168        return new MediaModerationEmailer(
169            new ServiceOptions(
170                MediaModerationEmailer::CONSTRUCTOR_OPTIONS,
171                $services->getMainConfig(),
172            ),
173            $services->getEmailer(),
174            $services->get( 'MediaModerationFileLookup' ),
175            $messageLocalizer,
176            $services->getLanguageFactory()->getLanguage( 'en' ),
177            LoggerFactory::getInstance( 'mediamoderation' )
178        );
179    },
180];
181// @codeCoverageIgnoreEnd