Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 52 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
WebInstallerLanguage | |
0.00% |
0 / 52 |
|
0.00% |
0 / 2 |
182 | |
0.00% |
0 / 1 |
execute | |
0.00% |
0 / 41 |
|
0.00% |
0 / 1 |
132 | |||
getLanguageSelector | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
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. |
8 | * |
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. |
13 | * |
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 |
18 | * |
19 | * @file |
20 | * @ingroup Installer |
21 | */ |
22 | |
23 | namespace MediaWiki\Installer; |
24 | |
25 | use MediaWiki\Html\Html; |
26 | use MediaWiki\Languages\LanguageNameUtils; |
27 | use MediaWiki\MediaWikiServices; |
28 | use MediaWiki\Xml\XmlSelect; |
29 | |
30 | class WebInstallerLanguage extends WebInstallerPage { |
31 | |
32 | /** |
33 | * @return string|null |
34 | */ |
35 | public function execute() { |
36 | global $wgLang; |
37 | $r = $this->parent->request; |
38 | $userLang = $r->getVal( 'uselang' ); |
39 | $contLang = $r->getVal( 'ContLang' ); |
40 | |
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 |
47 | } |
48 | |
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'; |
61 | } |
62 | $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) ); |
63 | } else { |
64 | if ( isset( $languages[$userLang] ) ) { |
65 | $this->setVar( '_UserLang', $userLang ); |
66 | } |
67 | if ( isset( $languages[$contLang] ) ) { |
68 | $this->setVar( 'wgLanguageCode', $contLang ); |
69 | } |
70 | |
71 | return 'continue'; |
72 | } |
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 ) ); |
78 | } |
79 | |
80 | $this->parent->setSession( 'test', true ); |
81 | |
82 | if ( !isset( $languages[$userLang] ) ) { |
83 | $userLang = $this->getVar( '_UserLang', 'en' ); |
84 | } |
85 | if ( !isset( $languages[$contLang] ) ) { |
86 | $contLang = $this->getVar( 'wgLanguageCode', 'en' ); |
87 | } |
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 ); |
96 | |
97 | return null; |
98 | } |
99 | |
100 | /** |
101 | * Get a "<select>" for selecting languages. |
102 | * |
103 | * @param string $name |
104 | * @param string $label |
105 | * @param string $selectedCode |
106 | * @param string $helpHtml |
107 | * |
108 | * @return string |
109 | */ |
110 | public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) { |
111 | $output = $helpHtml; |
112 | |
113 | $select = new XmlSelect( $name, $name, $selectedCode ); |
114 | $select->setAttribute( 'tabindex', $this->parent->nextTabIndex() ); |
115 | $select->setAttribute( 'class', 'cdx-select' ); |
116 | |
117 | $languages = MediaWikiServices::getInstance() |
118 | ->getLanguageNameUtils() |
119 | ->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::SUPPORTED ); |
120 | foreach ( $languages as $code => $lang ) { |
121 | $select->addOption( "$code - $lang", $code ); |
122 | } |
123 | |
124 | $output .= $select->getHTML(); |
125 | return $this->parent->label( $label, $name, $output ); |
126 | } |
127 | |
128 | } |