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