X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=languages%2FLanguageConverter.php;h=e51dca93eebdd77c0437ca26035dec51d60781b9;hb=4df0c71911500466a6330b8fe29c623ef5b51e41;hp=494280cc41e4b93319d0defcc0ceb8117f1c6729;hpb=7ca601fd08e9abf7f36ec13164742e143e8efd3f;p=lhc%2Fweb%2Fwiklou.git diff --git a/languages/LanguageConverter.php b/languages/LanguageConverter.php index 494280cc41..e51dca93ee 100644 --- a/languages/LanguageConverter.php +++ b/languages/LanguageConverter.php @@ -85,7 +85,7 @@ class LanguageConverter { * @param array $flags Defining the custom strings that maps to the flags * @param array $manualLevel Limit for supported variants */ - public function __construct( $langobj, $maincode, $variants = [], + public function __construct( Language $langobj, $maincode, $variants = [], $variantfallbacks = [], $flags = [], $manualLevel = [] ) { global $wgDisabledVariants; @@ -175,13 +175,11 @@ class LanguageConverter { $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; @@ -217,25 +215,9 @@ class LanguageConverter { * @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; } @@ -268,7 +250,7 @@ class LanguageConverter { * @return mixed Variant if one found, null otherwise */ protected function getUserVariant() { - global $wgUser, $wgContLang; + global $wgUser; // memoizing this function wreaks havoc on parserTest.php /* @@ -284,7 +266,10 @@ class LanguageConverter { 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 ); @@ -311,7 +296,7 @@ class LanguageConverter { 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 ) ) { @@ -563,18 +548,17 @@ class LanguageConverter { $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 ); } } } @@ -658,8 +642,12 @@ class LanguageConverter { * -{flags|code1:text1;code2:text2;...}- or * -{text}- in which case no conversion should take place for text * - * @param string $text Text to be converted - * @return string Converted text + * @warning Glossary state is maintained between calls. Never feed this + * method input that hasn't properly been escaped as it may result in + * an XSS in subsequent calls, even if those subsequent calls properly + * escape things. + * @param string $text Text to be converted, already html escaped. + * @return string Converted text (html) */ public function convert( $text ) { $variant = $this->getPreferredVariant(); @@ -669,9 +657,11 @@ class LanguageConverter { /** * Same as convert() except a extra parameter to custom variant. * - * @param string $text Text to be converted + * @param string $text Text to be converted, already html escaped + * @param-taint $text exec_html * @param string $variant The target variant code * @return string Converted text + * @return-taint escaped */ public function convertTo( $text, $variant ) { global $wgDisableLangConversion; @@ -789,7 +779,7 @@ class LanguageConverter { $warningDone = true; } $startPos += 2; - continue; + break; } // Recursively parse another rule $inner .= $this->recursiveConvertRule( $text, $variant, $startPos, $depth + 1 );