MediaWiki REL1_39
HTMLSelectLanguageField.php
Go to the documentation of this file.
1<?php
2
5
12
17 public function __construct( $params ) {
18 parent::__construct( $params );
19
20 if ( $this->mParent instanceof HTMLForm ) {
21 $config = $this->mParent->getConfig();
22 $languageCode = $config->get( MainConfigNames::LanguageCode );
23 } else {
24 $languageCode = MediaWikiServices::getInstance()->getMainConfig()->get(
25 MainConfigNames::LanguageCode );
26 }
27
28 $languages = MediaWikiServices::getInstance()
29 ->getLanguageNameUtils()
30 ->getLanguageNames();
31
32 // Make sure the site language is in the list;
33 // a custom language code might not have a defined nameā€¦
34 if ( !array_key_exists( $languageCode, $languages ) ) {
35 $languages[$languageCode] = $languageCode;
36 }
37
38 ksort( $languages );
39
40 foreach ( $languages as $code => $name ) {
41 $this->mParams['options'][$code . ' - ' . $name] = $code;
42 }
43
44 if ( !array_key_exists( 'default', $params ) ) {
45 $this->mParams['default'] = $languageCode;
46 }
47 }
48}
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:150
A select dropdown field.
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.