r71165 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71164‎ | r71165 | r71166 >
Date:18:49, 16 August 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Use ParserOptions::getUserLang if it exists to prevent cache corruption
Modified paths:
  • /trunk/extensions/Translate/tag/PageTranslationHooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/tag/PageTranslationHooks.php
@@ -19,7 +19,7 @@
2020 // For translation pages, parse plural, grammar etc with correct language
2121 if ( $page = TranslatablePage::isTranslationPage( $title ) ) {
2222 list( , $code ) = TranslateUtils::figureMessage( $title->getText() );
23 - $parser->mOptions->setTargetLanguage( Language::factory( $code ) );
 23+ $parser->getOptions()->setTargetLanguage( Language::factory( $code ) );
2424 }
2525
2626 return true;
@@ -195,18 +195,19 @@
196196 // Sort by language code, which seems to be the only sane method
197197 ksort( $status );
198198
199 - $sk = $parser->mOptions->getSkin();
 199+ $options = $parser->getOptions();
200200
201 - /* We rely on $wgLang, which should not matter as
202 - * languages are cached per language. However it
203 - * would be nicer to use $parser->getFunctionLang();
204 - * but that needs to be set correct first. */
205 - // $lobj = $parser->getFunctionLang();
206 - global $wgLang;
 201+ $sk = $options->getSkin();
 202+ if ( method_exists( $options, 'getUserLang' ) ) {
 203+ $userLangCode = $options->getUserLang();
 204+ } else {
 205+ global $wgLang;
 206+ $userLangCode = $wgLang->getCode();
 207+ }
207208
208209 $languages = array();
209210 foreach ( $status as $code => $percent ) {
210 - $name = TranslateUtils::getLanguageName( $code, false, $wgLang->getCode() );
 211+ $name = TranslateUtils::getLanguageName( $code, false, $userLangCode );
211212 $name = htmlspecialchars( $name ); // Unlikely, but better safe
212213
213214 /* Percentages are too accurate and take more
@@ -232,7 +233,7 @@
233234
234235 if ( $parser->getTitle()->getText() === $_title->getText() ) {
235236 $languages[] = Html::rawElement( 'b', null, "*$name* $percent" );
236 - } elseif ( $code === $wgLang->getCode() ) {
 237+ } elseif ( $code === $userLangCode ) {
237238 $languages[] = $sk->linkKnown( $_title, Html::rawElement( 'b', null, "$name $percent" ) );
238239 } else {
239240 $languages[] = $sk->linkKnown( $_title, "$name $percent" );

Status & tagging log