'lang' attrib in #mw-content-text should be set to variant code.
Change-Id: I15cd8c102991c5007b43e06939a0c1a7593d0933
This commit is contained in:
parent
617d0f03c8
commit
da43314022
4 changed files with 104 additions and 5 deletions
|
|
@ -153,7 +153,7 @@ class ImagePage extends Article {
|
|||
if ( $this->mPage->getID() ) {
|
||||
# NS_FILE is in the user language, but this section (the actual wikitext)
|
||||
# should be in page content language
|
||||
$pageLang = $this->getTitle()->getPageLanguage();
|
||||
$pageLang = $this->getTitle()->getPageViewLanguage();
|
||||
$out->addHTML( Xml::openElement( 'div', array( 'id' => 'mw-imagepage-content',
|
||||
'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
|
||||
'class' => 'mw-content-'.$pageLang->getDir() ) ) );
|
||||
|
|
|
|||
|
|
@ -407,7 +407,7 @@ class SkinTemplate extends Skin {
|
|||
if ( !in_array( $title->getNamespace(), array( NS_SPECIAL, NS_FILE ) ) &&
|
||||
in_array( $request->getVal( 'action', 'view' ), array( 'view', 'historysubmit' ) ) &&
|
||||
( $title->exists() || $title->getNamespace() == NS_MEDIAWIKI ) ) {
|
||||
$pageLang = $title->getPageLanguage();
|
||||
$pageLang = $title->getPageViewLanguage();
|
||||
$realBodyAttribs['lang'] = $pageLang->getHtmlCode();
|
||||
$realBodyAttribs['dir'] = $pageLang->getDir();
|
||||
$realBodyAttribs['class'] = 'mw-content-'.$pageLang->getDir();
|
||||
|
|
|
|||
|
|
@ -4494,9 +4494,9 @@ class Title {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the language in which the content of this page is written.
|
||||
* Defaults to $wgContLang, but in certain cases it can be e.g.
|
||||
* $wgLang (such as special pages, which are in the user language).
|
||||
* Get the language in which the content of this page is written in
|
||||
* wikitext. Defaults to $wgContLang, but in certain cases it can be
|
||||
* e.g. $wgLang (such as special pages, which are in the user language).
|
||||
*
|
||||
* @since 1.18
|
||||
* @return Language
|
||||
|
|
@ -4521,4 +4521,29 @@ class Title {
|
|||
wfRunHooks( 'PageContentLanguage', array( $this, &$pageLang, $wgLang ) );
|
||||
return wfGetLangObj( $pageLang );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the language in which the content of this page is written when
|
||||
* viewed by user. Defaults to $wgContLang, but in certain cases it can be
|
||||
* e.g. $wgLang (such as special pages, which are in the user language).
|
||||
*
|
||||
* @since 1.20
|
||||
* @return Language
|
||||
*/
|
||||
public function getPageViewLanguage() {
|
||||
$pageLang = $this->getPageLanguage();
|
||||
// If this is nothing special (so the content is converted when viewed)
|
||||
if ( !$this->isSpecialPage()
|
||||
&& !$this->isCssOrJsPage() && !$this->isCssJsSubpage()
|
||||
&& $this->getNamespace() !== NS_MEDIAWIKI
|
||||
) {
|
||||
// If the user chooses a variant, the content is actually
|
||||
// in a language whose code is the variant code.
|
||||
$variant = $pageLang->getPreferredVariant();
|
||||
if ( $pageLang->getCode() !== $variant ) {
|
||||
$pageLang = Language::factory( $variant );
|
||||
}
|
||||
}
|
||||
return $pageLang;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,4 +77,78 @@ class TitleTest extends MediaWikiTestCase {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider provideCasesForGetpageviewlanguage
|
||||
*/
|
||||
function testGetpageviewlanguage( $expected, $titleText, $contLang, $lang, $variant, $msg='' ) {
|
||||
// Save globals
|
||||
global $wgContLang, $wgLang, $wgAllowUserJs, $wgLanguageCode, $wgDefaultLanguageVariant;
|
||||
$save['wgContLang'] = $wgContLang;
|
||||
$save['wgLang'] = $wgLang;
|
||||
$save['wgAllowUserJs'] = $wgAllowUserJs;
|
||||
$save['wgLanguageCode'] = $wgLanguageCode;
|
||||
$save['wgDefaultLanguageVariant'] = $wgDefaultLanguageVariant;
|
||||
|
||||
// Setup test environnement:
|
||||
$wgContLang = Language::factory( $contLang );
|
||||
$wgLang = Language::factory( $lang );
|
||||
# To test out .js titles:
|
||||
$wgAllowUserJs = true;
|
||||
$wgLanguageCode = $contLang;
|
||||
$wgDefaultLanguageVariant = $variant;
|
||||
|
||||
$title = Title::newFromText( $titleText );
|
||||
$this->assertInstanceOf( 'Title', $title,
|
||||
"Test must be passed a valid title text, you gave '$titleText'"
|
||||
);
|
||||
$this->assertEquals( $expected,
|
||||
$title->getPageViewLanguage()->getCode(),
|
||||
$msg
|
||||
);
|
||||
|
||||
// Restore globals
|
||||
$wgContLang = $save['wgContLang'];
|
||||
$wgLang = $save['wgLang'];
|
||||
$wgAllowUserJs = $save['wgAllowUserJs'];
|
||||
$wgLanguageCode = $save['wgLanguageCode'];
|
||||
$wgDefaultLanguageVariant = $save['wgDefaultLanguageVariant'];
|
||||
}
|
||||
|
||||
function provideCasesForGetpageviewlanguage() {
|
||||
# Format:
|
||||
# - expected
|
||||
# - Title name
|
||||
# - wgContLang (expected in most case)
|
||||
# - wgLang (on some specific pages)
|
||||
# - wgDefaultLanguageVariant
|
||||
# - Optional message
|
||||
return array(
|
||||
array( 'fr', 'Main_page', 'fr', 'fr', false ),
|
||||
array( 'es', 'Main_page', 'es', 'zh-tw', false ),
|
||||
array( 'zh', 'Main_page', 'zh', 'zh-tw', false ),
|
||||
|
||||
array( 'es', 'Main_page', 'es', 'zh-tw', 'zh-cn' ),
|
||||
array( 'es', 'MediaWiki:About', 'es', 'zh-tw', 'zh-cn' ),
|
||||
array( 'es', 'MediaWiki:About/', 'es', 'zh-tw', 'zh-cn' ),
|
||||
array( 'de', 'MediaWiki:About/de', 'es', 'zh-tw', 'zh-cn' ),
|
||||
array( 'en', 'MediaWiki:Common.js', 'es', 'zh-tw', 'zh-cn' ),
|
||||
array( 'en', 'MediaWiki:Common.css', 'es', 'zh-tw', 'zh-cn' ),
|
||||
array( 'en', 'User:JohnDoe/Common.js', 'es', 'zh-tw', 'zh-cn' ),
|
||||
array( 'en', 'User:JohnDoe/Monobook.css', 'es', 'zh-tw', 'zh-cn' ),
|
||||
|
||||
array( 'zh-cn', 'Main_page', 'zh', 'zh-tw', 'zh-cn' ),
|
||||
array( 'zh', 'MediaWiki:About', 'zh', 'zh-tw', 'zh-cn' ),
|
||||
array( 'de', 'MediaWiki:About/de', 'zh', 'zh-tw', 'zh-cn' ),
|
||||
array( 'zh-cn', 'MediaWiki:About/zh-cn', 'zh', 'zh-tw', 'zh-cn' ),
|
||||
array( 'zh-tw', 'MediaWiki:About/zh-tw', 'zh', 'zh-tw', 'zh-cn' ),
|
||||
array( 'en', 'MediaWiki:Common.js', 'zh', 'zh-tw', 'zh-cn' ),
|
||||
array( 'en', 'MediaWiki:Common.css', 'zh', 'zh-tw', 'zh-cn' ),
|
||||
array( 'en', 'User:JohnDoe/Common.js', 'zh', 'zh-tw', 'zh-cn' ),
|
||||
array( 'en', 'User:JohnDoe/Monobook.css', 'zh', 'zh-tw', 'zh-cn' ),
|
||||
|
||||
array( 'zh-tw', 'Special:NewPages', 'es', 'zh-tw', 'zh-cn' ),
|
||||
array( 'zh-tw', 'Special:NewPages', 'zh', 'zh-tw', 'zh-cn' ),
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue