Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
98.73% |
78 / 79 |
|
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 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\Languages; |
22 | |
23 | use InvalidArgumentException; |
24 | use MediaWiki\Config\ServiceOptions; |
25 | use MediaWiki\HookContainer\HookContainer; |
26 | use MediaWiki\HookContainer\HookRunner; |
27 | use MediaWiki\Language\LanguageCode; |
28 | use MediaWiki\MainConfigNames; |
29 | use MediaWiki\Title\MediaWikiTitleCodec; |
30 | use Wikimedia\ObjectCache\BagOStuff; |
31 | use Wikimedia\ObjectCache\HashBagOStuff; |
32 | |
33 | /** |
34 | * A service that provides utilities to do with language names and codes. |
35 | * |
36 | * See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more information. |
37 | * |
38 | * @since 1.34 |
39 | * @ingroup Language |
40 | */ |
41 | class LanguageNameUtils { |
42 | /** |
43 | * Return autonyms in getLanguageName(s). |
44 | */ |
45 | public const AUTONYMS = null; |
46 | |
47 | /** |
48 | * Return all known languages in getLanguageName(s). |
49 | */ |
50 | public const ALL = 'all'; |
51 | |
52 | /** |
53 | * Return in getLanguageName(s) only the languages that are defined by MediaWiki. |
54 | */ |
55 | public const DEFINED = 'mw'; |
56 | |
57 | /** |
58 | * Return in getLanguageName(s) only the languages for which we have at least some localisation. |
59 | */ |
60 | public const SUPPORTED = 'mwfile'; |
61 | |
62 | /** @var ServiceOptions */ |
63 | private $options; |
64 | |
65 | /** |
66 | * Cache for language names |
67 | * @var HashBagOStuff|null |
68 | */ |
69 | private $languageNameCache; |
70 | |
71 | /** |
72 | * Cache for validity of language codes |
73 | * @var array |
74 | */ |
75 | private $validCodeCache = []; |
76 | |
77 | /** |
78 | * @internal For use by ServiceWiring |
79 | */ |
80 | public const CONSTRUCTOR_OPTIONS = [ |
81 | MainConfigNames::ExtraLanguageNames, |
82 | MainConfigNames::UsePigLatinVariant, |
83 | MainConfigNames::UseXssLanguage, |
84 | ]; |
85 | |
86 | /** @var HookRunner */ |
87 | private $hookRunner; |
88 | |
89 | /** |
90 | * @param ServiceOptions $options |
91 | * @param HookContainer $hookContainer |
92 | */ |
93 | public function __construct( ServiceOptions $options, HookContainer $hookContainer ) { |