Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / installer / WebInstallerLanguage.php
blob386c33afe081e07ee17257aedd2f54d1e56e3b1d
1 <?php
3 /**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
19 * @file
20 * @ingroup Installer
23 namespace MediaWiki\Installer;
25 use MediaWiki\Html\Html;
26 use MediaWiki\Languages\LanguageNameUtils;
27 use MediaWiki\MediaWikiServices;
28 use MediaWiki\Xml\XmlSelect;
30 class WebInstallerLanguage extends WebInstallerPage {
32 /**
33 * @return string|null
35 public function execute() {
36 global $wgLang;
37 $r = $this->parent->request;
38 $userLang = $r->getVal( 'uselang' );
39 $contLang = $r->getVal( 'ContLang' );
41 $languages = MediaWikiServices::getInstance()
42 ->getLanguageNameUtils()
43 ->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::SUPPORTED );
44 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
45 if ( !$lifetime ) {
46 $lifetime = 1440; // PHP default
49 if ( $r->wasPosted() ) {
50 # Do session test
51 if ( $this->parent->getSession( 'test' ) === null ) {
52 $requestTime = $r->getIntOrNull( 'LanguageRequestTime' );
53 if ( !$requestTime ) {
54 // The most likely explanation is that the user was knocked back
55 // from another page on POST due to session expiry
56 $msg = 'config-session-expired';
57 } elseif ( time() - $requestTime > $lifetime ) {
58 $msg = 'config-session-expired';
59 } else {
60 $msg = 'config-no-session';
62 $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
63 } else {
64 if ( isset( $languages[$userLang] ) ) {
65 $this->setVar( '_UserLang', $userLang );
67 if ( isset( $languages[$contLang] ) ) {
68 $this->setVar( 'wgLanguageCode', $contLang );
71 return 'continue';
73 } elseif ( $this->parent->showSessionWarning ) {
74 # The user was knocked back from another page to the start
75 # This probably indicates a session expiry
76 $this->parent->showError( 'config-session-expired',
77 $wgLang->formatTimePeriod( $lifetime ) );
80 $this->parent->setSession( 'test', true );
82 if ( !isset( $languages[$userLang] ) ) {
83 $userLang = $this->getVar( '_UserLang', 'en' );
85 if ( !isset( $languages[$contLang] ) ) {
86 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
88 $this->startForm();
89 $s = Html::hidden( 'LanguageRequestTime', time() ) .
90 $this->getLanguageSelector( 'uselang', 'config-your-language', $userLang,
91 $this->parent->getHelpBox( 'config-your-language-help' ) ) .
92 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang,
93 $this->parent->getHelpBox( 'config-wiki-language-help' ) );
94 $this->addHTML( $s );
95 $this->endForm( 'continue', false );
97 return null;
101 * Get a "<select>" for selecting languages.
103 * @param string $name
104 * @param string $label
105 * @param string $selectedCode
106 * @param string $helpHtml
108 * @return string
110 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
111 $output = $helpHtml;
113 $select = new XmlSelect( $name, $name, $selectedCode );
114 $select->setAttribute( 'tabindex', $this->parent->nextTabIndex() );
115 $select->setAttribute( 'class', 'cdx-select' );
117 $languages = MediaWikiServices::getInstance()
118 ->getLanguageNameUtils()
119 ->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::SUPPORTED );
120 foreach ( $languages as $code => $lang ) {
121 $select->addOption( "$code - $lang", $code );
124 $output .= $select->getHTML();
125 return $this->parent->label( $label, $name, $output );