Index: trunk/extensions/LanguageSelector/LanguageSelector.php |
— | — | @@ -90,19 +90,22 @@ |
91 | 91 | $wgExtensionMessagesFiles['LanguageSelector'] = $dir . 'LanguageSelector.i18n.php'; |
92 | 92 | $wgJSAutoloadClasses['LanguageSelector'] = 'extensions/LanguageSelector/LanguageSelector.js'; |
93 | 93 | |
| 94 | +/** |
| 95 | + * @param $parser Parser |
| 96 | + * @return bool |
| 97 | + */ |
94 | 98 | function wfLanguageSelectorSetHook( $parser ) { |
95 | 99 | $parser->setHook( 'languageselector', 'wfLanguageSelectorTag' ); |
96 | 100 | return true; |
97 | 101 | } |
98 | 102 | |
99 | 103 | function wfLanguageSelectorExtension() { |
100 | | - global $wgLanguageSelectorLanguages, $wgLanguageSelectorLocation, |
| 104 | + global $wgLanguageSelectorLocation, |
101 | 105 | $wgLanguageSelectorShowAll, $wgHooks; |
102 | 106 | |
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(); |
107 | 110 | |
108 | 111 | if ( $wgLanguageSelectorLocation != LANGUAGE_SELECTOR_MANUAL && $wgLanguageSelectorLocation != LANGUAGE_SELECTOR_AT_TOP_OF_TEXT ) { |
109 | 112 | switch ( $wgLanguageSelectorLocation ) { |
— | — | @@ -116,8 +119,23 @@ |
117 | 120 | } |
118 | 121 | } |
119 | 122 | |
| 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 | + */ |
120 | 138 | function wfLanguageSelectorGetLanguageCode( $user, &$code ) { |
121 | | - global $wgLanguageSelectorLanguages, $wgLanguageSelectorDetectLanguage, |
| 139 | + global $wgLanguageSelectorDetectLanguage, |
122 | 140 | $wgCommandLineMode, $wgRequest, $wgContLang; |
123 | 141 | |
124 | 142 | if ( $wgCommandLineMode ) { |
— | — | @@ -125,7 +143,7 @@ |
126 | 144 | } |
127 | 145 | |
128 | 146 | $setlang = $wgRequest->getVal( 'setlang' ); |
129 | | - if ( $setlang && !in_array( $setlang, $wgLanguageSelectorLanguages ) ) { |
| 147 | + if ( $setlang && !in_array( $setlang, wfGetLanguageSelectorLanguages() ) ) { |
130 | 148 | $setlang = null; // ignore invalid |
131 | 149 | } |
132 | 150 | |
— | — | @@ -159,7 +177,7 @@ |
160 | 178 | // look for a language that is acceptable to the client |
161 | 179 | // and known to the wiki. |
162 | 180 | foreach( $languages as $reqCode => $q ) { |
163 | | - if ( in_array( $reqCode, $wgLanguageSelectorLanguages ) ) { |
| 181 | + if ( in_array( $reqCode, wfGetLanguageSelectorLanguages() ) ) { |
164 | 182 | $code = $reqCode; |
165 | 183 | break; |
166 | 184 | } |
— | — | @@ -172,6 +190,10 @@ |
173 | 191 | return true; |
174 | 192 | } |
175 | 193 | |
| 194 | +/** |
| 195 | + * @param $out OutputPage |
| 196 | + * @return bool |
| 197 | + */ |
176 | 198 | function wfLanguageSelectorBeforePageDisplay( &$out ) { |
177 | 199 | global $wgLanguageSelectorLocation; |
178 | 200 | |
— | — | @@ -205,6 +227,12 @@ |
206 | 228 | return true; |
207 | 229 | } |
208 | 230 | |
| 231 | +/** |
| 232 | + * @param $input String |
| 233 | + * @param $args Array |
| 234 | + * @param $parser Parser |
| 235 | + * @return string |
| 236 | + */ |
209 | 237 | function wfLanguageSelectorTag( $input, $args, $parser ) { |
210 | 238 | $style = @$args['style']; |
211 | 239 | $class = @$args['class']; |
— | — | @@ -244,14 +272,19 @@ |
245 | 273 | return wfLanguageSelectorHTML( $parser->getTitle(), $style, $class, $selectorstyle, $buttonstyle, $showcode ); |
246 | 274 | } |
247 | 275 | |
| 276 | +/** |
| 277 | + * @param $skin Skin |
| 278 | + * @param $tpl QuickTemplate |
| 279 | + * @return bool |
| 280 | + */ |
248 | 281 | function wfLanguageSelectorSkinTemplateOutputPageBeforeExec( &$skin, &$tpl ) { |
249 | | - global $wgLanguageSelectorLocation, $wgLanguageSelectorLanguages; |
| 282 | + global $wgLanguageSelectorLocation; |
250 | 283 | global $wgLang, $wgContLang; |
251 | 284 | |
252 | 285 | if ($wgLanguageSelectorLocation == LANGUAGE_SELECTOR_AS_PORTLET) { |
253 | 286 | $code = $wgLang->getCode(); |
254 | 287 | $lines = array(); |
255 | | - foreach ($wgLanguageSelectorLanguages as $ln) { |
| 288 | + foreach ( wfGetLanguageSelectorLanguages() as $ln ) { |
256 | 289 | $lines[] = array( |
257 | 290 | $href = $skin->getTitle()->getFullURL( 'setlang=' . $ln ), |
258 | 291 | 'text' => $wgContLang->getLanguageName($ln), |
— | — | @@ -282,6 +315,10 @@ |
283 | 316 | return true; |
284 | 317 | } |
285 | 318 | |
| 319 | +/** |
| 320 | + * @param $u User |
| 321 | + * @return bool |
| 322 | + */ |
286 | 323 | function wfLanguageSelectorAddNewAccount( $u ) { |
287 | 324 | global $wgUser, $wgLang; |
288 | 325 | |
— | — | @@ -296,12 +333,18 @@ |
297 | 334 | return true; |
298 | 335 | } |
299 | 336 | |
| 337 | +/** |
| 338 | + * @param $outputPage OutputPage |
| 339 | + * @param $parserOutput ParserOutput |
| 340 | + * @param $data |
| 341 | + * @return void |
| 342 | + */ |
300 | 343 | function wfLanguageSelectorAddJavascript( $outputPage, $parserOutput, $data ) { |
301 | 344 | $outputPage->addModules( 'ext.languageSelector' ); |
302 | 345 | } |
303 | 346 | |
304 | 347 | 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, |
306 | 349 | $wgLanguageSelectorShowCode; |
307 | 350 | |
308 | 351 | if ( $showCode === null ) { |
— | — | @@ -333,7 +376,7 @@ |
334 | 377 | 'style' => $selectorstyle |
335 | 378 | ) ); |
336 | 379 | |
337 | | - foreach ( $wgLanguageSelectorLanguages as $ln ) { |
| 380 | + foreach ( wfGetLanguageSelectorLanguages() as $ln ) { |
338 | 381 | $name = $wgContLang->getLanguageName( $ln ); |
339 | 382 | if ( $showCode ) $name = wfBCP47( $ln ) . ' - ' . $name; |
340 | 383 | |