r90320 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90319‎ | r90320 | r90321 >
Date:21:48, 17 June 2011
Author:robin
Status:resolved (Comments)
Tags:
Comment:
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)
Modified paths:
  • /trunk/phase3/includes/CategoryPage.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/parser/ParserOptions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/CategoryPage.php
@@ -179,6 +179,12 @@
180180 $r = wfMsgExt( 'category-empty', array( 'parse' ) );
181181 }
182182
 183+ global $wgBetterDirectionality, $wgLang;
 184+ if( $wgBetterDirectionality ) {
 185+ $langAttribs = array( 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir() );
 186+ $r = Html::rawElement( 'div', $langAttribs, $r );
 187+ }
 188+
183189 wfProfileOut( __METHOD__ );
184190 return $wgContLang->convert( $r );
185191 }
@@ -501,12 +507,21 @@
502508 */
503509 function formatList( $articles, $articles_start_char, $cutoff = 6 ) {
504510 if ( count ( $articles ) > $cutoff ) {
505 - return self::columnList( $articles, $articles_start_char );
 511+ $list = self::columnList( $articles, $articles_start_char );
506512 } elseif ( count( $articles ) > 0 ) {
507513 // for short lists of articles in categories.
508 - return self::shortList( $articles, $articles_start_char );
 514+ $list = self::shortList( $articles, $articles_start_char );
509515 }
510 - return '';
 516+ global $wgBetterDirectionality;
 517+ if( $wgBetterDirectionality ) {
 518+ global $wgOut, $wgContLang;
 519+ $getPageLang = $wgOut->parserOptions()->getTargetLanguage();
 520+ $pageLang = ( $getPageLang ? Language::factory( $getPageLang ) : $wgContLang );
 521+ $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() );
 522+ $list = Html::rawElement( 'div', $realBodyAttribs, $list );
 523+ }
 524+
 525+ return $list;
511526 }
512527
513528 /**
Index: trunk/phase3/includes/parser/ParserOptions.php
@@ -66,7 +66,15 @@
6767 function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; }
6868 function getTidy() { return $this->mTidy; }
6969 function getInterfaceMessage() { return $this->mInterfaceMessage; }
70 - function getTargetLanguage() { return $this->mTargetLanguage; }
 70+ function getTargetLanguage( $title = null ) {
 71+ // Parse mediawiki messages with correct target language
 72+ if ( $title && $title->getNamespace() == NS_MEDIAWIKI ) {
 73+ list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $title->getText() );
 74+ $obj = wfGetLangObj( $lang );
 75+ return $obj;
 76+ }
 77+ return $this->mTargetLanguage;
 78+}
7179 function getMaxIncludeSize() { return $this->mMaxIncludeSize; }
7280 function getMaxPPNodeCount() { return $this->mMaxPPNodeCount; }
7381 function getMaxPPExpandDepth() { return $this->mMaxPPExpandDepth; }
Index: trunk/phase3/includes/EditPage.php
@@ -1815,6 +1815,14 @@
18161816 'style' => '' // avoid php notices when appending preferences (appending allows customAttribs['style'] to still work
18171817 );
18181818
 1819+ global $wgBetterDirectionality, $wgContLang;
 1820+ if( $wgBetterDirectionality ) {
 1821+ $getPageLang = $wgOut->parserOptions()->getTargetLanguage( $this->mTitle );
 1822+ $pageLang = ( $getPageLang ? $getPageLang : $wgContLang );
 1823+ $attribs['lang'] = $pageLang->getCode();
 1824+ $attribs['dir'] = $pageLang->getDir();
 1825+ }
 1826+
18191827 $wgOut->addHTML( Html::textarea( $name, $wikitext, $attribs ) );
18201828 }
18211829
@@ -2058,13 +2066,6 @@
20592067
20602068 wfRunHooks( 'EditPageGetPreviewText', array( $this, &$toparse ) );
20612069
2062 - // Parse mediawiki messages with correct target language
2063 - if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
2064 - list( /* $unused */, $lang ) = MessageCache::singleton()->figureMessage( $this->mTitle->getText() );
2065 - $obj = wfGetLangObj( $lang );
2066 - $parserOptions->setTargetLanguage( $obj );
2067 - }
2068 -
20692070 $parserOptions->setTidy( true );
20702071 $parserOptions->enableLimitReport();
20712072 $parserOutput = $wgParser->parse( $this->mArticle->preSaveTransform( $toparse ),
@@ -2091,6 +2092,13 @@
20922093 $wgOut->parse( $note ) . $conflict . "</div>\n";
20932094
20942095 wfProfileOut( __METHOD__ );
 2096+ global $wgBetterDirectionality, $wgContLang;
 2097+ if( $wgBetterDirectionality ) {
 2098+ $getPageLang = $wgOut->parserOptions()->getTargetLanguage( $this->mTitle );
 2099+ $pageLang = ( $getPageLang ? $getPageLang : $wgContLang );
 2100+ $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() );
 2101+ $previewHTML = Html::rawElement( 'div', $realBodyAttribs, $previewHTML );
 2102+ }
