Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
ResourceLoaderULSModule | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
getData | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
getScript | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
enableModuleContentVersion | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * ResourceLoader module for UniversalLanguageSelector |
4 | * |
5 | * Copyright (C) 2012 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris, |
6 | * Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other |
7 | * contributors. See CREDITS for a list. |
8 | * |
9 | * UniversalLanguageSelector is dual licensed GPLv2 or later and MIT. You don't |
10 | * have to do anything special to choose one license or the other and you don't |
11 | * have to notify anyone which license you are using. You are free to use |
12 | * UniversalLanguageSelector in commercial projects as long as the copyright |
13 | * header is left intact. See files GPL-LICENSE and MIT-LICENSE for details. |
14 | * |
15 | * @file |
16 | * @author Niklas Laxström |
17 | * @ingroup Extensions |
18 | * @license GPL-2.0-or-later |
19 | * @license MIT |
20 | */ |
21 | |
22 | namespace UniversalLanguageSelector; |
23 | |
24 | use MediaWiki\Languages\LanguageNameUtils; |
25 | use MediaWiki\MediaWikiServices; |
26 | use MediaWiki\ResourceLoader\Context; |
27 | use MediaWiki\ResourceLoader\Module; |
28 | use MediaWiki\ResourceLoader\ResourceLoader; |
29 | |
30 | /** |
31 | * ResourceLoader module for UniversalLanguageSelector |
32 | */ |
33 | class ResourceLoaderULSModule extends Module { |
34 | /** |
35 | * Get all the dynamic data for the content language to an array. |
36 | * |
37 | * @param string $languageCode |
38 | * @return array |
39 | */ |
40 | private function getData( $languageCode ) { |
41 | $vars = []; |
42 | $vars['wgULSLanguages'] = MediaWikiServices::getInstance()->getLanguageNameUtils()->getLanguageNames( |
43 | $languageCode, |
44 | LanguageNameUtils::SUPPORTED |
45 | ); |
46 | return $vars; |
47 | } |
48 | |
49 | /** |
50 | * @suppress PhanParamSignatureRealMismatchParamType, UnusedSuppression -- T308443 |
51 | * @param Context $context |
52 | * @return string JavaScript code |
53 | */ |
54 | public function getScript( Context $context ) { |
55 | $languageCode = $context->getLanguage(); |
56 | return ResourceLoader::makeConfigSetScript( $this->getData( $languageCode ) ); |
57 | } |
58 | |
59 | /** |
60 | * @return bool |
61 | */ |
62 | public function enableModuleContentVersion() { |
63 | return true; |
64 | } |
65 | } |