Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
HTMLSelectLanguageField
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace MediaWiki\HTMLForm\Field;
4
5use MediaWiki\HTMLForm\HTMLForm;
6use MediaWiki\MainConfigNames;
7use MediaWiki\MediaWikiServices;
8
9/**
10 * Language select field.
11 *
12 * @stable to extend
13 */
14class HTMLSelectLanguageField extends HTMLSelectField {
15
16    /**
17     * @stable to call
18     * @inheritDoc
19     */
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(
28                MainConfigNames::LanguageCode );
29        }
30
31        $languages = MediaWikiServices::getInstance()
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
51/** @deprecated class alias since 1.42 */
52class_alias( HTMLSelectLanguageField::class, 'HTMLSelectLanguageField' );