r64587 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64586‎ | r64587 | r64588 >
Date:06:36, 4 April 2010
Author:maxsem
Status:resolved (Comments)
Tags:
Comment:
new-installer: added language sniffing
Modified paths:
  • /branches/new-installer/phase3/includes/installer/WebInstaller.php (modified) (history)
  • /branches/new-installer/phase3/languages/messages/MessagesRu.php (modified) (history)

Diff [purge]

Index: branches/new-installer/phase3/includes/installer/WebInstaller.php
@@ -81,6 +81,7 @@
8282 if ( isset( $session['settings'] ) ) {
8383 $this->settings = $session['settings'] + $this->settings;
8484 }
 85+ $this->setupLanguage();
8586
8687 if ( isset( $session['happyPages'] ) ) {
8788 $this->happyPages = $session['happyPages'];
@@ -325,6 +326,49 @@
326327 }
327328
328329 /**
 330+ * Initializes language-related variables
 331+ */
 332+ function setupLanguage() {
 333+ global $wgLang, $wgContLang, $wgLanguageCode;
 334+ if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) {
 335+ $wgLanguageCode = $this->getAcceptLanguage();
 336+ $wgLang = $wgContLang = Language::factory( $wgLanguageCode );
 337+ $this->setVar( 'wgLanguageCode', $wgLanguageCode );
 338+ $this->setVar( '_UserLang', $wgLanguageCode );
 339+ } else {
 340+ $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
 341+ $wgLang = Language::factory( $this->getVar( '_UserLang' ) );
 342+ $wgContLang = Language::factory( $wgLanguageCode );
 343+ }
 344+ }
 345+
 346+ /**
 347+ * Retrieves MediaWiki language from Accept-Language HTTP header
 348+ */
 349+ function getAcceptLanguage() {
 350+ global $wgLanguageCode;
 351+
 352+ $mwLanguages = Language::getLanguageNames();
 353+ $langs = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
 354+ foreach ( explode( ';', $langs ) as $splitted ) {
 355+ foreach ( explode( ',', $splitted ) as $lang ) {
 356+ $lang = trim( strtolower( $lang ) );
 357+ if ( $lang == '' || $lang[0] == 'q' ) {
 358+ continue;
 359+ }
 360+ if ( isset( $mwLanguages[$lang] ) ) {
 361+ return $lang;
 362+ }
 363+ $lang = preg_replace( '/^(.*?)(?=-[^-]*)$/', '\\1', $lang );
 364+ if ( $lang != '' && isset( $mwLanguages[$lang] ) ) {
 365+ return $lang;
 366+ }
 367+ }
 368+ }
 369+ return $wgLanguageCode;
 370+ }
 371+
 372+ /**
329373 * Called by execute() before page output starts, to show a page list
330374 */
331375 function startPageWrapper( $currentPageName ) {
Index: branches/new-installer/phase3/languages/messages/MessagesRu.php
@@ -3345,7 +3345,8 @@
33463346 'duplicate-defaultsort' => 'Внимание. Ключ сортировки по умолчанию «$2» переопределяет прежний ключ сортировки по умолчанию «$1».',
33473347
33483348 # Installer
3349 -
 3349+'config-title' => 'Установка MediaWiki $1',
 3350+'config-page-language' => 'Язык',
33503351 'config-admin-default-username' => 'ВикиАдминистратор',
33513352
33523353 # Special:Version

Follow-up revisions

RevisionCommit summaryAuthorDate
r70356Follow-up to r64587:...maxsem20:16, 2 August 2010

Comments

#Comment by Tim Starling (talk | contribs)   02:18, 30 June 2010

This Accept-Language header parsing is sloppy and doesn't match the HTTP spec. I spent a lot of time chastising Philip for doing the same thing (see r49157), it would be unfair if I let you get away with it. Maybe it would be best if you borrowed his code, which is almost as short and appears to actually work? See LanguageConverter::getHeaderVariant() in HEAD.

Status & tagging log