* @maintainers fdcn <fdcn64@gmail.com>, shinjiman <shinjiman@gmail.com>, PhiLiP <philip.npc@gmail.com>
*/
class LanguageConverter {
+
+ /**
+ * languages supporting variants
+ * @since 1.20
+ * @var array
+ */
+ static public $languagesWithVariants = array(
+ 'gan',
+ 'iu',
+ 'kk',
+ 'ku',
+ 'shi',
+ 'sr',
+ 'tg',
+ 'uz',
+ 'zh',
+ );
+
var $mMainLanguageCode;
var $mVariants, $mVariantFallbacks, $mVariantNames;
var $mTablesLoaded = false;
*/
public function convertTo( $text, $variant ) {
global $wgDisableLangConversion;
- if ( $wgDisableLangConversion || $this->guessVariant( $text, $variant ) ) {
+ if ( $wgDisableLangConversion ) {
return $text;
}
return $this->recursiveConvertTopLevel( $text, $variant );
$startPos = 0;
$out = '';
$length = strlen( $text );
+ $shouldConvert = !$this->guessVariant( $text, $variant );
+
while ( $startPos < $length ) {
$pos = strpos( $text, '-{', $startPos );
if ( $pos === false ) {
// No more markup, append final segment
- $out .= $this->autoConvert( substr( $text, $startPos ), $variant );
+ $fragment = substr( $text, $startPos );
+ $out .= $shouldConvert? $this->autoConvert( $fragment, $variant ): $fragment;
return $out;
}
// Markup found
// Append initial segment
- $out .= $this->autoConvert( substr( $text, $startPos, $pos - $startPos ), $variant );
+ $fragment = substr( $text, $startPos, $pos - $startPos );
+ $out .= $shouldConvert? $this->autoConvert( $fragment, $variant ): $fragment;
// Advance position
$startPos = $pos;
$inner .= '-{';
if ( !$warningDone ) {
$inner .= '<span class="error">' .
- wfMsgForContent( 'language-converter-depth-warning',
- $this->mMaxDepth ) .
+ wfMessage( 'language-converter-depth-warning' )
+ ->numParams( $this->mMaxDepth )->inContentLanguage()->text() .
'</span>';
$warningDone = true;
}
* @param $fromCache Boolean: load from memcached? Defaults to true.
*/
function loadTables( $fromCache = true ) {
+ global $wgLangConvMemc;
+
if ( $this->mTablesLoaded ) {
return;
}
$this->mTables = false;
if ( $fromCache ) {
wfProfileIn( __METHOD__ . '-cache' );
- $this->mTables = $this->cacheFetch( $this->mCacheKey );
+ $this->mTables = $wgLangConvMemc->get( $this->mCacheKey );
wfProfileOut( __METHOD__ . '-cache' );
}
if ( !$this->mTables
$this->postLoadTables();
$this->mTables[self::CACHE_VERSION_KEY] = true;
- $this->cacheStore( $this->mCacheKey, $this->mTables, 43200 );
+ $wgLangConvMemc->set( $this->mCacheKey, $this->mTables, 43200 );
wfProfileOut( __METHOD__ . '-recache' );
}
wfProfileOut( __METHOD__ );
}
- /**
- * Read an object from the cache
- * @param $key string
- * @return mixed
- */
- protected function cacheFetch( $key ) {
- global $wgLanguageConverterCacheType, $wgMemc;
-
- if ( $wgLanguageConverterCacheType === 'apc' ) {
- return apc_fetch( $key );
- } elseif ( $wgLanguageConverterCacheType === 'main' ) {
- return $wgMemc->get( $key );
- }
-
- return false; // disabled
- }
-
- /**
- * Store an object into the cache
- * @param $key string
- * @param $val mixed
- * @param $ttl integer Seconds to live
- * @return bool Success
- */
- protected function cacheStore( $key, $val, $ttl ) {
- global $wgLanguageConverterCacheType, $wgMemc;
-
- if ( $wgLanguageConverterCacheType === 'apc' ) {
- return apc_store( $key, $val, $ttl );
- } elseif ( $wgLanguageConverterCacheType === 'main' ) {
- return $wgMemc->set( $key, $val, $ttl );
- }
-
- return true; // disabled
- }
-
/**
* Hook for post processing after conversion tables are loaded.
*/
class ConverterRule {
var $mText; // original text in -{text}-
var $mConverter; // LanguageConverter object
- var $mManualCodeError = '<strong class="error">code error!</strong>';
var $mRuleDisplay = '';
var $mRuleTitle = false;
var $mRules = '';// string : the text of the rules
}
}
if ( $this->mRuleDisplay === false ) {
- $this->mRuleDisplay = $this->mManualCodeError;
+ $this->mRuleDisplay = '<span class="error">'
+ . wfMessage( 'converter-manual-rule-error' )->inContentLanguage()->escaped()
+ . '</span>';
}
$this->generateConvTable();