MediaWiki master
WebInstallerLanguage.php
Go to the documentation of this file.
1<?php
2
23namespace MediaWiki\Installer;
24
28use XmlSelect;
29
31
35 public function execute() {
36 global $wgLang;
37 $r = $this->parent->request;
38 $userLang = $r->getVal( 'uselang' );
39 $contLang = $r->getVal( 'ContLang' );
40
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
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}
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
Definition Setup.php:536
This class is a collection of static functions that serve two purposes:
Definition Html.php:56
getLanguageSelector( $name, $label, $selectedCode, $helpHtml='')
Get a "<select>" for selecting languages.
Abstract class to define pages for the web installer.
endForm( $continue='continue', $back='back')
A service that provides utilities to do with language names and codes.
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Class for generating HTML <select> or <datalist> elements.
Definition XmlSelect.php:28