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
6use CirrusSearch\CirrusSearch;
7use CirrusSearch\CirrusSearchHookRunner;
8use CirrusSearch\Connection;
9use CirrusSearch\EventBusWeightedTagSerializer;
10use CirrusSearch\EventBusWeightedTagsUpdater;
11use CirrusSearch\InterwikiResolver;
12use CirrusSearch\InterwikiResolverFactory;
13use CirrusSearch\Profile\SearchProfileServiceFactory;
14use CirrusSearch\Query\DeepcatFeature;
15use CirrusSearch\SearchConfig;
16use CirrusSearch\Updater;
17use CirrusSearch\WeightedTagsUpdater;
18use MediaWiki\Extension\EventBus\Serializers\EventSerializer;
19use MediaWiki\Extension\EventBus\Serializers\MediaWiki\PageEntitySerializer;
20use MediaWiki\Http\Telemetry;
21use MediaWiki\MediaWikiServices;
22use MediaWiki\Registration\ExtensionRegistry;
23use 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
30return [
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