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