MediaWiki 1.42.0
HTMLSelectLanguageField.php
Go to the documentation of this file.
1<?php
2
4
8
15
20 public function __construct( $params ) {
21 parent::__construct( $params );
22
23 if ( $this->mParent instanceof HTMLForm ) {
24 $config = $this->mParent->getConfig();
25 $languageCode = $config->get( MainConfigNames::LanguageCode );
26 } else {
27 $languageCode = MediaWikiServices::getInstance()->getMainConfig()->get(
29 }
30
32 ->getLanguageNameUtils()
33 ->getLanguageNames();
34
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;
39 }
40
41 ksort( $languages );
42
43 foreach ( $languages as $code => $name ) {
44 $this->mParams['options'][$code . ' - ' . $name] = $code;
45 }
46
47 $this->mParams['default'] ??= $languageCode;
48 }
49}
50
52class_alias( HTMLSelectLanguageField::class, 'HTMLSelectLanguageField' );
array $params
The job parameters.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:206
A class containing constants representing the names of configuration variables.
const LanguageCode
Name constant for the LanguageCode setting, for use with Config::get()
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.