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 dDjlNwzWFmMntLYyaAgGhHiscrU. See the
427 * PHP manual for definitions. There are a number of extensions, which
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
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
443 * Backslash escaping is also supported.
445 * @param string $format
446 * @param string $ts 14-character timestamp
450 function sprintfDate( $format, $ts ) {
456 for ( $p = 0; $p < strlen( $format ); $p++
) {
459 if ( $code == 'x' && $p < strlen( $format ) - 1 ) {
460 $code .= $format[++
$p];
471 $rawToggle = !$rawToggle;
477 $s .= $this->getMonthNameGen( substr( $ts, 4, 2 ) );
480 $num = substr( $ts, 6, 2 );
483 if ( !$unix ) $unix = wfTimestamp( TS_UNIX
, $ts );
484 $s .= $this->getWeekdayAbbreviation( date( 'w', $unix ) +
1 );
487 $num = intval( substr( $ts, 6, 2 ) );
490 if ( !$unix ) $unix = wfTimestamp( TS_UNIX
, $ts );
491 $s .= $this->getWeekdayName( date( 'w', $unix ) +
1 );
494 if ( !$unix ) $unix = wfTimestamp( TS_UNIX
, $ts );
495 $w = date( 'w', $unix );
499 if ( !$unix ) $unix = wfTimestamp( TS_UNIX
, $ts );
500 $num = date( 'w', $unix );
503 if ( !$unix ) $unix = wfTimestamp( TS_UNIX
, $ts );
504 $num = date( 'z', $unix );
507 if ( !$unix ) $unix = wfTimestamp( TS_UNIX
, $ts );
508 $num = date( 'W', $unix );
511 $s .= $this->getMonthName( substr( $ts, 4, 2 ) );
514 $num = substr( $ts, 4, 2 );
517 $s .= $this->getMonthAbbreviation( substr( $ts, 4, 2 ) );
520 $num = intval( substr( $ts, 4, 2 ) );
523 if ( !$unix ) $unix = wfTimestamp( TS_UNIX
, $ts );
524 $num = date( 't', $unix );
527 if ( !$unix ) $unix = wfTimestamp( TS_UNIX
, $ts );
528 $num = date( 'L', $unix );
531 $num = substr( $ts, 0, 4 );
534 $num = substr( $ts, 2, 2 );
537 $s .= intval( substr( $ts, 8, 2 ) ) < 12 ?
'am' : 'pm';
540 $s .= intval( substr( $ts, 8, 2 ) ) < 12 ?
'AM' : 'PM';
543 $h = substr( $ts, 8, 2 );
544 $num = $h %
12 ?
$h %
12 : 12;
547 $num = intval( substr( $ts, 8, 2 ) );
550 $h = substr( $ts, 8, 2 );
551 $num = sprintf( '%02d', $h %
12 ?
$h %
12 : 12 );
554 $num = substr( $ts, 8, 2 );
557 $num = substr( $ts, 10, 2 );
560 $num = substr( $ts, 12, 2 );
563 if ( !$unix ) $unix = wfTimestamp( TS_UNIX
, $ts );
564 $s .= date( 'c', $unix );
567 if ( !$unix ) $unix = wfTimestamp( TS_UNIX
, $ts );
568 $s .= date( 'r', $unix );
571 if ( !$unix ) $unix = wfTimestamp( TS_UNIX
, $ts );
576 if ( $p < strlen( $format ) - 1 ) {
584 if ( $p < strlen( $format ) - 1 ) {
585 $endQuote = strpos( $format, '"', $p +
1 );
586 if ( $endQuote === false ) {
587 # No terminating quote, assume literal "
590 $s .= substr( $format, $p +
1, $endQuote - $p - 1 );
594 # Quote at end of string, assume literal "
601 if ( $num !== false ) {
602 if ( $rawToggle ||
$raw ) {
605 } elseif ( $roman ) {
606 $s .= self
::romanNumeral( $num );
609 $s .= $this->formatNum( $num, true );
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 ) {
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;
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
649 * function timeanddate([...], $format = true) {
650 * $datePreference = $this->dateFormat($format);
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.
660 function dateFormat( $usePrefs = true ) {
663 if( is_bool( $usePrefs ) ) {
665 $datePreference = $wgUser->getDatePreference();
667 $options = User
::getDefaultOptions();
668 $datePreference = (string)$options['date'];
671 $datePreference = (string)$usePrefs;
675 if( $datePreference == '' ) {
679 return $datePreference;
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
693 function date( $ts, $adj = false, $format = true, $timecorrection = false ) {
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 );
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
717 function time( $ts, $adj = false, $format = true, $timecorrection = false ) {
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 );
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
743 function timeanddate( $ts, $adj = false, $format = true, $timecorrection = false) {
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 ) {
759 return @$this->messages
[$key];
762 function getAllMessages() {
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' ) )
807 if ( self
::isMultibyte( $str ) )
808 return mb_strtoupper( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
810 return ucfirst( $str );
812 return self
::isMultibyte( $str ) ?
mb_strtoupper( $str ) : strtoupper( $str );
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"),
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' ) )
833 if ( self
::isMultibyte( $str ) )
834 return mb_strtolower( mb_substr( $str, 0, 1 ) ) . mb_substr( $str, 1 );
836 return strtolower( substr( $str, 0, 1 ) ) . substr( $str, 1 );
838 return self
::isMultibyte( $str ) ?
mb_strtolower( $str ) : strtolower( $str );
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"),
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(
867 array($this,"ucwordsCallbackMB"),
871 return preg_replace_callback(
873 array($this,"ucwordsCallbackWiki"),
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(
895 array($this,"ucwordbreaksCallbackMB"),
899 return preg_replace_callback(
901 array($this,"ucwordsCallbackWiki"),
906 return preg_replace_callback(
907 '/\b([\w\x80-\xff]+)\b/',
908 array($this,"ucwordbreaksCallbackAscii"),
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() {
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.
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' ) ) {
947 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
948 "'U8' . bin2hex( \"$1\" )",
949 mb_strtolower( $string ) );
951 list( , $wikiLowerChars ) = self
::getCaseMaps();
953 "/([\\xc0-\\xff][\\x80-\\xbf]*)/e",
954 "'U8' . bin2hex( strtr( \"\$1\", \$wikiLowerChars ) )",
957 wfProfileOut( __METHOD__
);
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
968 * Get the first character of a 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' ) {
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;
1011 if( $enc == 'UTF-8' ) {
1014 return $this->iconv( $enc, 'UTF-8', $s );
1019 * For right-to-left language support
1029 * A hidden direction mark (LRM or RLM), depending on the language direction
1033 function getDirMark() {
1034 return $this->isRTL() ?
"\xE2\x80\x8F" : "\xE2\x80\x8E";
1038 * An arrow, depending on the language direction
1042 function getArrow() {
1043 return $this->isRTL() ?
'←' : '→';
1047 * To allow "foo[[bar]]" to extend the link over the whole word "foobar"
1051 function linkPrefixExtension() {
1053 return $this->linkPrefixExtension
;
1056 function &getMagicWords() {
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
];
1070 $magicWords =& $this->getMagicWords();
1071 if ( isset( $magicWords[$mw->mId
] ) ) {
1072 $rawEntry = $magicWords[$mw->mId
];
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
1092 * @param string $text The text to be emphasized.
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:
1109 * wfMsg( 'message', $wgLang->formatNum( $num ) )
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
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
1123 function formatNum( $number, $nocommafy = false ) {
1124 global $wgTranslateNumerals;
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); }
1140 * Adds commas to a given number
1145 function commafy($_) {
1146 return strrev((string)preg_replace('/(\d{3})(?=\d)(?!\d*\.)/','$1,',strrev($_)));
1149 function digitTransformTable() {
1151 return $this->digitTransformTable
;
1154 function separatorTransformTable() {
1156 return $this->separatorTransformTable
;
1161 * For the credit list in includes/Credits.php (action=credits)
1166 function listToText( $l ) {
1169 for ($i = $m; $i >= 0; $i--) {
1172 } else if ($i == $m - 1) {
1173 $s = $l[$i] . ' ' . $this->getMessageFromDB( 'and' ) . ' ' . $s;
1175 $s = $l[$i] . ', ' . $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 ) {
1192 if ( strlen( $string ) <= abs( $length ) ) {
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
1207 return $string . $ellipsis;
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
1227 function convertGrammar( $word, $case ) {
1228 global $wgGrammarForms;
1229 if ( isset($wgGrammarForms['en'][$case][$word]) ) {
1230 return $wgGrammarForms['en'][$case][$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)
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 == '-') {
1270 foreach (explode(',', $scBlockExpiryOptions) as $option) {
1271 if ( strpos($option, ":") === false )
1273 list($show, $value) = explode(":", $option);
1274 if ( strcmp ( $str, $value) == 0 )
1275 return '<span title="' . htmlspecialchars($str). '">' .
1276 htmlspecialchars( trim( $show ) ) . '</span>';
1283 * languages like Chinese need to be segmented in order for the diff
1286 * @param string $text
1289 function segmentForDiff( $text ) {
1294 * and unsegment to show the result
1296 * @param string $text
1299 function unsegmentForDiff( $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?
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
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.
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.
1419 function linkTrail() {
1421 return $this->linkTrail
;
1424 function getLangObj() {
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;
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' ) );
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 );
1483 # Check file modification times
1484 foreach ( $cache['deps'] as $file => $mtime ) {
1485 if ( filemtime( $file ) > $mtime ) {
1490 if ( self
::isLocalisationOutOfDate( $cache ) ) {
1491 $wgMemc->delete( $memcKey );
1493 wfDebug( "Localisation cache for $code had expired due to update of $file\n" );
1495 self
::$mLocalisationCache[$code] = $cache;
1496 wfDebug( "Got localisation for $code from cache\n" );
1497 wfProfileOut( __METHOD__
);
1498 return $cache['deps'];
1502 wfProfileIn( __METHOD__
);
1505 if ( $code != 'en' ) {
1511 # Load the primary localisation from the source file
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" );
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] );
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__
);
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
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];
1591 foreach ( $cache['deps'] as $file => $mtime ) {
1592 if ( filemtime( $file ) > $mtime ) {
1601 * Get the fallback for a given language
1603 static function getFallbackFor( $code ) {
1604 self
::loadLocalisation( $code );
1605 return self
::$mLocalisationCache[$code]['fallback'];
1609 * Get all messages for a given language
1611 static function getMessagesFor( $code ) {
1612 self
::loadLocalisation( $code );
1613 return self
::$mLocalisationCache[$code]['messages'];
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
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;
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;
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" );
1715 wfProfileOut( __METHOD__
);
1716 return array( $wikiUpperChars, $wikiLowerChars );