r80745 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80744‎ | r80745 | r80746 >
Date:13:01, 22 January 2011
Author:nikerabbit
Status:ok
Tags:
Comment:
Cleanup language selector:
* in hook, use $parser
* the header( vary ) options have not been working for ages (ever?), so apparently they are not needed
* move stubautolang class into different file
* fixed a bug in wfLanguageSelectorGetCacheVaryCookies (apparently never used)
* don't try to use possible unset global variable

Also found a bug in OutputPage::addVaryHeader
Modified paths:
  • /trunk/extensions/LanguageSelector/LanguageSelector.php (modified) (history)
  • /trunk/extensions/LanguageSelector/StubAutoLang.php (added) (history)

Diff [purge]

Index: trunk/extensions/LanguageSelector/LanguageSelector.php
@@ -45,7 +45,6 @@
4646 /**
4747 * Languages to offer in the language selector. Per default, this includes all languages MediaWiki knows
4848 * about by virtue of $wgLanguageNames. A shorter list may be more usable, though.
49 -* If the Polyglot extension is installed, $wgPolyglotLanguages is used as fallback.
5049 */
5150 $wgLanguageSelectorLanguages = null;
5251
@@ -87,10 +86,10 @@
8887 $dir = dirname(__FILE__) . '/';
8988 $wgExtensionMessagesFiles['LanguageSelector'] = $dir . 'LanguageSelector.i18n.php';
9089 $wgJSAutoloadClasses['LanguageSelector'] = 'extensions/LanguageSelector/LanguageSelector.js';
 90+$wgAutoloadClasses['StubAutoLang'] = $dir . 'StubAutoLang.php';
9191
92 -function wfLanguageSelectorSetHook() {
93 - global $wgParser;
94 - $wgParser->setHook( 'languageselector', 'wfLanguageSelectorTag' );
 92+function wfLanguageSelectorSetHook( $parser ) {
 93+ $parser->setHook( 'languageselector', 'wfLanguageSelectorTag' );
9594 return true;
9695 }
9796
@@ -105,10 +104,6 @@
106105 }
107106
108107 if ( $wgLanguageSelectorLanguages === null ) {
109 - $wgLanguageSelectorLanguages = @$GLOBALS['wgPolyglotLanguages'];
110 - }
111 -
112 - if ( $wgLanguageSelectorLanguages === null ) {
113108 $wgLanguageSelectorLanguages = array_keys( Language::getLanguageNames( !$wgLanguageSelectorShowAll ) );
114109 sort( $wgLanguageSelectorLanguages );
115110 }
@@ -134,42 +129,9 @@
135130 }
136131
137132 if ( !$wgRequest->getVal( 'uselang' ) && $wgUser->isAnon() ) {
138 -
139 - //NOTE: we need this for anons, so squids don't get confused.
140 - // but something is still wrong with caching...
141 - header( 'Vary: Cookie', false ); //hrm, this is pretty BAD.
142 - header( 'Vary: Accept-Language', false );
143 -
144133 if ( $wgLanguageSelectorRequestedLanguage || $wgLanguageSelectorDetectLanguage != LANGUAGE_SELECTOR_USE_CONTENT_LANG ) {
145 -
146 - if ( !class_exists( 'StubAutoLang' ) ) {
147 - class StubAutoLang extends StubObject {
148 - function __construct() {
149 - parent::__construct( 'wgLang' );
150 - }
151 -
152 - function __call( $name, $args ) {
153 - return $this->_call( $name, $args );
154 - }
155 -
156 - //partially copied from StubObject.php. There should be a better way...
157 - function _newObject() {
158 - global $wgContLanguageCode, $wgContLang, $wgLanguageSelectorDetectLanguage, $wgLanguageSelectorRequestedLanguage;
159 -
160 - $code = $wgLanguageSelectorRequestedLanguage;
161 - if (!$code) $code = wfLanguageSelectorDetectLanguage( $wgLanguageSelectorDetectLanguage );
162 -
163 - if( $code == $wgContLanguageCode ) {
164 - return $wgContLang;
165 - } else {
166 - $obj = Language::factory( $code );
167 - return $obj;
168 - }
169 - }
170 - }
171 - }
172 -
173134 $wgLang = new StubAutoLang;
 135+ $wgLang->setRequestedLanguage( $wgLanguageSelectorRequestedLanguage );
174136 }
175137 }
176138
@@ -204,11 +166,8 @@
205167 return true;
206168 }
207169
208 -function wfLanguageSelectorGetCacheVaryCookies( &$cookies ) {
209 - global $wgCookiePrefix;
210 -
 170+function wfLanguageSelectorGetCacheVaryCookies( $out, &$cookies ) {
211171 $cookies[] = $wgCookiePrefix.'LanguageSelectorLanguage';
212 -
213172 return true;
214173 }
215174
Index: trunk/extensions/LanguageSelector/StubAutoLang.php
@@ -0,0 +1,32 @@
 2+<?php
 3+
 4+class StubAutoLang extends StubObject {
 5+ protected $requestedLanguage;
 6+
 7+ function __construct() {
 8+ parent::__construct( 'wgLang' );
 9+ }
 10+
 11+ function __call( $name, $args ) {
 12+ return $this->_call( $name, $args );
 13+ }
 14+
 15+ function setRequestedLanguage( $code ) {
 16+ $this->requestedLanguage = $code;
 17+ }
 18+
 19+ //partially copied from StubObject.php. There should be a better way...
 20+ function _newObject() {
 21+ global $wgContLanguageCode, $wgContLang, $wgLanguageSelectorDetectLanguage;
 22+
 23+ $code = $this->requestedLanguage;
 24+ if (!$code) $code = wfLanguageSelectorDetectLanguage( $wgLanguageSelectorDetectLanguage );
 25+
 26+ if( $code == $wgContLanguageCode ) {
 27+ return $wgContLang;
 28+ } else {
 29+ $obj = Language::factory( $code );
 30+ return $obj;
 31+ }
 32+ }
 33+}
\ No newline at end of file
Property changes on: trunk/extensions/LanguageSelector/StubAutoLang.php
___________________________________________________________________
Added: svn:eol-style
134 + native

Status & tagging log