Smaller recursion limit for less ugly backtraces.
[lhc/web/wiklou.git] / languages / Language.php
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage Language
5 */
6
7 if( !defined( 'MEDIAWIKI' ) ) {
8 echo "This file is part of MediaWiki, it is not a valid entry point.\n";
9 exit( 1 );
10 }
11
12 #
13 # In general you should not make customizations in these language files
14 # directly, but should use the MediaWiki: special namespace to customize
15 # user interface messages through the wiki.
16 # See http://meta.wikipedia.org/wiki/MediaWiki_namespace
17 #
18 # NOTE TO TRANSLATORS: Do not copy this whole file when making translations!
19 # A lot of common constants and a base class with inheritable methods are
20 # defined here, which should not be redefined. See the other LanguageXx.php
21 # files for examples.
22 #
23
24 # Read language names
25 global $wgLanguageNames;
26 require_once( 'Names.php' );
27
28 global $wgInputEncoding, $wgOutputEncoding;
29 global $wgDBname, $wgMemc;
30
31 /**
32 * These are always UTF-8, they exist only for backwards compatibility
33 */
34 $wgInputEncoding = "UTF-8";
35 $wgOutputEncoding = "UTF-8";
36
37 if( function_exists( 'mb_strtoupper' ) ) {
38 mb_internal_encoding('UTF-8');
39 }
40
41 /* a fake language converter */
42 class FakeConverter {
43 var $mLang;
44 function FakeConverter($langobj) {$this->mLang = $langobj;}
45 function convert($t, $i) {return $t;}
46 function parserConvert($t, $p) {return $t;}
47 function getVariants() { return array( $this->mLang->getCode() ); }
48 function getPreferredVariant() {return $this->mLang->getCode(); }
49 function findVariantLink(&$l, &$n) {}
50 function getExtraHashOptions() {return '';}
51 function getParsedTitle() {return '';}
52 function markNoConversion($text) {return $text;}
53 function convertCategoryKey( $key ) {return $key; }
54
55 }
56
57 #--------------------------------------------------------------------------
58 # Internationalisation code
59 #--------------------------------------------------------------------------
60
61 class Language {
62 var $mConverter, $mVariants, $mCode, $mLoaded = false;
63
64 static public $mLocalisationKeys = array( 'fallback', 'namespaceNames',
65 'quickbarSettings', 'skinNames', 'mathNames',
66 'bookstoreList', 'magicWords', 'messages', 'rtl', 'digitTransformTable',
67 'separatorTransformTable', 'fallback8bitEncoding', 'linkPrefixExtension',
68 'defaultUserOptionOverrides', 'linkTrail', 'namespaceAliases',
69 'dateFormats', 'datePreferences', 'datePreferenceMigrationMap',
70 'defaultDateFormat', 'extraUserToggles' );
71
72 static public $mMergeableMapKeys = array( 'messages', 'namespaceNames', 'mathNames',
73 'dateFormats', 'defaultUserOptionOverrides', 'magicWords' );
74
75 static public $mMergeableListKeys = array( 'extraUserToggles' );
76
77 static public $mLocalisationCache = array();
78
79 static public $mWeekdayMsgs = array(
80 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday',
81 'friday', 'saturday'
82 );
83
84 static public $mWeekdayAbbrevMsgs = array(
85 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'
86 );
87
88 static public $mMonthMsgs = array(
89 'january', 'february', 'march', 'april', 'may_long', 'june',
90 'july', 'august', 'september', 'october', 'november',
91 'december'
92 );
93 static public $mMonthGenMsgs = array(
94 'january-gen', 'february-gen', 'march-gen', 'april-gen', 'may-gen', 'june-gen',
95 'july-gen', 'august-gen', 'september-gen', 'october-gen', 'november-gen',
96 'december-gen'
97 );
98 static public $mMonthAbbrevMsgs = array(
99 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug',
100 'sep', 'oct', 'nov', 'dec'
101 );
102
103 /**
104 * Create a language object for a given language code
105 */
106 static function factory( $code ) {
107 global $IP;
108 static $recursionLevel = 0;
109
110 if ( $code == 'en' ) {
111 $class = 'Language';
112 } else {
113 $class = 'Language' . str_replace( '-', '_', ucfirst( $code ) );
114 // Preload base classes to work around APC/PHP5 bug
115 if ( file_exists( "$IP/languages/$class.deps.php" ) ) {
116 include_once("$IP/languages/$class.deps.php");
117 }
118 if ( file_exists( "$IP/languages/$class.php" ) ) {
119 include_once("$IP/languages/$class.php");
120 }
121 }
122
123 if ( $recursionLevel > 5 ) {
124 throw new MWException( "Language fallback loop detected when creating class $class\n" );
125 }
126
127 if( ! class_exists( $class ) ) {
128 $fallback = Language::getFallbackFor( $code );
129 ++$recursionLevel;
130 $lang = Language::factory( $fallback );
131 --$recursionLevel;
132 $lang->setCode( $code );
133 } else {
134 $lang = new $class;
135 }
136
137 return $lang;
138 }
139
140 function __construct() {
141 $this->mConverter = new FakeConverter($this);
142 // Set the code to the name of the descendant
143 if ( get_class( $this ) == 'Language' ) {
144 $this->mCode = 'en';
145 } else {
146 $this->mCode = str_replace( '_', '-', strtolower( substr( get_class( $this ), 8 ) ) );
147 }
148 }
149
150 /**
151 * Hook which will be called if this is the content language.
152 * Descendants can use this to register hook functions or modify globals
153 */
154 function initContLang() {}
155
156 /**
157 * @deprecated
158 * @return array
159 */
160 function getDefaultUserOptions() {
161 return User::getDefaultOptions();
162 }
163
164 /**
165 * Exports $wgBookstoreListEn
166 * @return array
167 */
168 function getBookstoreList() {
169 $this->load();
170 return $this->bookstoreList;
171 }
172
173 /**
174 * @return array
175 */
176 function getNamespaces() {
177 $this->load();
178 return $this->namespaceNames;
179 }
180
181 /**
182 * A convenience function that returns the same thing as
183 * getNamespaces() except with the array values changed to ' '
184 * where it found '_', useful for producing output to be displayed
185 * e.g. in <select> forms.
186 *
187 * @return array
188 */
189 function getFormattedNamespaces() {
190 $ns = $this->getNamespaces();
191 foreach($ns as $k => $v) {
192 $ns[$k] = strtr($v, '_', ' ');
193 }
194 return $ns;
195 }
196
197 /**
198 * Get a namespace value by key
199 * <code>
200 * $mw_ns = $wgContLang->getNsText( NS_MEDIAWIKI );
201 * echo $mw_ns; // prints 'MediaWiki'
202 * </code>
203 *
204 * @param int $index the array key of the namespace to return
205 * @return mixed, string if the namespace value exists, otherwise false
206 */
207 function getNsText( $index ) {
208 $ns = $this->getNamespaces();
209 return isset( $ns[$index] ) ? $ns[$index] : false;
210 }
211
212 /**
213 * A convenience function that returns the same thing as
214 * getNsText() except with '_' changed to ' ', useful for
215 * producing output.
216 *
217 * @return array
218 */
219 function getFormattedNsText( $index ) {
220 $ns = $this->getNsText( $index );
221 return strtr($ns, '_', ' ');
222 }
223
224 /**
225 * Get a namespace key by value, case insensetive.
226 *
227 * @param string $text
228 * @return mixed An integer if $text is a valid value otherwise false
229 */
230 function getNsIndex( $text ) {
231 $this->load();
232 $index = @$this->mNamespaceIds[$this->lc($text)];
233 if ( is_null( $index ) ) {
234 return false;
235 } else {
236 return $index;
237 }
238 }
239
240 /**
241 * short names for language variants used for language conversion links.
242 *
243 * @param string $code
244 * @return string
245 */
246 function getVariantname( $code ) {
247 return wfMsg( "variantname-$code" );
248 }
249
250 function specialPage( $name ) {
251 return $this->getNsText(NS_SPECIAL) . ':' . $name;
252 }
253
254 function getQuickbarSettings() {
255 $this->load();
256 return $this->quickbarSettings;
257 }
258
259 function getSkinNames() {
260 $this->load();
261 return $this->skinNames;
262 }
263
264 function getMathNames() {
265 $this->load();
266 return $this->mathNames;
267 }
268
269 function getDatePreferences() {
270 $this->load();
271 return $this->datePreferences;
272 }
273
274 function getDateFormats() {
275 $this->load();
276 return $this->dateFormats;
277 }
278
279 function getDatePreferenceMigrationMap() {
280 $this->load();
281 return $this->datePreferenceMigrationMap;
282 }
283
284 function getDefaultUserOptionOverrides() {
285 $this->load();
286 return $this->defaultUserOptionOverrides;
287 }
288
289 function getExtraUserToggles() {
290 $this->load();
291 return $this->extraUserToggles;
292 }
293
294 function getUserToggle( $tog ) {
295 return wfMsg( "tog-$tog" );
296 }
297
298 /**
299 * Get language names, indexed by code.
300 * If $customisedOnly is true, only returns codes with a messages file
301 */
302 function getLanguageNames( $customisedOnly = false ) {
303 global $wgLanguageNames;
304 if ( !$customisedOnly ) {
305 return $wgLanguageNames;
306 }
307
308 global $IP;
309 $messageFiles = glob( "$IP/languages/Messages*.php" );
310 $names = array();
311 foreach ( $messageFiles as $file ) {
312 if( preg_match( '/Messages([A-Z][a-z_]+)\.php$/', $file, $m ) ) {
313 $code = str_replace( '_', '-', strtolower( $m[1] ) );
314 if ( isset( $wgLanguageNames[$code] ) ) {
315 $names[$code] = $wgLanguageNames[$code];
316 }
317 }
318 }
319 return $names;
320 }
321
322 /**
323 * Ugly hack to get a message maybe from the MediaWiki namespace, if this
324 * language object is the content or user language.
325 */
326 function getMessageFromDB( $msg ) {
327 global $wgContLang, $wgLang;
328 if ( $wgContLang->getCode() == $this->getCode() ) {
329 # Content language
330 return wfMsgForContent( $msg );
331 } elseif ( $wgLang->getCode() == $this->getCode() ) {
332 # User language
333 return wfMsg( $msg );
334 } else {
335 # Neither, get from localisation
336 return $this->getMessage( $msg );
337 }
338 }
339
340 function getLanguageName( $code ) {
341 global $wgLanguageNames;
342 if ( ! array_key_exists( $code, $wgLanguageNames ) ) {
343 return '';
344 }
345 return $wgLanguageNames[$code];
346 }
347
348 function getMonthName( $key ) {
349 return $this->getMessageFromDB( self::$mMonthMsgs[$key-1] );
350 }
351
352 function getMonthNameGen( $key ) {
353 return $this->getMessageFromDB( self::$mMonthGenMsgs[$key-1] );
354 }
355
356 function getMonthAbbreviation( $key ) {
357 return $this->getMessageFromDB( self::$mMonthAbbrevMsgs[$key-1] );
358 }
359
360 function getWeekdayName( $key ) {
361 return $this->getMessageFromDB( self::$mWeekdayMsgs[$key-1] );
362 }
363
364 function getWeekdayAbbreviation( $key ) {
365 return $this->getMessageFromDB( self::$mWeekdayAbbrevMsgs[$key-1] );
366 }
367
368 /**
369 * Used by date() and time() to adjust the time output.
370 * @public
371 * @param int $ts the time in date('YmdHis') format
372 * @param mixed $tz adjust the time by this amount (default false,
373 * mean we get user timecorrection setting)
374 * @return int
375 */
376 function userAdjust( $ts, $tz = false ) {
377 global $wgUser, $wgLocalTZoffset;
378
379 if (!$tz) {
380 $tz = $wgUser->getOption( 'timecorrection' );
381 }
382
383 # minutes and hours differences:
384 $minDiff = 0;
385 $hrDiff = 0;
386
387 if ( $tz === '' ) {
388 # Global offset in minutes.
389 if( isset($wgLocalTZoffset) ) {
390 $hrDiff = $wgLocalTZoffset % 60;
391 $minDiff = $wgLocalTZoffset - ($hrDiff * 60);
392 }
393 } elseif ( strpos( $tz, ':' ) !== false ) {
394 $tzArray = explode( ':', $tz );
395 $hrDiff = intval($tzArray[0]);
396 $minDiff = intval($hrDiff < 0 ? -$tzArray[1] : $tzArray[1]);
397 } else {
398 $hrDiff = intval( $tz );
399 }
400
401 # No difference ? Return time unchanged
402 if ( 0 == $hrDiff && 0 == $minDiff ) { return $ts; }
403
404 # Generate an adjusted date
405 $t = mktime( (
406 (int)substr( $ts, 8, 2) ) + $hrDiff, # Hours
407 (int)substr( $ts, 10, 2 ) + $minDiff, # Minutes
408 (int)substr( $ts, 12, 2 ), # Seconds
409 (int)substr( $ts, 4, 2 ), # Month
410 (int)substr( $ts, 6, 2 ), # Day
411 (int)substr( $ts, 0, 4 ) ); #Year
412 return date( 'YmdHis', $t );
413 }
414
415 /**
416 * This is a workalike of PHP's date() function, but with better
417 * internationalisation, a reduced set of format characters, and a better
418 * escaping format.
419 *
420 * Supported format characters are dDjlFmMnYyHis. See the PHP manual for
421 * definitions. There are a number of extensions, which start with "x":
422 *
423 * xn Do not translate digits of the next numeric format character
424 * xr Use roman numerals for the next numeric format character
425 * xx Literal x
426 * xg Genitive month name
427 *
428 * Characters enclosed in double quotes will be considered literal (with
429 * the quotes themselves removed). Unmatched quotes will be considered
430 * literal quotes. Example:
431 *
432 * "The month is" F => The month is January
433 * i's" => 20'11"
434 *
435 * Backslash escaping is also supported.
436 *
437 * @param string $format
438 * @param string $ts 14-character timestamp
439 * YYYYMMDDHHMMSS
440 * 01234567890123
441 */
442 function sprintfDate( $format, $ts ) {
443 $s = '';
444 $raw = false;
445 $roman = false;
446 for ( $p = 0; $p < strlen( $format ); $p++ ) {
447 $num = false;
448 $code = $format[$p];
449 if ( $code == 'x' && $p < strlen( $format ) - 1 ) {
450 $code .= $format[++$p];
451 }
452
453 switch ( $code ) {
454 case 'xx':
455 $s .= 'x';
456 break;
457 case 'xn':
458 $raw = true;
459 break;
460 case 'xr':
461 $roman = true;
462 break;
463 case 'xg':
464 $s .= $this->getMonthNameGen( substr( $ts, 4, 2 ) );
465 break;
466 case 'd':
467 $num = substr( $ts, 6, 2 );
468 break;
469 case 'D':
470 $s .= $this->getWeekdayAbbreviation( self::calculateWeekday( $ts ) );
471 break;
472 case 'j':
473 $num = intval( substr( $ts, 6, 2 ) );
474 break;
475 case 'l':
476 $s .= $this->getWeekdayName( self::calculateWeekday( $ts ) );
477 break;
478 case 'F':
479 $s .= $this->getMonthName( substr( $ts, 4, 2 ) );
480 break;
481 case 'm':
482 $num = substr( $ts, 4, 2 );
483 break;
484 case 'M':
485 $s .= $this->getMonthAbbreviation( substr( $ts, 4, 2 ) );
486 break;
487 case 'n':
488 $num = intval( substr( $ts, 4, 2 ) );
489 break;
490 case 'Y':
491 $num = substr( $ts, 0, 4 );
492 break;
493 case 'y':
494 $num = substr( $ts, 2, 2 );
495 break;
496 case 'H':
497 $num = substr( $ts, 8, 2 );
498 break;
499 case 'G':
500 $num = intval( substr( $ts, 8, 2 ) );
501 break;
502 case 'i':
503 $num = substr( $ts, 10, 2 );
504 break;
505 case 's':
506 $num = substr( $ts, 12, 2 );
507 break;
508 case '\\':
509 # Backslash escaping
510 if ( $p < strlen( $format ) - 1 ) {
511 $s .= $format[++$p];
512 } else {
513 $s .= '\\';
514 }
515 break;
516 case '"':
517 # Quoted literal
518 if ( $p < strlen( $format ) - 1 ) {
519 $endQuote = strpos( $format, '"', $p + 1 );
520 if ( $endQuote === false ) {
521 # No terminating quote, assume literal "
522 $s .= '"';
523 } else {
524 $s .= substr( $format, $p + 1, $endQuote - $p - 1 );
525 $p = $endQuote;
526 }
527 } else {
528 # Quote at end of string, assume literal "
529 $s .= '"';
530 }
531 break;
532 default:
533 $s .= $format[$p];
534 }
535 if ( $num !== false ) {
536 if ( $raw ) {
537 $s .= $num;
538 $raw = false;
539 } elseif ( $roman ) {
540 $s .= Language::romanNumeral( $num );
541 $roman = false;
542 } else {
543 $s .= $this->formatNum( $num, true );
544 }
545 $num = false;
546 }
547 }
548 return $s;
549 }
550
551 /**
552 * Roman number formatting up to 100
553 */
554 static function romanNumeral( $num ) {
555 static $units = array( 0, 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X' );
556 static $decades = array( 0, 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', 'C' );
557 $num = intval( $num );
558 if ( $num > 100 || $num <= 0 ) {
559 return $num;
560 }
561 $s = '';
562 if ( $num >= 10 ) {
563 $s .= $decades[floor( $num / 10 )];
564 $num = $num % 10;
565 }
566 if ( $num >= 1 ) {
567 $s .= $units[$num];
568 }
569 return $s;
570 }
571
572 /**
573 * Calculate the day of the week for a 14-character timestamp
574 * 0 for Sunday through to 6 for Saturday
575 * This takes about 100us on a slow computer
576 */
577 static function calculateWeekday( $ts ) {
578 return date( 'w', wfTimestamp( TS_UNIX, $ts ) );
579 }
580
581 /**
582 * This is meant to be used by time(), date(), and timeanddate() to get
583 * the date preference they're supposed to use, it should be used in
584 * all children.
585 *
586 *<code>
587 * function timeanddate([...], $format = true) {
588 * $datePreference = $this->dateFormat($format);
589 * [...]
590 * }
591 *</code>
592 *
593 * @param mixed $usePrefs: if true, the user's preference is used
594 * if false, the site/language default is used
595 * if int/string, assumed to be a format.
596 * @return string
597 */
598 function dateFormat( $usePrefs = true ) {
599 global $wgUser;
600
601 if( is_bool( $usePrefs ) ) {
602 if( $usePrefs ) {
603 $datePreference = $wgUser->getDatePreference();
604 } else {
605 $options = User::getDefaultOptions();
606 $datePreference = (string)$options['date'];
607 }
608 } else {
609 $datePreference = (string)$usePrefs;
610 }
611
612 // return int
613 if( $datePreference == '' ) {
614 return 'default';
615 }
616
617 return $datePreference;
618 }
619
620 /**
621 * @public
622 * @param mixed $ts the time format which needs to be turned into a
623 * date('YmdHis') format with wfTimestamp(TS_MW,$ts)
624 * @param bool $adj whether to adjust the time output according to the
625 * user configured offset ($timecorrection)
626 * @param mixed $format true to use user's date format preference
627 * @param string $timecorrection the time offset as returned by
628 * validateTimeZone() in Special:Preferences
629 * @return string
630 */
631 function date( $ts, $adj = false, $format = true, $timecorrection = false ) {
632 $this->load();
633 if ( $adj ) {
634 $ts = $this->userAdjust( $ts, $timecorrection );
635 }
636
637 $pref = $this->dateFormat( $format );
638 if( $pref == 'default' || !isset( $this->dateFormats["$pref date"] ) ) {
639 $pref = $this->defaultDateFormat;
640 }
641 return $this->sprintfDate( $this->dateFormats["$pref date"], $ts );
642 }
643
644 /**
645 * @public
646 * @param mixed $ts the time format which needs to be turned into a
647 * date('YmdHis') format with wfTimestamp(TS_MW,$ts)
648 * @param bool $adj whether to adjust the time output according to the
649 * user configured offset ($timecorrection)
650 * @param mixed $format true to use user's date format preference
651 * @param string $timecorrection the time offset as returned by
652 * validateTimeZone() in Special:Preferences
653 * @return string
654 */
655 function time( $ts, $adj = false, $format = true, $timecorrection = false ) {
656 $this->load();
657 if ( $adj ) {
658 $ts = $this->userAdjust( $ts, $timecorrection );
659 }
660
661 $pref = $this->dateFormat( $format );
662 if( $pref == 'default' || !isset( $this->dateFormats["$pref time"] ) ) {
663 $pref = $this->defaultDateFormat;
664 }
665 return $this->sprintfDate( $this->dateFormats["$pref time"], $ts );
666 }
667
668 /**
669 * @public
670 * @param mixed $ts the time format which needs to be turned into a
671 * date('YmdHis') format with wfTimestamp(TS_MW,$ts)
672 * @param bool $adj whether to adjust the time output according to the
673 * user configured offset ($timecorrection)
674
675 * @param mixed $format what format to return, if it's false output the
676 * default one (default true)
677 * @param string $timecorrection the time offset as returned by
678 * validateTimeZone() in Special:Preferences
679 * @return string
680 */
681 function timeanddate( $ts, $adj = false, $format = true, $timecorrection = false) {
682 $this->load();
683 if ( $adj ) {
684 $ts = $this->userAdjust( $ts, $timecorrection );
685 }
686
687 $pref = $this->dateFormat( $format );
688 if( $pref == 'default' || !isset( $this->dateFormats["$pref both"] ) ) {
689 $pref = $this->defaultDateFormat;
690 }
691
692 return $this->sprintfDate( $this->dateFormats["$pref both"], $ts );
693 }
694
695 function getMessage( $key ) {
696 $this->load();
697 return @$this->messages[$key];
698 }
699
700 function getAllMessages() {
701 $this->load();
702 return $this->messages;
703 }
704
705 function iconv( $in, $out, $string ) {
706 # For most languages, this is a wrapper for iconv
707 return iconv( $in, $out, $string );
708 }
709
710 function ucfirst( $str ) {
711 return self::uc( $str, true );
712 }
713
714 function uc( $str, $first = false ) {
715 if ( function_exists( 'mb_strtoupper' ) )
716 if ( $first )
717 if ( self::isMultibyte( $str ) )
718 return mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
719 else
720 return ucfirst( $str );
721 else
722 return self::isMultibyte( $str ) ? mb_strtoupper( $str ) : strtoupper( $str );
723 else
724 if ( self::isMultibyte( $str ) ) {
725 list( $wikiUpperChars ) = $this->getCaseMaps();
726 $x = $first ? '^' : '';
727 return preg_replace(
728 "/$x([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e",
729 "strtr( \"\$1\" , \$wikiUpperChars )",
730 $str
731 );
732 } else
733 return $first ? ucfirst( $str ) : strtoupper( $str );
734 }
735
736 function lcfirst( $str ) {
737 return self::lc( $str, true );
738 }
739
740 function lc( $str, $first = false ) {
741 if ( function_exists( 'mb_strtolower' ) )
742 if ( $first )
743 if ( self::isMultibyte( $str ) )
744 return mb_strtolower( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
745 else
746 return strtolower( substr( $str, 0, 1 ) ) . substr( $str, 1 );
747 else
748 return self::isMultibyte( $str ) ? mb_strtolower( $str ) : strtolower( $str );
749 else
750 if ( self::isMultibyte( $str ) ) {
751 list( , $wikiLowerChars ) = self::getCaseMaps();
752 $x = $first ? '^' : '';
753 return preg_replace(
754 "/$x([A-Z]|[\\xc0-\\xff][\\x80-\\xbf]*)/e",
755 "strtr( \"\$1\" , \$wikiLowerChars )",
756 $str
757 );
758 } else
759 return $first ? strtolower( substr( $str, 0, 1 ) ) . substr( $str, 1 ) : strtolower( $str );
760 }
761
762 function isMultibyte( $str ) {
763 return (bool)preg_match( '/^[\x80-\xff]/', $str );
764 }
765
766 function checkTitleEncoding( $s ) {
767 if( is_array( $s ) ) {
768 wfDebugDieBacktrace( 'Given array to checkTitleEncoding.' );
769 }
770 # Check for non-UTF-8 URLs
771 $ishigh = preg_match( '/[\x80-\xff]/', $s);
772 if(!$ishigh) return $s;
773
774 $isutf8 = preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
775 '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
776 if( $isutf8 ) return $s;
777
778 return $this->iconv( $this->fallback8bitEncoding(), "utf-8", $s );
779 }
780
781 function fallback8bitEncoding() {
782 $this->load();
783 return $this->fallback8bitEncoding;
784 }
785
786 /**
787 * Some languages have special punctuation to strip out
788 * or characters which need to be converted for MySQL's
789 * indexing to grok it correctly. Make such changes here.
790 *
791 * @param string $in
792 * @return string
793 */
794 function stripForSearch( $string ) {
795 # MySQL fulltext index doesn't grok utf-8, so we
796 # need to fold cases and convert to hex
797
798 wfProfileIn( __METHOD__ );
799 if( function_exists( 'mb_strtolower' ) ) {
800 $out = preg_replace(
801 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
802 "'U8' . bin2hex( \"$1\" )",
803 mb_strtolower( $string ) );
804 } else {
805 list( , $wikiLowerChars ) = self::getCaseMaps();
806 $out = preg_replace(
807 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
808 "'U8' . bin2hex( strtr( \"\$1\", \$wikiLowerChars ) )",
809 $string );
810 }
811 wfProfileOut( __METHOD__ );
812 return $out;
813 }
814
815 function convertForSearchResult( $termsArray ) {
816 # some languages, e.g. Chinese, need to do a conversion
817 # in order for search results to be displayed correctly
818 return $termsArray;
819 }
820
821 /**
822 * Get the first character of a string.
823 *
824 * @param string $s
825 * @return string
826 */
827 function firstChar( $s ) {
828 preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
829 '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})/', $s, $matches);
830
831 return isset( $matches[1] ) ? $matches[1] : "";
832 }
833
834 function initEncoding() {
835 # Some languages may have an alternate char encoding option
836 # (Esperanto X-coding, Japanese furigana conversion, etc)
837 # If this language is used as the primary content language,
838 # an override to the defaults can be set here on startup.
839 }
840
841 function recodeForEdit( $s ) {
842 # For some languages we'll want to explicitly specify
843 # which characters make it into the edit box raw
844 # or are converted in some way or another.
845 # Note that if wgOutputEncoding is different from
846 # wgInputEncoding, this text will be further converted
847 # to wgOutputEncoding.
848 global $wgEditEncoding;
849 if( $wgEditEncoding == '' or
850 $wgEditEncoding == 'UTF-8' ) {
851 return $s;
852 } else {
853 return $this->iconv( 'UTF-8', $wgEditEncoding, $s );
854 }
855 }
856
857 function recodeInput( $s ) {
858 # Take the previous into account.
859 global $wgEditEncoding;
860 if($wgEditEncoding != "") {
861 $enc = $wgEditEncoding;
862 } else {
863 $enc = 'UTF-8';
864 }
865 if( $enc == 'UTF-8' ) {
866 return $s;
867 } else {
868 return $this->iconv( $enc, 'UTF-8', $s );
869 }
870 }
871
872 /**
873 * For right-to-left language support
874 *
875 * @return bool
876 */
877 function isRTL() {
878 $this->load();
879 return $this->rtl;
880 }
881
882 /**
883 * A hidden direction mark (LRM or RLM), depending on the language direction
884 *
885 * @return string
886 */
887 function getDirMark() { return $this->isRTL() ? "\xE2\x80\x8F" : "\xE2\x80\x8E"; }
888
889 /**
890 * To allow "foo[[bar]]" to extend the link over the whole word "foobar"
891 *
892 * @return bool
893 */
894 function linkPrefixExtension() {
895 $this->load();
896 return $this->linkPrefixExtension;
897 }
898
899 function &getMagicWords() {
900 $this->load();
901 return $this->magicWords;
902 }
903
904 # Fill a MagicWord object with data from here
905 function getMagic( &$mw ) {
906 if ( !isset( $this->mMagicExtensions ) ) {
907 $this->mMagicExtensions = array();
908 wfRunHooks( 'LanguageGetMagic', array( &$this->mMagicExtensions, $this->getCode() ) );
909 }
910 if ( isset( $this->mMagicExtensions[$mw->mId] ) ) {
911 $rawEntry = $this->mMagicExtensions[$mw->mId];
912 } else {
913 $magicWords =& $this->getMagicWords();
914 if ( isset( $magicWords[$mw->mId] ) ) {
915 $rawEntry = $magicWords[$mw->mId];
916 } else {
917 # Fall back to English if local list is incomplete
918 $magicWords =& Language::getMagicWords();
919 $rawEntry = $magicWords[$mw->mId];
920 }
921 }
922
923 $mw->mCaseSensitive = $rawEntry[0];
924 $mw->mSynonyms = array_slice( $rawEntry, 1 );
925 }
926
927 /**
928 * Italic is unsuitable for some languages
929 *
930 * @public
931 *
932 * @param string $text The text to be emphasized.
933 * @return string
934 */
935 function emphasize( $text ) {
936 return "<em>$text</em>";
937 }
938
939 /**
940 * Normally we output all numbers in plain en_US style, that is
941 * 293,291.235 for twohundredninetythreethousand-twohundredninetyone
942 * point twohundredthirtyfive. However this is not sutable for all
943 * languages, some such as Pakaran want ੨੯੩,੨੯੫.੨੩੫ and others such as
944 * Icelandic just want to use commas instead of dots, and dots instead
945 * of commas like "293.291,235".
946 *
947 * An example of this function being called:
948 * <code>
949 * wfMsg( 'message', $wgLang->formatNum( $num ) )
950 * </code>
951 *
952 * See LanguageGu.php for the Gujarati implementation and
953 * LanguageIs.php for the , => . and . => , implementation.
954 *
955 * @todo check if it's viable to use localeconv() for the decimal
956 * seperator thing.
957 * @public
958 * @param mixed $number the string to be formatted, should be an integer or
959 * a floating point number.
960 * @param bool $nocommafy Set to true for special numbers like dates
961 * @return string
962 */
963 function formatNum( $number, $nocommafy = false ) {
964 global $wgTranslateNumerals;
965 if (!$nocommafy) {
966 $number = $this->commafy($number);
967 $s = $this->separatorTransformTable();
968 if (!is_null($s)) { $number = strtr($number, $s); }
969 }
970
971 if ($wgTranslateNumerals) {
972 $s = $this->digitTransformTable();
973 if (!is_null($s)) { $number = strtr($number, $s); }
974 }
975
976 return $number;
977 }
978
979 /**
980 * Adds commas to a given number
981 *
982 * @param mixed $_
983 * @return string
984 */
985 function commafy($_) {
986 return strrev((string)preg_replace('/(\d{3})(?=\d)(?!\d*\.)/','$1,',strrev($_)));
987 }
988
989 function digitTransformTable() {
990 $this->load();
991 return $this->digitTransformTable;
992 }
993
994 function separatorTransformTable() {
995 $this->load();
996 return $this->separatorTransformTable;
997 }
998
999
1000 /**
1001 * For the credit list in includes/Credits.php (action=credits)
1002 *
1003 * @param array $l
1004 * @return string
1005 */
1006 function listToText( $l ) {
1007 $s = '';
1008 $m = count($l) - 1;
1009 for ($i = $m; $i >= 0; $i--) {
1010 if ($i == $m) {
1011 $s = $l[$i];
1012 } else if ($i == $m - 1) {
1013 $s = $l[$i] . ' ' . wfMsg('and') . ' ' . $s;
1014 } else {
1015 $s = $l[$i] . ', ' . $s;
1016 }
1017 }
1018 return $s;
1019 }
1020
1021 # Crop a string from the beginning or end to a certain number of bytes.
1022 # (Bytes are used because our storage has limited byte lengths for some
1023 # columns in the database.) Multibyte charsets will need to make sure that
1024 # only whole characters are included!
1025 #
1026 # $length does not include the optional ellipsis.
1027 # If $length is negative, snip from the beginning
1028 function truncate( $string, $length, $ellipsis = "" ) {
1029 if( $length == 0 ) {
1030 return $ellipsis;
1031 }
1032 if ( strlen( $string ) <= abs( $length ) ) {
1033 return $string;
1034 }
1035 if( $length > 0 ) {
1036 $string = substr( $string, 0, $length );
1037 $char = ord( $string[strlen( $string ) - 1] );
1038 if ($char >= 0xc0) {
1039 # We got the first byte only of a multibyte char; remove it.
1040 $string = substr( $string, 0, -1 );
1041 } elseif( $char >= 0x80 &&
1042 preg_match( '/^(.*)(?:[\xe0-\xef][\x80-\xbf]|' .
1043 '[\xf0-\xf7][\x80-\xbf]{1,2})$/', $string, $m ) ) {
1044 # We chopped in the middle of a character; remove it
1045 $string = $m[1];
1046 }
1047 return $string . $ellipsis;
1048 } else {
1049 $string = substr( $string, $length );
1050 $char = ord( $string[0] );
1051 if( $char >= 0x80 && $char < 0xc0 ) {
1052 # We chopped in the middle of a character; remove the whole thing
1053 $string = preg_replace( '/^[\x80-\xbf]+/', '', $string );
1054 }
1055 return $ellipsis . $string;
1056 }
1057 }
1058
1059 /**
1060 * Grammatical transformations, needed for inflected languages
1061 * Invoked by putting {{grammar:case|word}} in a message
1062 *
1063 * @param string $word
1064 * @param string $case
1065 * @return string
1066 */
1067 function convertGrammar( $word, $case ) {
1068 global $wgGrammarForms;
1069 if ( isset($wgGrammarForms['en'][$case][$word]) ) {
1070 return $wgGrammarForms['en'][$case][$word];
1071 }
1072 return $word;
1073 }
1074
1075 /**
1076 * Plural form transformations, needed for some languages.
1077 * For example, where are 3 form of plural in Russian and Polish,
1078 * depending on "count mod 10". See [[w:Plural]]
1079 * For English it is pretty simple.
1080 *
1081 * Invoked by putting {{plural:count|wordform1|wordform2}}
1082 * or {{plural:count|wordform1|wordform2|wordform3}}
1083 *
1084 * Example: {{plural:{{NUMBEROFARTICLES}}|article|articles}}
1085 *
1086 * @param integer $count
1087 * @param string $wordform1
1088 * @param string $wordform2
1089 * @param string $wordform3 (optional)
1090 * @return string
1091 */
1092 function convertPlural( $count, $w1, $w2, $w3) {
1093 return $count == '1' ? $w1 : $w2;
1094 }
1095
1096 /**
1097 * For translaing of expiry times
1098 * @param string The validated block time in English
1099 * @return Somehow translated block time
1100 * @see LanguageFi.php for example implementation
1101 */
1102 function translateBlockExpiry( $str ) {
1103
1104 $scBlockExpiryOptions = wfMsg( 'ipboptions' );
1105
1106 if ( $scBlockExpiryOptions == '-') {
1107 return $str;
1108 }
1109
1110 foreach (explode(',', $scBlockExpiryOptions) as $option) {
1111 if ( strpos($option, ":") === false )
1112 continue;
1113 list($show, $value) = explode(":", $option);
1114 if ( strcmp ( $str, $value) == 0 )
1115 return '<span title="' . htmlspecialchars($str). '">' .
1116 htmlspecialchars( trim( $show ) ) . '</span>';
1117 }
1118
1119 return $str;
1120 }
1121
1122 /**
1123 * languages like Chinese need to be segmented in order for the diff
1124 * to be of any use
1125 *
1126 * @param string $text
1127 * @return string
1128 */
1129 function segmentForDiff( $text ) {
1130 return $text;
1131 }
1132
1133 /**
1134 * and unsegment to show the result
1135 *
1136 * @param string $text
1137 * @return string
1138 */
1139 function unsegmentForDiff( $text ) {
1140 return $text;
1141 }
1142
1143 # convert text to different variants of a language.
1144 function convert( $text, $isTitle = false) {
1145 return $this->mConverter->convert($text, $isTitle);
1146 }
1147
1148 # Convert text from within Parser
1149 function parserConvert( $text, &$parser ) {
1150 return $this->mConverter->parserConvert( $text, $parser );
1151 }
1152
1153 /**
1154 * Perform output conversion on a string, and encode for safe HTML output.
1155 * @param string $text
1156 * @param bool $isTitle -- wtf?
1157 * @return string
1158 * @todo this should get integrated somewhere sane
1159 */
1160 function convertHtml( $text, $isTitle = false ) {
1161 return htmlspecialchars( $this->convert( $text, $isTitle ) );
1162 }
1163
1164 function convertCategoryKey( $key ) {
1165 return $this->mConverter->convertCategoryKey( $key );
1166 }
1167
1168 /**
1169 * get the list of variants supported by this langauge
1170 * see sample implementation in LanguageZh.php
1171 *
1172 * @return array an array of language codes
1173 */
1174 function getVariants() {
1175 return $this->mConverter->getVariants();
1176 }
1177
1178
1179 function getPreferredVariant( $fromUser = true ) {
1180 return $this->mConverter->getPreferredVariant( $fromUser );
1181 }
1182
1183 /**
1184 * if a language supports multiple variants, it is
1185 * possible that non-existing link in one variant
1186 * actually exists in another variant. this function
1187 * tries to find it. See e.g. LanguageZh.php
1188 *
1189 * @param string $link the name of the link
1190 * @param mixed $nt the title object of the link
1191 * @return null the input parameters may be modified upon return
1192 */
1193 function findVariantLink( &$link, &$nt ) {
1194 $this->mConverter->findVariantLink($link, $nt);
1195 }
1196
1197 /**
1198 * returns language specific options used by User::getPageRenderHash()
1199 * for example, the preferred language variant
1200 *
1201 * @return string
1202 * @public
1203 */
1204 function getExtraHashOptions() {
1205 return $this->mConverter->getExtraHashOptions();
1206 }
1207
1208 /**
1209 * for languages that support multiple variants, the title of an
1210 * article may be displayed differently in different variants. this
1211 * function returns the apporiate title defined in the body of the article.
1212 *
1213 * @return string
1214 */
1215 function getParsedTitle() {
1216 return $this->mConverter->getParsedTitle();
1217 }
1218
1219 /**
1220 * Enclose a string with the "no conversion" tag. This is used by
1221 * various functions in the Parser
1222 *
1223 * @param string $text text to be tagged for no conversion
1224 * @return string the tagged text
1225 */
1226 function markNoConversion( $text ) {
1227 return $this->mConverter->markNoConversion( $text );
1228 }
1229
1230 /**
1231 * A regular expression to match legal word-trailing characters
1232 * which should be merged onto a link of the form [[foo]]bar.
1233 *
1234 * @return string
1235 * @public
1236 */
1237 function linkTrail() {
1238 $this->load();
1239 return $this->linkTrail;
1240 }
1241
1242 function getLangObj() {
1243 return $this;
1244 }
1245
1246 /**
1247 * Get the RFC 3066 code for this language object
1248 */
1249 function getCode() {
1250 return $this->mCode;
1251 }
1252
1253 function setCode( $code ) {
1254 $this->mCode = $code;
1255 }
1256
1257 static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
1258 return $prefix . str_replace( '-', '_', ucfirst( $code ) ) . $suffix;
1259 }
1260
1261 static function getLocalisationArray( $code, $disableCache = false ) {
1262 self::loadLocalisation( $code, $disableCache );
1263 return self::$mLocalisationCache[$code];
1264 }
1265
1266 /**
1267 * Load localisation data for a given code into the static cache
1268 *
1269 * @return array Dependencies, map of filenames to mtimes
1270 */
1271 static function loadLocalisation( $code, $disableCache = false ) {
1272 static $recursionGuard = array();
1273 global $wgMemc, $wgDBname, $IP;
1274
1275 if ( !$code ) {
1276 throw new MWException( "Invalid language code requested" );
1277 }
1278
1279 if ( !$disableCache ) {
1280 # Try the per-process cache
1281 if ( isset( self::$mLocalisationCache[$code] ) ) {
1282 return self::$mLocalisationCache[$code]['deps'];
1283 }
1284
1285 wfProfileIn( __METHOD__ );
1286
1287 # Try the serialized directory
1288 $cache = wfGetPrecompiledData( self::getFileName( "Messages", $code, '.ser' ) );
1289 if ( $cache ) {
1290 self::$mLocalisationCache[$code] = $cache;
1291 wfDebug( "Got localisation for $code from precompiled data file\n" );
1292 wfProfileOut( __METHOD__ );
1293 return self::$mLocalisationCache[$code]['deps'];
1294 }
1295
1296 # Try the global cache
1297 $memcKey = "$wgDBname:localisation:$code";
1298 $cache = $wgMemc->get( $memcKey );
1299 if ( $cache ) {
1300 $expired = false;
1301 # Check file modification times
1302 foreach ( $cache['deps'] as $file => $mtime ) {
1303 if ( filemtime( $file ) > $mtime ) {
1304 $expired = true;
1305 break;
1306 }
1307 }
1308 if ( self::isLocalisationOutOfDate( $cache ) ) {
1309 $wgMemc->delete( $memcKey );
1310 $cache = false;
1311 wfDebug( "Localisation cache for $code had expired due to update of $file\n" );
1312 } else {
1313 self::$mLocalisationCache[$code] = $cache;
1314 wfDebug( "Got localisation for $code from cache\n" );
1315 wfProfileOut( __METHOD__ );
1316 return $cache['deps'];
1317 }
1318 }
1319 } else {
1320 wfProfileIn( __METHOD__ );
1321 }
1322
1323 if ( $code != 'en' ) {
1324 $fallback = 'en';
1325 } else {
1326 $fallback = false;
1327 }
1328
1329 # Load the primary localisation from the source file
1330 global $IP;
1331 $filename = self::getFileName( "$IP/languages/Messages", $code, '.php' );
1332 if ( !file_exists( $filename ) ) {
1333 wfDebug( "No localisation file for $code, using implicit fallback to en\n" );
1334 $cache = array();
1335 $deps = array();
1336 } else {
1337 $deps = array( $filename => filemtime( $filename ) );
1338 require( $filename );
1339 $cache = compact( self::$mLocalisationKeys );
1340 wfDebug( "Got localisation for $code from source\n" );
1341 }
1342
1343 if ( !empty( $fallback ) ) {
1344 # Load the fallback localisation, with a circular reference guard
1345 if ( isset( $recursionGuard[$code] ) ) {
1346 throw new MWException( "Error: Circular fallback reference in language code $code" );
1347 }
1348 $recursionGuard[$code] = true;
1349 $newDeps = self::loadLocalisation( $fallback );
1350 unset( $recursionGuard[$code] );
1351
1352 $secondary = self::$mLocalisationCache[$fallback];
1353 $deps = array_merge( $deps, $newDeps );
1354
1355 # Merge the fallback localisation with the current localisation
1356 foreach ( self::$mLocalisationKeys as $key ) {
1357 if ( isset( $cache[$key] ) ) {
1358 if ( isset( $secondary[$key] ) ) {
1359 if ( in_array( $key, self::$mMergeableMapKeys ) ) {
1360 $cache[$key] = $cache[$key] + $secondary[$key];
1361 } elseif ( in_array( $key, self::$mMergeableListKeys ) ) {
1362 $cache[$key] = array_merge( $secondary[$key], $cache[$key] );
1363 }
1364 }
1365 } else {
1366 $cache[$key] = $secondary[$key];
1367 }
1368 }
1369
1370 # Merge bookstore lists if requested
1371 if ( !empty( $cache['bookstoreList']['inherit'] ) ) {
1372 $cache['bookstoreList'] = array_merge( $cache['bookstoreList'], $secondary['bookstoreList'] );
1373 }
1374 if ( isset( $cache['bookstoreList']['inherit'] ) ) {
1375 unset( $cache['bookstoreList']['inherit'] );
1376 }
1377 }
1378
1379 # Add dependencies to the cache entry
1380 $cache['deps'] = $deps;
1381
1382 # Save to both caches
1383 self::$mLocalisationCache[$code] = $cache;
1384 if ( !$disableCache ) {
1385 $wgMemc->set( $memcKey, $cache );
1386 }
1387
1388 wfProfileOut( __METHOD__ );
1389 return $deps;
1390 }
1391
1392 /**
1393 * Test if a given localisation cache is out of date with respect to the
1394 * source Messages files. This is done automatically for the global cache
1395 * in $wgMemc, but is only done on certain occasions for the serialized
1396 * data file.
1397 *
1398 * @param $cache mixed Either a language code or a cache array
1399 */
1400 static function isLocalisationOutOfDate( $cache ) {
1401 if ( !is_array( $cache ) ) {
1402 self::loadLocalisation( $cache );
1403 $cache = self::$mLocalisationCache[$cache];
1404 }
1405 $expired = false;
1406 foreach ( $cache['deps'] as $file => $mtime ) {
1407 if ( filemtime( $file ) > $mtime ) {
1408 $expired = true;
1409 break;
1410 }
1411 }
1412 return $expired;
1413 }
1414
1415 /**
1416 * Get the fallback for a given language
1417 */
1418 static function getFallbackFor( $code ) {
1419 self::loadLocalisation( $code );
1420 return self::$mLocalisationCache[$code]['fallback'];
1421 }
1422
1423 /**
1424 * Get all messages for a given language
1425 */
1426 static function getMessagesFor( $code ) {
1427 self::loadLocalisation( $code );
1428 return self::$mLocalisationCache[$code]['messages'];
1429 }
1430
1431 /**
1432 * Load localisation data for this object
1433 */
1434 function load() {
1435 if ( !$this->mLoaded ) {
1436 self::loadLocalisation( $this->getCode() );
1437 $cache =& self::$mLocalisationCache[$this->getCode()];
1438 foreach ( self::$mLocalisationKeys as $key ) {
1439 $this->$key = $cache[$key];
1440 }
1441 $this->mLoaded = true;
1442
1443 $this->fixUpSettings();
1444 }
1445 }
1446
1447 /**
1448 * Do any necessary post-cache-load settings adjustment
1449 */
1450 function fixUpSettings() {
1451 global $wgExtraNamespaces, $wgMetaNamespace, $wgMetaNamespaceTalk, $wgMessageCache,
1452 $wgNamespaceAliases, $wgAmericanDates;
1453 wfProfileIn( __METHOD__ );
1454 if ( $wgExtraNamespaces ) {
1455 $this->namespaceNames = $wgExtraNamespaces + $this->namespaceNames;
1456 }
1457
1458 $this->namespaceNames[NS_PROJECT] = $wgMetaNamespace;
1459 if ( $wgMetaNamespaceTalk ) {
1460 $this->namespaceNames[NS_PROJECT_TALK] = $wgMetaNamespaceTalk;
1461 } else {
1462 $talk = $this->namespaceNames[NS_PROJECT_TALK];
1463 $talk = str_replace( '$1', $wgMetaNamespace, $talk );
1464
1465 # Allow grammar transformations
1466 # Allowing full message-style parsing would make simple requests
1467 # such as action=raw much more expensive than they need to be.
1468 # This will hopefully cover most cases.
1469 $talk = preg_replace_callback( '/{{grammar:(.*?)\|(.*?)}}/',
1470 array( &$this, 'replaceGrammarInNamespace' ), $talk );
1471 $talk = str_replace( ' ', '_', $talk );
1472 $this->namespaceNames[NS_PROJECT_TALK] = $talk;
1473 }
1474
1475 # The above mixing may leave namespaces out of canonical order.
1476 # Re-order by namespace ID number...
1477 ksort( $this->namespaceNames );
1478
1479 # Put namespace names and aliases into a hashtable.
1480 # If this is too slow, then we should arrange it so that it is done
1481 # before caching. The catch is that at pre-cache time, the above
1482 # class-specific fixup hasn't been done.
1483 $this->mNamespaceIds = array();
1484 foreach ( $this->namespaceNames as $index => $name ) {
1485 $this->mNamespaceIds[$this->lc($name)] = $index;
1486 }
1487 if ( $this->namespaceAliases ) {
1488 foreach ( $this->namespaceAliases as $name => $index ) {
1489 $this->mNamespaceIds[$this->lc($name)] = $index;
1490 }
1491 }
1492 if ( $wgNamespaceAliases ) {
1493 foreach ( $wgNamespaceAliases as $name => $index ) {
1494 $this->mNamespaceIds[$this->lc($name)] = $index;
1495 }
1496 }
1497
1498 if ( $this->defaultDateFormat == 'dmy or mdy' ) {
1499 $this->defaultDateFormat = $wgAmericanDates ? 'mdy' : 'dmy';
1500 }
1501 wfProfileOut( __METHOD__ );
1502 }
1503
1504 function replaceGrammarInNamespace( $m ) {
1505 return $this->convertGrammar( trim( $m[2] ), trim( $m[1] ) );
1506 }
1507
1508 static function getCaseMaps() {
1509 static $wikiUpperChars, $wikiLowerChars;
1510 global $IP;
1511 if ( isset( $wikiUpperChars ) ) {
1512 return array( $wikiUpperChars, $wikiLowerChars );
1513 }
1514
1515 wfProfileIn( __METHOD__ );
1516 $arr = wfGetPrecompiledData( 'Utf8Case.ser' );
1517 if ( $arr === false ) {
1518 throw new MWException(
1519 "Utf8Case.ser is missing, please run \"make\" in the serialized directory\n" );
1520 }
1521 extract( $arr );
1522 wfProfileOut( __METHOD__ );
1523 return array( $wikiUpperChars, $wikiLowerChars );
1524 }
1525 }
1526
1527 /** @deprecated */
1528 class LanguageUtf8 extends Language {}
1529 ?>