r86801 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86800‎ | r86801 | r86802 >
Date:21:55, 23 April 2011
Author:happy-melon
Status:deferred
Tags:
Comment:
Follow-up r86775: the execution order is slightly changed by that commit; and the UserGetLanguageCode hook is now called before $wgExtensionFunctions code is run. I don't want to restore that by moving the declaration of $wgLang below the extensionfunctions run, because that will mean $wgLang is now undefined in all those functions, which seems a more substantial break with B/C than the current change. Fix LanguageSelector by moving the code from the extension function (fallback initialisation for a global variable) to a global getter for the variable; which seems a nicer behaviour anyway.
Modified paths:
  • /trunk/extensions/LanguageSelector/LanguageSelector.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LanguageSelector/LanguageSelector.php
@@ -90,19 +90,22 @@
9191 $wgExtensionMessagesFiles['LanguageSelector'] = $dir . 'LanguageSelector.i18n.php';
9292 $wgJSAutoloadClasses['LanguageSelector'] = 'extensions/LanguageSelector/LanguageSelector.js';
9393
 94+/**
 95+ * @param $parser Parser
 96+ * @return bool
 97+ */
9498 function wfLanguageSelectorSetHook( $parser ) {
9599 $parser->setHook( 'languageselector', 'wfLanguageSelectorTag' );
96100 return true;
97101 }
98102
99103 function wfLanguageSelectorExtension() {
100 - global $wgLanguageSelectorLanguages, $wgLanguageSelectorLocation,
 104+ global $wgLanguageSelectorLocation,
101105 $wgLanguageSelectorShowAll, $wgHooks;
102106
103 - if ( $wgLanguageSelectorLanguages === null ) {
104 - $wgLanguageSelectorLanguages = array_keys( Language::getLanguageNames( !$wgLanguageSelectorShowAll ) );
105 - sort( $wgLanguageSelectorLanguages );
106 - }
 107+ // We'll probably be beaten to this by the call in wfLanguageSelectorGetLanguageCode(),
 108+ // but just in case, call this to make sure the global is properly initialised
 109+ wfGetLanguageSelectorLanguages();
107110
108111 if ( $wgLanguageSelectorLocation != LANGUAGE_SELECTOR_MANUAL && $wgLanguageSelectorLocation != LANGUAGE_SELECTOR_AT_TOP_OF_TEXT ) {
109112 switch ( $wgLanguageSelectorLocation ) {
@@ -116,8 +119,23 @@
117120 }
118121 }
119122
 123+function wfGetLanguageSelectorLanguages(){
 124+ global $wgLanguageSelectorLanguages, $wgLanguageSelectorShowAll;
 125+ if ( $wgLanguageSelectorLanguages === null ) {
 126+ $wgLanguageSelectorLanguages = array_keys( Language::getLanguageNames( !$wgLanguageSelectorShowAll ) );
 127+ sort( $wgLanguageSelectorLanguages );
 128+ }
 129+ return $wgLanguageSelectorLanguages;
 130+}
 131+
 132+/**
 133+ * Hook to UserGetLanguageObject
 134+ * @param $user User
 135+ * @param $code String
 136+ * @return bool
 137+ */
120138 function wfLanguageSelectorGetLanguageCode( $user, &$code ) {
121 - global $wgLanguageSelectorLanguages, $wgLanguageSelectorDetectLanguage,
 139+ global $wgLanguageSelectorDetectLanguage,
122140 $wgCommandLineMode, $wgRequest, $wgContLang;
123141
124142 if ( $wgCommandLineMode ) {
@@ -125,7 +143,7 @@
126144 }
127145
128146 $setlang = $wgRequest->getVal( 'setlang' );
129 - if ( $setlang && !in_array( $setlang, $wgLanguageSelectorLanguages ) ) {
 147+ if ( $setlang && !in_array( $setlang, wfGetLanguageSelectorLanguages() ) ) {
130148 $setlang = null; // ignore invalid
131149 }
132150
@@ -159,7 +177,7 @@
160178 // look for a language that is acceptable to the client
161179 // and known to the wiki.
162180 foreach( $languages as $reqCode => $q ) {
163 - if ( in_array( $reqCode, $wgLanguageSelectorLanguages ) ) {
 181+ if ( in_array( $reqCode, wfGetLanguageSelectorLanguages() ) ) {
164182 $code = $reqCode;
165183 break;
166184 }
@@ -172,6 +190,10 @@
173191 return true;
174192 }
175193
 194+/**
 195+ * @param $out OutputPage
 196+ * @return bool
 197+ */
176198 function wfLanguageSelectorBeforePageDisplay( &$out ) {
177199 global $wgLanguageSelectorLocation;
178200
@@ -205,6 +227,12 @@
206228 return true;
207229 }
208230
 231+/**
 232+ * @param $input String
 233+ * @param $args Array
 234+ * @param $parser Parser
 235+ * @return string
 236+ */
209237 function wfLanguageSelectorTag( $input, $args, $parser ) {
210238 $style = @$args['style'];
211239 $class = @$args['class'];
@@ -244,14 +272,19 @@
245273 return wfLanguageSelectorHTML( $parser->getTitle(), $style, $class, $selectorstyle, $buttonstyle, $showcode );
246274 }
247275
 276+/**
 277+ * @param $skin Skin
 278+ * @param $tpl QuickTemplate
 279+ * @return bool
 280+ */
248281 function wfLanguageSelectorSkinTemplateOutputPageBeforeExec( &$skin, &$tpl ) {
249 - global $wgLanguageSelectorLocation, $wgLanguageSelectorLanguages;
 282+ global $wgLanguageSelectorLocation;
250283 global $wgLang, $wgContLang;
251284
252285 if ($wgLanguageSelectorLocation == LANGUAGE_SELECTOR_AS_PORTLET) {
253286 $code = $wgLang->getCode();
254287 $lines = array();
255 - foreach ($wgLanguageSelectorLanguages as $ln) {
 288+ foreach ( wfGetLanguageSelectorLanguages() as $ln ) {
256289 $lines[] = array(
257290 $href = $skin->getTitle()->getFullURL( 'setlang=' . $ln ),
258291 'text' => $wgContLang->getLanguageName($ln),
@@ -282,6 +315,10 @@
283316 return true;
284317 }
285318
 319+/**
 320+ * @param $u User
 321+ * @return bool
 322+ */
286323 function wfLanguageSelectorAddNewAccount( $u ) {
287324 global $wgUser, $wgLang;
288325
@@ -296,12 +333,18 @@
297334 return true;
298335 }
299336
 337+/**
 338+ * @param $outputPage OutputPage
 339+ * @param $parserOutput ParserOutput
 340+ * @param $data
 341+ * @return void
 342+ */
300343 function wfLanguageSelectorAddJavascript( $outputPage, $parserOutput, $data ) {
301344 $outputPage->addModules( 'ext.languageSelector' );
302345 }
303346
304347 function wfLanguageSelectorHTML( Title $title, $style = null, $class = null, $selectorstyle = null, $buttonstyle = null, $showCode = null ) {
305 - global $wgLanguageSelectorLanguages, $wgLang, $wgContLang, $wgScript,
 348+ global $wgLang, $wgContLang, $wgScript,
306349 $wgLanguageSelectorShowCode;
307350
308351 if ( $showCode === null ) {
@@ -333,7 +376,7 @@
334377 'style' => $selectorstyle
335378 ) );
336379
337 - foreach ( $wgLanguageSelectorLanguages as $ln ) {
 380+ foreach ( wfGetLanguageSelectorLanguages() as $ln ) {
338381 $name = $wgContLang->getLanguageName( $ln );
339382 if ( $showCode ) $name = wfBCP47( $ln ) . ' - ' . $name;
340383

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r86775Stop stubbing $wgLang and $wgContLang. There are no major code paths which d...happy-melon15:19, 23 April 2011

Status & tagging log