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