r6560 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r6559‎ | r6560 | r6561 >
Date:20:22, 7 December 2004
Author:zhengzhu
Status:old
Tags:
Comment:
more fixes for languages with no language files; allow UI customization for all languages.
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)
  • /trunk/phase3/includes/SpecialAllmessages.php (modified) (history)
  • /trunk/phase3/includes/SpecialPreferences.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/maintenance/InitialiseMessages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/InitialiseMessages.inc
@@ -19,7 +19,7 @@
2020 global $IP;
2121
2222 # overwrite language conversion option so that all variants
23 - # of the selected language are initialised
 23+ # of the messages are initialised
2424 $wgDisableLangConversion = false;
2525
2626 if ( $messageArray ) {
@@ -31,36 +31,26 @@
3232 ksort( $sortedArray );
3333 $messages=array();
3434
35 - /* check special case where the language does
36 - not have a language file
37 - */
38 - if( get_class($wgContLang) != 'language'.strtolower($wgContLanguageCode) ) {
 35+ $variants = $wgContLang->getVariants();
 36+ if(!in_array($wgContLanguageCode, $variants))
 37+ $variants[]=$wgContLanguageCode;
 38+
 39+ foreach ($variants as $v) {
 40+ $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
 41+ if( !class_exists($langclass) ) {
 42+ die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?");
 43+ }
 44+ $lang = new $langclass;
 45+
 46+ if($v==$wgContLanguageCode)
 47+ $suffix='';
 48+ else
 49+ $suffix="/$v";
3950 foreach ($sortedArray as $key => $msg) {
40 - $messages[$key] = $wgContLang->getMessage($key);
 51+ $messages[$key.$suffix] = $lang->getMessage($key);
4152 }
4253 }
43 - else {
44 - $variants = $wgContLang->getVariants();
45 - if(!in_array($wgContLanguageCode, $variants))
46 - $variants[]=$wgContLanguageCode;
4754
48 - foreach ($variants as $v) {
49 - $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
50 - if( !class_exists($langclass) ) {
51 - die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?");
52 - }
53 - $lang = new $langclass;
54 -
55 - if($v==$wgContLanguageCode)
56 - $suffix='';
57 - else
58 - $suffix="/$v";
59 - foreach ($sortedArray as $key => $msg) {
60 - $messages[$key.$suffix] = $lang->getMessage($key);
61 - }
62 - }
63 - }
64 -
6555 initialiseMessagesReal( $overwrite, $messages );
6656 }
6757
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -378,46 +378,16 @@
379379 $fname = 'wfMsgReal';
380380 wfProfileIn( $fname );
381381
382 - if( $forContent ) {
383 - /**
384 - * Message is needed for page content, and needs
385 - * to be consistent with the site's configured
386 - * language. It might be part of a page title,
387 - * or a link, or text that will go into the
388 - * parser cache and be served back to other
389 - * visitors.
390 - */
391 - $cache = &$wgMessageCache;
392 - $lang = &$wgContLang;
393 - } else {
394 - /**
395 - * Message is for display purposes only.
396 - * The user may have selected a conversion-based
397 - * language variant or a separate user interface
398 - * language; if so use that.
399 - */
400 - if ( is_object( $wgContLang ) ) {
401 - if( in_array( $wgLanguageCode, $wgContLang->getVariants() ) ) {
402 - $cache = &$wgMessageCache;
403 - $lang = &$wgLang;
404 - } else {
405 - $cache = false;
406 - $lang = &$wgLang;
407 - }
 382+ if( is_object( $wgMessageCache ) ) {
 383+ $message = $wgMessageCache->get( $key, $useDB, $forContent );
 384+ }
 385+ else {
 386+ if( $forContent ) {
 387+ $lang = &$wgContLang;
408388 } else {
409 - $cache = false;
410 - $lang = false;
 389+ $lang = &$wgLang;
411390 }
412 - }
413391
414 -
415 - if( is_object( $cache ) ) {
416 - $message = $cache->get( $key, $useDB, $forContent );
417 - } else {
418 - if ( !is_object( $lang ) ) {
419 - $lang = new Language;
420 - }
421 -
422392 wfSuppressWarnings();
423393 $message = $lang->getMessage( $key );
424394 wfRestoreWarnings();
Index: trunk/phase3/includes/Setup.php
@@ -239,28 +239,29 @@
240240 wfProfileOut( $fname.'-User' );
241241 wfProfileIn( $fname.'-language2' );
242242
243 -function setupLangObj(&$langclass, $langcode) {
 243+function setupLangObj(&$langclass) {
244244 global $wgUseLatin1, $IP;
245245
 246+ if( ! class_exists( $langclass ) ) {
 247+ # Default to English/UTF-8, or for non-UTF-8, to latin-1
 248+ $baseclass = 'LanguageUtf8';
 249+ if( $wgUseLatin1 )
 250+ $baseclass = 'LanguageLatin1';
 251+ require_once( "$IP/languages/$baseclass.php" );
 252+ $lc = strtolower(substr($langclass, 8));
 253+ $snip = "
 254+ class $langclass extends $baseclass {
 255+ function getVariants() {
 256+ return array(\"$lc\");
 257+ }
246258
247 - if( ! class_exists( $langclass ) ) {
248 - # Default to English/UTF-8
249 - require_once( "$IP/languages/LanguageUtf8.php" );
250 - $langclass = 'LanguageUtf8';
 259+ }";
 260+
 261+ eval($snip);
251262 }
252263
253264 $lang = new $langclass();
254 - if ( !is_object($lang) ) {
255 - print "No language class ($wgLang)\N";
256 - }
257265
258 - if( $wgUseLatin1 ) {
259 - # For non-UTF-8 latin-1 downconversion
260 - require_once( "$IP/languages/LanguageLatin1.php" );
261 - $xxx = new LanguageLatin1( $lang );
262 - unset( $lang );
263 - $lang = $xxx;
264 - }
265266 return $lang;
266267 }
267268
@@ -270,8 +271,7 @@
271272 $wgContLanguageCode = $wgLanguageCode;
272273 $wgContLangClass = 'Language' . str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
273274
274 -$wgContLang = setupLangObj( $wgContLangClass, $wgContLangClass );
275 -$n = get_class($wgContLang);
 275+$wgContLang = setupLangObj( $wgContLangClass );
276276
277277 // set default user option from content language
278278 if( !$wgUser->mDataLoaded ) {
@@ -286,11 +286,13 @@
287287 if( $wgLangClass == $wgContLangClass ) {
288288 $wgLang = &$wgContLang;
289289 } else {
290 - require_once("$IP/languages/$wgLangClass.php");
291 - $wgLang = setupLangObj( $wgLangClass, $wgLanguageCode );
 290+ wfSuppressWarnings();
 291+ include_once("$IP/languages/$wgLangClass.php");
 292+ wfRestoreWarnings();
 293+
 294+ $wgLang = setupLangObj( $wgLangClass );
292295 }
293296
294 -
295297 wfProfileOut( $fname.'-language' );
296298 wfProfileIn( $fname.'-MessageCache' );
297299
Index: trunk/phase3/includes/SpecialAllmessages.php
@@ -13,12 +13,6 @@
1414 global $wgLanguageCode, $wgContLanguageCode, $wgContLang;
1515 global $wgUseDatabaseMessages;
1616
17 - if($wgLanguageCode != $wgContLanguageCode &&
18 - !in_array($wgLanguageCode, $wgContLang->getVariants())) {
19 - $err = wfMsg('allmessagesnotsupportedUI', $wgLanguageCode);
20 - $wgOut->addHTML( $err );
21 - return;
22 - }
2317 if(!$wgUseDatabaseMessages) {
2418 $wgOut->addHTML(wfMsg('allmessagesnotsupportedDB'));
2519 return;
@@ -94,7 +88,7 @@
9589 *
9690 */
9791 function makeHTMLText( $messages ) {
98 - global $wgLang, $wgUser, $wgLanguageCode, $wgContLanguageCode;
 92+ global $wgLang, $wgUser, $wgLanguageCode, $wgContLanguageCode, $wgContLang;
9993 $fname = "makeHTMLText";
10094 wfProfileIn( $fname );
10195
@@ -128,11 +122,13 @@
129123 wfProfileOut( "$fname-check" );
130124
131125 wfProfileIn( "$fname-output" );
 126+
132127 foreach( $messages as $key => $m ) {
133128
134129 $title = $wgLang->ucfirst( $key );
135130 if($wgLanguageCode != $wgContLanguageCode)
136131 $title.="/$wgLanguageCode";
 132+
137133 $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
138134 $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
139135
Index: trunk/phase3/includes/SpecialPreferences.php
@@ -323,7 +323,7 @@
324324 global $wgUser, $wgOut, $wgLang, $wgContLang, $wgUseDynamicDates, $wgValidSkinNames;
325325 global $wgAllowRealName, $wgImageLimits;
326326 global $wgLanguageNames, $wgDisableLangConversion;
327 -
 327+ global $wgContLanguageCode;
328328 $wgOut->setPageTitle( wfMsg( 'preferences' ) );
329329 $wgOut->setArticleRelated( false );
330330 $wgOut->setRobotpolicy( 'noindex,nofollow' );
@@ -417,7 +417,7 @@
418418 global $IP;
419419 /* only add languages that have a file */
420420 $langfile="$IP/languages/Language".str_replace('-', '_', ucfirst($code)).".php";
421 - if(file_exists($langfile)) {
 421+ if(file_exists($langfile) || $code == $wgContLanguageCode) {
422422 $sel = ($code == $this->mUserLanguage)? 'selected="selected"' : '';
423423 $wgOut->addHtml("\t<option value=\"$code\" $sel>$code - $name</option>\n");
424424 }
Index: trunk/phase3/languages/Language.php
@@ -2184,20 +2184,14 @@
21852185 // utf8 if the language does not have a language file)
21862186 $v = $this->getVariants();
21872187 if( !empty( $v ) ) {
2188 - foreach ($v as $v2) {
2189 - if($v2 != 'utf8') {
2190 - $lang = $v2;
2191 - break;
2192 - }
2193 - }
 2188+ return $v[0];
21942189 }
21952190 if($lang != '')
21962191 return $lang;
21972192
21982193 // get it from the class name
21992194 $lang = strtolower( substr( get_class( $this ), 8 ) );
2200 - if($lang == 'utf8')
2201 - $lang = 'en';
 2195+
22022196 return $lang;
22032197 }
22042198

Follow-up revisions

RevisionCommit summaryAuthorDate
r24530Remove "allmessagesnotsupportedUI" message: not used since r6560.rotem21:20, 1 August 2007
r24631Merged revisions 24480-24600 via svnmerge from...david18:39, 6 August 2007

Status & tagging log