r90742 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90741‎ | r90742 | r90743 >
Date:22:10, 24 June 2011
Author:robin
Status:resolved (Comments)
Tags:
Comment:
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).
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Parser.php
@@ -4012,7 +4012,10 @@
40134013 if ( $dot ) {
40144014 $numbering .= '.';
40154015 }
4016 - $numbering .= $wgContLang->formatNum( $sublevelCount[$i] );
 4016+ global $wgBetterDirectionality;
 4017+ $pagelang = $this->mTitle->getPageLanguage();
 4018+ $toclang = ( $wgBetterDirectionality ? $pagelang : $wgContLang );
 4019+ $numbering .= $toclang->formatNum( $sublevelCount[$i] );
40174020 $dot = 1;
40184021 }
40194022 }
Index: trunk/phase3/includes/Title.php
@@ -4223,23 +4223,34 @@
42244224 }
42254225
42264226 /**
4227 - * Get the language this page is written in
4228 - * Defaults to $wgContLang
 4227+ * Get the language in which the content of this page is written.
 4228+ * Defaults to $wgContLang, but in certain cases it can be e.g.
 4229+ * $wgLang (such as special pages, which are in the user language).
42294230 *
42304231 * @return object Language
42314232 */
42324233 public function getPageLanguage() {
4233 - global $wgContLang;
4234 - $pageLang = $wgContLang;
4235 - if ( $this->isCssOrJsPage() ) {
 4234+ global $wgLang;
 4235+ if ( $this->getNamespace() == NS_SPECIAL ) {
 4236+ // special pages are in the user language
 4237+ return $wgLang;
 4238+ } elseif ( $this->isRedirect() ) {
 4239+ // the arrow on a redirect page is aligned according to the user language
 4240+ return $wgLang;
 4241+ } elseif ( $this->isCssOrJsPage() ) {
42364242 // css/js should always be LTR and is, in fact, English
4237 - $pageLang = wfGetLangObj( 'en' );
 4243+ return wfGetLangObj( 'en' );
42384244 } elseif ( $this->getNamespace() == NS_MEDIAWIKI ) {
42394245 // Parse mediawiki messages with correct target language
42404246 list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $this->getText() );
4241 - $pageLang = wfGetLangObj( $lang );
 4247+ return wfGetLangObj( $lang );
42424248 }
4243 - return $pageLang;
 4249+ global $wgContLang;
 4250+ // If nothing special, it should be in the wiki content language
 4251+ $pageLang = $wgContLang;
 4252+ // Hook at the end because we don't want to override the above stuff
 4253+ wfRunHooks( 'PageContentLanguage', array( $this, &$pageLang, $wgLang ) );
 4254+ return wfGetLangObj( $pageLang );
42444255 }
42454256 }
42464257
Index: trunk/phase3/includes/Article.php
@@ -1624,13 +1624,13 @@
16251625 * @return string containing HMTL with redirect link
16261626 */
16271627 public function viewRedirect( $target, $appendSubtitle = true, $forceKnown = false ) {
1628 - global $wgOut, $wgContLang, $wgStylePath;
 1628+ global $wgOut, $wgStylePath;
16291629
16301630 if ( !is_array( $target ) ) {
16311631 $target = array( $target );
16321632 }
16331633
1634 - $imageDir = $wgContLang->getDir();
 1634+ $imageDir = wfUILang()->getDir();
16351635
16361636 if ( $appendSubtitle ) {
16371637 $wgOut->appendSubtitle( wfMsgHtml( 'redirectpagesub' ) );
@@ -1646,7 +1646,7 @@
16471647 }
16481648
16491649 $nextRedirect = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
1650 - $alt = $wgContLang->isRTL() ? '←' : '→';
 1650+ $alt = wfUILang()->isRTL() ? '←' : '→';
16511651 // Automatically append redirect=no to each link, since most of them are redirect pages themselves.
16521652 foreach ( $target as $rt ) {
16531653 $link .= Html::element( 'img', array( 'src' => $nextRedirect, 'alt' => $alt ) );

Follow-up revisions

RevisionCommit summaryAuthorDate
r90743Directionality improvements as part of bug 6100 (under $wgBetterDirectionality):...robin23:01, 24 June 2011
r90925Follow-up r90742: the parser should call getFunctionLang()robin23:58, 27 June 2011
r91315* Add release notes for my recent commits (bug 6100 and others like bugs 2803...robin22:50, 1 July 2011
r91518(bug 6100; follow-up to r91315) Being bold and removing $wgBetterDirectionali...robin02:26, 6 July 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r14495* (bug 6100) BiDi: different directionality for user interface and wiki conte...nikerabbit15:19, 31 May 2006
r44000(bug 6100) Strip Unicode BiDi embedding/override characters (U+202A - U+202E)...vyznev20:11, 27 November 2008
r60786Make LTR wgLang do the right thing on RTL wgContLang wikis. See bug 6100 and...mah09:32, 7 January 2010
r90264(part of bug 6100) Set the directionality based on user language instead of c...robin11:32, 17 June 2011
r90320Follow-up to r90265: directionality improvements as part of bug 6100 (under $...robin21:48, 17 June 2011
r90334Follow-up to r90265: directionality improvements as part of bug 6100 (under $...robin13:12, 18 June 2011
r90517* Improvements as part of bug 6100: Use wfUILang() instead of $wgContLang whe...robin10:14, 21 June 2011
r90581Directionality improvements as part of bug 6100 (under $wgBetterDirectionalit...robin13:10, 22 June 2011
r90734(bug 12406) Pages with names in RTL scripts are not listed correctly in Speci...robin20:25, 24 June 2011

Comments

#Comment by Platonides (talk | contribs)   22:58, 27 June 2011

The parser shouldn't call mTitle->getPageLanguage(); Use of Parser->getFunctionLang (that you changed in r90858) seems a better option.

#Comment by SPQRobin (talk | contribs)   00:00, 28 June 2011

Agreed. Done in r90925 (and removed $wgBetterDirectionality check because it's not really needed).

#Comment by Aaron Schulz (talk | contribs)   23:03, 9 August 2011

PageContentLanguage is not in hooks.txt.

#Comment by SPQRobin (talk | contribs)   15:21, 11 August 2011

Added in r94248 & r94250.

Status & tagging log