r51204 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51203‎ | r51204 | r51205 >
Date:19:49, 30 May 2009
Author:shinjiman
Status:resolved (Comments)
Tags:
Comment:
* (bug 10837) Introducing the StubUserVariant class to determine the variant variable instead of using this to overrules the user language preference.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/StubObject.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/StubObject.php
@@ -145,6 +145,45 @@
146146 global $wgContLanguageCode, $wgRequest, $wgUser, $wgContLang;
147147 $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) );
148148
 149+ # Validate $code
 150+ if( empty( $code ) || !preg_match( '/^[a-z-]+$/', $code ) || ( $code === 'qqq' ) ) {
 151+ wfDebug( "Invalid user language code\n" );
 152+ $code = $wgContLanguageCode;
 153+ }
 154+
 155+ if( $code === $wgContLanguageCode ) {
 156+ return $wgContLang;
 157+ } else {
 158+ $obj = Language::factory( $code );
 159+ return $obj;
 160+ }
 161+ }
 162+}
 163+
 164+/**
 165+ * Stub object for the user variant. It depends of the user preferences and
 166+ * "variant" parameter that can be passed to index.php. This object have to be
 167+ * in $wgVariant global.
 168+ */
 169+class StubUserVariant extends StubObject {
 170+
 171+ function __construct() {
 172+ parent::__construct( 'wgVariant' );
 173+ }
 174+
 175+ function __call( $name, $args ) {
 176+ return $this->_call( $name, $args );
 177+ }
 178+
 179+ function _newObject() {
 180+ global $wgContLanguageCode, $wgRequest, $wgUser, $wgContLang;
 181+
 182+ if( $wgContLang->hasVariants() ) {
 183+ $code = $wgRequest->getVal( 'variant', $wgUser->getOption( 'variant' ) );
 184+ } else {
 185+ $code = $wgRequest->getVal( 'variant', $wgUser->getOption( 'language' ) );
 186+ }
 187+
149188 // if variant is explicitely selected, use it instead the one from wgUser
150189 // see bug #7605
151190 if( $wgContLang->hasVariants() && in_array($code, $wgContLang->getVariants()) ){
@@ -155,7 +194,7 @@
156195
157196 # Validate $code
158197 if( empty( $code ) || !preg_match( '/^[a-z-]+$/', $code ) || ( $code === 'qqq' ) ) {
159 - wfDebug( "Invalid user language code\n" );
 198+ wfDebug( "Invalid user variant code\n" );
160199 $code = $wgContLanguageCode;
161200 }
162201
Index: trunk/phase3/includes/Setup.php
@@ -269,6 +269,7 @@
270270
271271 $wgUser = new StubUser;
272272 $wgLang = new StubUserLang;
 273+$wgVariant = new StubUserVariant;
273274 $wgOut = new StubObject( 'wgOut', 'OutputPage' );
274275 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
275276
Index: trunk/phase3/includes/Skin.php
@@ -352,7 +352,7 @@
353353 */
354354 static function makeGlobalVariablesScript( $data ) {
355355 global $wgScript, $wgTitle, $wgStylePath, $wgUser;
356 - global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
 356+ global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang, $wgVariant;
357357 global $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
358358 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
359359 global $wgUseAjax, $wgAjaxWatch;
@@ -394,6 +394,7 @@
395395 'wgIsArticle' => $wgOut->isArticle(),
396396 'wgUserName' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
397397 'wgUserGroups' => $wgUser->isAnon() ? NULL : $wgUser->getEffectiveGroups(),
 398+ 'wgUserVariant' => $wgVariant->getCode(),
398399 'wgUserLanguage' => $wgLang->getCode(),
399400 'wgContentLanguage' => $wgContLang->getCode(),
400401 'wgBreakFrames' => $wgBreakFrames,
@@ -404,6 +405,9 @@
405406 'wgSeparatorTransformTable' => $compactSeparatorTransTable,
406407 'wgDigitTransformTable' => $compactDigitTransTable,
407408 );
 409+ if ( !( $wgContLang->hasVariants() ) ) {
 410+ unset( $vars['wgUserVariant'] );
 411+ }
408412
409413 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
410414 $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate();
Index: trunk/phase3/RELEASE-NOTES
@@ -38,6 +38,8 @@
3939 * Subpages are now enabled in the MediaWiki namespace by default. This is
4040 mainly a cosmetic change, and does not in any way affect the MessageCache,
4141 which was already effectively treating the namespace as if it had subpages.
 42+* (bug 10837) $wgVariant is a user variant selected in the user's preferences
 43+ if the $wgContLang does not have variant, then the $wgLang is used instead.
4244
4345 === New features in 1.16 ===
4446
@@ -174,6 +176,8 @@
175177 uploading/moving is disabled for registered users as well (e.g. only sysops)
176178 * (bug 18943) Handle invalid titles gracefully at Special:Mostlinked
177179 * (bug 8873) Enable variant conversion in text on 'alt' and 'title' attributes
 180+* (bug 10837) Introducing the StubUserVariant class to determine the variant
 181+ variable instead of using this to overrules the user language preference.
178182
179183 == API changes in 1.16 ==
180184

Follow-up revisions

RevisionCommit summaryAuthorDate
r55746Fixes for r51204: removed useless $wgVariant and StubUserVariant. In Skin::ma...tstarling07:19, 2 September 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r28802* Use variant only if interface language === content language...nikerabbit18:00, 23 December 2007
r37662* (bug 10837) Language variants overrides languages other than the variant ma...rainman21:32, 14 July 2008

Comments

#Comment by Tim Starling (talk | contribs)   07:48, 3 June 2009

StubObject exists only for backwards-compatibility. Do not use it in new code. Use an accessor function instead, such as Language::variantSingleton().

Note that if you actually use this for anything, you will have to include the variant code in User::getPageRenderingHash() or its caller ParserCache::getKey(). The user language is currently included, which makes sure the different variants are stored to different keys.

#Comment by Tim Starling (talk | contribs)   06:59, 2 September 2009

Note that the code here does actually do something, contrary to what I originally thought. The effect is to make it so that the return value of Language::getPreferredVariant() does not override the language in $wgLang. Instead, that override is only done for $wgVariant, which is never referenced except for the global variable script.

#Comment by Tim Starling (talk | contribs)   07:20, 2 September 2009

Fixed in r55746.

Status & tagging log