X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=languages%2FLanguageConverter.php;h=77210155fcd8d10287f81514fbf66b0f87349b12;hb=f7e1770fb832aa77bf4e16ce8cc815f2b24dd10d;hp=06fec448388c747c4afddf0ac5053f408a3b3b5a;hpb=732d0b6c20bf7fca37e092d4d38beb5f8759f334;p=lhc%2Fweb%2Fwiklou.git diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index 06fec44838..19d644c57e 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -36,6 +36,7 @@ class LanguageConverter { * @var array */ static public $languagesWithVariants = [ + 'en', 'gan', 'iu', 'kk', @@ -48,6 +49,10 @@ class LanguageConverter { ]; public $mMainLanguageCode; + + /** + * @var string[] + */ public $mVariants; public $mVariantFallbacks; public $mVariantNames; @@ -56,11 +61,6 @@ class LanguageConverter { // 'bidirectional' 'unidirectional' 'disable' for each variant public $mManualLevel; - /** - * @var string Memcached key name - */ - public $mCacheKey; - public $mLangObj; public $mFlags; public $mDescCodeSep = ':', $mDescVarSep = ';'; @@ -75,11 +75,9 @@ class LanguageConverter { const CACHE_VERSION_KEY = 'VERSION 7'; /** - * Constructor - * * @param Language $langobj * @param string $maincode The main language code of this language - * @param array $variants The supported variants of this language + * @param string[] $variants The supported variants of this language * @param array $variantfallbacks The fallback language of each variant * @param array $flags Defining the custom strings that maps to the flags * @param array $manualLevel Limit for supported variants @@ -93,19 +91,18 @@ class LanguageConverter { $this->mVariants = array_diff( $variants, $wgDisabledVariants ); $this->mVariantFallbacks = $variantfallbacks; $this->mVariantNames = Language::fetchLanguageNames(); - $this->mCacheKey = wfMemcKey( 'conversiontables', $maincode ); $defaultflags = [ // 'S' show converted text // '+' add rules for alltext // 'E' the gave flags is error // these flags above are reserved for program - 'A' => 'A', // add rule for convert code (all text convert) - 'T' => 'T', // title convert - 'R' => 'R', // raw content - 'D' => 'D', // convert description (subclass implement) - '-' => '-', // remove convert (not implement) - 'H' => 'H', // add rule for convert code (but no display in placed code) - 'N' => 'N' // current variant name + 'A' => 'A', // add rule for convert code (all text convert) + 'T' => 'T', // title convert + 'R' => 'R', // raw content + 'D' => 'D', // convert description (subclass implement) + '-' => '-', // remove convert (not implement) + 'H' => 'H', // add rule for convert code (but no display in placed code) + 'N' => 'N', // current variant name ]; $this->mFlags = array_merge( $defaultflags, $flags ); foreach ( $this->mVariants as $v ) { @@ -122,7 +119,7 @@ class LanguageConverter { * Get all valid variants. * Call this instead of using $this->mVariants directly. * - * @return array Contains all valid variants + * @return string[] Contains all valid variants */ public function getVariants() { return $this->mVariants; @@ -357,10 +354,10 @@ class LanguageConverter { } /* we convert everything except: - 1. HTML markups (anything between < and >) - 2. HTML entities - 3. placeholders created by the parser - */ + * 1. HTML markups (anything between < and >) + * 2. HTML entities + * 3. placeholders created by the parser + */ $marker = '|' . Parser::MARKER_PREFIX . '[\-a-zA-Z0-9]+'; // this one is needed when the text is inside an HTML markup @@ -380,6 +377,7 @@ class LanguageConverter { $literalBlob = ''; // Guard against delimiter nulls in the input + // (should never happen: see T159174) $text = str_replace( "\000", '', $text ); $markupMatches = null; @@ -489,7 +487,7 @@ class LanguageConverter { protected function applyManualConv( $convRule ) { // Use syntax -{T|zh-cn:TitleCN; zh-tw:TitleTw}- to custom // title conversion. - // Bug 24072: $mConvRuleTitle was overwritten by other manual + // T26072: $mConvRuleTitle was overwritten by other manual // rule(s) not for title, this breaks the title conversion. $newConvRuleTitle = $convRule->getTitle(); if ( $newConvRuleTitle ) { @@ -844,9 +842,8 @@ class LanguageConverter { * @throws MWException */ function loadDefaultTables() { - $name = get_class( $this ); - - throw new MWException( "Must implement loadDefaultTables() method in class $name" ); + $class = static::class; + throw new MWException( "Must implement loadDefaultTables() method in class $class" ); } /** @@ -864,13 +861,11 @@ class LanguageConverter { $this->mTablesLoaded = true; $this->mTables = false; $cache = ObjectCache::getInstance( $wgLanguageConverterCacheType ); + $cacheKey = $cache->makeKey( 'conversiontables', $this->mMainLanguageCode ); if ( $fromCache ) { - wfProfileIn( __METHOD__ . '-cache' ); - $this->mTables = $cache->get( $this->mCacheKey ); - wfProfileOut( __METHOD__ . '-cache' ); + $this->mTables = $cache->get( $cacheKey ); } if ( !$this->mTables || !array_key_exists( self::CACHE_VERSION_KEY, $this->mTables ) ) { - wfProfileIn( __METHOD__ . '-recache' ); // not in cache, or we need a fresh reload. // We will first load the default tables // then update them using things in MediaWiki:Conversiontable/* @@ -883,8 +878,7 @@ class LanguageConverter { $this->postLoadTables(); $this->mTables[self::CACHE_VERSION_KEY] = true; - $cache->set( $this->mCacheKey, $this->mTables, 43200 ); - wfProfileOut( __METHOD__ . '-recache' ); + $cache->set( $cacheKey, $this->mTables, 43200 ); } } @@ -1085,12 +1079,12 @@ class LanguageConverter { // text should be splited by ";" only if a valid variant // name exist after the markup, for example: // -{zh-hans:xxx;zh-hant:\ - // yyy;}- + // yyy;}- // we should split it as: // [ - // [0] => 'zh-hans:xxx' - // [1] => 'zh-hant:yyy' - // [2] => '' + // [0] => 'zh-hans:xxx' + // [1] => 'zh-hant:yyy' + // [2] => '' // ] $pat = '/;\s*(?='; foreach ( $this->mVariants as $variant ) {