$req = $this->validateVariant( $wgDefaultLanguageVariant );
}
- $req = $this->validateVariant( $req );
-
// This function, unlike the other get*Variant functions, is
// 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;
* @return mixed Returns the variant if it is valid, null otherwise
*/
public function validateVariant( $variant = null ) {
- if ( $variant === null ) {
- return null;
- }
- // Our internal variants are always lower-case; the variant we
- // are validating may have mixed case.
- $variant = LanguageCode::replaceDeprecatedCodes( strtolower( $variant ) );
- if ( in_array( $variant, $this->mVariants ) ) {
+ if ( $variant !== null && in_array( $variant, $this->mVariants ) ) {
return $variant;
}
- // Browsers are supposed to use BCP 47 standard in the
- // Accept-Language header, but not all of our internal
- // mediawiki variant codes are BCP 47. Map BCP 47 code
- // to our internal code.
- foreach ( $this->mVariants as $v ) {
- // Case-insensitive match (BCP 47 is mixed case)
- if ( strtolower( LanguageCode::bcp47( $v ) ) === $variant ) {
- return $v;
- }
- }
return null;
}
* @return mixed Variant if one found, null otherwise
*/
protected function getUserVariant() {
- global $wgUser, $wgContLang;
+ global $wgUser;
// memoizing this function wreaks havoc on parserTest.php
/*
return false;
}
if ( $wgUser->isLoggedIn() ) {
- if ( $this->mMainLanguageCode == $wgContLang->getCode() ) {
+ if (
+ $this->mMainLanguageCode ==
+ MediaWikiServices::getInstance()->getContentLanguage()->getCode()
+ ) {
$ret = $wgUser->getOption( 'variant' );
} else {
$ret = $wgUser->getOption( 'variant-' . $this->mMainLanguageCode );
return $this->mHeaderVariant;
}
- // See if some supported language variant is set in the
+ // see if some supported language variant is set in the
// HTTP header.
$languages = array_keys( $wgRequest->getAcceptLang() );
if ( empty( $languages ) ) {
$convTable = $convRule->getConvTable();
$action = $convRule->getRulesAction();
foreach ( $convTable as $variant => $pair ) {
- $v = $this->validateVariant( $variant );
- if ( !$v ) {
+ if ( !$this->validateVariant( $variant ) ) {
continue;
}
if ( $action == 'add' ) {
// More efficient than array_merge(), about 2.5 times.
foreach ( $pair as $from => $to ) {
- $this->mTables[$v]->setPair( $from, $to );
+ $this->mTables[$variant]->setPair( $from, $to );
}
} elseif ( $action == 'remove' ) {
- $this->mTables[$v]->removeArray( $pair );
+ $this->mTables[$variant]->removeArray( $pair );
}
}
}