Directionality and language improvements as part of bug 6100 (under $wgBetterDirectio...
authorRobin Pepermans <robin@users.mediawiki.org>
Fri, 24 Jun 2011 22:10:39 +0000 (22:10 +0000)
committerRobin Pepermans <robin@users.mediawiki.org>
Fri, 24 Jun 2011 22:10:39 +0000 (22:10 +0000)
* 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
includes/Title.php
includes/parser/Parser.php

index d66795d..ffd6a16 100644 (file)
@@ -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 ) );
index b55a6d8..65f143e 100644 (file)
@@ -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 );
        }
 }
 
index 8d86436..26c54af 100644 (file)
@@ -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;
                                }
                        }