MediaWiki REL1_40
WebInstallerLanguage.php
Go to the documentation of this file.
1<?php
25
27
31 public function execute() {
32 global $wgLang;
33 $r = $this->parent->request;
34 $userLang = $r->getVal( 'uselang' );
35 $contLang = $r->getVal( 'ContLang' );
36
37 $languages = MediaWikiServices::getInstance()
38 ->getLanguageNameUtils()
39 ->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::SUPPORTED );
40 $lifetime = intval( ini_get( 'session.gc_maxlifetime' ) );
41 if ( !$lifetime ) {
42 $lifetime = 1440; // PHP default
43 }
44
45 if ( $r->wasPosted() ) {
46 # Do session test
47 if ( $this->parent->getSession( 'test' ) === null ) {
48 $requestTime = $r->getIntOrNull( 'LanguageRequestTime' );
49 if ( !$requestTime ) {
50 // The most likely explanation is that the user was knocked back
51 // from another page on POST due to session expiry
52 $msg = 'config-session-expired';
53 } elseif ( time() - $requestTime > $lifetime ) {
54 $msg = 'config-session-expired';
55 } else {
56 $msg = 'config-no-session';
57 }
58 $this->parent->showError( $msg, $wgLang->formatTimePeriod( $lifetime ) );
59 } else {
60 if ( isset( $languages[$userLang] ) ) {
61 $this->setVar( '_UserLang', $userLang );
62 }
63 if ( isset( $languages[$contLang] ) ) {
64 $this->setVar( 'wgLanguageCode', $contLang );
65 }
66
67 return 'continue';
68 }
69 } elseif ( $this->parent->showSessionWarning ) {
70 # The user was knocked back from another page to the start
71 # This probably indicates a session expiry
72 $this->parent->showError( 'config-session-expired',
73 $wgLang->formatTimePeriod( $lifetime ) );
74 }
75
76 $this->parent->setSession( 'test', true );
77
78 if ( !isset( $languages[$userLang] ) ) {
79 $userLang = $this->getVar( '_UserLang', 'en' );
80 }
81 if ( !isset( $languages[$contLang] ) ) {
82 $contLang = $this->getVar( 'wgLanguageCode', 'en' );
83 }
84 $this->startForm();
85 $s = Html::hidden( 'LanguageRequestTime', time() ) .
86 $this->getLanguageSelector( 'uselang', 'config-your-language', $userLang,
87 $this->parent->getHelpBox( 'config-your-language-help' ) ) .
88 $this->getLanguageSelector( 'ContLang', 'config-wiki-language', $contLang,
89 $this->parent->getHelpBox( 'config-wiki-language-help' ) );
90 $this->addHTML( $s );
91 $this->endForm( 'continue', false );
92
93 return null;
94 }
95
106 public function getLanguageSelector( $name, $label, $selectedCode, $helpHtml = '' ) {
107 $output = $helpHtml;
108
109 $select = new XmlSelect( $name, $name, $selectedCode );
110 $select->setAttribute( 'tabindex', $this->parent->nextTabIndex() );
111
112 $languages = MediaWikiServices::getInstance()
113 ->getLanguageNameUtils()
114 ->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::SUPPORTED );
115 foreach ( $languages as $code => $lang ) {
116 $select->addOption( "$code - $lang", $code );
117 }
118
119 $output .= $select->getHTML();
120 return $this->parent->label( $label, $name, $output );
121 }
122
123}
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode $wgLang
Definition Setup.php:527
This class is a collection of static functions that serve two purposes:
Definition Html.php:55
A service that provides utilities to do with language names and codes.
Service locator for MediaWiki core services.
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:28
if(!isset( $args[0])) $lang