Follow-up to r90265: directionality improvements as part of bug 6100 (under $wgBetterDirectionality):

* Use ParserOptions()->getTargetLanguage() for setting the page language/direction
* Set headings on categories in user language/direction
* Only set language/direction when viewing a page (or editing but only preview and textarea)
This commit is contained in:
Robin Pepermans 2011-06-17 21:48:43 +00:00
parent a392d14dae
commit 0288575c25
4 changed files with 52 additions and 24 deletions

View file

@ -179,6 +179,12 @@ class CategoryViewer {
$r = wfMsgExt( 'category-empty', array( 'parse' ) ); $r = wfMsgExt( 'category-empty', array( 'parse' ) );
} }
global $wgBetterDirectionality, $wgLang;
if( $wgBetterDirectionality ) {
$langAttribs = array( 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() );
$r = Html::rawElement( 'div', $langAttribs, $r );
}
wfProfileOut( __METHOD__ ); wfProfileOut( __METHOD__ );
return $wgContLang->convert( $r ); return $wgContLang->convert( $r );
} }
@ -501,12 +507,21 @@ class CategoryViewer {
*/ */
function formatList( $articles, $articles_start_char, $cutoff = 6 ) { function formatList( $articles, $articles_start_char, $cutoff = 6 ) {
if ( count ( $articles ) > $cutoff ) { if ( count ( $articles ) > $cutoff ) {
return self::columnList( $articles, $articles_start_char ); $list = self::columnList( $articles, $articles_start_char );
} elseif ( count( $articles ) > 0 ) { } elseif ( count( $articles ) > 0 ) {
// for short lists of articles in categories. // for short lists of articles in categories.
return self::shortList( $articles, $articles_start_char ); $list = self::shortList( $articles, $articles_start_char );
} }
return ''; global $wgBetterDirectionality;
if( $wgBetterDirectionality ) {
global $wgOut, $wgContLang;
$getPageLang = $wgOut->parserOptions()->getTargetLanguage();
$pageLang = ( $getPageLang ? Language::factory( $getPageLang ) : $wgContLang );
$realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() );
$list = Html::rawElement( 'div', $realBodyAttribs, $list );
}
return $list;
} }
/** /**

View file

@ -1815,6 +1815,14 @@ HTML
'style' => '' // avoid php notices when appending preferences (appending allows customAttribs['style'] to still work 'style' => '' // avoid php notices when appending preferences (appending allows customAttribs['style'] to still work
); );
global $wgBetterDirectionality, $wgContLang;
if( $wgBetterDirectionality ) {
$getPageLang = $wgOut->parserOptions()->getTargetLanguage( $this->mTitle );
$pageLang = ( $getPageLang ? $getPageLang : $wgContLang );
$attribs['lang'] = $pageLang->getCode();
$attribs['dir'] = $pageLang->getDir();
}
$wgOut->addHTML( Html::textarea( $name, $wikitext, $attribs ) ); $wgOut->addHTML( Html::textarea( $name, $wikitext, $attribs ) );
} }
@ -2058,13 +2066,6 @@ HTML
wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) ); wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
// Parse mediawiki messages with correct target language
if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $this->mTitle->getText() );
$obj = wfGetLangObj( $lang );
$parserOptions->setTargetLanguage( $obj );
}
$parserOptions->setTidy( true ); $parserOptions->setTidy( true );
$parserOptions->enableLimitReport(); $parserOptions->enableLimitReport();
$parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ), $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ),
@ -2091,6 +2092,13 @@ HTML
$wgOut->parse( $note ) . $conflict . "</div>\n"; $wgOut->parse( $note ) . $conflict . "</div>\n";
wfProfileOut( __METHOD__ ); wfProfileOut( __METHOD__ );
global $wgBetterDirectionality, $wgContLang;
if( $wgBetterDirectionality ) {
$getPageLang = $wgOut->parserOptions()->getTargetLanguage( $this->mTitle );
$pageLang = ( $getPageLang ? $getPageLang : $wgContLang );
$realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() );
$previewHTML = Html::rawElement( 'div', $realBodyAttribs, $previewHTML );
}
return $previewhead . $previewHTML . $this->previewTextAfterContent; return $previewhead . $previewHTML . $this->previewTextAfterContent;
} }

View file

@ -455,21 +455,18 @@ class SkinTemplate extends Skin {
$tpl->set( 'printfooter', $this->printSource() ); $tpl->set( 'printfooter', $this->printSource() );
global $wgBetterDirectionality; global $wgBetterDirectionality;
if ( $wgBetterDirectionality && $this->getTitle()->getNamespace() != NS_SPECIAL ) { if ( $wgBetterDirectionality ) {
if( $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) { // not for special pages AND only when viewing AND if the page exists
// If the page is in the MediaWiki NS, the lang and dir attribute should depend on that, // (or is in MW namespace, because that has default content)
// i.e. MediaWiki:Message/ar -> lang=ar, dir=rtl. This assumes every message is translated, if( $this->getTitle()->getNamespace() != NS_SPECIAL &&
// but it's anyway better than assuming it is always in the content lang in_array( $action, array( 'view', 'render', 'print' ) ) &&
$nsMWTitle = $wgContLang->lcfirst( $this->getTitle()->getText() ); ( $this->getTitle()->exists() || $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) ) {
list( $nsMWName, $nsMWLang ) = MessageCache::singleton()->figureMessage( $nsMWTitle ); $getPageLang = $out->parserOptions()->getTargetLanguage( $this->getTitle() );
$nsMWDir = Language::factory( $nsMWLang )->getDir(); $pageLang = ( $getPageLang ? $getPageLang : $wgContLang );
$realBodyAttribs = array( 'lang' => $nsMWLang, 'dir' => $nsMWDir ); $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() );
} else {
// Body text is in the site content language (see also bug 6100 and 28970)
$realBodyAttribs = array( 'lang' => $wgLanguageCode, 'dir' => $wgContLang->getDir() );
}
$out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext ); $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
} }
}
$tpl->setRef( 'bodytext', $out->mBodytext ); $tpl->setRef( 'bodytext', $out->mBodytext );
# Language links # Language links

View file

@ -66,7 +66,15 @@ class ParserOptions {
function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; } function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; }
function getTidy() { return $this->mTidy; } function getTidy() { return $this->mTidy; }
function getInterfaceMessage() { return $this->mInterfaceMessage; } function getInterfaceMessage() { return $this->mInterfaceMessage; }
function getTargetLanguage() { return $this->mTargetLanguage; } function getTargetLanguage( $title = null ) {
// Parse mediawiki messages with correct target language
if ( $title && $title->getNamespace() == NS_MEDIAWIKI ) {
list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $title->getText() );
$obj = wfGetLangObj( $lang );
return $obj;
}
return $this->mTargetLanguage;
}
function getMaxIncludeSize() { return $this->mMaxIncludeSize; } function getMaxIncludeSize() { return $this->mMaxIncludeSize; }
function getMaxPPNodeCount() { return $this->mMaxPPNodeCount; } function getMaxPPNodeCount() { return $this->mMaxPPNodeCount; }
function getMaxPPExpandDepth() { return $this->mMaxPPExpandDepth; } function getMaxPPExpandDepth() { return $this->mMaxPPExpandDepth; }