Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 4 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
WikibaseServices | |
0.00% |
0 / 4 |
|
0.00% |
0 / 3 |
12 | |
0.00% |
0 / 1 |
getService | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
getEntityLookup | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getEntityLookupWithoutCache | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace WikibaseQuality\ConstraintReport; |
6 | |
7 | use MediaWiki\MediaWikiServices; |
8 | use Wikibase\DataModel\Services\Lookup\EntityLookup; |
9 | |
10 | /** |
11 | * A few Wikibase-related services. |
12 | * |
13 | * Originally, this class and the associated ServiceWiring-Wikibase.php |
14 | * contained some services that Wikibase did not register in the service container; |
15 | * we needed them to be in the service container for tests, |
16 | * so we added them there under WikibaseQualityConstraints-specific names. |
17 | * Subsequently, the service migration in Wikibase moved its services into the service container, |
18 | * which made this class mostly obsolete. |
19 | * It survives only for a few services that are not quite available from Wikibase directly. |
20 | * |
21 | * @license GPL-2.0-or-later |
22 | */ |
23 | class WikibaseServices { |
24 | |
25 | public const ENTITY_LOOKUP = 'WBQC_EntityLookup'; |
26 | public const ENTITY_LOOKUP_WITHOUT_CACHE = 'WBQC_EntityLookupWithoutCache'; |
27 | |
28 | private static function getService( ?MediaWikiServices $services, $name ) { |
29 | $services ??= MediaWikiServices::getInstance(); |
30 | return $services->getService( $name ); |
31 | } |
32 | |
33 | /** |
34 | * An EntityLookup. |
35 | * |
36 | * Unlike {@link WikibaseRepo::getEntityLookup()}, |
37 | * this lookup ignores exceptions (such as unresolved redirects, T93273), |
38 | * as it is more convenient to treat them all as missing entities in WBQC. |
39 | */ |
40 | public static function getEntityLookup( ?MediaWikiServices $services = null ): EntityLookup { |
41 | return self::getService( $services, self::ENTITY_LOOKUP ); |
42 | } |
43 | |
44 | /** |
45 | * An EntityLookup that does not store entities in the cache. |
46 | * |
47 | * This was introduced because the many entities loaded by some {@link SymmetricChecker} checks |
48 | * were exceeding the request memory limit when they were all added to the cache (T227450). |
49 | * Also, like {@link self::getEntityLookup()}, this lookup ignores exceptions. |
50 | */ |
51 | public static function getEntityLookupWithoutCache( ?MediaWikiServices $services = null ): EntityLookup { |
52 | return self::getService( $services, self::ENTITY_LOOKUP_WITHOUT_CACHE ); |
53 | } |
54 | |
55 | } |