MediaWiki REL1_37
WebInstallerLanguage.php
Go to the documentation of this file.
1<?php
23
25
29 public function execute() {
30 global $wgLang;
31 $r = $this->parent->request;
32 $userLang = $r->getVal( 'uselang' );
33 $contLang = $r->getVal( 'ContLang' );
34
35 $languages = MediaWikiServices::getInstance()
36 ->getLanguageNameUtils()
37 ->getLanguageNames( null, 'mwfile' );
38 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
39 if ( !$lifetime ) {
40 $lifetime = 1440; // PHP default
41 }
42
43 if ( $r->wasPosted() ) {
44 # Do session test
45 if ( $this->parent->getSession( 'test' ) === null ) {
46 $requestTime = $r->getVal( 'LanguageRequestTime' );
47 if ( !$requestTime ) {
48 // The most likely explanation is that the user was knocked back
49 // from another page on POST due to session expiry
50 $msg = 'config-session-expired';
51 } elseif ( time() - $requestTime > $lifetime ) {
52 $msg = 'config-session-expired';
53 } else {
54 $msg = 'config-no-session';
55 }
56 $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
57 } else {
58 if ( isset( $languages[$userLang] ) ) {
59 $this->setVar( '_UserLang', $userLang );
60 }
61 if ( isset( $languages[$contLang] ) ) {
62 $this->setVar( 'wgLanguageCode', $contLang );
63 }
64
65 return 'continue';
66 }
67 } elseif ( $this->parent->showSessionWarning ) {
68 # The user was knocked back from another page to the start
69 # This probably indicates a session expiry
70 $this->parent->showError( 'config-session-expired',
71 $wgLang->formatTimePeriod( $lifetime ) );
72 }
73
74 $this->parent->setSession( 'test', true );
75
76 if ( !isset( $languages[$userLang] ) ) {
77 $userLang = $this->getVar( '_UserLang', 'en' );
78 }
79 if ( !isset( $languages[$contLang] ) ) {
80 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
81 }
82 $this->startForm();
83 $s = Html::hidden( 'LanguageRequestTime', time() ) .
84 $this->getLanguageSelector( 'uselang', 'config-your-language', $userLang,
85 $this->parent->getHelpBox( 'config-your-language-help' ) ) .
86 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang,
87 $this->parent->getHelpBox( 'config-wiki-language-help' ) );
88 $this->addHTML( $s );
89 $this->endForm( 'continue', false );
90
91 return null;
92 }
93
104 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
105 $output = $helpHtml;
106
107 $select = new XmlSelect( $name, $name, $selectedCode );
108 $select->setAttribute( 'tabindex', $this->parent->nextTabIndex() );
109
110 $languages = MediaWikiServices::getInstance()
111 ->getLanguageNameUtils()
112 ->getLanguageNames( null, 'mwfile' );
113 foreach ( $languages as $code => $lang ) {
114 $select->addOption( "$code - $lang", $code );
115 }
116
117 $output .= $select->getHTML();
118 return $this->parent->label( $label, $name, $output );
119 }
120
121}
$wgLang
Definition Setup.php:831
MediaWikiServices is the service locator for the application scope of MediaWiki.
getLanguageSelector( $name, $label, $selectedCode, $helpHtml='')
Get a "<select>" for selecting languages.
Abstract class to define pages for the web installer.
setVar( $name, $value)
endForm( $continue='continue', $back='back')
getVar( $var, $default=null)
Class for generating HTML <select> or <datalist> elements.
Definition XmlSelect.php:26
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s
if(!isset( $args[0])) $lang