ResourceLoaderLanguageNamesModule.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. * ResourceLoader module for populating language specific data.
  29. */
  30. class ResourceLoaderLanguageNamesModule extends ResourceLoaderFileModule {
  31. protected $targets = [ 'desktop', 'mobile' ];
  32. /**
  33. * @param ResourceLoaderContext $context
  34. * @return array
  35. */
  36. protected function getData( ResourceLoaderContext $context ) {
  37. return Language::fetchLanguageNames(
  38. $context->getLanguage(),
  39. 'all'
  40. );
  41. }
  42. /**
  43. * @param ResourceLoaderContext $context
  44. * @return string JavaScript code
  45. */
  46. public function getScript( ResourceLoaderContext $context ) {
  47. return Xml::encodeJsCall(
  48. 'mw.language.setData',
  49. [
  50. $context->getLanguage(),
  51. 'languageNames',
  52. $this->getData( $context )
  53. ],
  54. ResourceLoader::inDebugMode()
  55. );
  56. }
  57. /**
  58. * @param ResourceLoaderContext|null $context
  59. * @return array
  60. */
  61. public function getDependencies( ResourceLoaderContext $context = null ) {
  62. return [ 'mediawiki.language' ];
  63. }
  64. /**
  65. * @return bool
  66. */
  67. public function enableModuleContentVersion() {
  68. return true;
  69. }
  70. }