MediaWiki  master
HTMLSelectLanguageField.php
Go to the documentation of this file.
1 <?php
2 
4 
9  public function __construct( $params ) {
10  parent::__construct( $params );
11 
12  if ( $this->mParent instanceof HTMLForm ) {
13  $config = $this->mParent->getConfig();
14  $languageCode = $config->get( 'LanguageCode' );
15  } else {
16  global $wgLanguageCode;
17  $languageCode = $wgLanguageCode;
18  }
19 
20  $languages = MediaWikiServices::getInstance()
21  ->getLanguageNameUtils()
22  ->getLanguageNames( null, 'mw' );
23 
24  // Make sure the site language is in the list;
25  // a custom language code might not have a defined nameā€¦
26  if ( !array_key_exists( $languageCode, $languages ) ) {
27  $languages[$languageCode] = $languageCode;
28  }
29 
30  ksort( $languages );
31 
32  foreach ( $languages as $code => $name ) {
33  $this->mParams['options'][$code . ' - ' . $name] = $code;
34  }
35 
36  if ( !array_key_exists( 'default', $params ) ) {
37  $this->mParams['default'] = $languageCode;
38  }
39  }
40 }
HTMLSelectLanguageField\__construct
__construct( $params)
Initialise the object.
Definition: HTMLSelectLanguageField.php:9
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:149
HTMLSelectField
A select dropdown field.
Definition: HTMLSelectField.php:6
HTMLSelectLanguageField
Language select field.
Definition: HTMLSelectLanguageField.php:8
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:3064
HTMLForm
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition: HTMLForm.php:133