20952103 return $previewhead . $previewHTML . $this->previewTextAfterContent;
20962104 }
20972105
Index: trunk/phase3/includes/SkinTemplate.php
@@ -455,20 +455,17 @@
456456 $tpl->set( 'printfooter', $this->printSource() );
457457
458458 global $wgBetterDirectionality;
459 - if ( $wgBetterDirectionality && $this->getTitle()->getNamespace() != NS_SPECIAL ) {
460 - if( $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) {
461 - // If the page is in the MediaWiki NS, the lang and dir attribute should depend on that,
462 - // i.e. MediaWiki:Message/ar -> lang=ar, dir=rtl. This assumes every message is translated,
463 - // but it's anyway better than assuming it is always in the content lang
464 - $nsMWTitle = $wgContLang->lcfirst( $this->getTitle()->getText() );
465 - list( $nsMWName, $nsMWLang ) = MessageCache::singleton()->figureMessage( $nsMWTitle );
466 - $nsMWDir = Language::factory( $nsMWLang )->getDir();
467 - $realBodyAttribs = array( 'lang' => $nsMWLang, 'dir' => $nsMWDir );
468 - } else {
469 - // Body text is in the site content language (see also bug 6100 and 28970)
470 - $realBodyAttribs = array( 'lang' => $wgLanguageCode, 'dir' => $wgContLang->getDir() );
 459+ if ( $wgBetterDirectionality ) {
 460+ // not for special pages AND only when viewing AND if the page exists
 461+ // (or is in MW namespace, because that has default content)
 462+ if( $this->getTitle()->getNamespace() != NS_SPECIAL &&
 463+ in_array( $action, array( 'view', 'render', 'print' ) ) &&
 464+ ( $this->getTitle()->exists() || $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) ) {
 465+ $getPageLang = $out->parserOptions()->getTargetLanguage( $this->getTitle() );
 466+ $pageLang = ( $getPageLang ? $getPageLang : $wgContLang );
 467+ $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir() );
 468+ $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
471469 }
472 - $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
473470 }
474471 $tpl->setRef( 'bodytext', $out->mBodytext );
475472

Follow-up revisions

RevisionCommit summaryAuthorDate
r90334Follow-up to r90265: directionality improvements as part of bug 6100 (under $...robin13:12, 18 June 2011
r90335Follow up r90320. The purpose of wfProfileIn/Out is to profile...platonides14:01, 18 June 2011
r90337Address comment by Platonides on r90320:...robin14:49, 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
r90742Directionality and language improvements as part of bug 6100 (under $wgBetter...robin22:10, 24 June 2011
r90743Directionality improvements as part of bug 6100 (under $wgBetterDirectionality):...robin23:01, 24 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
r90265Improve lang and dir of content div (when $wgBetterDirectionality is enabled):...robin11:49, 17 June 2011

Comments

#Comment by SPQRobin (talk | contribs)   21:50, 17 June 2011

Only I am not sure if ParserOptions.php is the right place to set the language of MediaWiki pages...

#Comment by Nikerabbit (talk | contribs)   12:39, 18 June 2011

And I don't think $wgOut's ParserOptions is the correct ParserOptions.

#Comment by SPQRobin (talk | contribs)   13:20, 18 June 2011

It does work as intended...

I first tried to set the targetlanguage in a different way, but $wgOut is now actually not needed anymore, so I can use $parserOptions = ParserOptions::newFromUser( $wgUser );

Would that be better?

#Comment by Nikerabbit (talk | contribs)   13:22, 18 June 2011

If I'm not mistaked $wgOut's ParserOptions are only for the interface, not the actual page content.

#Comment by Platonides (talk | contribs)   13:46, 18 June 2011
  • CategoryPage::formatList() returns (without $wgBetterDirectionality) the undefined variable $list if it doesn't enter on any if
  • The change to ParserOptions::getTargetLanguage() looks wrong.

If you want to get the page language, you should check $wgContLang. Since you want to get the language per-title, adding a new method to the title class seems appropiate. The check to see if $getPageLang is null shouldn't be needed.

#Comment by Platonides (talk | contribs)   18:48, 19 June 2011

I consider this resolved for $wgBetterDirectionality = false;

Status & tagging log