From c59b619ff835d84d684783651440572bf043b6e4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niklas=20Laxstr=C3=B6m?= Date: Wed, 31 May 2006 15:19:40 +0000 Subject: [PATCH] * (bug 6100) BiDi: different directionality for user interface and wiki content (core parts of the patch) --- RELEASE-NOTES | 2 +- includes/Article.php | 4 +- includes/EditPage.php | 5 +- includes/GlobalFunctions.php | 30 +++++++++ includes/OutputPage.php | 9 ++- includes/Skin.php | 23 ++++--- includes/SkinTemplate.php | 25 +++++-- skins/CologneBlue.php | 7 +- skins/MonoBook.php | 7 +- skins/Standard.php | 14 ++-- skins/common/common_content_rtl.css | 1 + skins/monobook/content_rtl.css | 100 ++++++++++++++++++++++++++++ skins/monobook/main.css | 6 +- skins/monobook/rtl.css | 60 +++++------------ 14 files changed, 213 insertions(+), 80 deletions(-) create mode 100644 skins/common/common_content_rtl.css create mode 100644 skins/monobook/content_rtl.css diff --git a/RELEASE-NOTES b/RELEASE-NOTES index c4926e23d2..7d65490d92 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -391,7 +391,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 6126) Allow fallback to customized primary language when user language message contains '-'; fixes licenses selector on Commons configuration after recent addition of the message to Messages.php - +* (bug 6100) BiDi: different directionality for user interface and wiki content == Compatibility == diff --git a/includes/Article.php b/includes/Article.php index d4a3cdef44..d970a20aee 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -734,7 +734,7 @@ class Article { * the given title. */ function view() { - global $wgUser, $wgOut, $wgRequest, $wgContLang; + global $wgUser, $wgOut, $wgRequest, $wgLang; global $wgEnableParserCache, $wgStylePath, $wgUseRCPatrol, $wgParser; global $wgUseTrackbacks; $sk = $wgUser->getSkin(); @@ -891,7 +891,7 @@ class Article { $wgOut->addHTML( '
'.htmlspecialchars($this->mContent)."\n
" ); } else if ( $rt = Title::newFromRedirect( $text ) ) { # Display redirect - $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr'; + $imageDir = $wgLang->isRTL() ? 'rtl' : 'ltr'; $imageUrl = $wgStylePath.'/common/images/redirect' . $imageDir . '.png'; # Don't overwrite the subtitle if this was an old revision if( !$wasRedirected && $this->isCurrent() ) { diff --git a/includes/EditPage.php b/includes/EditPage.php index 341427b63a..30ed522591 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1313,7 +1313,10 @@ END $wgOut->addParserOutputNoText( $parserOutput ); wfProfileOut( $fname ); - return $previewhead . $previewHTML; + return $previewhead . + '
' . + $previewHTML . + '
'; } } diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index f8ef126ace..389a7973e0 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1850,6 +1850,36 @@ function wfExplodeMarkup( $separator, $text ) { return $items; } +/** @todo document */ +/* returns a dir="rtl" or dir="ltr" for the layout (eg: uselang) */ +function layoutdir() { + global $wgLang, $wgLanguageCode, $wgContLang, $wgContLanguageCode; + $lang = ""; + $dir = ""; + if ( $wgLanguageCode != $wgContLanguageCode ) { + $lang = " lang='$wgLanguageCode'"; + } + if ( $wgLang->isRTL() != $wgContLang->isRTL() ) { + $dir = $wgLang->isRTL() ? " dir='rtl'" : " dir='ltr'"; + } + return $lang . $dir; +} + +/** @todo document */ +/* returns a dir="rtl" or dir="ltr" for the content (wiki lang) */ +function contentdir() { + global $wgLang, $wgLanguageCode, $wgContLang, $wgContLanguageCode; + $lang = ""; + $dir = ""; + if ( $wgLanguageCode != $wgContLanguageCode ) { + $lang = " lang='$wgContLanguageCode'"; + } + if ( $wgLang->isRTL() != $wgContLang->isRTL() ) { + $dir = $wgContLang->isRTL() ? " dir='rtl'" : " dir='ltr'"; + } + return $lang . $dir; +} + class ReplacerCallback { function ReplacerCallback( $from, $to ) { $this->from = $from; diff --git a/includes/OutputPage.php b/includes/OutputPage.php index c155d380c4..98977e4a79 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -332,7 +332,9 @@ class OutputPage { $text = $parserOutput->getText(); wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) ); $parserOutput->setText( $text ); + $this->addHTML( '
'); $this->addHTML( $parserOutput->getText() ); + $this->addHTML( '
'); } /** @@ -385,7 +387,9 @@ class OutputPage { $this->mNewSectionLink = $parserOutput->getNewSection(); $text = $parserOutput->getText(); wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) ); + $this->addHTML( '
'); $this->addHTML( $text ); + $this->addHTML( '
'); $t = $parserOutput->getTitleText(); if( !empty( $t ) ) { $this->setPageTitle( $t ); @@ -948,6 +952,7 @@ class OutputPage { function headElement() { global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType; global $wgUser, $wgContLang, $wgUseTrackbacks, $wgTitle; + global $wgLang, $wgLanguageCode; if( $wgMimeType == 'text/xml' || $wgMimeType == 'application/xhtml+xml' || $wgMimeType == 'application/xml' ) { $ret = "\n"; @@ -961,8 +966,8 @@ class OutputPage { $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() )); } - $rtl = $wgContLang->isRTL() ? " dir='RTL'" : ''; - $ret .= "\n"; + $rtl = $wgLang->isRTL() ? " dir='RTL'" : ''; + $ret .= "\n"; $ret .= "\n" . htmlspecialchars( $this->getHTMLTitle() ) . "\n"; array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) ); diff --git a/includes/Skin.php b/includes/Skin.php index 5bf36abec4..a66fe2ec31 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -297,11 +297,12 @@ class Skin extends Linker { # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way) function getUserStylesheet() { - global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage; + global $wgStylePath, $wgRequest, $wgLang, $wgContLang, $wgSquidMaxage; $sheet = $this->getStylesheet(); $action = $wgRequest->getText('action'); $s = "@import \"$wgStylePath/$sheet\";\n"; - if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n"; + if($wgLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n"; + if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_content_rtl.css\";\n"; $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage"; $s .= '@import "' . $this->makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" . @@ -434,7 +435,7 @@ END; } function doBeforeContent() { - global $wgContLang; + global $wgLang; $fname = 'Skin::doBeforeContent'; wfProfileIn( $fname ); @@ -455,7 +456,7 @@ END; $shove = ($qb != 0); $left = ($qb == 1 || $qb == 3); - if($wgContLang->isRTL()) $left = !$left; + if($wgLang->isRTL()) $left = !$left; if ( !$shove ) { $s .= "\n" . @@ -463,13 +464,13 @@ END; } elseif( $left ) { $s .= $this->getQuickbarCompensator( $rows ); } - $l = $wgContLang->isRTL() ? 'right' : 'left'; + $l = $wgLang->isRTL() ? 'right' : 'left'; $s .= "\n"; $s .= $this->topLinks() ; $s .= "

" . $this->pageTitleLinks() . "

\n"; - $r = $wgContLang->isRTL() ? "left" : "right"; + $r = $wgLang->isRTL() ? "left" : "right"; $s .= "\n"; $s .= $this->nameAndLogin(); $s .= "\n
" . $this->searchForm() . ""; @@ -996,7 +997,7 @@ END; if ( '' != $align ) { $a = " align='{$align}'"; } else { $a = ''; } - $mp = wfMsg( 'mainpage' ); + $mp = wfMsgForContent( 'mainpage' ); $titleObj = Title::newFromText( $mp ); if ( is_object( $titleObj ) ) { $url = $titleObj->escapeLocalURL(); @@ -1251,7 +1252,7 @@ END; } function otherLanguages() { - global $wgOut, $wgContLang, $wgHideInterlanguageLinks; + global $wgOut, $wgLang, $wgHideInterlanguageLinks; if ( $wgHideInterlanguageLinks ) { return ''; @@ -1264,20 +1265,20 @@ END; $s = wfMsg( 'otherlanguages' ) . ': '; $first = true; - if($wgContLang->isRTL()) $s .= ''; + if($wgLang->isRTL()) $s .= ''; foreach( $a as $l ) { if ( ! $first ) { $s .= ' | '; } $first = false; $nt = Title::newFromText( $l ); $url = $nt->escapeFullURL(); - $text = $wgContLang->getLanguageName( $nt->getInterwiki() ); + $text = $wgLang->getLanguageName( $nt->getInterwiki() ); if ( '' == $text ) { $text = $l; } $style = $this->getExternalLinkAttributes( $l, $text ); $s .= "{$text}"; } - if($wgContLang->isRTL()) $s .= ''; + if($wgLang->isRTL()) $s .= ''; return $s; } diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index f054153ada..5b86d02197 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -134,7 +134,7 @@ class SkinTemplate extends Skin { */ function outputPage( &$out ) { global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut; - global $wgScript, $wgStylePath, $wgContLanguageCode; + global $wgScript, $wgStylePath, $wgLanguageCode, $wgContLanguageCode; global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest; global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks; global $wgMaxCredits, $wgShowCreditsIfMax; @@ -247,8 +247,20 @@ class SkinTemplate extends Skin { $tpl->setRef( 'stylepath', $wgStylePath ); $tpl->setRef( 'logopath', $wgLogo ); $tpl->setRef( "lang", $wgContLanguageCode ); - $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" ); - $tpl->set( 'rtl', $wgContLang->isRTL() ); + $tpl->setRef( 'uselang', $wgLanguageCode ); + $tpl->set( 'dir', $wgLang->isRTL() ? "rtl" : "ltr" ); + $tpl->set( 'rtl', $wgLang->isRTL() ); + /* display, if needed, dir=ltr or dir=rtl for the + firstHeading title. This is when the title is + content, eg a site-localized string; + that is the case for all the pages not in Special: + when action is view or history + */ + $tpl->set( 'titledir', + ($this->mTitle->getNamespace() != NS_SPECIAL && + ($action == 'view' || $action == 'history')) ? + contentdir() : "" + ); $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) ); $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) ); $tpl->setRef( 'username', $this->username ); @@ -392,7 +404,7 @@ class SkinTemplate extends Skin { $nt = Title::newFromText( $l ); $language_urls[] = array( 'href' => $nt->getFullURL(), - 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l), + 'text' => ($wgLang->getLanguageName( $nt->getInterwiki()) != ''?$wgLang->getLanguageName( $nt->getInterwiki()) : $l), 'class' => $class ); } @@ -887,7 +899,7 @@ class SkinTemplate extends Skin { $fname = 'SkinTemplate::setupUserCss'; wfProfileIn( $fname ); - global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser; + global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgLang, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser; $sitecss = ''; $usercss = ''; @@ -911,7 +923,8 @@ class SkinTemplate extends Skin { $siteargs .= '&ts=' . $wgUser->mTouched; } - if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css";' . "\n"; + if ($wgLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/rtl.css";' . "\n"; + if ($wgContLang->isRTL()) $sitecss .= '@import "' . $wgStylePath . '/' . $this->stylename . '/content_rtl.css";' . "\n"; # If we use the site's dynamic CSS, throw that in, too if ( $wgUseSiteCss ) { diff --git a/skins/CologneBlue.php b/skins/CologneBlue.php index 9cb3ef32dd..d08bbbe0d6 100644 --- a/skins/CologneBlue.php +++ b/skins/CologneBlue.php @@ -98,14 +98,15 @@ class SkinCologneBlue extends Skin { } function doGetUserStyles() { - global $wgOut; + global $wgOut, $wgLang, $wgUser; $s = parent::doGetUserStyles(); $qb = $this->qbSetting(); - if ( 2 == $qb ) { # Right + if ( (!$wgUser->isLoggedIn() && $wgLang->isRTL() ) || + ( 2 == $qb ) ) { # Right $s .= "#quickbar { position: absolute; right: 4px; }\n" . "#article { margin-left: 4px; margin-right: 148px; }\n"; - } else if ( 1 == $qb ) { + } else if ( (!$wgUser->isLoggedIn()) || ( 1 == $qb ) ) { $s .= "#quickbar { position: absolute; left: 4px; }\n" . "#article { margin-left: 148px; margin-right: 4px; }\n"; } else if ( 3 == $qb ) { # Floating left diff --git a/skins/MonoBook.php b/skins/MonoBook.php index d4c6638519..024c126097 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -51,7 +51,7 @@ class MonoBookTemplate extends QuickTemplate { wfSuppressWarnings(); ?> - + html('headlinks') ?> @@ -93,7 +93,7 @@ class MonoBookTemplate extends QuickTemplate {
data['sitenotice']) { ?>
html('sitenotice') ?>
-

data['displaytitle']!=""?$this->text('title'):$this->html('title') ?>

+

text('titledir') ?>>data['displaytitle']!=""?$this->text('title'):$this->html('title') ?>

msg('tagline') ?>

html('subtitle') ?>
@@ -124,6 +124,9 @@ class MonoBookTemplate extends QuickTemplate {
msg('personaltools') ?>