Index: trunk/phase3/includes/StubObject.php |
— | — | @@ -145,6 +145,45 @@ |
146 | 146 | global $wgContLanguageCode, $wgRequest, $wgUser, $wgContLang; |
147 | 147 | $code = $wgRequest->getVal( 'uselang', $wgUser->getOption( 'language' ) ); |
148 | 148 | |
| 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 | + |
149 | 188 | // if variant is explicitely selected, use it instead the one from wgUser |
150 | 189 | // see bug #7605 |
151 | 190 | if( $wgContLang->hasVariants() && in_array($code, $wgContLang->getVariants()) ){ |
— | — | @@ -155,7 +194,7 @@ |
156 | 195 | |
157 | 196 | # Validate $code |
158 | 197 | if( empty( $code ) || !preg_match( '/^[a-z-]+$/', $code ) || ( $code === 'qqq' ) ) { |
159 | | - wfDebug( "Invalid user language code\n" ); |
| 198 | + wfDebug( "Invalid user variant code\n" ); |
160 | 199 | $code = $wgContLanguageCode; |
161 | 200 | } |
162 | 201 | |
Index: trunk/phase3/includes/Setup.php |
— | — | @@ -269,6 +269,7 @@ |
270 | 270 | |
271 | 271 | $wgUser = new StubUser; |
272 | 272 | $wgLang = new StubUserLang; |
| 273 | +$wgVariant = new StubUserVariant; |
273 | 274 | $wgOut = new StubObject( 'wgOut', 'OutputPage' ); |
274 | 275 | $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) ); |
275 | 276 | |
Index: trunk/phase3/includes/Skin.php |
— | — | @@ -352,7 +352,7 @@ |
353 | 353 | */ |
354 | 354 | static function makeGlobalVariablesScript( $data ) { |
355 | 355 | global $wgScript, $wgTitle, $wgStylePath, $wgUser; |
356 | | - global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang; |
| 356 | + global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang, $wgVariant; |
357 | 357 | global $wgCanonicalNamespaceNames, $wgOut, $wgArticle; |
358 | 358 | global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths; |
359 | 359 | global $wgUseAjax, $wgAjaxWatch; |
— | — | @@ -394,6 +394,7 @@ |
395 | 395 | 'wgIsArticle' => $wgOut->isArticle(), |
396 | 396 | 'wgUserName' => $wgUser->isAnon() ? NULL : $wgUser->getName(), |
397 | 397 | 'wgUserGroups' => $wgUser->isAnon() ? NULL : $wgUser->getEffectiveGroups(), |
| 398 | + 'wgUserVariant' => $wgVariant->getCode(), |
398 | 399 | 'wgUserLanguage' => $wgLang->getCode(), |
399 | 400 | 'wgContentLanguage' => $wgContLang->getCode(), |
400 | 401 | 'wgBreakFrames' => $wgBreakFrames, |
— | — | @@ -404,6 +405,9 @@ |
405 | 406 | 'wgSeparatorTransformTable' => $compactSeparatorTransTable, |
406 | 407 | 'wgDigitTransformTable' => $compactDigitTransTable, |
407 | 408 | ); |
| 409 | + if ( !( $wgContLang->hasVariants() ) ) { |
| 410 | + unset( $vars['wgUserVariant'] ); |
| 411 | + } |
408 | 412 | |
409 | 413 | if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){ |
410 | 414 | $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate(); |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -38,6 +38,8 @@ |
39 | 39 | * Subpages are now enabled in the MediaWiki namespace by default. This is |
40 | 40 | mainly a cosmetic change, and does not in any way affect the MessageCache, |
41 | 41 | 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. |
42 | 44 | |
43 | 45 | === New features in 1.16 === |
44 | 46 | |
— | — | @@ -174,6 +176,8 @@ |
175 | 177 | uploading/moving is disabled for registered users as well (e.g. only sysops) |
176 | 178 | * (bug 18943) Handle invalid titles gracefully at Special:Mostlinked |
177 | 179 | * (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. |
178 | 182 | |
179 | 183 | == API changes in 1.16 == |
180 | 184 | |