r90265 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90264‎ | r90265 | r90266 >
Date:11:49, 17 June 2011
Author:robin
Status:resolved (Comments)
Tags:
Comment:
Improve lang and dir of content div (when $wgBetterDirectionality is enabled):
* Do not set lang and dir for special pages (those are in the user language)
* Set lang and dir of content of pages in MediaWiki namespace based on the current page instead of site language, e.g. MediaWiki:Message/ar is lang="ar" and dir="rtl"
Modified paths:
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SkinTemplate.php
@@ -455,8 +455,19 @@
456456 $tpl->set( 'printfooter', $this->printSource() );
457457
458458 global $wgBetterDirectionality;
459 - if ( $wgBetterDirectionality ) {
460 - $realBodyAttribs = array( 'lang' => $wgLanguageCode, 'dir' => $wgContLang->getDir() );
 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() );
 471+ }
461472 $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
462473 }
463474 $tpl->setRef( 'bodytext', $out->mBodytext );

Follow-up revisions

RevisionCommit summaryAuthorDate
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

Comments

#Comment by Nikerabbit (talk | contribs)   12:47, 17 June 2011

It's just not Mediawiki namespace pages. For example translated pages need this too. Is it possible to make this more general? For example dig the values out of ParserOutput?

#Comment by SPQRobin (talk | contribs)   13:04, 17 June 2011

You mean all page titles that are a translated subpage, i.e. ending on /xx ?

#Comment by Nikerabbit (talk | contribs)   13:29, 17 June 2011

Well currently the titles in Translate extension are in that format, but I don't think that is a good way to detect it.

#Comment by SPQRobin (talk | contribs)   13:37, 17 June 2011

I know, but I'm not sure how else this could be made more general.

#Comment by Nikerabbit (talk | contribs)   13:42, 17 June 2011

Like I said, ParserOutput should have this information.

#Comment by SPQRobin (talk | contribs)   14:02, 17 June 2011

Sorry, but I don't see how to do that... How can the parser know in which language a page is written?

#Comment by Nikerabbit (talk | contribs)   14:06, 17 June 2011

Parser doesn't decide that, but we can tell the parser that. Translate extension already does it:

$parser->getOptions()->setTargetLanguage( Language::factory( $code ) );

Someday we will probably have magic words that can be used to set the language of the page.

#Comment by SPQRobin (talk | contribs)   16:44, 17 June 2011

Something like this?

if ( $wgBetterDirectionality && $this->getTitle()->getNamespace() != NS_SPECIAL ) {
	if( $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) {
		$nsMWTitle = $wgContLang->lcfirst( $this->getTitle()->getText() );
		list( , $nsMWLang ) = MessageCache::singleton()->figureMessage( $nsMWTitle );
		$out->parserOptions()->setTargetLanguage( $nsMWLang );
	} else {
		$out->parserOptions()->setTargetLanguage( $wgLanguageCode );
	}
	$getPageLang = $out->parserOptions()->getTargetLanguage();
	if( isset( $getPageLang ) ) {
		$pageLangDir = Language::factory( $getPageLang )->getDir();
		$realBodyAttribs = array( 'lang' => $getPageLang, 'dir' => $pageLangDir );
		$out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
	}
}

It should actually only do this on page view, edit preview and edit form. (Not on the whole edit page as there are interface messages etc.)

And I found $parserOptions->setTargetLanguage( $obj ); (under if NS = MediaWiki) in EditPage.php but getTargetLanguage() wouldn't return that value when editing a MediaWiki namespace page.

Also, setTargetLanguage( Language::factory( $nsMWLang ) ) didn't work but setTargetLanguage( $nsMWLang ) did.

Anyway, I think it would be better if you or someone else improved this. I am not a very experienced MediaWiki programmer :-)

And indeed... I was thinking about a magic word as well. That would be useful for multilingual wikis.

#Comment by Nikerabbit (talk | contribs)   16:57, 17 June 2011

You should read the value here, not set it.

#Comment by Nikerabbit (talk | contribs)   10:23, 17 August 2011

Why doesn't this call Title->getPageContentLanguage()? Or has it already been changed in some later revision?

#Comment by SPQRobin (talk | contribs)   23:24, 17 August 2011

Yeah, the code here is largely replaced by other code, including calling Title->getPageLanguage()

Status & tagging log