* API: All pages list
[mediawiki.git] / languages / Language.php
bloba3990d67d03da13baf370dc227e0a10f18b92140
1 <?php
2 /**
3 * @package MediaWiki
4 * @subpackage Language
5 */
7 if( !defined( 'MEDIAWIKI' ) ) {
8 echo "This file is part of MediaWiki, it is not a valid entry point.\n";
9 exit( 1 );
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
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.
24 # Read language names
25 global $wgLanguageNames;
26 require_once( 'Names.php' );
28 global $wgInputEncoding, $wgOutputEncoding;
29 global $wgDBname, $wgMemc;
31 /**
32 * These are always UTF-8, they exist only for backwards compatibility
34 $wgInputEncoding = "UTF-8";
35 $wgOutputEncoding = "UTF-8";
37 if( function_exists( 'mb_strtoupper' ) ) {
38 mb_internal_encoding('UTF-8');
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, $noParse=false) {return $text;}
53 function convertCategoryKey( $key ) {return $key; }
54 function convertLinkToAllVariants($text){ return array( $this->mLang->getCode() => $text); }
55 function setNoTitleConvert(){}
58 #--------------------------------------------------------------------------
59 # Internationalisation code
60 #--------------------------------------------------------------------------
62 class Language {
63 var $mConverter, $mVariants, $mCode, $mLoaded = false;
65 static public $mLocalisationKeys = array( 'fallback', 'namespaceNames',
66 'quickbarSettings', 'skinNames', 'mathNames',
67 'bookstoreList', 'magicWords', 'messages', 'rtl', 'digitTransformTable',
68 'separatorTransformTable', 'fallback8bitEncoding', 'linkPrefixExtension',
69 'defaultUserOptionOverrides', 'linkTrail', 'namespaceAliases',
70 'dateFormats', 'datePreferences', 'datePreferenceMigrationMap',
71 'defaultDateFormat', 'extraUserToggles' );
73 static public $mMergeableMapKeys = array( 'messages', 'namespaceNames', 'mathNames',
74 'dateFormats', 'defaultUserOptionOverrides', 'magicWords' );
76 static public $mMergeableListKeys = array( 'extraUserToggles' );
78 static public $mLocalisationCache = array();
80 static public $mWeekdayMsgs = array(
81 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday',
82 'friday', 'saturday'
85 static public $mWeekdayAbbrevMsgs = array(
86 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'
89 static public $mMonthMsgs = array(
90 'january', 'february', 'march', 'april', 'may_long', 'june',
91 'july', 'august', 'september', 'october', 'november',
92 'december'
94 static public $mMonthGenMsgs = array(
95 'january-gen', 'february-gen', 'march-gen', 'april-gen', 'may-gen', 'june-gen',
96 'july-gen', 'august-gen', 'september-gen', 'october-gen', 'november-gen',
97 'december-gen'
99 static public $mMonthAbbrevMsgs = array(
100 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug',
101 'sep', 'oct', 'nov', 'dec'
105 * Create a language object for a given language code
107 static function factory( $code ) {
108 global $IP;
109 static $recursionLevel = 0;
111 if ( $code == 'en' ) {
112 $class = 'Language';
113 } else {
114 $class = 'Language' . str_replace( '-', '_', ucfirst( $code ) );
115 // Preload base classes to work around APC/PHP5 bug
116 if ( file_exists( "$IP/languages/$class.deps.php" ) ) {
117 include_once("$IP/languages/$class.deps.php");
119 if ( file_exists( "$IP/languages/$class.php" ) ) {
120 include_once("$IP/languages/$class.php");
124 if ( $recursionLevel > 5 ) {
125 throw new MWException( "Language fallback loop detected when creating class $class\n" );
128 if( ! class_exists( $class ) ) {
129 $fallback = Language::getFallbackFor( $code );
130 ++$recursionLevel;
131 $lang = Language::factory( $fallback );
132 --$recursionLevel;
133 $lang->setCode( $code );
134 } else {
135 $lang = new $class;
138 return $lang;
141 function __construct() {
142 $this->mConverter = new FakeConverter($this);
143 // Set the code to the name of the descendant
144 if ( get_class( $this ) == 'Language' ) {
145 $this->mCode = 'en';
146 } else {
147 $this->mCode = str_replace( '_', '-', strtolower( substr( get_class( $this ), 8 ) ) );
152 * Hook which will be called if this is the content language.
153 * Descendants can use this to register hook functions or modify globals
155 function initContLang() {}
158 * @deprecated
159 * @return array
161 function getDefaultUserOptions() {
162 return User::getDefaultOptions();
166 * Exports $wgBookstoreListEn
167 * @return array
169 function getBookstoreList() {
170 $this->load();
171 return $this->bookstoreList;
175 * @return array
177 function getNamespaces() {
178 $this->load();
179 return $this->namespaceNames;
183 * A convenience function that returns the same thing as
184 * getNamespaces() except with the array values changed to ' '
185 * where it found '_', useful for producing output to be displayed
186 * e.g. in <select> forms.
188 * @return array
190 function getFormattedNamespaces() {
191 $ns = $this->getNamespaces();
192 foreach($ns as $k => $v) {
193 $ns[$k] = strtr($v, '_', ' ');
195 return $ns;
199 * Get a namespace value by key
200 * <code>
201 * $mw_ns = $wgContLang->getNsText( NS_MEDIAWIKI );
202 * echo $mw_ns; // prints 'MediaWiki'
203 * </code>
205 * @param int $index the array key of the namespace to return
206 * @return mixed, string if the namespace value exists, otherwise false
208 function getNsText( $index ) {
209 $ns = $this->getNamespaces();
210 return isset( $ns[$index] ) ? $ns[$index] : false;
214 * A convenience function that returns the same thing as
215 * getNsText() except with '_' changed to ' ', useful for
216 * producing output.
218 * @return array
220 function getFormattedNsText( $index ) {
221 $ns = $this->getNsText( $index );
222 return strtr($ns, '_', ' ');
226 * Get a namespace key by value, case insensetive.
228 * @param string $text
229 * @return mixed An integer if $text is a valid value otherwise false
231 function getNsIndex( $text ) {
232 $this->load();
233 $index = @$this->mNamespaceIds[$this->lc($text)];
234 if ( is_null( $index ) ) {
235 return false;
236 } else {
237 return $index;
242 * short names for language variants used for language conversion links.
244 * @param string $code
245 * @return string
247 function getVariantname( $code ) {
248 return $this->getMessageFromDB( "variantname-$code" );
251 function specialPage( $name ) {
252 return $this->getNsText(NS_SPECIAL) . ':' . $name;
255 function getQuickbarSettings() {
256 $this->load();
257 return $this->quickbarSettings;
260 function getSkinNames() {
261 $this->load();
262 return $this->skinNames;
265 function getMathNames() {
266 $this->load();
267 return $this->mathNames;
270 function getDatePreferences() {
271 $this->load();
272 return $this->datePreferences;
275 function getDateFormats() {
276 $this->load();
277 return $this->dateFormats;
280 function getDefaultDateFormat() {
281 $this->load();
282 return $this->defaultDateFormat;
285 function getDatePreferenceMigrationMap() {
286 $this->load();
287 return $this->datePreferenceMigrationMap;
290 function getDefaultUserOptionOverrides() {
291 $this->load();
292 return $this->defaultUserOptionOverrides;
295 function getExtraUserToggles() {
296 $this->load();
297 return $this->extraUserToggles;
300 function getUserToggle( $tog ) {
301 return $this->getMessageFromDB( "tog-$tog" );
305 * Get language names, indexed by code.
306 * If $customisedOnly is true, only returns codes with a messages file
308 function getLanguageNames( $customisedOnly = false ) {
309 global $wgLanguageNames;
310 if ( !$customisedOnly ) {
311 return $wgLanguageNames;
314 global $IP;
315 $messageFiles = glob( "$IP/languages/Messages*.php" );
316 $names = array();
317 foreach ( $messageFiles as $file ) {
318 if( preg_match( '/Messages([A-Z][a-z_]+)\.php$/', $file, $m ) ) {
319 $code = str_replace( '_', '-', strtolower( $m[1] ) );
320 if ( isset( $wgLanguageNames[$code] ) ) {
321 $names[$code] = $wgLanguageNames[$code];
325 return $names;
329 * Ugly hack to get a message maybe from the MediaWiki namespace, if this
330 * language object is the content or user language.
332 function getMessageFromDB( $msg ) {
333 global $wgContLang, $wgLang;
334 if ( $wgContLang->getCode() == $this->getCode() ) {
335 # Content language
336 return wfMsgForContent( $msg );
337 } elseif ( $wgLang->getCode() == $this->getCode() ) {
338 # User language
339 return wfMsg( $msg );
340 } else {
341 # Neither, get from localisation
342 return $this->getMessage( $msg );
346 function getLanguageName( $code ) {
347 global $wgLanguageNames;
348 if ( ! array_key_exists( $code, $wgLanguageNames ) ) {
349 return '';
351 return $wgLanguageNames[$code];
354 function getMonthName( $key ) {
355 return $this->getMessageFromDB( self::$mMonthMsgs[$key-1] );
358 function getMonthNameGen( $key ) {
359 return $this->getMessageFromDB( self::$mMonthGenMsgs[$key-1] );
362 function getMonthAbbreviation( $key ) {
363 return $this->getMessageFromDB( self::$mMonthAbbrevMsgs[$key-1] );
366 function getWeekdayName( $key ) {
367 return $this->getMessageFromDB( self::$mWeekdayMsgs[$key-1] );
370 function getWeekdayAbbreviation( $key ) {
371 return $this->getMessageFromDB( self::$mWeekdayAbbrevMsgs[$key-1] );
375 * Used by date() and time() to adjust the time output.
376 * @public
377 * @param int $ts the time in date('YmdHis') format
378 * @param mixed $tz adjust the time by this amount (default false,
379 * mean we get user timecorrection setting)
380 * @return int
382 function userAdjust( $ts, $tz = false ) {
383 global $wgUser, $wgLocalTZoffset;
385 if (!$tz) {
386 $tz = $wgUser->getOption( 'timecorrection' );
389 # minutes and hours differences:
390 $minDiff = 0;
391 $hrDiff = 0;
393 if ( $tz === '' ) {
394 # Global offset in minutes.
395 if( isset($wgLocalTZoffset) ) {
396 $hrDiff = $wgLocalTZoffset % 60;
397 $minDiff = $wgLocalTZoffset - ($hrDiff * 60);
399 } elseif ( strpos( $tz, ':' ) !== false ) {
400 $tzArray = explode( ':', $tz );
401 $hrDiff = intval($tzArray[0]);
402 $minDiff = intval($hrDiff < 0 ? -$tzArray[1] : $tzArray[1]);
403 } else {
404 $hrDiff = intval( $tz );
407 # No difference ? Return time unchanged
408 if ( 0 == $hrDiff && 0 == $minDiff ) { return $ts; }
410 # Generate an adjusted date
411 $t = mktime( (
412 (int)substr( $ts, 8, 2) ) + $hrDiff, # Hours
413 (int)substr( $ts, 10, 2 ) + $minDiff, # Minutes
414 (int)substr( $ts, 12, 2 ), # Seconds
415 (int)substr( $ts, 4, 2 ), # Month
416 (int)substr( $ts, 6, 2 ), # Day
417 (int)substr( $ts, 0, 4 ) ); #Year
418 return date( 'YmdHis', $t );
422 * This is a workalike of PHP's date() function, but with better
423 * internationalisation, a reduced set of format characters, and a better
424 * escaping format.
426 * Supported format characters are dDjlNwzWFmMntLYyaAgGhHiscrU. See the
427 * PHP manual for definitions. There are a number of extensions, which
428 * start with "x":
430 * xn Do not translate digits of the next numeric format character
431 * xN Toggle raw digit (xn) flag, stays set until explicitly unset
432 * xr Use roman numerals for the next numeric format character
433 * xx Literal x
434 * xg Genitive month name
436 * Characters enclosed in double quotes will be considered literal (with
437 * the quotes themselves removed). Unmatched quotes will be considered
438 * literal quotes. Example:
440 * "The month is" F => The month is January
441 * i's" => 20'11"
443 * Backslash escaping is also supported.
445 * @param string $format
446 * @param string $ts 14-character timestamp
447 * YYYYMMDDHHMMSS
448 * 01234567890123
450 function sprintfDate( $format, $ts ) {
451 $s = '';
452 $raw = false;
453 $roman = false;
454 $unix = false;
455 $rawToggle = false;
456 for ( $p = 0; $p < strlen( $format ); $p++ ) {
457 $num = false;
458 $code = $format[$p];
459 if ( $code == 'x' && $p < strlen( $format ) - 1 ) {
460 $code .= $format[++$p];
463 switch ( $code ) {
464 case 'xx':
465 $s .= 'x';
466 break;
467 case 'xn':
468 $raw = true;
469 break;
470 case 'xN':
471 $rawToggle = !$rawToggle;
472 break;
473 case 'xr':
474 $roman = true;
475 break;
476 case 'xg':
477 $s .= $this->getMonthNameGen( substr( $ts, 4, 2 ) );
478 break;
479 case 'd':
480 $num = substr( $ts, 6, 2 );
481 break;
482 case 'D':
483 if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
484 $s .= $this->getWeekdayAbbreviation( date( 'w', $unix ) + 1 );
485 break;
486 case 'j':
487 $num = intval( substr( $ts, 6, 2 ) );
488 break;
489 case 'l':
490 if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
491 $s .= $this->getWeekdayName( date( 'w', $unix ) + 1 );
492 break;
493 case 'N':
494 if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
495 $w = date( 'w', $unix );
496 $num = $w ? $w : 7;
497 break;
498 case 'w':
499 if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
500 $num = date( 'w', $unix );
501 break;
502 case 'z':
503 if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
504 $num = date( 'z', $unix );
505 break;
506 case 'W':
507 if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
508 $num = date( 'W', $unix );
509 break;
510 case 'F':
511 $s .= $this->getMonthName( substr( $ts, 4, 2 ) );
512 break;
513 case 'm':
514 $num = substr( $ts, 4, 2 );
515 break;
516 case 'M':
517 $s .= $this->getMonthAbbreviation( substr( $ts, 4, 2 ) );
518 break;
519 case 'n':
520 $num = intval( substr( $ts, 4, 2 ) );
521 break;
522 case 't':
523 if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
524 $num = date( 't', $unix );
525 break;
526 case 'L':
527 if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
528 $num = date( 'L', $unix );
529 break;
530 case 'Y':
531 $num = substr( $ts, 0, 4 );
532 break;
533 case 'y':
534 $num = substr( $ts, 2, 2 );
535 break;
536 case 'a':
537 $s .= intval( substr( $ts, 8, 2 ) ) < 12 ? 'am' : 'pm';
538 break;
539 case 'A':
540 $s .= intval( substr( $ts, 8, 2 ) ) < 12 ? 'AM' : 'PM';
541 break;
542 case 'g':
543 $h = substr( $ts, 8, 2 );
544 $num = $h % 12 ? $h % 12 : 12;
545 break;
546 case 'G':
547 $num = intval( substr( $ts, 8, 2 ) );
548 break;
549 case 'h':
550 $h = substr( $ts, 8, 2 );
551 $num = sprintf( '%02d', $h % 12 ? $h % 12 : 12 );
552 break;
553 case 'H':
554 $num = substr( $ts, 8, 2 );
555 break;
556 case 'i':
557 $num = substr( $ts, 10, 2 );
558 break;
559 case 's':
560 $num = substr( $ts, 12, 2 );
561 break;
562 case 'c':
563 if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
564 $s .= date( 'c', $unix );
565 break;
566 case 'r':
567 if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
568 $s .= date( 'r', $unix );
569 break;
570 case 'U':
571 if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts );
572 $num = $unix;
573 break;
574 case '\\':
575 # Backslash escaping
576 if ( $p < strlen( $format ) - 1 ) {
577 $s .= $format[++$p];
578 } else {
579 $s .= '\\';
581 break;
582 case '"':
583 # Quoted literal
584 if ( $p < strlen( $format ) - 1 ) {
585 $endQuote = strpos( $format, '"', $p + 1 );
586 if ( $endQuote === false ) {
587 # No terminating quote, assume literal "
588 $s .= '"';
589 } else {
590 $s .= substr( $format, $p + 1, $endQuote - $p - 1 );
591 $p = $endQuote;
593 } else {
594 # Quote at end of string, assume literal "
595 $s .= '"';
597 break;
598 default:
599 $s .= $format[$p];
601 if ( $num !== false ) {
602 if ( $rawToggle || $raw ) {
603 $s .= $num;
604 $raw = false;
605 } elseif ( $roman ) {
606 $s .= self::romanNumeral( $num );
607 $roman = false;
608 } else {
609 $s .= $this->formatNum( $num, true );
611 $num = false;
614 return $s;
618 * Roman number formatting up to 3000
620 static function romanNumeral( $num ) {
621 static $table = array(
622 array( '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X' ),
623 array( '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', 'C' ),
624 array( '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', 'M' ),
625 array( '', 'M', 'MM', 'MMM' )
628 $num = intval( $num );
629 if ( $num > 3000 || $num <= 0 ) {
630 return $num;
633 $s = '';
634 for ( $pow10 = 1000, $i = 3; $i >= 0; $pow10 /= 10, $i-- ) {
635 if ( $num >= $pow10 ) {
636 $s .= $table[$i][floor($num / $pow10)];
638 $num = $num % $pow10;
640 return $s;
644 * This is meant to be used by time(), date(), and timeanddate() to get
645 * the date preference they're supposed to use, it should be used in
646 * all children.
648 *<code>
649 * function timeanddate([...], $format = true) {
650 * $datePreference = $this->dateFormat($format);
651 * [...]
653 *</code>
655 * @param mixed $usePrefs: if true, the user's preference is used
656 * if false, the site/language default is used
657 * if int/string, assumed to be a format.
658 * @return string
660 function dateFormat( $usePrefs = true ) {
661 global $wgUser;
663 if( is_bool( $usePrefs ) ) {
664 if( $usePrefs ) {
665 $datePreference = $wgUser->getDatePreference();
666 } else {
667 $options = User::getDefaultOptions();
668 $datePreference = (string)$options['date'];
670 } else {
671 $datePreference = (string)$usePrefs;
674 // return int
675 if( $datePreference == '' ) {
676 return 'default';
679 return $datePreference;
683 * @public
684 * @param mixed $ts the time format which needs to be turned into a
685 * date('YmdHis') format with wfTimestamp(TS_MW,$ts)
686 * @param bool $adj whether to adjust the time output according to the
687 * user configured offset ($timecorrection)
688 * @param mixed $format true to use user's date format preference
689 * @param string $timecorrection the time offset as returned by
690 * validateTimeZone() in Special:Preferences
691 * @return string
693 function date( $ts, $adj = false, $format = true, $timecorrection = false ) {
694 $this->load();
695 if ( $adj ) {
696 $ts = $this->userAdjust( $ts, $timecorrection );
699 $pref = $this->dateFormat( $format );
700 if( $pref == 'default' || !isset( $this->dateFormats["$pref date"] ) ) {
701 $pref = $this->defaultDateFormat;
703 return $this->sprintfDate( $this->dateFormats["$pref date"], $ts );
707 * @public
708 * @param mixed $ts the time format which needs to be turned into a
709 * date('YmdHis') format with wfTimestamp(TS_MW,$ts)
710 * @param bool $adj whether to adjust the time output according to the
711 * user configured offset ($timecorrection)
712 * @param mixed $format true to use user's date format preference
713 * @param string $timecorrection the time offset as returned by
714 * validateTimeZone() in Special:Preferences
715 * @return string
717 function time( $ts, $adj = false, $format = true, $timecorrection = false ) {
718 $this->load();
719 if ( $adj ) {
720 $ts = $this->userAdjust( $ts, $timecorrection );
723 $pref = $this->dateFormat( $format );
724 if( $pref == 'default' || !isset( $this->dateFormats["$pref time"] ) ) {
725 $pref = $this->defaultDateFormat;
727 return $this->sprintfDate( $this->dateFormats["$pref time"], $ts );
731 * @public
732 * @param mixed $ts the time format which needs to be turned into a
733 * date('YmdHis') format with wfTimestamp(TS_MW,$ts)
734 * @param bool $adj whether to adjust the time output according to the
735 * user configured offset ($timecorrection)
737 * @param mixed $format what format to return, if it's false output the
738 * default one (default true)
739 * @param string $timecorrection the time offset as returned by
740 * validateTimeZone() in Special:Preferences
741 * @return string
743 function timeanddate( $ts, $adj = false, $format = true, $timecorrection = false) {
744 $this->load();
745 if ( $adj ) {
746 $ts = $this->userAdjust( $ts, $timecorrection );
749 $pref = $this->dateFormat( $format );
750 if( $pref == 'default' || !isset( $this->dateFormats["$pref both"] ) ) {
751 $pref = $this->defaultDateFormat;
754 return $this->sprintfDate( $this->dateFormats["$pref both"], $ts );
757 function getMessage( $key ) {
758 $this->load();
759 return @$this->messages[$key];
762 function getAllMessages() {
763 $this->load();
764 return $this->messages;
767 function iconv( $in, $out, $string ) {
768 # For most languages, this is a wrapper for iconv
769 return iconv( $in, $out, $string );
772 // callback functions for uc(), lc(), ucwords(), ucwordbreaks()
773 function ucwordbreaksCallbackAscii($matches){
774 return $this->ucfirst($matches[1]);
777 function ucwordbreaksCallbackMB($matches){
778 return mb_strtoupper($matches[0]);
781 function ucCallback($matches){
782 list( $wikiUpperChars ) = self::getCaseMaps();
783 return strtr( $matches[1], $wikiUpperChars );
786 function lcCallback($matches){
787 list( , $wikiLowerChars ) = self::getCaseMaps();
788 return strtr( $matches[1], $wikiLowerChars );
791 function ucwordsCallbackMB($matches){
792 return mb_strtoupper($matches[0]);
795 function ucwordsCallbackWiki($matches){
796 list( $wikiUpperChars ) = self::getCaseMaps();
797 return strtr( $matches[0], $wikiUpperChars );
800 function ucfirst( $str ) {
801 return self::uc( $str, true );
804 function uc( $str, $first = false ) {
805 if ( function_exists( 'mb_strtoupper' ) )
806 if ( $first )
807 if ( self::isMultibyte( $str ) )
808 return mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
809 else
810 return ucfirst( $str );
811 else
812 return self::isMultibyte( $str ) ? mb_strtoupper( $str ) : strtoupper( $str );
813 else
814 if ( self::isMultibyte( $str ) ) {
815 list( $wikiUpperChars ) = $this->getCaseMaps();
816 $x = $first ? '^' : '';
817 return preg_replace_callback(
818 "/$x([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/",
819 array($this,"ucCallback"),
820 $str
822 } else
823 return $first ? ucfirst( $str ) : strtoupper( $str );
826 function lcfirst( $str ) {
827 return self::lc( $str, true );
830 function lc( $str, $first = false ) {
831 if ( function_exists( 'mb_strtolower' ) )
832 if ( $first )
833 if ( self::isMultibyte( $str ) )
834 return mb_strtolower( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
835 else
836 return strtolower( substr( $str, 0, 1 ) ) . substr( $str, 1 );
837 else
838 return self::isMultibyte( $str ) ? mb_strtolower( $str ) : strtolower( $str );
839 else
840 if ( self::isMultibyte( $str ) ) {
841 list( , $wikiLowerChars ) = self::getCaseMaps();
842 $x = $first ? '^' : '';
843 return preg_replace_callback(
844 "/$x([A-Z]|[\\xc0-\\xff][\\x80-\\xbf]*)/",
845 array($this,"lcCallback"),
846 $str
848 } else
849 return $first ? strtolower( substr( $str, 0, 1 ) ) . substr( $str, 1 ) : strtolower( $str );
852 function isMultibyte( $str ) {
853 return (bool)preg_match( '/[\x80-\xff]/', $str );
856 function ucwords($str) {
857 if ( self::isMultibyte( $str ) ) {
858 $str = self::lc($str);
860 // regexp to find first letter in each word (i.e. after each space)
861 $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)| ([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
863 // function to use to capitalize a single char
864 if ( function_exists( 'mb_strtoupper' ) )
865 return preg_replace_callback(
866 $replaceRegexp,
867 array($this,"ucwordsCallbackMB"),
868 $str
870 else
871 return preg_replace_callback(
872 $replaceRegexp,
873 array($this,"ucwordsCallbackWiki"),
874 $str
877 else
878 return ucwords( strtolower( $str ) );
881 # capitalize words at word breaks
882 function ucwordbreaks($str){
883 if (self::isMultibyte( $str ) ) {
884 $str = self::lc($str);
886 // since \b doesn't work for UTF-8, we explicitely define word break chars
887 $breaks= "[ \-\(\)\}\{\.,\?!]";
889 // find first letter after word break
890 $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)|$breaks([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
892 if ( function_exists( 'mb_strtoupper' ) )
893 return preg_replace_callback(
894 $replaceRegexp,
895 array($this,"ucwordbreaksCallbackMB"),
896 $str
898 else
899 return preg_replace_callback(
900 $replaceRegexp,
901 array($this,"ucwordsCallbackWiki"),
902 $str
905 else
906 return preg_replace_callback(
907 '/\b([\w\x80-\xff]+)\b/',
908 array($this,"ucwordbreaksCallbackAscii"),
909 $str );
912 function checkTitleEncoding( $s ) {
913 if( is_array( $s ) ) {
914 wfDebugDieBacktrace( 'Given array to checkTitleEncoding.' );
916 # Check for non-UTF-8 URLs
917 $ishigh = preg_match( '/[\x80-\xff]/', $s);
918 if(!$ishigh) return $s;
920 $isutf8 = preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
921 '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
922 if( $isutf8 ) return $s;
924 return $this->iconv( $this->fallback8bitEncoding(), "utf-8", $s );
927 function fallback8bitEncoding() {
928 $this->load();
929 return $this->fallback8bitEncoding;
933 * Some languages have special punctuation to strip out
934 * or characters which need to be converted for MySQL's
935 * indexing to grok it correctly. Make such changes here.
937 * @param string $in
938 * @return string
940 function stripForSearch( $string ) {
941 # MySQL fulltext index doesn't grok utf-8, so we
942 # need to fold cases and convert to hex
944 wfProfileIn( __METHOD__ );
945 if( function_exists( 'mb_strtolower' ) ) {
946 $out = preg_replace(
947 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
948 "'U8' . bin2hex( \"$1\" )",
949 mb_strtolower( $string ) );
950 } else {
951 list( , $wikiLowerChars ) = self::getCaseMaps();
952 $out = preg_replace(
953 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
954 "'U8' . bin2hex( strtr( \"\$1\", \$wikiLowerChars ) )",
955 $string );
957 wfProfileOut( __METHOD__ );
958 return $out;
961 function convertForSearchResult( $termsArray ) {
962 # some languages, e.g. Chinese, need to do a conversion
963 # in order for search results to be displayed correctly
964 return $termsArray;
968 * Get the first character of a string.
970 * @param string $s
971 * @return string
973 function firstChar( $s ) {
974 preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
975 '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})/', $s, $matches);
977 return isset( $matches[1] ) ? $matches[1] : "";
980 function initEncoding() {
981 # Some languages may have an alternate char encoding option
982 # (Esperanto X-coding, Japanese furigana conversion, etc)
983 # If this language is used as the primary content language,
984 # an override to the defaults can be set here on startup.
987 function recodeForEdit( $s ) {
988 # For some languages we'll want to explicitly specify
989 # which characters make it into the edit box raw
990 # or are converted in some way or another.
991 # Note that if wgOutputEncoding is different from
992 # wgInputEncoding, this text will be further converted
993 # to wgOutputEncoding.
994 global $wgEditEncoding;
995 if( $wgEditEncoding == '' or
996 $wgEditEncoding == 'UTF-8' ) {
997 return $s;
998 } else {
999 return $this->iconv( 'UTF-8', $wgEditEncoding, $s );
1003 function recodeInput( $s ) {
1004 # Take the previous into account.
1005 global $wgEditEncoding;
1006 if($wgEditEncoding != "") {
1007 $enc = $wgEditEncoding;
1008 } else {
1009 $enc = 'UTF-8';
1011 if( $enc == 'UTF-8' ) {
1012 return $s;
1013 } else {
1014 return $this->iconv( $enc, 'UTF-8', $s );
1019 * For right-to-left language support
1021 * @return bool
1023 function isRTL() {
1024 $this->load();
1025 return $this->rtl;
1029 * A hidden direction mark (LRM or RLM), depending on the language direction
1031 * @return string
1033 function getDirMark() {
1034 return $this->isRTL() ? "\xE2\x80\x8F" : "\xE2\x80\x8E";
1038 * An arrow, depending on the language direction
1040 * @return string
1042 function getArrow() {
1043 return $this->isRTL() ? '←' : '→';
1047 * To allow "foo[[bar]]" to extend the link over the whole word "foobar"
1049 * @return bool
1051 function linkPrefixExtension() {
1052 $this->load();
1053 return $this->linkPrefixExtension;
1056 function &getMagicWords() {
1057 $this->load();
1058 return $this->magicWords;
1061 # Fill a MagicWord object with data from here
1062 function getMagic( &$mw ) {
1063 if ( !isset( $this->mMagicExtensions ) ) {
1064 $this->mMagicExtensions = array();
1065 wfRunHooks( 'LanguageGetMagic', array( &$this->mMagicExtensions, $this->getCode() ) );
1067 if ( isset( $this->mMagicExtensions[$mw->mId] ) ) {
1068 $rawEntry = $this->mMagicExtensions[$mw->mId];
1069 } else {
1070 $magicWords =& $this->getMagicWords();
1071 if ( isset( $magicWords[$mw->mId] ) ) {
1072 $rawEntry = $magicWords[$mw->mId];
1073 } else {
1074 # Fall back to English if local list is incomplete
1075 $magicWords =& Language::getMagicWords();
1076 $rawEntry = $magicWords[$mw->mId];
1080 if( !is_array( $rawEntry ) ) {
1081 error_log( "\"$rawEntry\" is not a valid magic thingie for \"$mw->mId\"" );
1083 $mw->mCaseSensitive = $rawEntry[0];
1084 $mw->mSynonyms = array_slice( $rawEntry, 1 );
1088 * Italic is unsuitable for some languages
1090 * @public
1092 * @param string $text The text to be emphasized.
1093 * @return string
1095 function emphasize( $text ) {
1096 return "<em>$text</em>";
1100 * Normally we output all numbers in plain en_US style, that is
1101 * 293,291.235 for twohundredninetythreethousand-twohundredninetyone
1102 * point twohundredthirtyfive. However this is not sutable for all
1103 * languages, some such as Pakaran want ੨੯੩,੨੯੫.੨੩੫ and others such as
1104 * Icelandic just want to use commas instead of dots, and dots instead
1105 * of commas like "293.291,235".
1107 * An example of this function being called:
1108 * <code>
1109 * wfMsg( 'message', $wgLang->formatNum( $num ) )
1110 * </code>
1112 * See LanguageGu.php for the Gujarati implementation and
1113 * LanguageIs.php for the , => . and . => , implementation.
1115 * @todo check if it's viable to use localeconv() for the decimal
1116 * seperator thing.
1117 * @public
1118 * @param mixed $number the string to be formatted, should be an integer or
1119 * a floating point number.
1120 * @param bool $nocommafy Set to true for special numbers like dates
1121 * @return string
1123 function formatNum( $number, $nocommafy = false ) {
1124 global $wgTranslateNumerals;
1125 if (!$nocommafy) {
1126 $number = $this->commafy($number);
1127 $s = $this->separatorTransformTable();
1128 if (!is_null($s)) { $number = strtr($number, $s); }
1131 if ($wgTranslateNumerals) {
1132 $s = $this->digitTransformTable();
1133 if (!is_null($s)) { $number = strtr($number, $s); }
1136 return $number;
1140 * Adds commas to a given number
1142 * @param mixed $_
1143 * @return string
1145 function commafy($_) {
1146 return strrev((string)preg_replace('/(\d{3})(?=\d)(?!\d*\.)/','$1,',strrev($_)));
1149 function digitTransformTable() {
1150 $this->load();
1151 return $this->digitTransformTable;
1154 function separatorTransformTable() {
1155 $this->load();
1156 return $this->separatorTransformTable;
1161 * For the credit list in includes/Credits.php (action=credits)
1163 * @param array $l
1164 * @return string
1166 function listToText( $l ) {
1167 $s = '';
1168 $m = count($l) - 1;
1169 for ($i = $m; $i >= 0; $i--) {
1170 if ($i == $m) {
1171 $s = $l[$i];
1172 } else if ($i == $m - 1) {
1173 $s = $l[$i] . ' ' . $this->getMessageFromDB( 'and' ) . ' ' . $s;
1174 } else {
1175 $s = $l[$i] . ', ' . $s;
1178 return $s;
1181 # Crop a string from the beginning or end to a certain number of bytes.
1182 # (Bytes are used because our storage has limited byte lengths for some
1183 # columns in the database.) Multibyte charsets will need to make sure that
1184 # only whole characters are included!
1186 # $length does not include the optional ellipsis.
1187 # If $length is negative, snip from the beginning
1188 function truncate( $string, $length, $ellipsis = "" ) {
1189 if( $length == 0 ) {
1190 return $ellipsis;
1192 if ( strlen( $string ) <= abs( $length ) ) {
1193 return $string;
1195 if( $length > 0 ) {
1196 $string = substr( $string, 0, $length );
1197 $char = ord( $string[strlen( $string ) - 1] );
1198 if ($char >= 0xc0) {
1199 # We got the first byte only of a multibyte char; remove it.
1200 $string = substr( $string, 0, -1 );
1201 } elseif( $char >= 0x80 &&
1202 preg_match( '/^(.*)(?:[\xe0-\xef][\x80-\xbf]|' .
1203 '[\xf0-\xf7][\x80-\xbf]{1,2})$/', $string, $m ) ) {
1204 # We chopped in the middle of a character; remove it
1205 $string = $m[1];
1207 return $string . $ellipsis;
1208 } else {
1209 $string = substr( $string, $length );
1210 $char = ord( $string[0] );
1211 if( $char >= 0x80 && $char < 0xc0 ) {
1212 # We chopped in the middle of a character; remove the whole thing
1213 $string = preg_replace( '/^[\x80-\xbf]+/', '', $string );
1215 return $ellipsis . $string;
1220 * Grammatical transformations, needed for inflected languages
1221 * Invoked by putting {{grammar:case|word}} in a message
1223 * @param string $word
1224 * @param string $case
1225 * @return string
1227 function convertGrammar( $word, $case ) {
1228 global $wgGrammarForms;
1229 if ( isset($wgGrammarForms['en'][$case][$word]) ) {
1230 return $wgGrammarForms['en'][$case][$word];
1232 return $word;
1236 * Plural form transformations, needed for some languages.
1237 * For example, where are 3 form of plural in Russian and Polish,
1238 * depending on "count mod 10". See [[w:Plural]]
1239 * For English it is pretty simple.
1241 * Invoked by putting {{plural:count|wordform1|wordform2}}
1242 * or {{plural:count|wordform1|wordform2|wordform3}}
1244 * Example: {{plural:{{NUMBEROFARTICLES}}|article|articles}}
1246 * @param integer $count
1247 * @param string $wordform1
1248 * @param string $wordform2
1249 * @param string $wordform3 (optional)
1250 * @return string
1252 function convertPlural( $count, $w1, $w2, $w3) {
1253 return $count == '1' ? $w1 : $w2;
1257 * For translaing of expiry times
1258 * @param string The validated block time in English
1259 * @return Somehow translated block time
1260 * @see LanguageFi.php for example implementation
1262 function translateBlockExpiry( $str ) {
1264 $scBlockExpiryOptions = $this->getMessageFromDB( 'ipboptions' );
1266 if ( $scBlockExpiryOptions == '-') {
1267 return $str;
1270 foreach (explode(',', $scBlockExpiryOptions) as $option) {
1271 if ( strpos($option, ":") === false )
1272 continue;
1273 list($show, $value) = explode(":", $option);
1274 if ( strcmp ( $str, $value) == 0 )
1275 return '<span title="' . htmlspecialchars($str). '">' .
1276 htmlspecialchars( trim( $show ) ) . '</span>';
1279 return $str;
1283 * languages like Chinese need to be segmented in order for the diff
1284 * to be of any use
1286 * @param string $text
1287 * @return string
1289 function segmentForDiff( $text ) {
1290 return $text;
1294 * and unsegment to show the result
1296 * @param string $text
1297 * @return string
1299 function unsegmentForDiff( $text ) {
1300 return $text;
1303 # convert text to different variants of a language.
1304 function convert( $text, $isTitle = false) {
1305 return $this->mConverter->convert($text, $isTitle);
1308 # Convert text from within Parser
1309 function parserConvert( $text, &$parser ) {
1310 return $this->mConverter->parserConvert( $text, $parser );
1313 # Tell the converter that it shouldn't convert titles
1314 function setNoTitleConvert(){
1315 $this->mConverter->setNotitleConvert();
1318 # Check if this is a language with variants
1319 function hasVariants(){
1320 return sizeof($this->getVariants())>1;
1325 * Perform output conversion on a string, and encode for safe HTML output.
1326 * @param string $text
1327 * @param bool $isTitle -- wtf?
1328 * @return string
1329 * @todo this should get integrated somewhere sane
1331 function convertHtml( $text, $isTitle = false ) {
1332 return htmlspecialchars( $this->convert( $text, $isTitle ) );
1335 function convertCategoryKey( $key ) {
1336 return $this->mConverter->convertCategoryKey( $key );
1340 * get the list of variants supported by this langauge
1341 * see sample implementation in LanguageZh.php
1343 * @return array an array of language codes
1345 function getVariants() {
1346 return $this->mConverter->getVariants();
1350 function getPreferredVariant( $fromUser = true ) {
1351 return $this->mConverter->getPreferredVariant( $fromUser );
1355 * if a language supports multiple variants, it is
1356 * possible that non-existing link in one variant
1357 * actually exists in another variant. this function
1358 * tries to find it. See e.g. LanguageZh.php
1360 * @param string $link the name of the link
1361 * @param mixed $nt the title object of the link
1362 * @return null the input parameters may be modified upon return
1364 function findVariantLink( &$link, &$nt ) {
1365 $this->mConverter->findVariantLink($link, $nt);
1369 * If a language supports multiple variants, converts text
1370 * into an array of all possible variants of the text:
1371 * 'variant' => text in that variant
1374 function convertLinkToAllVariants($text){
1375 return $this->mConverter->convertLinkToAllVariants($text);
1380 * returns language specific options used by User::getPageRenderHash()
1381 * for example, the preferred language variant
1383 * @return string
1384 * @public
1386 function getExtraHashOptions() {
1387 return $this->mConverter->getExtraHashOptions();
1391 * for languages that support multiple variants, the title of an
1392 * article may be displayed differently in different variants. this
1393 * function returns the apporiate title defined in the body of the article.
1395 * @return string
1397 function getParsedTitle() {
1398 return $this->mConverter->getParsedTitle();
1402 * Enclose a string with the "no conversion" tag. This is used by
1403 * various functions in the Parser
1405 * @param string $text text to be tagged for no conversion
1406 * @return string the tagged text
1408 function markNoConversion( $text, $noParse=false ) {
1409 return $this->mConverter->markNoConversion( $text, $noParse );
1413 * A regular expression to match legal word-trailing characters
1414 * which should be merged onto a link of the form [[foo]]bar.
1416 * @return string
1417 * @public
1419 function linkTrail() {
1420 $this->load();
1421 return $this->linkTrail;
1424 function getLangObj() {
1425 return $this;
1429 * Get the RFC 3066 code for this language object
1431 function getCode() {
1432 return $this->mCode;
1435 function setCode( $code ) {
1436 $this->mCode = $code;
1439 static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
1440 return $prefix . str_replace( '-', '_', ucfirst( $code ) ) . $suffix;
1443 static function getLocalisationArray( $code, $disableCache = false ) {
1444 self::loadLocalisation( $code, $disableCache );
1445 return self::$mLocalisationCache[$code];
1449 * Load localisation data for a given code into the static cache
1451 * @return array Dependencies, map of filenames to mtimes
1453 static function loadLocalisation( $code, $disableCache = false ) {
1454 static $recursionGuard = array();
1455 global $wgMemc, $wgDBname, $IP;
1457 if ( !$code ) {
1458 throw new MWException( "Invalid language code requested" );
1461 if ( !$disableCache ) {
1462 # Try the per-process cache
1463 if ( isset( self::$mLocalisationCache[$code] ) ) {
1464 return self::$mLocalisationCache[$code]['deps'];
1467 wfProfileIn( __METHOD__ );
1469 # Try the serialized directory
1470 $cache = wfGetPrecompiledData( self::getFileName( "Messages", $code, '.ser' ) );
1471 if ( $cache ) {
1472 self::$mLocalisationCache[$code] = $cache;
1473 wfDebug( "Got localisation for $code from precompiled data file\n" );
1474 wfProfileOut( __METHOD__ );
1475 return self::$mLocalisationCache[$code]['deps'];
1478 # Try the global cache
1479 $memcKey = "$wgDBname:localisation:$code";
1480 $cache = $wgMemc->get( $memcKey );
1481 if ( $cache ) {
1482 $expired = false;
1483 # Check file modification times
1484 foreach ( $cache['deps'] as $file => $mtime ) {
1485 if ( filemtime( $file ) > $mtime ) {
1486 $expired = true;
1487 break;
1490 if ( self::isLocalisationOutOfDate( $cache ) ) {
1491 $wgMemc->delete( $memcKey );
1492 $cache = false;
1493 wfDebug( "Localisation cache for $code had expired due to update of $file\n" );
1494 } else {
1495 self::$mLocalisationCache[$code] = $cache;
1496 wfDebug( "Got localisation for $code from cache\n" );
1497 wfProfileOut( __METHOD__ );
1498 return $cache['deps'];
1501 } else {
1502 wfProfileIn( __METHOD__ );
1505 if ( $code != 'en' ) {
1506 $fallback = 'en';
1507 } else {
1508 $fallback = false;
1511 # Load the primary localisation from the source file
1512 global $IP;
1513 $filename = self::getFileName( "$IP/languages/Messages", $code, '.php' );
1514 if ( !file_exists( $filename ) ) {
1515 wfDebug( "No localisation file for $code, using implicit fallback to en\n" );
1516 $cache = array();
1517 $deps = array();
1518 } else {
1519 $deps = array( $filename => filemtime( $filename ) );
1520 require( $filename );
1521 $cache = compact( self::$mLocalisationKeys );
1522 wfDebug( "Got localisation for $code from source\n" );
1525 if ( !empty( $fallback ) ) {
1526 # Load the fallback localisation, with a circular reference guard
1527 if ( isset( $recursionGuard[$code] ) ) {
1528 throw new MWException( "Error: Circular fallback reference in language code $code" );
1530 $recursionGuard[$code] = true;
1531 $newDeps = self::loadLocalisation( $fallback, $disableCache );
1532 unset( $recursionGuard[$code] );
1534 $secondary = self::$mLocalisationCache[$fallback];
1535 $deps = array_merge( $deps, $newDeps );
1537 # Merge the fallback localisation with the current localisation
1538 foreach ( self::$mLocalisationKeys as $key ) {
1539 if ( isset( $cache[$key] ) ) {
1540 if ( isset( $secondary[$key] ) ) {
1541 if ( in_array( $key, self::$mMergeableMapKeys ) ) {
1542 $cache[$key] = $cache[$key] + $secondary[$key];
1543 } elseif ( in_array( $key, self::$mMergeableListKeys ) ) {
1544 $cache[$key] = array_merge( $secondary[$key], $cache[$key] );
1547 } else {
1548 $cache[$key] = $secondary[$key];
1552 # Merge bookstore lists if requested
1553 if ( !empty( $cache['bookstoreList']['inherit'] ) ) {
1554 $cache['bookstoreList'] = array_merge( $cache['bookstoreList'], $secondary['bookstoreList'] );
1556 if ( isset( $cache['bookstoreList']['inherit'] ) ) {
1557 unset( $cache['bookstoreList']['inherit'] );
1561 # Add dependencies to the cache entry
1562 $cache['deps'] = $deps;
1564 # Replace spaces with underscores in namespace names
1565 $cache['namespaceNames'] = str_replace( ' ', '_', $cache['namespaceNames'] );
1567 # Save to both caches
1568 self::$mLocalisationCache[$code] = $cache;
1569 if ( !$disableCache ) {
1570 $wgMemc->set( $memcKey, $cache );
1573 wfProfileOut( __METHOD__ );
1574 return $deps;
1578 * Test if a given localisation cache is out of date with respect to the
1579 * source Messages files. This is done automatically for the global cache
1580 * in $wgMemc, but is only done on certain occasions for the serialized
1581 * data file.
1583 * @param $cache mixed Either a language code or a cache array
1585 static function isLocalisationOutOfDate( $cache ) {
1586 if ( !is_array( $cache ) ) {
1587 self::loadLocalisation( $cache );
1588 $cache = self::$mLocalisationCache[$cache];
1590 $expired = false;
1591 foreach ( $cache['deps'] as $file => $mtime ) {
1592 if ( filemtime( $file ) > $mtime ) {
1593 $expired = true;
1594 break;
1597 return $expired;
1601 * Get the fallback for a given language
1603 static function getFallbackFor( $code ) {
1604 self::loadLocalisation( $code );
1605 return self::$mLocalisationCache[$code]['fallback'];
1608 /**
1609 * Get all messages for a given language
1611 static function getMessagesFor( $code ) {
1612 self::loadLocalisation( $code );
1613 return self::$mLocalisationCache[$code]['messages'];
1616 /**
1617 * Get a message for a given language
1619 static function getMessageFor( $key, $code ) {
1620 self::loadLocalisation( $code );
1621 return @self::$mLocalisationCache[$code]['messages'][$key];
1625 * Load localisation data for this object
1627 function load() {
1628 if ( !$this->mLoaded ) {
1629 self::loadLocalisation( $this->getCode() );
1630 $cache =& self::$mLocalisationCache[$this->getCode()];
1631 foreach ( self::$mLocalisationKeys as $key ) {
1632 $this->$key = $cache[$key];
1634 $this->mLoaded = true;
1636 $this->fixUpSettings();
1641 * Do any necessary post-cache-load settings adjustment
1643 function fixUpSettings() {
1644 global $wgExtraNamespaces, $wgMetaNamespace, $wgMetaNamespaceTalk, $wgMessageCache,
1645 $wgNamespaceAliases, $wgAmericanDates;
1646 wfProfileIn( __METHOD__ );
1647 if ( $wgExtraNamespaces ) {
1648 $this->namespaceNames = $wgExtraNamespaces + $this->namespaceNames;
1651 $this->namespaceNames[NS_PROJECT] = $wgMetaNamespace;
1652 if ( $wgMetaNamespaceTalk ) {
1653 $this->namespaceNames[NS_PROJECT_TALK] = $wgMetaNamespaceTalk;
1654 } else {
1655 $talk = $this->namespaceNames[NS_PROJECT_TALK];
1656 $talk = str_replace( '$1', $wgMetaNamespace, $talk );
1658 # Allow grammar transformations
1659 # Allowing full message-style parsing would make simple requests
1660 # such as action=raw much more expensive than they need to be.
1661 # This will hopefully cover most cases.
1662 $talk = preg_replace_callback( '/{{grammar:(.*?)\|(.*?)}}/i',
1663 array( &$this, 'replaceGrammarInNamespace' ), $talk );
1664 $talk = str_replace( ' ', '_', $talk );
1665 $this->namespaceNames[NS_PROJECT_TALK] = $talk;
1668 # The above mixing may leave namespaces out of canonical order.
1669 # Re-order by namespace ID number...
1670 ksort( $this->namespaceNames );
1672 # Put namespace names and aliases into a hashtable.
1673 # If this is too slow, then we should arrange it so that it is done
1674 # before caching. The catch is that at pre-cache time, the above
1675 # class-specific fixup hasn't been done.
1676 $this->mNamespaceIds = array();
1677 foreach ( $this->namespaceNames as $index => $name ) {
1678 $this->mNamespaceIds[$this->lc($name)] = $index;
1680 if ( $this->namespaceAliases ) {
1681 foreach ( $this->namespaceAliases as $name => $index ) {
1682 $this->mNamespaceIds[$this->lc($name)] = $index;
1685 if ( $wgNamespaceAliases ) {
1686 foreach ( $wgNamespaceAliases as $name => $index ) {
1687 $this->mNamespaceIds[$this->lc($name)] = $index;
1691 if ( $this->defaultDateFormat == 'dmy or mdy' ) {
1692 $this->defaultDateFormat = $wgAmericanDates ? 'mdy' : 'dmy';
1694 wfProfileOut( __METHOD__ );
1697 function replaceGrammarInNamespace( $m ) {
1698 return $this->convertGrammar( trim( $m[2] ), trim( $m[1] ) );
1701 static function getCaseMaps() {
1702 static $wikiUpperChars, $wikiLowerChars;
1703 global $IP;
1704 if ( isset( $wikiUpperChars ) ) {
1705 return array( $wikiUpperChars, $wikiLowerChars );
1708 wfProfileIn( __METHOD__ );
1709 $arr = wfGetPrecompiledData( 'Utf8Case.ser' );
1710 if ( $arr === false ) {
1711 throw new MWException(
1712 "Utf8Case.ser is missing, please run \"make\" in the serialized directory\n" );
1714 extract( $arr );
1715 wfProfileOut( __METHOD__ );
1716 return array( $wikiUpperChars, $wikiLowerChars );