HTMLSelectLanguageField.php 912 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * Language select field.
  4. */
  5. class HTMLSelectLanguageField extends HTMLSelectField {
  6. public function __construct( $params ) {
  7. parent::__construct( $params );
  8. if ( $this->mParent instanceof HTMLForm ) {
  9. $config = $this->mParent->getConfig();
  10. $languageCode = $config->get( 'LanguageCode' );
  11. } else {
  12. global $wgLanguageCode;
  13. $languageCode = $wgLanguageCode;
  14. }
  15. $languages = Language::fetchLanguageNames( null, 'mw' );
  16. // Make sure the site language is in the list;
  17. // a custom language code might not have a defined name…
  18. if ( !array_key_exists( $languageCode, $languages ) ) {
  19. $languages[$languageCode] = $languageCode;
  20. }
  21. ksort( $languages );
  22. foreach ( $languages as $code => $name ) {
  23. $this->mParams['options'][$code . ' - ' . $name] = $code;
  24. }
  25. if ( !array_key_exists( 'default', $params ) ) {
  26. $this->mParams['default'] = $languageCode;
  27. }
  28. }
  29. }