mLang = $langobj; } function autoConvertToAllVariants( $text ) { return array( $this->mLang->getCode() => $text ); } function convert( $t ) { return $t; } function convertTitle( $t ) { return $t->getPrefixedText(); } function getVariants() { return array( $this->mLang->getCode() ); } function getPreferredVariant() { return $this->mLang->getCode(); } function getDefaultVariant() { return $this->mLang->getCode(); } function getURLVariant() { return ''; } function getConvRuleTitle() { return false; } function findVariantLink( &$l, &$n, $ignoreOtherCond = false ) { } function getExtraHashOptions() { return ''; } function getParsedTitle() { return ''; } function markNoConversion( $text, $noParse = false ) { return $text; } function convertCategoryKey( $key ) { return $key; } function convertLinkToAllVariants( $text ) { return $this->autoConvertToAllVariants( $text ); } function armourMath( $text ) { return $text; } } /** * Internationalisation code * @ingroup Language */ class Language { var $mConverter, $mVariants, $mCode, $mLoaded = false; var $mMagicExtensions = array(), $mMagicHookDone = false; var $mNamespaceIds, $namespaceNames, $namespaceAliases; var $dateFormatStrings = array(); var $mExtendedSpecialPageAliases; /** * ReplacementArray object caches */ var $transformData = array(); /** * @var LocalisationCache */ static public $dataCache; static public $mLangObjCache = array(); static public $mWeekdayMsgs = array( 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday' ); static public $mWeekdayAbbrevMsgs = array( 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat' ); static public $mMonthMsgs = array( 'january', 'february', 'march', 'april', 'may_long', 'june', 'july', 'august', 'september', 'october', 'november', 'december' ); static public $mMonthGenMsgs = array( 'january-gen', 'february-gen', 'march-gen', 'april-gen', 'may-gen', 'june-gen', 'july-gen', 'august-gen', 'september-gen', 'october-gen', 'november-gen', 'december-gen' ); static public $mMonthAbbrevMsgs = array( 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec' ); static public $mIranianCalendarMonthMsgs = array( 'iranian-calendar-m1', 'iranian-calendar-m2', 'iranian-calendar-m3', 'iranian-calendar-m4', 'iranian-calendar-m5', 'iranian-calendar-m6', 'iranian-calendar-m7', 'iranian-calendar-m8', 'iranian-calendar-m9', 'iranian-calendar-m10', 'iranian-calendar-m11', 'iranian-calendar-m12' ); static public $mHebrewCalendarMonthMsgs = array( 'hebrew-calendar-m1', 'hebrew-calendar-m2', 'hebrew-calendar-m3', 'hebrew-calendar-m4', 'hebrew-calendar-m5', 'hebrew-calendar-m6', 'hebrew-calendar-m7', 'hebrew-calendar-m8', 'hebrew-calendar-m9', 'hebrew-calendar-m10', 'hebrew-calendar-m11', 'hebrew-calendar-m12', 'hebrew-calendar-m6a', 'hebrew-calendar-m6b' ); static public $mHebrewCalendarMonthGenMsgs = array( 'hebrew-calendar-m1-gen', 'hebrew-calendar-m2-gen', 'hebrew-calendar-m3-gen', 'hebrew-calendar-m4-gen', 'hebrew-calendar-m5-gen', 'hebrew-calendar-m6-gen', 'hebrew-calendar-m7-gen', 'hebrew-calendar-m8-gen', 'hebrew-calendar-m9-gen', 'hebrew-calendar-m10-gen', 'hebrew-calendar-m11-gen', 'hebrew-calendar-m12-gen', 'hebrew-calendar-m6a-gen', 'hebrew-calendar-m6b-gen' ); static public $mHijriCalendarMonthMsgs = array( 'hijri-calendar-m1', 'hijri-calendar-m2', 'hijri-calendar-m3', 'hijri-calendar-m4', 'hijri-calendar-m5', 'hijri-calendar-m6', 'hijri-calendar-m7', 'hijri-calendar-m8', 'hijri-calendar-m9', 'hijri-calendar-m10', 'hijri-calendar-m11', 'hijri-calendar-m12' ); /** * Get a cached language object for a given language code * @param $code String * @return Language */ static function factory( $code ) { if ( !isset( self::$mLangObjCache[$code] ) ) { if ( count( self::$mLangObjCache ) > 10 ) { // Don't keep a billion objects around, that's stupid. self::$mLangObjCache = array(); } self::$mLangObjCache[$code] = self::newFromCode( $code ); } return self::$mLangObjCache[$code]; } /** * Create a language object for a given language code * @param $code String * @return Language */ protected static function newFromCode( $code ) { global $IP; static $recursionLevel = 0; // Protect against path traversal below if ( !Language::isValidCode( $code ) || strcspn( $code, ":/\\\000" ) !== strlen( $code ) ) { throw new MWException( "Invalid language code \"$code\"" ); } if ( !Language::isValidBuiltInCode( $code ) ) { // It's not possible to customise this code with class files, so // just return a Language object. This is to support uselang= hacks. $lang = new Language; $lang->setCode( $code ); return $lang; } if ( $code == 'en' ) { $class = 'Language'; } else { $class = 'Language' . str_replace( '-', '_', ucfirst( $code ) ); if ( !defined( 'MW_COMPILED' ) ) { // Preload base classes to work around APC/PHP5 bug if ( file_exists( "$IP/languages/classes/$class.deps.php" ) ) { include_once( "$IP/languages/classes/$class.deps.php" ); } if ( file_exists( "$IP/languages/classes/$class.php" ) ) { include_once( "$IP/languages/classes/$class.php" ); } } } if ( $recursionLevel > 5 ) { throw new MWException( "Language fallback loop detected when creating class $class\n" ); } if ( !MWInit::classExists( $class ) ) { $fallback = Language::getFallbackFor( $code ); ++$recursionLevel; $lang = Language::newFromCode( $fallback ); --$recursionLevel; $lang->setCode( $code ); } else { $lang = new $class; } return $lang; } /** * Returns true if a language code string is of a valid form, whether or * not it exists. This includes codes which are used solely for * customisation via the MediaWiki namespace. * * @param $code string * * @return bool */ public static function isValidCode( $code ) { return strcspn( $code, ":/\\\000" ) === strlen( $code ) && !preg_match( Title::getTitleInvalidRegex(), $code ); } /** * Returns true if a language code is of a valid form for the purposes of * internal customisation of MediaWiki, via Messages*.php. * * @param $code string * * @since 1.18 * @return bool */ public static function isValidBuiltInCode( $code ) { return preg_match( '/^[a-z0-9-]*$/i', $code ); } /** * Get the LocalisationCache instance * * @return LocalisationCache */ public static function getLocalisationCache() { if ( is_null( self::$dataCache ) ) { global $wgLocalisationCacheConf; $class = $wgLocalisationCacheConf['class']; self::$dataCache = new $class( $wgLocalisationCacheConf ); } return self::$dataCache; } function __construct() { $this->mConverter = new FakeConverter( $this ); // Set the code to the name of the descendant if ( get_class( $this ) == 'Language' ) { $this->mCode = 'en'; } else { $this->mCode = str_replace( '_', '-', strtolower( substr( get_class( $this ), 8 ) ) ); } self::getLocalisationCache(); } /** * Reduce memory usage */ function __destruct() { foreach ( $this as $name => $value ) { unset( $this->$name ); } } /** * Hook which will be called if this is the content language. * Descendants can use this to register hook functions or modify globals */ function initContLang() { } /** * @return array|bool */ function getFallbackLanguageCode() { if ( $this->mCode === 'en' ) { return false; } else { return self::$dataCache->getItem( $this->mCode, 'fallback' ); } } /** * Exports $wgBookstoreListEn * @return array */ function getBookstoreList() { return self::$dataCache->getItem( $this->mCode, 'bookstoreList' ); } /** * @return array */ function getNamespaces() { if ( is_null( $this->namespaceNames ) ) { global $wgMetaNamespace, $wgMetaNamespaceTalk, $wgExtraNamespaces; $this->namespaceNames = self::$dataCache->getItem( $this->mCode, 'namespaceNames' ); $validNamespaces = MWNamespace::getCanonicalNamespaces(); $this->namespaceNames = $wgExtraNamespaces + $this->namespaceNames + $validNamespaces; $this->namespaceNames[NS_PROJECT] = $wgMetaNamespace; if ( $wgMetaNamespaceTalk ) { $this->namespaceNames[NS_PROJECT_TALK] = $wgMetaNamespaceTalk; } else { $talk = $this->namespaceNames[NS_PROJECT_TALK]; $this->namespaceNames[NS_PROJECT_TALK] = $this->fixVariableInNamespace( $talk ); } # Sometimes a language will be localised but not actually exist on this wiki. foreach( $this->namespaceNames as $key => $text ) { if ( !isset( $validNamespaces[$key] ) ) { unset( $this->namespaceNames[$key] ); } } # The above mixing may leave namespaces out of canonical order. # Re-order by namespace ID number... ksort( $this->namespaceNames ); } return $this->namespaceNames; } /** * A convenience function that returns the same thing as * getNamespaces() except with the array values changed to ' ' * where it found '_', useful for producing output to be displayed * e.g. in