Improve docs for Title::getInternalURL/getCanonicalURL
[lhc/web/wiklou.git] / includes / resourceloader / ResourceLoaderLanguageNamesModule.php
1 <?php
2 /**
3 * ResourceLoader module for providing language names.
4 *
5 * By default these names will be autonyms however other extensions may
6 * provided language names in the context language (e.g. cldr extension)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
22 *
23 * @file
24 * @author Ed Sanders
25 * @author Trevor Parscal
26 */
27
28 /**
29 * ResourceLoader module for populating language specific data.
30 */
31 class ResourceLoaderLanguageNamesModule extends ResourceLoaderFileModule {
32
33 protected $targets = [ 'desktop', 'mobile' ];
34
35 /**
36 * @param ResourceLoaderContext $context
37 * @return array
38 */
39 protected function getData( ResourceLoaderContext $context ) {
40 return Language::fetchLanguageNames(
41 $context->getLanguage(),
42 'all'
43 );
44 }
45
46 /**
47 * @param ResourceLoaderContext $context
48 * @return string JavaScript code
49 */
50 public function getScript( ResourceLoaderContext $context ) {
51 return Xml::encodeJsCall(
52 'mw.language.setData',
53 [
54 $context->getLanguage(),
55 'languageNames',
56 $this->getData( $context )
57 ],
58 ResourceLoader::inDebugMode()
59 );
60 }
61
62 /**
63 * @param ResourceLoaderContext|null $context
64 * @return array
65 */
66 public function getDependencies( ResourceLoaderContext $context = null ) {
67 return [ 'mediawiki.language' ];
68 }
69
70 /**
71 * @return bool
72 */
73 public function enableModuleContentVersion() {
74 return true;
75 }
76
77 }