* in this case. Right now this is only used by zh.
*
* @param $variant String: the language code of the variant
- * @return String: The code of the fallback language or the
+ * @return String|array: The code of the fallback language or the
* main code if there is no fallback
*/
public function getVariantFallbacks( $variant ) {
// not memoized (i.e. there return value is not cached) since
// new information might appear during processing after this
// is first called.
- if ( $req ) {
+ if ( $this->validateVariant( $req ) ) {
return $req;
}
return $this->mMainLanguageCode;
* If you want to parse rules, try to use convert() or
* convertTo().
*
- * @param $text String: the text to be converted
- * @param $toVariant String: the target language code
- * @return String: the converted text
+ * @param $text String the text to be converted
+ * @param $toVariant bool|string the target language code
+ * @return String the converted text
*/
public function autoConvert( $text, $toVariant = false ) {
wfProfileIn( __METHOD__ );
}
}
- if( $this->guessVariant( $text, $toVariant ) ) {
- return $text;
- }
-
/* we convert everything except:
1. HTML markups (anything between < and >)
2. HTML entities
$sourceBlob .= substr( $text, $startPos, $elementPos - $startPos ) . "\000";
// Advance to the next position
- $startPos = $elementPos + strlen( $element );
+ $startPos = $elementPos + strlen( $element );
// Translate any alt or title attributes inside the matched element
- if ( $element !== '' && preg_match( '/^(<[^>\s]*)\s([^>]*)(.*)$/', $element,
- $elementMatches ) )
+ if ( $element !== '' && preg_match( '/^(<[^>\s]*)\s([^>]*)(.*)$/', $element,
+ $elementMatches ) )
{
$attrs = Sanitizer::decodeTagAttributes( $elementMatches[2] );
$changed = false;
if ( !strpos( $attr, '://' ) ) {
$attr = $this->translate( $attr, $toVariant );
}
-
+
// Remove HTML tags to avoid disrupting the layout
$attr = preg_replace( '/<[^>]+>/', '', $attr );
if ( $attr !== $attrs[$attrName] ) {
}
}
if ( $changed ) {
- $element = $elementMatches[1] . Html::expandAttributes( $attrs ) .
+ $element = $elementMatches[1] . Html::expandAttributes( $attrs ) .
$elementMatches[3];
}
}
/**
* Apply manual conversion rules.
*
- * @param $convRule Object: Object of ConverterRule
+ * @param $convRule ConverterRule Object of ConverterRule
*/
protected function applyManualConv( $convRule ) {
// Use syntax -{T|zh-cn:TitleCN; zh-tw:TitleTw}- to custom
* Auto convert a Title object to a readable string in the
* preferred variant.
*
- * @param $title Object: a object of Title
+ * @param $title Title a object of Title
* @return String: converted title text
*/
public function convertTitle( $title ) {
$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 || $this->guessVariant( $text, $variant ) ) {
+ if ( $wgDisableLangConversion ) {
return $text;
}
return $this->recursiveConvertTopLevel( $text, $variant );
*
* @param $text String: text to be converted
* @param $variant String: the target variant code
+ * @param $startPos int
* @param $depth Integer: depth of recursion
+ *
* @return String: converted text
*/
protected function recursiveConvertRule( $text, $variant, &$startPos, $depth = 0 ) {
/**
* Returns language specific hash options.
+ *
+ * @return string
*/
public function getExtraHashOptions() {
$variant = $this->getPreferredVariant();
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" );
}
/**
* @param $code String: language code
* @param $subpage String: subpage name
* @param $recursive Boolean: parse subpages recursively? Defaults to true.
+ *
+ * @return array
*/
function parseCachedTable( $code, $subpage = '', $recursive = true ) {
static $parsed = array();
/**
* Convert the sorting key for category links. This should make different
* keys that are variants of each other map to the same key.
+ *
+ * @param $key string
+ *
+ * @return string
*/
function convertCategoryKey( $key ) {
return $key;
* MediaWiki:Conversiontable* is updated.
* @private
*
- * @param $article Object: Article object
+ * @param $article Article object
* @param $user Object: User object for the current user
* @param $text String: article text (?)
* @param $summary String: edit summary of the edit
/**
* @private
+ *
+ * @return string
*/
function getRulesDesc() {
$codesep = $this->mConverter->mDescCodeSep;
/**
* Parse rules conversion.
* @private
+ *
+ * @param $variant
+ *
+ * @return string
*/
function getRuleConvertedStr( $variant ) {
$bidtable = $this->mBidtable;
if ( isset( $this->mVariantFlags[$variant] ) ) {
// then convert <text to convert> to current language
$this->mRules = $this->mConverter->autoConvert( $this->mRules,
- $variant );
+ $variant );
} else { // if current variant no in flags,
// then we check its fallback variants.
$variantFallbacks =
$this->mConverter->getVariantFallbacks( $variant );
- foreach ( $variantFallbacks as $variantFallback ) {
- // if current variant's fallback exist in flags
- if ( isset( $this->mVariantFlags[$variantFallback] ) ) {
- // then convert <text to convert> to fallback language
- $this->mRules =
- $this->mConverter->autoConvert( $this->mRules,
- $variantFallback );
- break;
+ if( is_array( $variantFallbacks ) ) {
+ foreach ( $variantFallbacks as $variantFallback ) {
+ // if current variant's fallback exist in flags
+ if ( isset( $this->mVariantFlags[$variantFallback] ) ) {
+ // then convert <text to convert> to fallback language
+ $this->mRules =
+ $this->mConverter->autoConvert( $this->mRules,
+ $variantFallback );
+ break;
+ }
}
}
}
/**
* Get display text on markup -{...}-
+ * @return string
*/
public function getDisplay() {
return $this->mRuleDisplay;
/**
* Get converted title.
+ * @return string
*/
public function getTitle() {
return $this->mRuleTitle;
/**
* Return how deal with conversion rules.
+ * @return string
*/
public function getRulesAction() {
return $this->mRulesAction;
/**
* Get conversion table. (bidirectional and unidirectional
* conversion table)
+ * @return array
*/
public function getConvTable() {
return $this->mConvTable;
/**
* Get conversion rules string.
+ * @return string
*/
public function getRules() {
return $this->mRules;
/**
* Get conversion flags.
+ * @return array
*/
public function getFlags() {
return $this->mFlags;