From 9f9047290f4d10995a8daa2ef44a7869fa591219 Mon Sep 17 00:00:00 2001 From: Robin Pepermans Date: Fri, 24 Jun 2011 22:10:39 +0000 Subject: [PATCH] Directionality and language improvements as part of bug 6100 (under $wgBetterDirectionality): * Make TOC numberings be in the page content language instead of wiki content language. * Update getPageLanguage() and add a hook (for bug 9360/28970). * Show redirects (when viewing a page with &redirect=no) in the user language direction (not essential but nicer imo). --- includes/Article.php | 6 +++--- includes/Title.php | 27 +++++++++++++++++++-------- includes/parser/Parser.php | 5 ++++- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index d66795dcba..ffd6a16f7f 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1624,13 +1624,13 @@ class Article { * @return string containing HMTL with redirect link */ public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) { - global $wgOut, $wgContLang, $wgStylePath; + global $wgOut, $wgStylePath; if ( !is_array( $target ) ) { $target = array( $target ); } - $imageDir = $wgContLang->getDir(); + $imageDir = wfUILang()->getDir(); if ( $appendSubtitle ) { $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) ); @@ -1646,7 +1646,7 @@ class Article { } $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png'; - $alt = $wgContLang->isRTL() ? '←' : '→'; + $alt = wfUILang()->isRTL() ? '←' : '→'; // Automatically append redirect=no to each link, since most of them are redirect pages themselves. foreach ( $target as $rt ) { $link .= Html::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) ); diff --git a/includes/Title.php b/includes/Title.php index b55a6d8954..65f143e470 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -4223,23 +4223,34 @@ class Title { } /** - * Get the language this page is written in - * Defaults to $wgContLang + * 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). * * @return object Language */ public function getPageLanguage() { - global $wgContLang; - $pageLang = $wgContLang; - if ( $this->isCssOrJsPage() ) { + global $wgLang; + if ( $this->getNamespace() == NS_SPECIAL ) { + // special pages are in the user language + return $wgLang; + } elseif ( $this->isRedirect() ) { + // the arrow on a redirect page is aligned according to the user language + return $wgLang; + } elseif ( $this->isCssOrJsPage() ) { // css/js should always be LTR and is, in fact, English - $pageLang = wfGetLangObj( 'en' ); + return wfGetLangObj( 'en' ); } elseif ( $this->getNamespace() == NS_MEDIAWIKI ) { // Parse mediawiki messages with correct target language list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $this->getText() ); - $pageLang = wfGetLangObj( $lang ); + return wfGetLangObj( $lang ); } - return $pageLang; + global $wgContLang; + // If nothing special, it should be in the wiki content language + $pageLang = $wgContLang; + // Hook at the end because we don't want to override the above stuff + wfRunHooks( 'PageContentLanguage', array( $this, &$pageLang, $wgLang ) ); + return wfGetLangObj( $pageLang ); } } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 8d86436102..26c54af4fe 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4012,7 +4012,10 @@ class Parser { if ( $dot ) { $numbering .= '.'; } - $numbering .= $wgContLang->formatNum( $sublevelCount[$i] ); + global $wgBetterDirectionality; + $pagelang = $this->mTitle->getPageLanguage(); + $toclang = ( $wgBetterDirectionality ? $pagelang : $wgContLang ); + $numbering .= $toclang->formatNum( $sublevelCount[$i] ); $dot = 1; } } -- 2.20.1