3 namespace MediaWiki\HTMLForm\Field
;
5 use MediaWiki\HTMLForm\HTMLForm
;
6 use MediaWiki\MainConfigNames
;
7 use MediaWiki\MediaWikiServices
;
10 * Language select field.
14 class HTMLSelectLanguageField
extends HTMLSelectField
{
20 public function __construct( $params ) {
21 parent
::__construct( $params );
23 if ( $this->mParent
instanceof HTMLForm
) {
24 $config = $this->mParent
->getConfig();
25 $languageCode = $config->get( MainConfigNames
::LanguageCode
);
27 $languageCode = MediaWikiServices
::getInstance()->getMainConfig()->get(
28 MainConfigNames
::LanguageCode
);
31 $languages = MediaWikiServices
::getInstance()
32 ->getLanguageNameUtils()
35 // Make sure the site language is in the list;
36 // a custom language code might not have a defined nameā¦
37 if ( !array_key_exists( $languageCode, $languages ) ) {
38 $languages[$languageCode] = $languageCode;
43 foreach ( $languages as $code => $name ) {
44 $this->mParams
['options'][$code . ' - ' . $name] = $code;
47 $this->mParams
['default'] ??
= $languageCode;
51 /** @deprecated class alias since 1.42 */
52 class_alias( HTMLSelectLanguageField
::class, 'HTMLSelectLanguageField' );