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 | * Services for CirrusSearch extensions |
4 | */ |
5 | |
6 | use CirrusSearch\CirrusSearch; |
7 | use CirrusSearch\CirrusSearchHookRunner; |
8 | use CirrusSearch\Connection; |
9 | use CirrusSearch\EventBusWeightedTagSerializer; |
10 | use CirrusSearch\EventBusWeightedTagsUpdater; |
11 | use CirrusSearch\InterwikiResolver; |
12 | use CirrusSearch\InterwikiResolverFactory; |
13 | use CirrusSearch\Profile\SearchProfileServiceFactory; |
14 | use CirrusSearch\Query\DeepcatFeature; |
15 | use CirrusSearch\SearchConfig; |
16 | use CirrusSearch\Updater; |
17 | use CirrusSearch\WeightedTagsUpdater; |
18 | use MediaWiki\Extension\EventBus\Serializers\EventSerializer; |
19 | use MediaWiki\Extension\EventBus\Serializers\MediaWiki\PageEntitySerializer; |
20 | use MediaWiki\Http\Telemetry; |
21 | use MediaWiki\MediaWikiServices; |
22 | use MediaWiki\Registration\ExtensionRegistry; |
23 | use MediaWiki\Sparql\SparqlClient; |
24 | |
25 | // PHP unit does not understand code coverage for this file |
26 | // as the @covers annotation cannot cover a specific file |
27 | // This is fully tested in ServiceWiringTest.php |
28 | // @codeCoverageIgnoreStart |
29 | |
30 | return [ |
31 | 'CirrusSearch' => static function ( MediaWikiServices $services ): CirrusSearch { |
32 | return new CirrusSearch(); |
33 | }, |
34 | |
35 | // SPARQL client for deep category search |
36 | 'CirrusCategoriesClient' => static function ( MediaWikiServices $services ): SparqlClient { |
37 | $config = $services->getMainConfig(); |
38 | $client = new SparqlClient( $config->get( 'CirrusSearchCategoryEndpoint' ), |
39 | $services->getHttpRequestFactory() ); |
40 | $client->setTimeout( DeepcatFeature::TIMEOUT ); |
41 | $client->setClientOptions( [ |
42 | 'userAgent' => DeepcatFeature::USER_AGENT, |
43 | ] ); |
44 | return $client; |
45 | }, |
46 | InterwikiResolver::SERVICE => static function ( MediaWikiServices $services ): InterwikiResolver { |
47 | $config = $services->getConfigFactory() |
48 | ->makeConfig( 'CirrusSearch' ); |
49 | $client = $services->getHttpRequestFactory()->createMultiClient( [ |
50 | 'connTimeout' => $config->get( 'CirrusSearchInterwikiHTTPConnectTimeout' ), |
51 | 'reqTimeout' => $config->get( 'CirrusSearchInterwikiHTTPTimeout' ) |
52 | ] ); |
53 | return InterwikiResolverFactory::build( |
54 | /** @phan-suppress-next-line PhanTypeMismatchArgumentSuperType $config is actually a SearchConfig */ |
55 | $config, |
56 | $services->getMainWANObjectCache(), |
57 | $services->getInterwikiLookup(), |
58 | $services->getExtensionRegistry(), |
59 | $client |
60 | ); |
61 | }, |
62 | SearchProfileServiceFactory::SERVICE_NAME => static function ( MediaWikiServices $services ): SearchProfileServiceFactory { |
63 | $config = $services->getConfigFactory() |
64 | ->makeConfig( 'CirrusSearch' ); |
65 | return new SearchProfileServiceFactory( $services->getService( InterwikiResolver::SERVICE ), |
66 | /** @phan-suppress-next-line PhanTypeMismatchArgumentSuperType $config is actually a SearchConfig */ |
67 | $config, |
68 | $services->getLocalServerObjectCache(), |
69 | new CirrusSearchHookRunner( $services->getHookContainer() ), |
70 | $services->getUserOptionsLookup(), |
71 | ExtensionRegistry::getInstance() |
72 | ); |
73 | }, |
74 | WeightedTagsUpdater::SERVICE => static function ( MediaWikiServices $services ): WeightedTagsUpdater { |
75 | /** |
76 | * @var SearchConfig $searchConfig |
77 | */ |
78 | $searchConfig = $services->getConfigFactory()->makeConfig( 'CirrusSearch' ); |
79 | |
80 | if ( $searchConfig->get( 'CirrusSearchEnableEventBusWeightedTags' ) ) { |
81 | $eventBusFactory = $services->getService( 'EventBus.EventBusFactory' ); |
82 | |
83 | $mainConfig = $services->getMainConfig(); |
84 | $globalIdGenerator = $services->getGlobalIdGenerator(); |
85 | |
86 | $eventSerializer = new EventSerializer( $mainConfig, $globalIdGenerator, Telemetry::getInstance() ); |
87 | $pageEntitySerializer = new PageEntitySerializer( $mainConfig, $services->getTitleFormatter() ); |
88 | $weightedTagSerializer = new EventBusWeightedTagSerializer( $eventSerializer, $pageEntitySerializer ); |
89 | $wikiPageFactory = $services->getWikiPageFactory(); |
90 | |
91 | return new EventBusWeightedTagsUpdater( $eventBusFactory, $weightedTagSerializer, $wikiPageFactory ); |
92 | } |
93 | |
94 | /** @phan-suppress-next-line PhanTypeMismatchArgumentSuperType $config is actually a SearchConfig */ |
95 | return new Updater( new Connection( $searchConfig ) ); |
96 | } |
97 | ]; |
98 | |
99 | // @codeCoverageIgnoreEnd |