r45401 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r45400‎ | r45401 | r45402 >
Date:19:22, 4 January 2009
Author:ialex
Status:deferred
Tags:
Comment:
* Trying to fix the JavaScript to submit the form when changing the language: walk recursively through parent node until it finds a form element
* Whitespaces fixes
Modified paths:
  • /trunk/extensions/LanguageSelector/LanguageSelector.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LanguageSelector/LanguageSelector.php
@@ -55,10 +55,10 @@
5656 define( 'LANGUAGE_SELECTOR_AT_TOP_OF_TEXT', 1 ); #put at the top of page content
5757 define( 'LANGUAGE_SELECTOR_IN_TOOLBOX', 2 ); #put into toolbox
5858 define( 'LANGUAGE_SELECTOR_AS_PORTLET', 3 ); #as portlet
59 -define( 'LANGUAGE_SELECTOR_INTO_SITENOTICE', 11); #put after sitenotice text
60 -define( 'LANGUAGE_SELECTOR_INTO_TITLE', 12); #put after title text
61 -define( 'LANGUAGE_SELECTOR_INTO_SUBTITLE', 13); #put after subtitle text
62 -define( 'LANGUAGE_SELECTOR_INTO_CATLINKS', 14); #put after catlinks text
 59+define( 'LANGUAGE_SELECTOR_INTO_SITENOTICE', 11 ); #put after sitenotice text
 60+define( 'LANGUAGE_SELECTOR_INTO_TITLE', 12 ); #put after title text
 61+define( 'LANGUAGE_SELECTOR_INTO_SUBTITLE', 13 ); #put after subtitle text
 62+define( 'LANGUAGE_SELECTOR_INTO_CATLINKS', 14 ); #put after catlinks text
6363
6464 $wgLanguageSelectorLocation = LANGUAGE_SELECTOR_AT_TOP_OF_TEXT;
6565
@@ -75,7 +75,7 @@
7676
7777 function wgLanguageSelectorSetHook() {
7878 global $wgParser;
79 - $wgParser->setHook('languageselector', 'wfLanguageSelectorTag' );
 79+ $wgParser->setHook( 'languageselector', 'wfLanguageSelectorTag' );
8080 return true;
8181 }
8282
@@ -98,34 +98,34 @@
9999 $wgLanguageSelectorLanguages = array_keys( Language::getLanguageNames( true ) );
100100 }
101101
102 - $setlang = $wgRequest->getVal('setlang');
103 - if ($setlang && !in_array($setlang, $wgLanguageSelectorLanguages)) $setlang = NULL; //ignore invalid
 102+ $setlang = $wgRequest->getVal( 'setlang' );
 103+ if ( $setlang && !in_array( $setlang, $wgLanguageSelectorLanguages ) )
 104+ $setlang = NULL; //ignore invalid
104105
105 - if ($setlang) {
106 - setcookie($wgCookiePrefix.'LanguageSelectorLanguage', $setlang, 0, $wgCookiePath);
 106+ if ( $setlang ) {
 107+ setcookie( $wgCookiePrefix . 'LanguageSelectorLanguage', $setlang, 0, $wgCookiePath );
107108 $wgLanguageSelectorRequestedLanguage = $setlang;
108 - }
109 - else {
 109+ } else {
110110 $wgLanguageSelectorRequestedLanguage = @$_COOKIE[$wgCookiePrefix.'LanguageSelectorLanguage'];
111111 }
112112
113113 if ( !$wgUser->isAnon() && $setlang ) {
114 - if ($setlang != $wgUser->getOption('language')) {
115 - $wgUser->setOption('language', $wgLanguageSelectorRequestedLanguage);
 114+ if ( $setlang != $wgUser->getOption( 'language' ) ) {
 115+ $wgUser->setOption( 'language', $wgLanguageSelectorRequestedLanguage );
116116 $wgUser->saveSettings();
117117 }
118118 }
119119
120 - if ( $wgUser->isAnon() && !$wgRequest->getVal( 'uselang' )) {
 120+ if ( $wgUser->isAnon() && !$wgRequest->getVal( 'uselang' ) ) {
121121
122122 //NOTE: we need this for anons, so squids don't get confused.
123123 // but something is still wrong with caching...
124 - header('Vary: Cookie', false); //hrm, this is pretty BAD.
125 - header('Vary: Accept-Language', false);
 124+ header( 'Vary: Cookie', false ); //hrm, this is pretty BAD.
 125+ header( 'Vary: Accept-Language', false );
126126
127127 if ( $wgLanguageSelectorRequestedLanguage || $wgLanguageSelectorDetectLanguage != LANGUAGE_SELECTOR_USE_CONTENT_LANG ) {
128128
129 - if (!class_exists('StubAutoLang')) {
 129+ if ( !class_exists( 'StubAutoLang' ) ) {
130130 class StubAutoLang extends StubObject {
131131 function __construct() {
132132 parent::__construct( 'wgLang' );
@@ -140,7 +140,7 @@
141141 global $wgContLanguageCode, $wgContLang, $wgLanguageSelectorDetectLanguage, $wgLanguageSelectorRequestedLanguage;
142142
143143 $code = $wgLanguageSelectorRequestedLanguage;
144 - if (!$code) $code = wfLanguageSelectorDetectLanguage($wgLanguageSelectorDetectLanguage);
 144+ if (!$code) $code = wfLanguageSelectorDetectLanguage( $wgLanguageSelectorDetectLanguage );
145145
146146 if( $code == $wgContLanguageCode ) {
147147 return $wgContLang;
@@ -156,7 +156,7 @@
157157 }
158158 }
159159
160 - if ($wgLanguageSelectorLocation != LANGUAGE_SELECTOR_MANUAL) {
 160+ if ( $wgLanguageSelectorLocation != LANGUAGE_SELECTOR_MANUAL ) {
161161 switch($wgLanguageSelectorLocation) {
162162 case LANGUAGE_SELECTOR_AT_TOP_OF_TEXT: $wgHooks['BeforePageDisplay'][] = 'wfLanguageSelectorBeforePageDisplay'; break;
163163 case LANGUAGE_SELECTOR_IN_TOOLBOX: $wgHooks['MonoBookTemplateToolboxEnd'][] = 'wfLanguageSelectorSkinHook'; break;
@@ -176,7 +176,16 @@
177177 if (!btn) break;
178178
179179 btn.style.display = "none";
180 - sel.onchange = function() { this.parentNode.submit(); };
 180+ sel.onchange = function() {
 181+ node = this.parentNode;
 182+ while( true ) {
 183+ if( node.tagName.toLowerCase() == "form" ) {
 184+ node.submit();
 185+ break;
 186+ }
 187+ node = node.parentNode;
 188+ }
 189+ };
181190
182191 i++;
183192 }

Status & tagging log