* @return Mixed: variant if one found, false otherwise.
*/
protected function getUserVariant() {
- global $wgUser;
+ global $wgUser, $wgContLang;
// memoizing this function wreaks havoc on parserTest.php
/*
// Don't call this on stub objects because that causes infinite
// recursion during initialisation
if ( $wgUser->isLoggedIn() ) {
- $ret = $wgUser->getOption( 'variant' );
+ if ( $this->mMainLanguageCode == $wgContLang->getCode() ) {
+ $ret = $wgUser->getOption( 'variant' );
+ } else {
+ $ret = $wgUser->getOption( 'variant-' . $this->mMainLanguageCode );
+ }
} else {
// figure out user lang without constructing wgLang to avoid
// infinite recursion
// this one is needed when the text is inside an HTML markup
$htmlfix = '|<[^>]+$|^[^<>]*>';
- // disable convert to variants between <code></code> tags
+ // disable convert to variants between <code> tags
$codefix = '<code>.+?<\/code>|';
- // disable convertsion of <script type="text/javascript"> ... </script>
+ // disable conversion of <script> tags
$scriptfix = '<script.*?>.*?<\/script>|';
- // disable conversion of <pre xxxx> ... </pre>
+ // disable conversion of <pre> tags
$prefix = '<pre.*?>.*?<\/pre>|';
$reg = '/' . $codefix . $scriptfix . $prefix .
$variant = $this->getPreferredVariant();
$index = $title->getNamespace();
if ( $index !== NS_MAIN ) {
- $text = $this->convertNamespace( $index ) . ':';
+ $text = $this->convertNamespace( $index, $variant ) . ':';
} else {
$text = '';
}
* Get the namespace display name in the preferred variant.
*
* @param $index int namespace id
+ * @param $variant string|null variant code or null for preferred variant
* @return String: namespace name for display
*/
- public function convertNamespace( $index ) {
- $variant = $this->getPreferredVariant();
+ public function convertNamespace( $index, $variant = null ) {
+ if ( $variant === null ) {
+ $variant = $this->getPreferredVariant();
+ }
if ( $index === NS_MAIN ) {
return '';
} else {
$txt = $revision->getContent( Revision::RAW )->getNativeData();
}
- //@todo: in the future, use a specialized content model, perhaps based on json!
+ // @todo in the future, use a specialized content model, perhaps based on json!
}
}
}
* and may return false in this case (so this title conversion rule
* will be ignored and the original title is shown).
*
- * @since 1.21
+ * @since 1.22
* @param $variant The variant code to display page title in
* @return String|false The converted title or false if just page name
*/