public function __construct( $langobj, $maincode, $variants = array(),
$variantfallbacks = array(), $flags = array(),
$manualLevel = array() ) {
- global $wgDisabledVariants, $wgLanguageNames;
+ global $wgDisabledVariants;
$this->mLangObj = $langobj;
$this->mMainLanguageCode = $maincode;
$this->mVariants = array_diff( $variants, $wgDisabledVariants );
$this->mVariantFallbacks = $variantfallbacks;
- $this->mVariantNames = $wgLanguageNames;
+ $this->mVariantNames = Language::getLanguageNames();
$this->mCacheKey = wfMemcKey( 'conversiontables', $maincode );
$defaultflags = array(
// 'S' show converted text
if ( !$this->mHeaderVariant ) {
// process fallback languages now
$fallback_languages = array_unique( $fallbackLanguages );
- foreach ( $fallbackLanguages as $language ) {
+ foreach ( $fallback_languages as $language ) {
$this->mHeaderVariant = $this->validateVariant( $language );
if ( $this->mHeaderVariant ) {
break;
}
}
+ if( $this->guessVariant( $text, $toVariant ) ) {
+ return $text;
+ }
+
/* we convert everything except:
1. HTML markups (anything between < and >)
2. HTML entities
*
* @param $text String: the text to be converted
* @return Array: variant => converted text
- * @deprecated Use autoConvertToAllVariants() instead
+ * @deprecated since 1.17 Use autoConvertToAllVariants() instead
*/
public function convertLinkToAllVariants( $text ) {
return $this->autoConvertToAllVariants( $text );
$text = '';
} else {
// first let's check if a message has given us a converted name
- $nsConvKey = 'conversion-ns' . $index;
- if ( !wfEmptyMsg( $nsConvKey ) ) {
- $text = wfMsgForContentNoTrans( $nsConvKey );
+ $nsConvMsg = wfMessage( 'conversion-ns' . $index )->inContentLanguage();
+ if ( $nsConvMsg->exists() ) {
+ $text = $nsConvMsg->plain();
} else {
// the message does not exist, try retrieve it from the current
// variant's namespace names.
*/
public function convertTo( $text, $variant ) {
global $wgDisableLangConversion;
- if ( $wgDisableLangConversion ) {
+ if ( $wgDisableLangConversion || $this->guessVariant( $text, $variant ) ) {
return $text;
}
return $this->recursiveConvertTopLevel( $text, $variant );
return '!' . $variant;
}
+ /**
+ * Guess if a text is written in a variant. This should be implemented in subclasses.
+ *
+ * @param string $text the text to be checked
+ * @param string $variant language code of the variant to be checked for
+ * @return bool true if $text appears to be written in $variant, false if not
+ *
+ * @author Nikola Smolenski <smolensk@eunet.rs>
+ * @since 1.18
+ */
+ public function guessVariant($text, $variant) {
+ return false;
+ }
+
/**
* Load default conversion tables.
* This method must be implemented in derived class.
*/
function loadDefaultTables() {
$name = get_class( $this );
- wfDie( "Must implement loadDefaultTables() method in class $name" );
+ throw new MWException( "Must implement loadDefaultTables() method in class $name" );
}
/**
if ( strpos( $code, '/' ) === false ) {
$txt = MessageCache::singleton()->get( 'Conversiontable', true, $code );
if ( $txt === false ) {
- # FIXME: this method doesn't seem to be expecting
+ # @todo FIXME: This method doesn't seem to be expecting
# this possible outcome...
$txt = '<Conversiontable>';
}