7 if( !defined( 'MEDIAWIKI' ) ) {
8 echo "This file is part of MediaWiki, it is not a valid entry point.\n";
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
25 global $wgLanguageNames;
26 require_once( 'Names.php' );
28 global $wgInputEncoding, $wgOutputEncoding;
29 global $wgDBname, $wgMemc;
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 */
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 #--------------------------------------------------------------------------
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',
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',
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',
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 ) {
109 static $recursionLevel = 0;
111 if ( $code == 'en' ) {
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 );
131 $lang = Language
::factory( $fallback );
133 $lang->setCode( $code );
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' ) {
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() {}
161 function getDefaultUserOptions() {
162 return User
::getDefaultOptions();
166 * Exports $wgBookstoreListEn
169 function getBookstoreList() {
171 return $this->bookstoreList
;
177 function getNamespaces() {
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.
190 function getFormattedNamespaces() {
191 $ns = $this->getNamespaces();
192 foreach($ns as $k => $v) {
193 $ns[$k] = strtr($v, '_', ' ');
199 * Get a namespace value by key
201 * $mw_ns = $wgContLang->getNsText( NS_MEDIAWIKI );
202 * echo $mw_ns; // prints 'MediaWiki'
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
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 ) {
233 $index = @$this->mNamespaceIds
[$this->lc($text)];
234 if ( is_null( $index ) ) {
242 * short names for language variants used for language conversion links.
244 * @param string $code
247 function getVariantname( $code ) {
248 return $this->getMessageFromDB( "variantname-$code" );
251 function specialPage( $name ) {
252 return $this->getNsText(NS_SPECIAL
) . ':' . $name;
255 function getQuickbarSettings() {
257 return $this->quickbarSettings
;
260 function getSkinNames() {
262 return $this->skinNames
;
265 function getMathNames() {
267 return $this->mathNames
;
270 function getDatePreferences() {
272 return $this->datePreferences
;
275 function getDateFormats() {
277 return $this->dateFormats
;
280 function getDefaultDateFormat() {
282 return $this->defaultDateFormat
;
285 function getDatePreferenceMigrationMap() {
287 return $this->datePreferenceMigrationMap
;
290 function getDefaultUserOptionOverrides() {
292 return $this->defaultUserOptionOverrides
;
295 function getExtraUserToggles() {
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;
315 $messageFiles = glob( "$IP/languages/Messages*.php" );
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];
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() ) {
336 return wfMsgForContent( $msg );
337 } elseif ( $wgLang->getCode() == $this->getCode() ) {
339 return wfMsg( $msg );
341 # Neither, get from localisation
342 return $this->getMessage( $msg );
346 function getLanguageName( $code ) {
347 global $wgLanguageNames;
348 if ( ! array_key_exists( $code, $wgLanguageNames ) ) {
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.
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)
382 function userAdjust( $ts, $tz = false ) {
383 global $wgUser, $wgLocalTZoffset;
386 $tz = $wgUser->getOption( 'timecorrection' );
389 # minutes and hours differences:
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]);
404 $hrDiff = intval( $tz );
407 # No difference ? Return time unchanged
408 if ( 0 == $hrDiff && 0 == $minDiff ) { return $ts; }
410 # Generate an adjusted date
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
426 * Supported format characters are dDjlFmMnYyHis. See the PHP manual for
427 * definitions. There are a number of extensions, which start with "x":
429 * xn Do not translate digits of the next numeric format character
430 * xr Use roman numerals for the next numeric format character
432 * xg Genitive month name
434 * Characters enclosed in double quotes will be considered literal (with
435 * the quotes themselves removed). Unmatched quotes will be considered
436 * literal quotes. Example:
438 * "The month is" F => The month is January
441 * Backslash escaping is also supported.
443 * @param string $format
444 * @param string $ts 14-character timestamp
448 function sprintfDate( $format, $ts ) {
452 for ( $p = 0; $p < strlen( $format ); $p++
) {
455 if ( $code == 'x' && $p < strlen( $format ) - 1 ) {
456 $code .= $format[++
$p];
470 $s .= $this->getMonthNameGen( substr( $ts, 4, 2 ) );
473 $num = substr( $ts, 6, 2 );
476 $s .= $this->getWeekdayAbbreviation( self
::calculateWeekday( $ts ) );
479 $num = intval( substr( $ts, 6, 2 ) );
482 $s .= $this->getWeekdayName( self
::calculateWeekday( $ts ) );
485 $s .= $this->getMonthName( substr( $ts, 4, 2 ) );
488 $num = substr( $ts, 4, 2 );
491 $s .= $this->getMonthAbbreviation( substr( $ts, 4, 2 ) );
494 $num = intval( substr( $ts, 4, 2 ) );
497 $num = substr( $ts, 0, 4 );
500 $num = substr( $ts, 2, 2 );
503 $num = substr( $ts, 8, 2 );
506 $num = intval( substr( $ts, 8, 2 ) );
509 $num = substr( $ts, 10, 2 );
512 $num = substr( $ts, 12, 2 );
516 if ( $p < strlen( $format ) - 1 ) {
524 if ( $p < strlen( $format ) - 1 ) {
525 $endQuote = strpos( $format, '"', $p +
1 );
526 if ( $endQuote === false ) {
527 # No terminating quote, assume literal "
530 $s .= substr( $format, $p +
1, $endQuote - $p - 1 );
534 # Quote at end of string, assume literal "
541 if ( $num !== false ) {
545 } elseif ( $roman ) {
546 $s .= Language
::romanNumeral( $num );
549 $s .= $this->formatNum( $num, true );
558 * Roman number formatting up to 100
560 static function romanNumeral( $num ) {
561 static $units = array( 0, 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X' );
562 static $decades = array( 0, 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', 'C' );
563 $num = intval( $num );
564 if ( $num > 100 ||
$num <= 0 ) {
569 $s .= $decades[floor( $num / 10 )];
579 * Calculate the day of the week for a 14-character timestamp
580 * 1 for Sunday through to 7 for Saturday
581 * This takes about 100us on a slow computer
583 static function calculateWeekday( $ts ) {
584 return date( 'w', wfTimestamp( TS_UNIX
, $ts ) ) +
1;
588 * This is meant to be used by time(), date(), and timeanddate() to get
589 * the date preference they're supposed to use, it should be used in
593 * function timeanddate([...], $format = true) {
594 * $datePreference = $this->dateFormat($format);
599 * @param mixed $usePrefs: if true, the user's preference is used
600 * if false, the site/language default is used
601 * if int/string, assumed to be a format.
604 function dateFormat( $usePrefs = true ) {
607 if( is_bool( $usePrefs ) ) {
609 $datePreference = $wgUser->getDatePreference();
611 $options = User
::getDefaultOptions();
612 $datePreference = (string)$options['date'];
615 $datePreference = (string)$usePrefs;
619 if( $datePreference == '' ) {
623 return $datePreference;
628 * @param mixed $ts the time format which needs to be turned into a
629 * date('YmdHis') format with wfTimestamp(TS_MW,$ts)
630 * @param bool $adj whether to adjust the time output according to the
631 * user configured offset ($timecorrection)
632 * @param mixed $format true to use user's date format preference
633 * @param string $timecorrection the time offset as returned by
634 * validateTimeZone() in Special:Preferences
637 function date( $ts, $adj = false, $format = true, $timecorrection = false ) {
640 $ts = $this->userAdjust( $ts, $timecorrection );
643 $pref = $this->dateFormat( $format );
644 if( $pref == 'default' ||
!isset( $this->dateFormats
["$pref date"] ) ) {
645 $pref = $this->defaultDateFormat
;
647 return $this->sprintfDate( $this->dateFormats
["$pref date"], $ts );
652 * @param mixed $ts the time format which needs to be turned into a
653 * date('YmdHis') format with wfTimestamp(TS_MW,$ts)
654 * @param bool $adj whether to adjust the time output according to the
655 * user configured offset ($timecorrection)
656 * @param mixed $format true to use user's date format preference
657 * @param string $timecorrection the time offset as returned by
658 * validateTimeZone() in Special:Preferences
661 function time( $ts, $adj = false, $format = true, $timecorrection = false ) {
664 $ts = $this->userAdjust( $ts, $timecorrection );
667 $pref = $this->dateFormat( $format );
668 if( $pref == 'default' ||
!isset( $this->dateFormats
["$pref time"] ) ) {
669 $pref = $this->defaultDateFormat
;
671 return $this->sprintfDate( $this->dateFormats
["$pref time"], $ts );
676 * @param mixed $ts the time format which needs to be turned into a
677 * date('YmdHis') format with wfTimestamp(TS_MW,$ts)
678 * @param bool $adj whether to adjust the time output according to the
679 * user configured offset ($timecorrection)
681 * @param mixed $format what format to return, if it's false output the
682 * default one (default true)
683 * @param string $timecorrection the time offset as returned by
684 * validateTimeZone() in Special:Preferences
687 function timeanddate( $ts, $adj = false, $format = true, $timecorrection = false) {
690 $ts = $this->userAdjust( $ts, $timecorrection );
693 $pref = $this->dateFormat( $format );
694 if( $pref == 'default' ||
!isset( $this->dateFormats
["$pref both"] ) ) {
695 $pref = $this->defaultDateFormat
;
698 return $this->sprintfDate( $this->dateFormats
["$pref both"], $ts );
701 function getMessage( $key ) {
703 return @$this->messages
[$key];
706 function getAllMessages() {
708 return $this->messages
;
711 function iconv( $in, $out, $string ) {
712 # For most languages, this is a wrapper for iconv
713 return iconv( $in, $out, $string );
716 // callback functions for uc(), lc(), ucwords(), ucwordbreaks()
717 function ucwordbreaksCallbackAscii($matches){
718 return $this->ucfirst($matches[1]);
721 function ucwordbreaksCallbackMB($matches){
722 return mb_strtoupper($matches[0]);
725 function ucCallback($matches){
726 list( $wikiUpperChars ) = self
::getCaseMaps();
727 return strtr( $matches[1], $wikiUpperChars );
730 function lcCallback($matches){
731 list( , $wikiLowerChars ) = self
::getCaseMaps();
732 return strtr( $matches[1], $wikiLowerChars );
735 function ucwordsCallbackMB($matches){
736 return mb_strtoupper($matches[0]);
739 function ucwordsCallbackWiki($matches){
740 list( $wikiUpperChars ) = self
::getCaseMaps();
741 return strtr( $matches[0], $wikiUpperChars );
744 function ucfirst( $str ) {
745 return self
::uc( $str, true );
748 function uc( $str, $first = false ) {
749 if ( function_exists( 'mb_strtoupper' ) )
751 if ( self
::isMultibyte( $str ) )
752 return mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
754 return ucfirst( $str );
756 return self
::isMultibyte( $str ) ?
mb_strtoupper( $str ) : strtoupper( $str );
758 if ( self
::isMultibyte( $str ) ) {
759 list( $wikiUpperChars ) = $this->getCaseMaps();
760 $x = $first ?
'^' : '';
761 return preg_replace_callback(
762 "/$x([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/",
763 array($this,"ucCallback"),
767 return $first ?
ucfirst( $str ) : strtoupper( $str );
770 function lcfirst( $str ) {
771 return self
::lc( $str, true );
774 function lc( $str, $first = false ) {
775 if ( function_exists( 'mb_strtolower' ) )
777 if ( self
::isMultibyte( $str ) )
778 return mb_strtolower( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
780 return strtolower( substr( $str, 0, 1 ) ) . substr( $str, 1 );
782 return self
::isMultibyte( $str ) ?
mb_strtolower( $str ) : strtolower( $str );
784 if ( self
::isMultibyte( $str ) ) {
785 list( , $wikiLowerChars ) = self
::getCaseMaps();
786 $x = $first ?
'^' : '';
787 return preg_replace_callback(
788 "/$x([A-Z]|[\\xc0-\\xff][\\x80-\\xbf]*)/",
789 array($this,"lcCallback"),
793 return $first ?
strtolower( substr( $str, 0, 1 ) ) . substr( $str, 1 ) : strtolower( $str );
796 function isMultibyte( $str ) {
797 return (bool)preg_match( '/[\x80-\xff]/', $str );
800 function ucwords($str) {
801 if ( self
::isMultibyte( $str ) ) {
802 $str = self
::lc($str);
804 // regexp to find first letter in each word (i.e. after each space)
805 $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)| ([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
807 // function to use to capitalize a single char
808 if ( function_exists( 'mb_strtoupper' ) )
809 return preg_replace_callback(
811 array($this,"ucwordsCallbackMB"),
815 return preg_replace_callback(
817 array($this,"ucwordsCallbackWiki"),
822 return ucwords( strtolower( $str ) );
825 # capitalize words at word breaks
826 function ucwordbreaks($str){
827 if (self
::isMultibyte( $str ) ) {
828 $str = self
::lc($str);
830 // since \b doesn't work for UTF-8, we explicitely define word break chars
831 $breaks= "[ \-\(\)\}\{\.,\?!]";
833 // find first letter after word break
834 $replaceRegexp = "/^([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)|$breaks([a-z]|[\\xc0-\\xff][\\x80-\\xbf]*)/";
836 if ( function_exists( 'mb_strtoupper' ) )
837 return preg_replace_callback(
839 array($this,"ucwordbreaksCallbackMB"),
843 return preg_replace_callback(
845 array($this,"ucwordsCallbackWiki"),
850 return preg_replace_callback(
851 '/\b([\w\x80-\xff]+)\b/',
852 array($this,"ucwordbreaksCallbackAscii"),
856 function checkTitleEncoding( $s ) {
857 if( is_array( $s ) ) {
858 wfDebugDieBacktrace( 'Given array to checkTitleEncoding.' );
860 # Check for non-UTF-8 URLs
861 $ishigh = preg_match( '/[\x80-\xff]/', $s);
862 if(!$ishigh) return $s;
864 $isutf8 = preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
865 '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})+$/', $s );
866 if( $isutf8 ) return $s;
868 return $this->iconv( $this->fallback8bitEncoding(), "utf-8", $s );
871 function fallback8bitEncoding() {
873 return $this->fallback8bitEncoding
;
877 * Some languages have special punctuation to strip out
878 * or characters which need to be converted for MySQL's
879 * indexing to grok it correctly. Make such changes here.
884 function stripForSearch( $string ) {
885 # MySQL fulltext index doesn't grok utf-8, so we
886 # need to fold cases and convert to hex
888 wfProfileIn( __METHOD__
);
889 if( function_exists( 'mb_strtolower' ) ) {
891 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
892 "'U8' . bin2hex( \"$1\" )",
893 mb_strtolower( $string ) );
895 list( , $wikiLowerChars ) = self
::getCaseMaps();
897 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
898 "'U8' . bin2hex( strtr( \"\$1\", \$wikiLowerChars ) )",
901 wfProfileOut( __METHOD__
);
905 function convertForSearchResult( $termsArray ) {
906 # some languages, e.g. Chinese, need to do a conversion
907 # in order for search results to be displayed correctly
912 * Get the first character of a string.
917 function firstChar( $s ) {
918 preg_match( '/^([\x00-\x7f]|[\xc0-\xdf][\x80-\xbf]|' .
919 '[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xf7][\x80-\xbf]{3})/', $s, $matches);
921 return isset( $matches[1] ) ?
$matches[1] : "";
924 function initEncoding() {
925 # Some languages may have an alternate char encoding option
926 # (Esperanto X-coding, Japanese furigana conversion, etc)
927 # If this language is used as the primary content language,
928 # an override to the defaults can be set here on startup.
931 function recodeForEdit( $s ) {
932 # For some languages we'll want to explicitly specify
933 # which characters make it into the edit box raw
934 # or are converted in some way or another.
935 # Note that if wgOutputEncoding is different from
936 # wgInputEncoding, this text will be further converted
937 # to wgOutputEncoding.
938 global $wgEditEncoding;
939 if( $wgEditEncoding == '' or
940 $wgEditEncoding == 'UTF-8' ) {
943 return $this->iconv( 'UTF-8', $wgEditEncoding, $s );
947 function recodeInput( $s ) {
948 # Take the previous into account.
949 global $wgEditEncoding;
950 if($wgEditEncoding != "") {
951 $enc = $wgEditEncoding;
955 if( $enc == 'UTF-8' ) {
958 return $this->iconv( $enc, 'UTF-8', $s );
963 * For right-to-left language support
973 * A hidden direction mark (LRM or RLM), depending on the language direction
977 function getDirMark() {
978 return $this->isRTL() ?
"\xE2\x80\x8F" : "\xE2\x80\x8E";
982 * An arrow, depending on the language direction
986 function getArrow() {
987 return $this->isRTL() ?
'←' : '→';
991 * To allow "foo[[bar]]" to extend the link over the whole word "foobar"
995 function linkPrefixExtension() {
997 return $this->linkPrefixExtension
;
1000 function &getMagicWords() {
1002 return $this->magicWords
;
1005 # Fill a MagicWord object with data from here
1006 function getMagic( &$mw ) {
1007 if ( !isset( $this->mMagicExtensions
) ) {
1008 $this->mMagicExtensions
= array();
1009 wfRunHooks( 'LanguageGetMagic', array( &$this->mMagicExtensions
, $this->getCode() ) );
1011 if ( isset( $this->mMagicExtensions
[$mw->mId
] ) ) {
1012 $rawEntry = $this->mMagicExtensions
[$mw->mId
];
1014 $magicWords =& $this->getMagicWords();
1015 if ( isset( $magicWords[$mw->mId
] ) ) {
1016 $rawEntry = $magicWords[$mw->mId
];
1018 # Fall back to English if local list is incomplete
1019 $magicWords =& Language
::getMagicWords();
1020 $rawEntry = $magicWords[$mw->mId
];
1024 if( !is_array( $rawEntry ) ) {
1025 error_log( "\"$rawEntry\" is not a valid magic thingie for \"$mw->mId\"" );
1027 $mw->mCaseSensitive
= $rawEntry[0];
1028 $mw->mSynonyms
= array_slice( $rawEntry, 1 );
1032 * Italic is unsuitable for some languages
1036 * @param string $text The text to be emphasized.
1039 function emphasize( $text ) {
1040 return "<em>$text</em>";
1044 * Normally we output all numbers in plain en_US style, that is
1045 * 293,291.235 for twohundredninetythreethousand-twohundredninetyone
1046 * point twohundredthirtyfive. However this is not sutable for all
1047 * languages, some such as Pakaran want ੨੯੩,੨੯੫.੨੩੫ and others such as
1048 * Icelandic just want to use commas instead of dots, and dots instead
1049 * of commas like "293.291,235".
1051 * An example of this function being called:
1053 * wfMsg( 'message', $wgLang->formatNum( $num ) )
1056 * See LanguageGu.php for the Gujarati implementation and
1057 * LanguageIs.php for the , => . and . => , implementation.
1059 * @todo check if it's viable to use localeconv() for the decimal
1062 * @param mixed $number the string to be formatted, should be an integer or
1063 * a floating point number.
1064 * @param bool $nocommafy Set to true for special numbers like dates
1067 function formatNum( $number, $nocommafy = false ) {
1068 global $wgTranslateNumerals;
1070 $number = $this->commafy($number);
1071 $s = $this->separatorTransformTable();
1072 if (!is_null($s)) { $number = strtr($number, $s); }
1075 if ($wgTranslateNumerals) {
1076 $s = $this->digitTransformTable();
1077 if (!is_null($s)) { $number = strtr($number, $s); }
1084 * Adds commas to a given number
1089 function commafy($_) {
1090 return strrev((string)preg_replace('/(\d{3})(?=\d)(?!\d*\.)/','$1,',strrev($_)));
1093 function digitTransformTable() {
1095 return $this->digitTransformTable
;
1098 function separatorTransformTable() {
1100 return $this->separatorTransformTable
;
1105 * For the credit list in includes/Credits.php (action=credits)
1110 function listToText( $l ) {
1113 for ($i = $m; $i >= 0; $i--) {
1116 } else if ($i == $m - 1) {
1117 $s = $l[$i] . ' ' . $this->getMessageFromDB( 'and' ) . ' ' . $s;
1119 $s = $l[$i] . ', ' . $s;
1125 # Crop a string from the beginning or end to a certain number of bytes.
1126 # (Bytes are used because our storage has limited byte lengths for some
1127 # columns in the database.) Multibyte charsets will need to make sure that
1128 # only whole characters are included!
1130 # $length does not include the optional ellipsis.
1131 # If $length is negative, snip from the beginning
1132 function truncate( $string, $length, $ellipsis = "" ) {
1133 if( $length == 0 ) {
1136 if ( strlen( $string ) <= abs( $length ) ) {
1140 $string = substr( $string, 0, $length );
1141 $char = ord( $string[strlen( $string ) - 1] );
1142 if ($char >= 0xc0) {
1143 # We got the first byte only of a multibyte char; remove it.
1144 $string = substr( $string, 0, -1 );
1145 } elseif( $char >= 0x80 &&
1146 preg_match( '/^(.*)(?:[\xe0-\xef][\x80-\xbf]|' .
1147 '[\xf0-\xf7][\x80-\xbf]{1,2})$/', $string, $m ) ) {
1148 # We chopped in the middle of a character; remove it
1151 return $string . $ellipsis;
1153 $string = substr( $string, $length );
1154 $char = ord( $string[0] );
1155 if( $char >= 0x80 && $char < 0xc0 ) {
1156 # We chopped in the middle of a character; remove the whole thing
1157 $string = preg_replace( '/^[\x80-\xbf]+/', '', $string );
1159 return $ellipsis . $string;
1164 * Grammatical transformations, needed for inflected languages
1165 * Invoked by putting {{grammar:case|word}} in a message
1167 * @param string $word
1168 * @param string $case
1171 function convertGrammar( $word, $case ) {
1172 global $wgGrammarForms;
1173 if ( isset($wgGrammarForms['en'][$case][$word]) ) {
1174 return $wgGrammarForms['en'][$case][$word];
1180 * Plural form transformations, needed for some languages.
1181 * For example, where are 3 form of plural in Russian and Polish,
1182 * depending on "count mod 10". See [[w:Plural]]
1183 * For English it is pretty simple.
1185 * Invoked by putting {{plural:count|wordform1|wordform2}}
1186 * or {{plural:count|wordform1|wordform2|wordform3}}
1188 * Example: {{plural:{{NUMBEROFARTICLES}}|article|articles}}
1190 * @param integer $count
1191 * @param string $wordform1
1192 * @param string $wordform2
1193 * @param string $wordform3 (optional)
1196 function convertPlural( $count, $w1, $w2, $w3) {
1197 return $count == '1' ?
$w1 : $w2;
1201 * For translaing of expiry times
1202 * @param string The validated block time in English
1203 * @return Somehow translated block time
1204 * @see LanguageFi.php for example implementation
1206 function translateBlockExpiry( $str ) {
1208 $scBlockExpiryOptions = $this->getMessageFromDB( 'ipboptions' );
1210 if ( $scBlockExpiryOptions == '-') {
1214 foreach (explode(',', $scBlockExpiryOptions) as $option) {
1215 if ( strpos($option, ":") === false )
1217 list($show, $value) = explode(":", $option);
1218 if ( strcmp ( $str, $value) == 0 )
1219 return '<span title="' . htmlspecialchars($str). '">' .
1220 htmlspecialchars( trim( $show ) ) . '</span>';
1227 * languages like Chinese need to be segmented in order for the diff
1230 * @param string $text
1233 function segmentForDiff( $text ) {
1238 * and unsegment to show the result
1240 * @param string $text
1243 function unsegmentForDiff( $text ) {
1247 # convert text to different variants of a language.
1248 function convert( $text, $isTitle = false) {
1249 return $this->mConverter
->convert($text, $isTitle);
1252 # Convert text from within Parser
1253 function parserConvert( $text, &$parser ) {
1254 return $this->mConverter
->parserConvert( $text, $parser );
1257 # Tell the converter that it shouldn't convert titles
1258 function setNoTitleConvert(){
1259 $this->mConverter
->setNotitleConvert();
1262 # Check if this is a language with variants
1263 function hasVariants(){
1264 return sizeof($this->getVariants())>1;
1269 * Perform output conversion on a string, and encode for safe HTML output.
1270 * @param string $text
1271 * @param bool $isTitle -- wtf?
1273 * @todo this should get integrated somewhere sane
1275 function convertHtml( $text, $isTitle = false ) {
1276 return htmlspecialchars( $this->convert( $text, $isTitle ) );
1279 function convertCategoryKey( $key ) {
1280 return $this->mConverter
->convertCategoryKey( $key );
1284 * get the list of variants supported by this langauge
1285 * see sample implementation in LanguageZh.php
1287 * @return array an array of language codes
1289 function getVariants() {
1290 return $this->mConverter
->getVariants();
1294 function getPreferredVariant( $fromUser = true ) {
1295 return $this->mConverter
->getPreferredVariant( $fromUser );
1299 * if a language supports multiple variants, it is
1300 * possible that non-existing link in one variant
1301 * actually exists in another variant. this function
1302 * tries to find it. See e.g. LanguageZh.php
1304 * @param string $link the name of the link
1305 * @param mixed $nt the title object of the link
1306 * @return null the input parameters may be modified upon return
1308 function findVariantLink( &$link, &$nt ) {
1309 $this->mConverter
->findVariantLink($link, $nt);
1313 * If a language supports multiple variants, converts text
1314 * into an array of all possible variants of the text:
1315 * 'variant' => text in that variant
1318 function convertLinkToAllVariants($text){
1319 return $this->mConverter
->convertLinkToAllVariants($text);
1324 * returns language specific options used by User::getPageRenderHash()
1325 * for example, the preferred language variant
1330 function getExtraHashOptions() {
1331 return $this->mConverter
->getExtraHashOptions();
1335 * for languages that support multiple variants, the title of an
1336 * article may be displayed differently in different variants. this
1337 * function returns the apporiate title defined in the body of the article.
1341 function getParsedTitle() {
1342 return $this->mConverter
->getParsedTitle();
1346 * Enclose a string with the "no conversion" tag. This is used by
1347 * various functions in the Parser
1349 * @param string $text text to be tagged for no conversion
1350 * @return string the tagged text
1352 function markNoConversion( $text, $noParse=false ) {
1353 return $this->mConverter
->markNoConversion( $text, $noParse );
1357 * A regular expression to match legal word-trailing characters
1358 * which should be merged onto a link of the form [[foo]]bar.
1363 function linkTrail() {
1365 return $this->linkTrail
;
1368 function getLangObj() {
1373 * Get the RFC 3066 code for this language object
1375 function getCode() {
1376 return $this->mCode
;
1379 function setCode( $code ) {
1380 $this->mCode
= $code;
1383 static function getFileName( $prefix = 'Language', $code, $suffix = '.php' ) {
1384 return $prefix . str_replace( '-', '_', ucfirst( $code ) ) . $suffix;
1387 static function getLocalisationArray( $code, $disableCache = false ) {
1388 self
::loadLocalisation( $code, $disableCache );
1389 return self
::$mLocalisationCache[$code];
1393 * Load localisation data for a given code into the static cache
1395 * @return array Dependencies, map of filenames to mtimes
1397 static function loadLocalisation( $code, $disableCache = false ) {
1398 static $recursionGuard = array();
1399 global $wgMemc, $wgDBname, $IP;
1402 throw new MWException( "Invalid language code requested" );
1405 if ( !$disableCache ) {
1406 # Try the per-process cache
1407 if ( isset( self
::$mLocalisationCache[$code] ) ) {
1408 return self
::$mLocalisationCache[$code]['deps'];
1411 wfProfileIn( __METHOD__
);
1413 # Try the serialized directory
1414 $cache = wfGetPrecompiledData( self
::getFileName( "Messages", $code, '.ser' ) );
1416 self
::$mLocalisationCache[$code] = $cache;
1417 wfDebug( "Got localisation for $code from precompiled data file\n" );
1418 wfProfileOut( __METHOD__
);
1419 return self
::$mLocalisationCache[$code]['deps'];
1422 # Try the global cache
1423 $memcKey = "$wgDBname:localisation:$code";
1424 $cache = $wgMemc->get( $memcKey );
1427 # Check file modification times
1428 foreach ( $cache['deps'] as $file => $mtime ) {
1429 if ( filemtime( $file ) > $mtime ) {
1434 if ( self
::isLocalisationOutOfDate( $cache ) ) {
1435 $wgMemc->delete( $memcKey );
1437 wfDebug( "Localisation cache for $code had expired due to update of $file\n" );
1439 self
::$mLocalisationCache[$code] = $cache;
1440 wfDebug( "Got localisation for $code from cache\n" );
1441 wfProfileOut( __METHOD__
);
1442 return $cache['deps'];
1446 wfProfileIn( __METHOD__
);
1449 if ( $code != 'en' ) {
1455 # Load the primary localisation from the source file
1457 $filename = self
::getFileName( "$IP/languages/Messages", $code, '.php' );
1458 if ( !file_exists( $filename ) ) {
1459 wfDebug( "No localisation file for $code, using implicit fallback to en\n" );
1463 $deps = array( $filename => filemtime( $filename ) );
1464 require( $filename );
1465 $cache = compact( self
::$mLocalisationKeys );
1466 wfDebug( "Got localisation for $code from source\n" );
1469 if ( !empty( $fallback ) ) {
1470 # Load the fallback localisation, with a circular reference guard
1471 if ( isset( $recursionGuard[$code] ) ) {
1472 throw new MWException( "Error: Circular fallback reference in language code $code" );
1474 $recursionGuard[$code] = true;
1475 $newDeps = self
::loadLocalisation( $fallback, $disableCache );
1476 unset( $recursionGuard[$code] );
1478 $secondary = self
::$mLocalisationCache[$fallback];
1479 $deps = array_merge( $deps, $newDeps );
1481 # Merge the fallback localisation with the current localisation
1482 foreach ( self
::$mLocalisationKeys as $key ) {
1483 if ( isset( $cache[$key] ) ) {
1484 if ( isset( $secondary[$key] ) ) {
1485 if ( in_array( $key, self
::$mMergeableMapKeys ) ) {
1486 $cache[$key] = $cache[$key] +
$secondary[$key];
1487 } elseif ( in_array( $key, self
::$mMergeableListKeys ) ) {
1488 $cache[$key] = array_merge( $secondary[$key], $cache[$key] );
1492 $cache[$key] = $secondary[$key];
1496 # Merge bookstore lists if requested
1497 if ( !empty( $cache['bookstoreList']['inherit'] ) ) {
1498 $cache['bookstoreList'] = array_merge( $cache['bookstoreList'], $secondary['bookstoreList'] );
1500 if ( isset( $cache['bookstoreList']['inherit'] ) ) {
1501 unset( $cache['bookstoreList']['inherit'] );
1505 # Add dependencies to the cache entry
1506 $cache['deps'] = $deps;
1508 # Replace spaces with underscores in namespace names
1509 $cache['namespaceNames'] = str_replace( ' ', '_', $cache['namespaceNames'] );
1511 # Save to both caches
1512 self
::$mLocalisationCache[$code] = $cache;
1513 if ( !$disableCache ) {
1514 $wgMemc->set( $memcKey, $cache );
1517 wfProfileOut( __METHOD__
);
1522 * Test if a given localisation cache is out of date with respect to the
1523 * source Messages files. This is done automatically for the global cache
1524 * in $wgMemc, but is only done on certain occasions for the serialized
1527 * @param $cache mixed Either a language code or a cache array
1529 static function isLocalisationOutOfDate( $cache ) {
1530 if ( !is_array( $cache ) ) {
1531 self
::loadLocalisation( $cache );
1532 $cache = self
::$mLocalisationCache[$cache];
1535 foreach ( $cache['deps'] as $file => $mtime ) {
1536 if ( filemtime( $file ) > $mtime ) {
1545 * Get the fallback for a given language
1547 static function getFallbackFor( $code ) {
1548 self
::loadLocalisation( $code );
1549 return self
::$mLocalisationCache[$code]['fallback'];
1553 * Get all messages for a given language
1555 static function getMessagesFor( $code ) {
1556 self
::loadLocalisation( $code );
1557 return self
::$mLocalisationCache[$code]['messages'];
1561 * Get a message for a given language
1563 static function getMessageFor( $key, $code ) {
1564 self
::loadLocalisation( $code );
1565 return @self
::$mLocalisationCache[$code]['messages'][$key];
1569 * Load localisation data for this object
1572 if ( !$this->mLoaded
) {
1573 self
::loadLocalisation( $this->getCode() );
1574 $cache =& self
::$mLocalisationCache[$this->getCode()];
1575 foreach ( self
::$mLocalisationKeys as $key ) {
1576 $this->$key = $cache[$key];
1578 $this->mLoaded
= true;
1580 $this->fixUpSettings();
1585 * Do any necessary post-cache-load settings adjustment
1587 function fixUpSettings() {
1588 global $wgExtraNamespaces, $wgMetaNamespace, $wgMetaNamespaceTalk, $wgMessageCache,
1589 $wgNamespaceAliases, $wgAmericanDates;
1590 wfProfileIn( __METHOD__
);
1591 if ( $wgExtraNamespaces ) {
1592 $this->namespaceNames
= $wgExtraNamespaces +
$this->namespaceNames
;
1595 $this->namespaceNames
[NS_PROJECT
] = $wgMetaNamespace;
1596 if ( $wgMetaNamespaceTalk ) {
1597 $this->namespaceNames
[NS_PROJECT_TALK
] = $wgMetaNamespaceTalk;
1599 $talk = $this->namespaceNames
[NS_PROJECT_TALK
];
1600 $talk = str_replace( '$1', $wgMetaNamespace, $talk );
1602 # Allow grammar transformations
1603 # Allowing full message-style parsing would make simple requests
1604 # such as action=raw much more expensive than they need to be.
1605 # This will hopefully cover most cases.
1606 $talk = preg_replace_callback( '/{{grammar:(.*?)\|(.*?)}}/i',
1607 array( &$this, 'replaceGrammarInNamespace' ), $talk );
1608 $talk = str_replace( ' ', '_', $talk );
1609 $this->namespaceNames
[NS_PROJECT_TALK
] = $talk;
1612 # The above mixing may leave namespaces out of canonical order.
1613 # Re-order by namespace ID number...
1614 ksort( $this->namespaceNames
);
1616 # Put namespace names and aliases into a hashtable.
1617 # If this is too slow, then we should arrange it so that it is done
1618 # before caching. The catch is that at pre-cache time, the above
1619 # class-specific fixup hasn't been done.
1620 $this->mNamespaceIds
= array();
1621 foreach ( $this->namespaceNames
as $index => $name ) {
1622 $this->mNamespaceIds
[$this->lc($name)] = $index;
1624 if ( $this->namespaceAliases
) {
1625 foreach ( $this->namespaceAliases
as $name => $index ) {
1626 $this->mNamespaceIds
[$this->lc($name)] = $index;
1629 if ( $wgNamespaceAliases ) {
1630 foreach ( $wgNamespaceAliases as $name => $index ) {
1631 $this->mNamespaceIds
[$this->lc($name)] = $index;
1635 if ( $this->defaultDateFormat
== 'dmy or mdy' ) {
1636 $this->defaultDateFormat
= $wgAmericanDates ?
'mdy' : 'dmy';
1638 wfProfileOut( __METHOD__
);
1641 function replaceGrammarInNamespace( $m ) {
1642 return $this->convertGrammar( trim( $m[2] ), trim( $m[1] ) );
1645 static function getCaseMaps() {
1646 static $wikiUpperChars, $wikiLowerChars;
1648 if ( isset( $wikiUpperChars ) ) {
1649 return array( $wikiUpperChars, $wikiLowerChars );
1652 wfProfileIn( __METHOD__
);
1653 $arr = wfGetPrecompiledData( 'Utf8Case.ser' );
1654 if ( $arr === false ) {
1655 throw new MWException(
1656 "Utf8Case.ser is missing, please run \"make\" in the serialized directory\n" );
1659 wfProfileOut( __METHOD__
);
1660 return array( $wikiUpperChars, $wikiLowerChars );