From: Robin Pepermans Date: Fri, 17 Jun 2011 21:48:43 +0000 (+0000) Subject: Follow-up to r90265: directionality improvements as part of bug 6100 (under $wgBetter... X-Git-Tag: 1.31.0-rc.0~29454 X-Git-Url: https://git.cyclocoop.org/admin/?a=commitdiff_plain;h=0288575c254d89e262d53087eeabfc3149af85b2;p=lhc%2Fweb%2Fwiklou.git 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) --- diff --git a/includes/CategoryPage.php b/includes/CategoryPage.php index 7ffaec8bf3..4b8ba0301f 100644 --- a/includes/CategoryPage.php +++ b/includes/CategoryPage.php @@ -179,6 +179,12 @@ class CategoryViewer { $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__ ); return $wgContLang->convert( $r ); } @@ -501,12 +507,21 @@ class CategoryViewer { */ function formatList( $articles, $articles_start_char, $cutoff = 6 ) { if ( count ( $articles ) > $cutoff ) { - return self::columnList( $articles, $articles_start_char ); + $list = self::columnList( $articles, $articles_start_char ); } elseif ( count( $articles ) > 0 ) { // 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; } /** diff --git a/includes/EditPage.php b/includes/EditPage.php index 578ebbc00d..e3e2c06d98 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1815,6 +1815,14 @@ HTML '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 ) ); } @@ -2058,13 +2066,6 @@ HTML 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->enableLimitReport(); $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ), @@ -2091,6 +2092,13 @@ HTML $wgOut->parse( $note ) . $conflict . "\n"; 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; } diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index ad309aa7e0..fad14f502f 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -455,20 +455,17 @@ class SkinTemplate extends Skin { $tpl->set( 'printfooter', $this->printSource() ); global $wgBetterDirectionality; - if ( $wgBetterDirectionality && $this->getTitle()->getNamespace() != NS_SPECIAL ) { - if( $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) { - // If the page is in the MediaWiki NS, the lang and dir attribute should depend on that, - // i.e. MediaWiki:Message/ar -> lang=ar, dir=rtl. This assumes every message is translated, - // but it's anyway better than assuming it is always in the content lang - $nsMWTitle = $wgContLang->lcfirst( $this->getTitle()->getText() ); - list( $nsMWName, $nsMWLang ) = MessageCache::singleton()->figureMessage( $nsMWTitle ); - $nsMWDir = Language::factory( $nsMWLang )->getDir(); - $realBodyAttribs = array( 'lang' => $nsMWLang, 'dir' => $nsMWDir ); - } else { - // Body text is in the site content language (see also bug 6100 and 28970) - $realBodyAttribs = array( 'lang' => $wgLanguageCode, 'dir' => $wgContLang->getDir() ); + if ( $wgBetterDirectionality ) { + // not for special pages AND only when viewing AND if the page exists + // (or is in MW namespace, because that has default content) + if( $this->getTitle()->getNamespace() != NS_SPECIAL && + in_array( $action, array( 'view', 'render', 'print' ) ) && + ( $this->getTitle()->exists() || $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) ) { + $getPageLang = $out->parserOptions()->getTargetLanguage( $this->getTitle() ); + $pageLang = ( $getPageLang ? $getPageLang : $wgContLang ); + $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() ); + $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext ); } - $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext ); } $tpl->setRef( 'bodytext', $out->mBodytext ); diff --git a/includes/parser/ParserOptions.php b/includes/parser/ParserOptions.php index 3b9b2d7808..0ce4354684 100644 --- a/includes/parser/ParserOptions.php +++ b/includes/parser/ParserOptions.php @@ -66,7 +66,15 @@ class ParserOptions { function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; } function getTidy() { return $this->mTidy; } 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 getMaxPPNodeCount() { return $this->mMaxPPNodeCount; } function getMaxPPExpandDepth() { return $this->mMaxPPExpandDepth; }