Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
97.50% |
78 / 80 |
|
90.91% |
10 / 11 |
CRAP | |
0.00% |
0 / 1 |
| LanguageNameUtils | |
98.73% |
78 / 79 |
|
90.91% |
10 / 11 |
41 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| isSupportedLanguage | |
88.89% |
8 / 9 |
|
0.00% |
0 / 1 |
6.05 | |||
| isValidCode | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
| isValidBuiltInCode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isKnownLanguageTag | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
| getLanguageNames | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
4 | |||
| getLanguageNamesUncached | |
100.00% |
30 / 30 |
|
100.00% |
1 / 1 |
15 | |||
| getLanguageName | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getFileName | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| getMessagesFileName | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getJsonMessagesFileName | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Language; |
| 8 | |
| 9 | use InvalidArgumentException; |
| 10 | use MediaWiki\Config\ServiceOptions; |
| 11 | use MediaWiki\HookContainer\HookContainer; |
| 12 | use MediaWiki\HookContainer\HookRunner; |
| 13 | use MediaWiki\Languages\Data\Names; |
| 14 | use MediaWiki\MainConfigNames; |
| 15 | use MediaWiki\Title\TitleParser; |
| 16 | use Wikimedia\ObjectCache\BagOStuff; |
| 17 | use Wikimedia\ObjectCache\HashBagOStuff; |
| 18 | |
| 19 | /** |
| 20 | * A service that provides utilities to do with language names and codes. |
| 21 | * |
| 22 | * See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more information. |
| 23 | * |
| 24 | * @since 1.34 |
| 25 | * @ingroup Language |
| 26 | */ |
| 27 | class LanguageNameUtils { |
| 28 | /** |
| 29 | * Return autonyms in getLanguageName(s). |
| 30 | */ |
| 31 | public const AUTONYMS = null; |
| 32 | |
| 33 | /** |
| 34 | * Return all known languages in getLanguageName(s). |
| 35 | */ |
| 36 | public const ALL = 'all'; |
| 37 | |
| 38 | /** |
| 39 | * Return in getLanguageName(s) only the languages that are defined by MediaWiki. |
| 40 | */ |
| 41 | public const DEFINED = 'mw'; |
| 42 | |
| 43 | /** |
| 44 | * Return in getLanguageName(s) only the languages for which we have at least some localisation. |
| 45 | */ |
| 46 | public const SUPPORTED = 'mwfile'; |
| 47 | |
| 48 | /** @var ServiceOptions */ |
| 49 | private $options; |
| 50 | |
| 51 | /** |
| 52 | * Cache for language names |
| 53 | * @var HashBagOStuff|null |
| 54 | */ |
| 55 | private $languageNameCache; |
| 56 | |
| 57 | /** |
| 58 | * Cache for validity of language codes |
| 59 | * @var array |
| 60 | */ |
| 61 | private $validCodeCache = []; |
| 62 | |
| 63 | /** |
| 64 | * @internal For use by ServiceWiring |
| 65 | */ |
| 66 | public const CONSTRUCTOR_OPTIONS = [ |
| 67 | MainConfigNames::ExtraLanguageNames, |
| 68 | MainConfigNames::UsePigLatinVariant, |
| 69 | MainConfigNames::UseXssLanguage, |
| 70 | ]; |
| 71 | |
| 72 | /** @var HookRunner */ |
| 73 | private $hookRunner; |
| 74 | |
| 75 | public function __construct( ServiceOptions $options, HookContainer $hookContainer ) { |