--- includes/templates/Userlogin.php_old	2006-05-27 19:30:51.000000000 +0200
+++ includes/templates/Userlogin.php	2006-05-28 13:56:57.000000000 +0200
@@ -34,14 +34,14 @@
 	<table>
 		<tr>
 			<td align='right'><label for='wpName1'><?php $this->msg('yourname') ?>:</label></td>
-			<td align='left'>
+			<td>
 				<input type='text' class='loginText' name="wpName" id="wpName1"
 					value="<?php $this->text('name') ?>" size='20' />
 			</td>
 		</tr>
 		<tr>
 			<td align='right'><label for='wpPassword1'><?php $this->msg('yourpassword') ?>:</label></td>
-			<td align='left'>
+			<td>
 				<input type='password' class='loginPassword' name="wpPassword" id="wpPassword1"
 					value="<?php $this->text('password') ?>" size='20' />
 			</td>
@@ -54,7 +54,7 @@
 	?>
 		<tr>
 			<td align='right'><?php $this->msg( 'yourdomainname' ) ?>:</td>
-			<td align='left'>
+			<td>
 				<select name="wpDomain" value="<?php $this->text( 'domain' ) ?>">
 					<?php echo $doms ?>
 				</select>
@@ -63,7 +63,7 @@
 	<?php } ?>
 		<tr>
 			<td></td>
-			<td align='left'>
+			<td>
 				<input type='checkbox' name="wpRemember"
 					value="1" id="wpRemember"
 					<?php if( $this->data['remember'] ) { ?>checked="checked"<?php } ?>
@@ -72,7 +72,7 @@
 		</tr>
 		<tr>
 			<td></td>
-			<td align='left' style="white-space:nowrap">
+			<td style="white-space:nowrap">
 				<input type='submit' name="wpLoginattempt" id="wpLoginattempt" value="<?php $this->msg('login') ?>" />&nbsp;<?php if( $this->data['useemail'] ) { ?><input type='submit' name="wpMailmypassword" id="wpMailmypassword"
 									value="<?php $this->msg('mailmypassword') ?>" />
 				<?php } ?>
@@ -109,14 +109,14 @@
 	<table>
 		<tr>
 			<td align='right'><label for='wpName2'><?php $this->msg('yourname') ?>:</label></td>
-			<td align='left'>
+			<td>
 				<input type='text' class='loginText' name="wpName" id="wpName2"
 					value="<?php $this->text('name') ?>" size='20' />
 			</td>
 		</tr>
 		<tr>
 			<td align='right'><label for='wpPassword2'><?php $this->msg('yourpassword') ?>:</label></td>
-			<td align='left'>
+			<td>
 				<input type='password' class='loginPassword' name="wpPassword" id="wpPassword2"
 					value="<?php $this->text('password') ?>" size='20' />
 			</td>
@@ -129,7 +129,7 @@
 	?>
 		<tr>
 			<td align='right'><?php $this->msg( 'yourdomainname' ) ?>:</td>
-			<td align='left'>
+			<td>
 				<select name="wpDomain" value="<?php $this->text( 'domain' ) ?>">
 					<?php echo $doms ?>
 				</select>
@@ -138,7 +138,7 @@
 	<?php } ?>
 		<tr>
 			<td align='right'><label for='wpRetype'><?php $this->msg('yourpasswordagain') ?>:</label></td>
-			<td align='left'>
+			<td>
 				<input type='password' class='loginPassword' name="wpRetype" id="wpRetype"
 					value="<?php $this->text('retype') ?>"
 					size='20' />
@@ -147,7 +147,7 @@
 		<tr>
 			<?php if( $this->data['useemail'] ) { ?>
 				<td align='right'><label for='wpEmail'><?php $this->msg('youremail') ?>:</label></td>
-				<td align='left'>
+				<td>
 					<input type='text' class='loginText' name="wpEmail" id="wpEmail"
 						value="<?php $this->text('email') ?>" size='20' />
 				</td>
@@ -156,7 +156,7 @@
 				</tr>
 				<tr>
 					<td align='right'><label for='wpRealName'><?php $this->msg('yourrealname') ?>:</label></td>
-					<td align='left'>
+					<td>
 						<input type='text' class='loginText' name="wpRealName" id="wpRealName"
 							value="<?php $this->text('realname') ?>" size='20' />
 					</td>
@@ -164,7 +164,7 @@
 		</tr>
 		<tr>
 			<td></td>
-			<td align='left'>
+			<td>
 				<input type='checkbox' name="wpRemember"
 					value="1" id="wpRemember"
 					<?php if( $this->data['remember'] ) { ?>checked="checked"<?php } ?>
@@ -173,7 +173,7 @@
 		</tr>
 		<tr>
 			<td></td>
-			<td align='left'>
+			<td>
 				<input type='submit' name="wpCreateaccount" id="wpCreateaccount"
 					value="<?php $this->msg('createaccount') ?>" />
 				<?php if( $this->data['createemail'] ) { ?>
--- includes/OutputPage.php_old	2006-05-25 13:34:53.000000000 +0200
+++ includes/OutputPage.php	2006-05-27 03:33:38.000000000 +0200
@@ -332,7 +332,9 @@
 		$text =	$parserOutput->getText();
 		wfRunHooks( 'OutputPageBeforeHTML',array( &$this, &$text ) );
 		$parserOutput->setText( $text );
+		$this->addHTML( '<div id="realContent"' . contentdir() . '>');
 		$this->addHTML( $parserOutput->getText() );
+		$this->addHTML( '</div><!-- realContent -->');
 	}
 
 	/**
@@ -385,7 +387,9 @@
 			$this->mNewSectionLink = $parserOutput->getNewSection();
 			$text = $parserOutput->getText();
 			wfRunHooks( 'OutputPageBeforeHTML', array( &$this, &$text ) );
+			$this->addHTML( '<div id="realContent"' . contentdir() . '>');
 			$this->addHTML( $text );
+			$this->addHTML( '</div><!-- realContent -->');
 			$t = $parserOutput->getTitleText();
 			if( !empty( $t ) ) {
 				$this->setPageTitle( $t );
@@ -948,6 +952,7 @@
 	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 = "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?>\n";
@@ -961,8 +966,8 @@
 			$this->setHTMLTitle(  wfMsg( 'pagetitle', $this->getPageTitle() ));
 		}
 
-		$rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
-		$ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
+		$rtl = $wgLang->isRTL() ? " dir='RTL'" : '';
+		$ret .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"$wgLanguageCode\" lang=\"$wgLanguageCode\" $rtl>\n";
 		$ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n";
 		array_push( $this->mMetatags, array( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" ) );
 
--- includes/GlobalFunctions.php_old	2006-05-25 13:43:56.000000000 +0200
+++ includes/GlobalFunctions.php	2006-05-27 17:54:19.000000000 +0200
@@ -1631,8 +1631,12 @@
 }
 
 function wfSpecialList( $page, $details ) {
-	global $wgContLang;
-	$details = $details ? ' ' . $wgContLang->getDirMark() . "($details)" : "";
+	global $wgLang, $wgContLang;
+
+	if ($wgLang->isRTL() != $wgContLang->isRTL()) {
+		$page = "<span" . contentdir() . ">$page</span>";
+	}
+	$details = $details ? ' ' . $wgLang->getDirMark() . "($details)" : "";
 	return $page . $details;
 }
 
@@ -1833,6 +1837,36 @@
 	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;
--- includes/Article.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/Article.php	2006-05-27 03:28:58.000000000 +0200
@@ -734,7 +734,7 @@
 	 * 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 @@
 				$wgOut->addHTML( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
 			} 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() ) {
--- includes/ChangesList.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/ChangesList.php	2006-05-28 23:10:03.000000000 +0200
@@ -168,10 +168,18 @@
 		$params = ( $unpatrolled && $rc->mAttribs['rc_type'] == RC_NEW )
 			? 'rcid='.$rc->mAttribs['rc_id']
 			: '';
-		$articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
+		$articlelink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params );
 		if($watched) $articlelink = '<strong>'.$articlelink.'</strong>';
+		# if directionality differe; put a span around article link
+		# to force into wiki directionality, so articles starting with
+		# non alphabetic chars display properly
+		global $wgLang, $wgContLang;
+		if ($wgLang->isRTL() != $wgContLang->isRTL()) {
+			$articlelink = "<span" . contentdir() . ">" .
+				$articlelink . "</span>";
+		}
 
-		$s .= ' '.$articlelink;
+		$s .= ' ' . $articlelink;
 	}
 
 	function insertTimestamp(&$s, &$rc) {
@@ -183,6 +191,11 @@
 	/** Insert links to user page, user talk page and eventually a blocking link */
 	function insertUserRelatedLinks(&$s, &$rc) {
 		$s .= $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
+		// this undoes any direction formating char that
+		// may be present in the previous string (user name),
+		// so avoinding vandalization of change lists by the
+		// creation of such user names 
+		$s .= '&#x202c;';
 		$s .= $this->skin->userToolLinks( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
 	}
 
@@ -215,7 +228,10 @@
 	 * Format a line using the old system (aka without any javascript).
 	 */
 	function recentChangesLine( &$rc, $watched = false ) {
-		global $wgContLang;
+		global $wgLang, $wgContLang;
+
+	       	// to keep text in correct direction
+		$dirmark = $wgLang->getDirMark();
 
 		$fname = 'ChangesList::recentChangesLineOld';
 		wfProfileIn( $fname );
@@ -230,7 +246,7 @@
 
 		$this->insertDateHeader($s,$rc_timestamp);
 
-		$s .= '<li>';
+		$s .= '<li>' . $dirmark;
 
 		// moved pages
 		if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
@@ -245,7 +261,9 @@
 			$this->insertDiffHist($s, $rc, $unpatrolled);
 
 			# M, N and ! (minor, new and unpatrolled)
+			$s .= $dirmark;
 			$s .= ' ' . $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $unpatrolled, '' );
+			$s .= $dirmark;
 			$this->insertArticleLink($s, $rc, $unpatrolled, $watched);
 
 			wfProfileOut($fname.'-page');
@@ -253,14 +271,24 @@
 
 		wfProfileIn( $fname.'-rest' );
 
+		// this undoes any direction formating char that
+		// may be present in the previous string (article title),
+		// so avoinding vandalization of change lists by the
+		// creation of such titled articles 
+		$s .= '&#x202c;';
+		$s .= $dirmark;
 		$this->insertTimestamp($s,$rc);
+		$s .= $dirmark;
 		$this->insertUserRelatedLinks($s,$rc);
+		$s .= $dirmark;
 		$this->insertComment($s, $rc);
 
 		if($rc->numberofWatchingusers > 0) {
+			$s .= $dirmark;
 			$s .= ' ' . wfMsg('number_of_watching_users_RCview',  $wgContLang->formatNum($rc->numberofWatchingusers));
 		}
 
+		$s .= $dirmark;
 		$s .= "</li>\n";
 
 		wfProfileOut( $fname.'-rest' );
@@ -535,8 +563,8 @@
 	 * @access private
 	 */
 	function sideArrow() {
-		global $wgContLang;
-		$dir = $wgContLang->isRTL() ? 'l' : 'r';
+		global $wgLang;
+		$dir = $wgLang->isRTL() ? 'l' : 'r';
 		return $this->arrow( $dir, '+' );
 	}
 
--- includes/EditPage.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/EditPage.php	2006-05-26 20:55:32.000000000 +0200
@@ -1305,7 +1305,10 @@
 			$wgOut->addParserOutputNoText( $parserOutput );
 
 			wfProfileOut( $fname );
-			return $previewhead . $previewHTML;
+			return $previewhead . 
+			'<div id="realContent"' . contentdir() . '>' .
+			$previewHTML . 
+			'</div><!-- realContent -->';
 		}
 	}
 
--- includes/ImagePage.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/ImagePage.php	2006-05-28 15:37:14.000000000 +0200
@@ -166,6 +166,7 @@
 
 	function openShowImage() {
 		global $wgOut, $wgUser, $wgImageLimits, $wgRequest, $wgUseImageResize;
+		global $wgLang;
 
 		$full_url  = $this->img->getURL();
 		$anchoropen = '';
@@ -252,18 +253,19 @@
 			}
 
 
+			$dirmark = $wgLang->getDirMark();
 			if ($showLink) {
 				$filename = wfEscapeWikiText( $this->img->getName() );
 				$info = wfMsg( 'fileinfo',
 					ceil($this->img->getSize()/1024.0),
-					$this->img->getMimeType() );
+					$dirmark . $this->img->getMimeType() );
 
 				if (!$this->img->isSafeFile()) {
 					$warning = wfMsg( 'mediawarning' );
 					$wgOut->addWikiText( <<<END
 <div class="fullMedia">
 <span class="dangerousLink">[[Media:$filename|$filename]]</span>
-<span class="fileInfo"> ($info)</span>
+<span class="fileInfo"> {$dirmark}($info)</span>
 </div>
 
 <div class="mediaWarning">$warning</div>
@@ -272,7 +274,8 @@
 				} else {
 					$wgOut->addWikiText( <<<END
 <div class="fullMedia">
-[[Media:$filename|$filename]] <span class="fileInfo"> ($info)</span>
+[[Media:$filename|$filename]] 
+<span class="fileInfo"> {$dirmark}($info)</span>
 </div>
 END
 						);
@@ -724,6 +727,7 @@
 		$del = wfMsg( 'deleteimg' );
 		$delall = wfMsg( 'deleteimgcompletely' );
 		$cur = wfMsg( 'cur' );
+		$dirmark = $wgLang->getDirMark();
 
 		if ( $iscur ) {
 			$url = Image::imageUrl( $img );
@@ -759,15 +763,15 @@
 			$userlink = $usertext;
 		} else {
 			$userlink = $this->skin->makeLinkObj( Title::makeTitle( NS_USER, $usertext ), $usertext );
-			$usertalk = $this->skin->makeLinkObj( Title::makeTitle( NS_USER_TALK, $usertext), $wgContLang->getNsText( NS_TALK ) );
-			$userdata = $userlink . ' (' . $usertalk . ')';
+			$usertalk = $this->skin->makeLinkObj( Title::makeTitle( NS_USER_TALK, $usertext), $wgLang->getNsText( NS_TALK ) );
+			$userdata = $userlink . " {$dirmark}(" . $usertalk . ')';
 		}
 		$nbytes = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ),
 			$wgLang->formatNum( $size ) );
 		$widthheight = wfMsg( 'widthheight', $width, $height );
 		$style = $this->skin->getInternalLinkAttributes( $url, $datetime );
 
-		$s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userdata} . . {$widthheight} ({$nbytes})";
+		$s = "<li> {$dirmark}({$dlink}) {$dirmark}({$rlink}) {$dirmark}<a href=\"{$url}\"{$style}>{$datetime}</a> . . {$dirmark}{$userdata} . . {$dirmark}{$widthheight} {$dirmark}({$nbytes}){$dirmark}";
 
 		$s .= $this->skin->commentBlock( $description, $wgTitle );
 		$s .= "</li>\n";
--- includes/Skin.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/Skin.php	2006-05-27 03:43:31.000000000 +0200
@@ -297,11 +297,12 @@
 
 	# 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" .
@@ -436,7 +437,7 @@
 	}
 
 	function doBeforeContent() {
-		global $wgContLang;
+		global $wgLang;
 		$fname = 'Skin::doBeforeContent';
 		wfProfileIn( $fname );
 
@@ -457,7 +458,7 @@
 
 		$shove = ($qb != 0);
 		$left = ($qb == 1 || $qb == 3);
-		if($wgContLang->isRTL()) $left = !$left;
+		if($wgLang->isRTL()) $left = !$left;
 
 		if ( !$shove ) {
 			$s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
@@ -465,13 +466,13 @@
 		} elseif( $left ) {
 			$s .= $this->getQuickbarCompensator( $rows );
 		}
-		$l = $wgContLang->isRTL() ? 'right' : 'left';
+		$l = $wgLang->isRTL() ? 'right' : 'left';
 		$s .= "<td {$borderhack} align='$l' valign='top'>\n";
 
 		$s .= $this->topLinks() ;
 		$s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
 
-		$r = $wgContLang->isRTL() ? "left" : "right";
+		$r = $wgLang->isRTL() ? "left" : "right";
 		$s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
 		$s .= $this->nameAndLogin();
 		$s .= "\n<br />" . $this->searchForm() . "</td>";
@@ -998,7 +999,7 @@
 		if ( '' != $align ) { $a = " align='{$align}'"; }
 		else { $a = ''; }
 
-		$mp = wfMsg( 'mainpage' );
+		$mp = wfMsgForContent( 'mainpage' );
 		$titleObj = Title::newFromText( $mp );
 		if ( is_object( $titleObj ) ) {
 			$url = $titleObj->escapeLocalURL();
@@ -1253,7 +1254,7 @@
 	}
 
 	function otherLanguages() {
-		global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
+		global $wgOut, $wgLang, $wgHideInterlanguageLinks;
 
 		if ( $wgHideInterlanguageLinks ) {
 			return '';
@@ -1266,20 +1267,20 @@
 
 		$s = wfMsg( 'otherlanguages' ) . ': ';
 		$first = true;
-		if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
+		if($wgLang->isRTL()) $s .= '<span dir="LTR">';
 		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 .= "<a href=\"{$url}\"{$style}>{$text}</a>";
 		}
-		if($wgContLang->isRTL()) $s .= '</span>';
+		if($wgLang->isRTL()) $s .= '</span>';
 		return $s;
 	}
 
--- includes/SkinTemplate.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SkinTemplate.php	2006-05-27 19:38:33.000000000 +0200
@@ -134,7 +134,7 @@
 	 */
 	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;
@@ -243,8 +243,20 @@
 		$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 );
@@ -388,7 +400,7 @@
 				$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
 				);
 			}
@@ -883,7 +895,7 @@
 		$fname = 'SkinTemplate::setupUserCss';
 		wfProfileIn( $fname );
 
-		global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
+		global $wgRequest, $wgAllowUserCss, $wgUseSiteCss, $wgLang, $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser;
 
 		$sitecss = '';
 		$usercss = '';
@@ -907,7 +919,8 @@
 			$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 ) {
--- includes/SpecialAllpages.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SpecialAllpages.php	2006-05-28 14:32:35.000000000 +0200
@@ -50,7 +50,7 @@
  * @param string $from Article name we are starting listing at.
  */
 function namespaceForm ( $namespace = NS_MAIN, $from = '' ) {
-	global $wgScript;
+	global $wgScript, $wgLang;
 	$t = Title::makeTitle( NS_SPECIAL, $this->name );
 
 	$namespaceselect = HTMLnamespaceselector($namespace, null);
@@ -59,17 +59,19 @@
 	            . htmlspecialchars ( $from ) . '"/>';
 	$submitbutton = '<input type="submit" value="' . wfMsgHtml( 'allpagessubmit' ) . '" />';
 
+	$left = ($wgLang->isRTL()) ? "right" : "left";
+	$right = ($wgLang->isRTL()) ? "left" : "right";
 	$out = "<div class='namespaceoptions'><form method='get' action='{$wgScript}'>";
 	$out .= '<input type="hidden" name="title" value="'.$t->getPrefixedText().'" />';
 	$out .= "
 <table id='nsselect' class='allpages'>
 	<tr>
-		<td align='right'>" . wfMsgHtml($this->nsfromMsg) . "</td>
-		<td align='left'><label for='nsfrom'>$frombox</label></td>
+		<td align='$right'>" . wfMsgHtml($this->nsfromMsg) . "</td>
+		<td align='$left'><label for='nsfrom'>$frombox</label></td>
 	</tr>
 	<tr>
-		<td align='right'><label for='namespace'>" . wfMsgHtml('namespace') . "</label></td>
-		<td align='left'>
+		<td align='$right'><label for='namespace'>" . wfMsgHtml('namespace') . "</label></td>
+		<td align='$left'>
 			$namespaceselect $submitbutton
 		</td>
 	</tr>
@@ -171,9 +173,12 @@
 	} else {
 		$morelinks = '';
 		if ( $morelinks != '' ) {
+			global $wgLang;
+			$left = ($wgLang->isRTL()) ? "right" : "left";	
+			$right = ($wgLang->isRTL()) ? "left" : "right";
 			$out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
-			$out2 .= '<tr valign="top"><td align="left">' . $nsForm;
-			$out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">';
+			$out2 .= "<tr valign=\"top\"><td align=\"$left\">" . $nsForm;
+			$out2 .= "</td><td align=\"$right\" style=\"font-size: smaller; margin-bottom: 1em;\">";
 			$out2 .= $morelinks . '</td></tr></table><hr />';
 		} else {
 			$out2 = $nsForm . '<hr />';
@@ -189,7 +194,7 @@
  * @param integer $namespace (Default NS_MAIN)
  */
 function showline( $inpoint, $outpoint, $namespace = NS_MAIN ) {
-	global $wgUser;
+	global $wgUser, $wgLang;
 	$sk = $wgUser->getSkin();
 	$dbr =& wfGetDB( DB_SLAVE );
 
@@ -199,12 +204,15 @@
 	$special = Title::makeTitle( NS_SPECIAL, $this->name . '/' . $inpoint );
 	$link = $special->escapeLocalUrl( $queryparams );
 
+	$dir = contentdir();	
+	$left = ($wgLang->isRTL()) ? "right" : "left";	
+	$right = ($wgLang->isRTL()) ? "left" : "right";
 	$out = wfMsgHtml(
 		'alphaindexline',
-		"<a href=\"$link\">$inpointf</a></td><td><a href=\"$link\">",
-		"</a></td><td align=\"left\"><a href=\"$link\">$outpointf</a>"
+		"<a href=\"$link\"$dir>$inpointf</a></td><td><a href=\"$link\">",
+		"</a></td><td align=\"$left\"><a href=\"$link\"$dir>$outpointf</a>"
 	);
-	return '<tr><td align="right">'.$out.'</td></tr>';
+	return "<tr><td align=\"$right\">$out</td></tr>";
 }
 
 /**
@@ -212,7 +220,7 @@
  * @param string $from list all pages from this name (default FALSE)
  */
 function showChunk( $namespace = NS_MAIN, $from, $including = false ) {
-	global $wgOut, $wgUser, $wgContLang;
+	global $wgOut, $wgUser, $wgLang, $wgContLang;
 
 	$fname = 'indexShowChunk';
 
@@ -251,14 +259,23 @@
 	$out = '<table style="background: inherit;" border="0" width="100%">';
 
 	$namespaces = $wgContLang->getFormattedNamespaces();
+
+	if ($wgLang->isRTL() != $wgContLang->isRTL()) {
+		$spandiropen = "<span" . contentdir() . ">";
+		$spandirclose = "</span>";
+	} else {
+		$spandiropen = '';
+		$spandirclose = '';
+	}
+
 	while( ($n < $this->maxPerPage) && ($s = $dbr->fetchObject( $res )) ) {
 		$t = Title::makeTitle( $s->page_namespace, $s->page_title );
 		if( $t ) {
-			$link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
+			$link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) . $spandiropen .
 				$sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
-				($s->page_is_redirect ? '</div>' : '' );
+				($s->page_is_redirect ? '</div>' : '' ) . $spandirclose;
 		} else {
-			$link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
+			$link = $spandiropen . '[[' . htmlspecialchars( $s->page_title ) . ']]' . $spandirclose;
 		}
 		if( $n % 3 == 0 ) {
 			$out .= '<tr>';
@@ -278,10 +295,13 @@
 	if ( $including ) {
 		$out2 = '';
 	} else {
+		global $wgLang;
 		$nsForm = $this->namespaceForm ( $namespace, $from );
+		$left = ($wgLang->isRTL()) ? "right" : "left";	
+		$right = ($wgLang->isRTL()) ? "left" : "right";
 		$out2 = '<table style="background: inherit;" width="100%" cellpadding="0" cellspacing="0" border="0">';
-		$out2 .= '<tr valign="top"><td align="left">' . $nsForm;
-		$out2 .= '</td><td align="right" style="font-size: smaller; margin-bottom: 1em;">' .
+		$out2 .= "<tr valign=\"top\"><td align=\"$left\">" . $nsForm;
+		$out2 .= "</td><td align=\"$right\" style=\"font-size: smaller; margin-bottom: 1em;\">" .
 				$sk->makeKnownLink( $wgContLang->specialPage( "Allpages" ),
 					wfMsgHtml ( 'allpages' ) );
 		if ( ($n == $this->maxPerPage) && ($s = $dbr->fetchObject( $res )) ) {
--- includes/SpecialBlockip.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SpecialBlockip.php	2006-05-27 19:01:21.000000000 +0200
@@ -49,10 +49,13 @@
 	}
 
 	function showForm( $err ) {
-		global $wgOut, $wgUser, $wgSysopUserBans;
+		global $wgOut, $wgUser, $wgSysopUserBans, $wgLang;
 
 		$wgOut->setPagetitle( wfMsg( 'blockip' ) );
 		$wgOut->addWikiText( wfMsg( 'blockiptext' ) );
+		
+		$left = ($wgLang->isRTL()) ? "right" : "left";
+		$right = ($wgLang->isRTL()) ? "left" : "right";
 
 		if($wgSysopUserBans) {
 			$mIpaddress = wfMsgHtml( 'ipadressorusername' );
@@ -100,16 +103,16 @@
 <form id=\"blockip\" method=\"post\" action=\"{$action}\">
 	<table border='0'>
 		<tr>
-			<td align=\"right\">{$mIpaddress}:</td>
-			<td align=\"left\">
+			<td align=\"{$right}\">{$mIpaddress}:</td>
+			<td align=\"${left}\">
 				<input tabindex='1' type='text' size='20' name=\"wpBlockAddress\" value=\"{$scBlockAddress}\" />
 			</td>
 		</tr>
 		<tr>");
 		if ($showblockoptions) {
 			$wgOut->addHTML("
-			<td align=\"right\">{$mIpbexpiry}:</td>
-			<td align=\"left\">
+			<td align=\"${right}\">{$mIpbexpiry}:</td>
+			<td align=\"${left}\">
 				<select tabindex='2' id='wpBlockExpiry' name=\"wpBlockExpiry\" onchange=\"considerChangingExpiryFocus()\">
 					$blockExpiryFormOptions
 				</select>
@@ -119,20 +122,20 @@
 		$wgOut->addHTML("
 		</tr>
 		<tr id='wpBlockOther'>
-			<td align=\"right\">{$mIpbother}:</td>
-			<td align=\"left\">
+			<td align=\"${right}\">{$mIpbother}:</td>
+			<td align=\"${left}\">
 				<input tabindex='3' type='text' size='40' name=\"wpBlockOther\" value=\"{$scBlockOtherTime}\" />
 			</td>
 		</tr>
 		<tr>
-			<td align=\"right\">{$mIpbreason}:</td>
-			<td align=\"left\">
+			<td align=\"${right}\">{$mIpbreason}:</td>
+			<td align=\"${left}\">
 				<input tabindex='3' type='text' size='40' name=\"wpBlockReason\" value=\"{$scBlockReason}\" />
 			</td>
 		</tr>
 		<tr>
 			<td>&nbsp;</td>
-			<td align=\"left\">
+			<td align=\"${left}\">
 				<input tabindex='4' type='submit' name=\"wpBlock\" value=\"{$mIpbsubmit}\" />
 			</td>
 		</tr>
--- includes/SpecialBrokenRedirects.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SpecialBrokenRedirects.php	2006-05-28 16:34:26.000000000 +0200
@@ -51,6 +51,8 @@
 	}
 
 	function formatResult( $skin, $result ) {
+		global $wgLang, $wgContLang;
+		
 		$fromObj = Title::makeTitle( $result->namespace, $result->title );
 		if ( isset( $result->pl_title ) ) {
 			$toObj = Title::makeTitle( $result->pl_namespace, $result->pl_title );
@@ -72,7 +74,22 @@
 		$edit = $skin->makeBrokenLinkObj( $fromObj , "(".wfMsg("qbedit").")" , 'redirect=no');
 		$to   = $skin->makeBrokenLinkObj( $toObj );
 
-		return "$from $edit &rarr; $to";
+		$dirmark = $wgLang->getDirMark();
+		// is using ascii arrow on purpose?
+		// if not, the unicode arrow below can be used
+		$arr = "=>";
+		//# Check the language; RTL wikis need a &larr;
+		//$arr = $wgLang->isRTL() ? '&larr;' : '&rarr;';
+		# if directionality is different, put <span> around
+		# the article names links
+		if ($wgLang->isRTL() != $wgContLang->isRTL()) {
+			$from = "<span" . contentdir() . ">" .
+				$from . "</span>";
+			$to = "<span" . contentdir() . ">" .
+				$to . "</span>";
+		}
+		
+		return "{$from} {$dirmark}{$edit} {$dirmark}{$arr} {$to}";
 	}
 }
 
--- includes/SpecialDisambiguations.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SpecialDisambiguations.php	2006-05-28 16:30:28.000000000 +0200
@@ -62,6 +62,8 @@
 	}
 
 	function formatResult( $skin, $result ) {
+		global $wgLang, $wgContLang;
+
 		$title = Title::newFromId( $result->value );
 		$dp = Title::makeTitle( $result->namespace, $result->title );
 
@@ -69,7 +71,19 @@
 		$edit = $skin->makeBrokenLinkObj( $title, "(".wfMsg("qbedit").")" , 'redirect=no');
 		$to   = $skin->makeKnownLinkObj( $dp,'');
 
-		return "$from $edit => $to";
+		$dirmark = $wgLang->getDirMark();
+		# Check the language; RTL wikis need a &larr;
+		$arr = $wgLang->isRTL() ? '&larr;' : '&rarr;';
+		# if directionality is different, put <span> around
+		# the article names links
+		if ($wgLang->isRTL() != $wgContLang->isRTL()) {
+			$from = "<span" . contentdir() . ">" .
+				$from . "</span>";
+			$to = "<span" . contentdir() . ">" .
+				$to . "</span>";
+		}
+
+		return "{$from} {$dirmark}{$edit} {$dirmark}{$arr} {$to}";
 	}
 }
 
--- includes/SpecialDoubleRedirects.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SpecialDoubleRedirects.php	2006-05-28 16:10:17.000000000 +0200
@@ -67,7 +67,7 @@
 	}
 
 	function formatResult( $skin, $result ) {
-		global $wgContLang;
+		global $wgLang, $wgContLang;
 	
 		$fname = 'DoubleRedirectsPage::formatResult';
 		$titleA = Title::makeTitle( $result->namespace, $result->title );
@@ -92,9 +92,19 @@
 		$edit = $skin->makeBrokenLinkObj( $titleA, "(".wfMsg("qbedit").")" , 'redirect=no');
 		$linkB = $skin->makeKnownLinkObj( $titleB, '', 'redirect=no' );
 		$linkC = $skin->makeKnownLinkObj( $titleC );
-		$arr = $wgContLang->isRTL() ? '&larr;' : '&rarr;';
 
-		return( "{$linkA} {$edit} {$arr} {$linkB} {$arr} {$linkC}" );
+		$dirmark = $wgLang->getDirMark();
+		# Check the language; RTL wikis need a &larr;
+		$arr = $wgLang->isRTL() ? '&larr;' : '&rarr;';
+		# if directionality is different, put <span> around
+		# the article names links
+		if ($wgLang->isRTL() != $wgContLang->isRTL()) {
+			$linkA = "<span" . contentdir() . ">" .  $linkA . "</span>";
+			$linkB = "<span" . contentdir() . ">" .  $linkB . "</span>";
+			$linkC = "<span" . contentdir() . ">" .  $linkC . "</span>";
+		}
+
+		return( "{$linkA} {$dirmark}{$edit} {$dirmark}{$arr} {$linkB} {$dirmark}{$arr} {$linkC}" );
 	}
 }
 
--- includes/SpecialImagelist.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SpecialImagelist.php	2006-05-28 21:57:18.000000000 +0200
@@ -86,6 +86,9 @@
 	$wgOut->addHTML( '<p>' );
 	$res = $dbr->query( $sql, "wfSpecialImagelist" );
 
+	$dirmark = $wgLang->getDirMark(); // to keep text in correct direction
+	$dir = contentdir();
+
 	while ( $s = $dbr->fetchObject( $res ) ) {
 		$name = $s->img_name;
 		$ut = $s->img_user_text;
@@ -95,7 +98,6 @@
 			$ul = $sk->makeLinkObj( Title::makeTitle( NS_USER, $ut ), $ut );
 		}
 
-		$dirmark = $wgContLang->getDirMark(); // to keep text in correct direction
 
 		$ilink = "<a href=\"" . htmlspecialchars( Image::imageUrl( $name ) ) .
 		  "\">" . strtr(htmlspecialchars( $name ), '_', ' ') . "</a>";
@@ -108,8 +110,8 @@
 
 		$date = $wgLang->timeanddate( $s->img_timestamp, true );
 		$comment = $sk->commentBlock( $s->img_description );
-
-		$l = "({$desc}) {$dirmark}{$ilink} . . {$dirmark}{$nb} . . {$dirmark}{$ul}".
+		
+		$l = "({$desc}) {$dirmark}<span{$dir}>{$ilink}</span> . . {$dirmark}{$nb} . . {$dirmark}{$ul}".
 			" . . {$dirmark}{$date} . . {$dirmark}{$comment}<br />\n";
 		$wgOut->addHTML( $l );
 	}
--- includes/SpecialListredirects.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SpecialListredirects.php	2006-05-28 16:21:34.000000000 +0200
@@ -31,7 +31,7 @@
 	}
 
 	function formatResult( $skin, $result ) {
-		global $wgContLang;
+		global $wgLang, $wgContLang;
 	
 		# Make a link to the redirect itself
 		$rd_title = Title::makeTitle( $result->namespace, $result->title );
@@ -54,7 +54,15 @@
 		}
 
 		# Check the language; RTL wikis need a &larr;
-		$arr = $wgContLang->isRTL() ? ' &larr; ' : ' &rarr; ';
+		$arr = $wgLang->isRTL() ? ' &rlm;&larr; ' : ' &lrm;&rarr; ';
+		# if directionality is different, put <span> around
+		# the article names links
+		if ($wgLang->isRTL() != $wgContLang->isRTL()) {
+			$rd_link = "<span" . contentdir() . ">" .
+				$rd_link . "</span>";
+			$targetLink = "<span" . contentdir() . ">" .
+				$targetLink . "</span>";
+		}
 
 		# Format the whole thing and return it
 		return( $rd_link . $arr . $targetLink );
@@ -69,4 +77,4 @@
 	$lrp->doQuery( $offset, $limit );
 }
 
-?>
\ Pas de fin de ligne à la fin du fichier.
+?>
--- includes/SpecialLog.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SpecialLog.php	2006-05-27 18:40:48.000000000 +0200
@@ -333,7 +333,8 @@
 		}
 
 		$action = LogPage::actionText( $s->log_type, $s->log_action, $title, $this->skin, $paramArray, true, true );
-		$out = "<li>$time $userLink $action $comment $revert</li>\n";
+		$dirmark = $wgLang->getDirMark();
+		$out = "<li>{$time} {$dirmark}{$userLink} {$dirmark}{$action} {$dirmark}{$comment} {$dirmark}{$revert}</li>\n";
 		return $out;
 	}
 
--- includes/SpecialNewpages.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SpecialNewpages.php	2006-05-27 18:42:47.000000000 +0200
@@ -72,10 +72,10 @@
 	}
 
 	function formatResult( $skin, $result ) {
-		global $wgLang, $wgContLang, $wgUser, $wgUseRCPatrol;
+		global $wgLang, $wgLang, $wgContLang, $wgUser, $wgUseRCPatrol;
 		$u = $result->user;
 		$ut = $result->user_text;
-		$dirmark = $wgContLang->getDirMark(); // To keep text in correct order
+		$dirmark = $wgLang->getDirMark(); // To keep text in correct order
 
 		$length = wfMsgExt( 'nbytes', array('parsemag', 'escape'),
 			$wgLang->formatNum( $result->length ) );
@@ -92,6 +92,9 @@
 
 		$userLink = $skin->userLink( $u, $ut );
 		$userTools = $skin->userToolLinks( $u, $ut );
+		if ($wgLang->isRTL() != $wgContLang->isRTL()) {
+			$link = "<span" . contentdir() . ">$link</span>";
+		}
 
 		$s = "{$d} {$dirmark}{$link} {$dirmark}({$length}) . . " .
 			"{$dirmark}{$userLink}{$dirmark}{$userTools}";
--- includes/SpecialPreferences.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SpecialPreferences.php	2006-05-28 17:26:07.000000000 +0200
@@ -386,12 +386,14 @@
 	 * @access private
 	 */
 	function namespacesCheckboxes() {
-		global $wgContLang;
+		global $wgLang, $wgContLang;
 
 		# Determine namespace checkboxes
 		$namespaces = $wgContLang->getNamespaces();
 		$r1 = null;
 
+		$dirmark = $wgLang->getDirMark();
+
 		foreach ( $namespaces as $i => $name ) {
 			if ($i < 0)
 				continue;
@@ -401,7 +403,7 @@
 			if ( empty($name) )
 				$name = wfMsg( 'blanknamespace' );
 
-			$r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> <label for='wpNs$i'>{$name}</label><br />\n";
+			$r1 .= "<input type='checkbox' value='1' name='wpNs$i' id='wpNs$i' {$checked}/> {$dirmark}<label for='wpNs$i'>{$name}</label><br />\n";
 		}
 		return $r1;
 	}
@@ -437,7 +439,12 @@
 	}
 
 	function addRow($td1, $td2) {
-		return "<tr><td align='right'>$td1</td><td align='left'>$td2</td></tr>";
+		global $wgLang;
+		if ($wgLang->isRTL()) {
+			return "<tr><td align='left'>$td1</td><td align='right'>$td2</td></tr>";
+		} else {
+			return "<tr><td align='right'>$td1</td><td align='left'>$td2</td></tr>";
+		}
 	}
 
 	/**
--- includes/SpecialPrefixindex.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SpecialPrefixindex.php	2006-05-28 14:29:21.000000000 +0200
@@ -52,7 +52,7 @@
  * @param string $from list all pages from this name (default FALSE)
  */
 function showChunk( $namespace = NS_MAIN, $from, $including = false ) {
-	global $wgOut, $wgUser, $wgContLang;
+	global $wgOut, $wgUser, $wgLang, $wgContLang;
 
 	$fname = 'indexShowChunk';
 
@@ -87,14 +87,23 @@
 	$out = '<table style="background: inherit;" border="0" width="100%">';
 
 	$namespaces = $wgContLang->getFormattedNamespaces();
+
+	if ($wgLang->isRTL() != $wgContLang->isRTL()) {
+		$spandiropen = "<span" . contentdir() . ">";
+		$spandirclose = "</span>";
+	} else {
+		$spandiropen = '';
+		$spandirclose = '';
+	}
+
 	while( ($n < $this->maxPerPage) && ($s = $dbr->fetchObject( $res )) ) {
 		$t = Title::makeTitle( $s->page_namespace, $s->page_title );
 		if( $t ) {
-			$link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
+			$link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) . $spandiropen .
 				$sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
-				($s->page_is_redirect ? '</div>' : '' );
+				($s->page_is_redirect ? '</div>' : '' ) . $spandirclose;
 		} else {
-			$link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
+			$link = $spandiropen . '[[' . htmlspecialchars( $s->page_title ) . ']]' . $spandirclose;
 		}
 		if( $n % 3 == 0 ) {
 			$out .= '<tr>';
--- includes/SpecialShortpages.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SpecialShortpages.php	2006-05-27 18:43:18.000000000 +0200
@@ -58,7 +58,10 @@
 		$title = Title::makeTitle( $result->namespace, $result->title );
 		$link = $skin->makeKnownLinkObj( $title, htmlspecialchars( $wgContLang->convert( $title->getPrefixedText() ) ) );
 		$histlink = $skin->makeKnownLinkObj( $title, wfMsgHtml('hist'), 'action=history' );
-		$dirmark = $wgContLang->getDirMark();
+		$dirmark = $wgLang->getDirMark();
+		if ($wgLang->isRTL() != $wgContLang->isRTL()) {
+			$link = "<span" . contentdir() . ">$link</span>";
+		}
 
 		return "({$histlink}) {$dirmark}$link {$dirmark}({$nb})";
 	}
--- includes/SpecialUnusedimages.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SpecialUnusedimages.php	2006-05-27 18:49:08.000000000 +0200
@@ -48,14 +48,16 @@
 		$title = Title::makeTitle( NS_IMAGE, $result->title );
 
 		$imageUrl = htmlspecialchars( Image::imageUrl( $result->title ) );
-		$dirmark = $wgContLang->getDirMark(); // To keep text in correct order
+		$dirmark = $wgLang->getDirMark(); // To keep text in correct order
+		$dir = ($wgLang->isRTL() != $wgContLang->isRTL()) ?
+			contentdir() : "";
 
 		$return =
 		# The 'desc' linking to the image page
 		'('.$skin->makeKnownLinkObj( $title, wfMsg('imgdesc') ).') ' . $dirmark .
 
 		# Link to the image itself
-		'<a href="' . $imageUrl . '">' . htmlspecialchars( $title->getText() ) .
+		'<a href="' . $imageUrl . '"' . $dir . '>' . htmlspecialchars( $title->getText() ) .
 			'</a> . . ' . $dirmark .
 
 		# Last modified date
--- includes/SpecialUpload.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SpecialUpload.php	2006-05-27 18:15:52.000000000 +0200
@@ -514,6 +514,7 @@
 	function uploadWarning( $warning ) {
 		global $wgOut;
 		global $wgUseCopyrightUpload;
+		global $wgLang;
 
 		$this->mSessionKey = $this->stashSession();
 		if( !$this->mSessionKey ) {
@@ -531,6 +532,8 @@
 		$titleObj = Title::makeTitle( NS_SPECIAL, 'Upload' );
 		$action = $titleObj->escapeLocalURL( 'action=submit' );
 
+		$left = ($wgLang->isRTL()) ? "right" : "left";
+		$right = ($wgLang->isRTL()) ? "left" : "right";
 		if ( $wgUseCopyrightUpload )
 		{
 			$copyright =  "
@@ -553,16 +556,16 @@
 	<table border='0'>
 		<tr>
 			<tr>
-				<td align='right'>
+				<td align='${right}'>
 					<input tabindex='2' type='submit' name='wpUpload' value=\"$save\" />
 				</td>
-				<td align='left'>$iw</td>
+				<td align='${left}'>$iw</td>
 			</tr>
 			<tr>
-				<td align='right'>
+				<td align='${right}'>
 					<input tabindex='2' type='submit' name='wpReUpload' value=\"{$reupload}\" />
 				</td>
-				<td align='left'>$reup</td>
+				<td align='${left}'>$reup</td>
 			</tr>
 		</tr>
 	</table></form>\n" );
@@ -578,6 +581,7 @@
 	function mainUploadForm( $msg='' ) {
 		global $wgOut, $wgUser;
 		global $wgUseCopyrightUpload;
+		global $wgLang;
 
 		$cols = intval($wgUser->getOption( 'cols' ));
 		$ew = $wgUser->getOption( 'editwidth' );
@@ -616,24 +620,26 @@
 			? 'checked="checked"'
 			: '';
 
+		$left = ($wgLang->isRTL()) ? "right" : "left";
+		$right = ($wgLang->isRTL()) ? "left" : "right";
 		$wgOut->addHTML( "
 	<form id='upload' method='post' enctype='multipart/form-data' action=\"$action\">
 		<table border='0'>
 		<tr>
-			<td align='right'><label for='wpUploadFile'>{$sourcefilename}:</label></td>
-			<td align='left'>
+			<td align='{$right}'><label for='wpUploadFile'>{$sourcefilename}:</label></td>
+			<td align='{$left}'>
 				<input tabindex='1' type='file' name='wpUploadFile' id='wpUploadFile' " . ($this->mDestFile?"":"onchange='fillDestFilename()' ") . "size='40' />
 			</td>
 		</tr>
 		<tr>
-			<td align='right'><label for='wpDestFile'>{$destfilename}:</label></td>
-			<td align='left'>
+			<td align='{$right}'><label for='wpDestFile'>{$destfilename}:</label></td>
+			<td align='{$left}'>
 				<input tabindex='2' type='text' name='wpDestFile' id='wpDestFile' size='40' value=\"$encDestFile\" />
 			</td>
 		</tr>
 		<tr>
-			<td align='right'><label for='wpUploadDescription'>{$summary}</label></td>
-			<td align='left'>
+			<td align='{$right}'><label for='wpUploadDescription'>{$summary}</label></td>
+			<td align='{$left}'>
 				<textarea tabindex='3' name='wpUploadDescription' id='wpUploadDescription' rows='6' cols='{$cols}'{$ew}>" . htmlspecialchars( $this->mUploadDescription ) . "</textarea>
 			</td>
 		</tr>
@@ -642,8 +648,8 @@
 		if ( $licenseshtml != '' ) {
 			global $wgStylePath;
 			$wgOut->addHTML( "
-			<td align='right'><label for='wpLicense'>$license:</label></td>
-			<td align='left'>
+			<td align='{$right}'><label for='wpLicense'>$license:</label></td>
+			<td align='{$left}'>
 				<script type='text/javascript' src=\"$wgStylePath/common/upload.js\"></script>
 				<select name='wpLicense' id='wpLicense' tabindex='4'
 					onchange='licenseSelectorCheck()'>
@@ -663,11 +669,11 @@
 			$uploadsource = htmlspecialchars( $this->mUploadSource );
 			
 			$wgOut->addHTML( "
-			        <td align='right' nowrap='nowrap'><label for='wpUploadCopyStatus'>$filestatus:</label></td>
+			        <td align='${right}' nowrap='nowrap'><label for='wpUploadCopyStatus'>$filestatus:</label></td>
 			        <td><input tabindex='5' type='text' name='wpUploadCopyStatus' id='wpUploadCopyStatus' value=\"$copystatus\" size='40' /></td>
 		        </tr>
 			<tr>
-		        	<td align='right'><label for='wpUploadCopyStatus'>$filesource:</label></td>
+		        	<td align='${right}'><label for='wpUploadCopyStatus'>$filesource:</label></td>
 			        <td><input tabindex='6' type='text' name='wpUploadSource' id='wpUploadCopyStatus' value=\"$uploadsource\" size='40' /></td>
 			</tr>
 			<tr>
@@ -689,12 +695,12 @@
 	</tr>
 	<tr>
 		<td></td>
-		<td align='left'><input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\" /></td>
+		<td align='${left}'><input tabindex='9' type='submit' name='wpUpload' value=\"{$ulb}\" /></td>
 	</tr>
 
 	<tr>
 		<td></td>
-		<td align='left'>
+		<td align='${left}'>
 		" );
 		$wgOut->addWikiText( wfMsgForContent( 'edittools' ) );
 		$wgOut->addHTML( "
--- includes/SpecialWatchlist.php_old	2006-05-25 05:40:57.000000000 +0200
+++ includes/SpecialWatchlist.php	2006-05-28 22:01:52.000000000 +0200
@@ -195,6 +195,10 @@
 		while( $s = $dbr->fetchObject( $res ) ) {
 			$list[$s->wl_namespace][$s->wl_title] = $s->page_is_redirect;
 		}
+		
+		$dirmark = $wgLang->getDirMark();
+		$dir = ($wgLang->isRTL() != $wgContLang->isRTL()) ?
+			contentdir() : "";
 
 		// TODO: Display a TOC
 		foreach($list as $ns => $titles) {
@@ -211,7 +215,6 @@
 						htmlspecialchars( $s->wl_title ) . '" in namespace ' . $s->wl_namespace . " -->\n"
 					);
 				} else {
-					global $wgContLang;
 					$toolLinks = array();
 					$titleText = $titleObj->getPrefixedText();
 					$pageLink = $sk->makeLinkObj( $titleObj );
@@ -219,15 +222,16 @@
 					if( $titleObj->exists() )
 						$toolLinks[] = $sk->makeKnownLinkObj( $titleObj, wfMsgHtml( 'history_short' ), 'action=history' );
 					$toolLinks = '(' . implode( ' | ', $toolLinks ) . ')';
-					$checkbox = '<input type="checkbox" name="id[]" value="' . htmlspecialchars( $titleObj->getPrefixedText() ) . '" /> ' . ( $wgContLang->isRTL() ? '&rlm;' : '&lrm;' );
+					$checkbox = '<input type="checkbox" name="id[]" value="' . htmlspecialchars( $titleObj->getPrefixedText() ) . '" /> ';
 					if( $redir ) {
-						$spanopen = '<span class="watchlistredir">';
+						$spanopen = '<span class="watchlistredir"' . $dir . '>';
 						$spanclosed = '</span>';
 					} else {
-						$spanopen = $spanclosed = '';
+						$spanopen = ($dir) ? '<span' . $dir . '>' : '';
+						$spanclosed = ($dir) ? '</span>' : '';
 					}
 					
-					$wgOut->addHTML( "<li>{$checkbox}{$spanopen}{$pageLink}{$spanclosed} {$toolLinks}</li>\n" );
+					$wgOut->addHTML( "<li>{$checkbox}{$dirmark}{$spanopen}{$pageLink}{$spanclosed} {$dirmark}{$toolLinks}</li>\n" );
 				}
 			}
 			$wgOut->addHTML( '</ul>' );
--- skins/monobook/rtl.css_old	2006-05-26 17:15:47.000000000 +0200
+++ skins/monobook/rtl.css	2006-05-27 16:23:30.000000000 +0200
@@ -52,19 +52,11 @@
 }
 
 /* Fix alignment */
-.documentByLine,
 .portletDetails,
 .portletMore,
 #p-personal {
 	text-align: left;
 }
-
-div div.thumbcaption {
-	text-align: right;
-}
-
-div.magnify,
-#div.townBox,
 #p-logo {
 	left: auto;
 	right: 0;
@@ -73,7 +65,20 @@
 	left: auto;
 	right: 0;
 }
+#p-navigation .pBody {
+	padding-right: auto;
+}
 
+/* the icon in front of the user name, single quotes
+in bg url to hide it from iemac */
+li#pt-userpage,
+li#pt-anonuserpage,
+li#pt-login {
+	background: url(user.gif) top right no-repeat;
+	padding-left: 0px;
+	padding-right: 20px;
+	text-transform: none;
+}
 #p-cactions {
 	left: auto;
 	right: 11.5em;
@@ -104,15 +109,15 @@
 /* Fix margins for non-css2 browsers */
 /* top right bottom left */
 
-ul {
+.portlet ul {
 	margin-left: 0;
 	margin-right: 1.5em;
 }
-ol {
+.portlet ol {
 	margin-left: 0;
 	margin-right: 2.4em;
 }
-dd {
+.portlet dd {
 	margin-left: 0;
 	margin-right: 1.6em;
 }
@@ -120,24 +125,6 @@
 	margin-right: 1em;
 	margin-left: 0;
 }
-.tocindent {
-	margin-left: 0;
-	margin-right: 2em;
-}
-div.tright, div.floatright, table.floatright {
-	clear: none;
-}
-div.tleft, div.floatleft, table.floatleft {
-	clear: left;
-}
-div.townBox {
-	margin-left: 0;
-	margin-right: 1em;
-}
-div.townBox dl dd {
-	margin-left: 0;
-	margin-right: 1.1em;
-}
 #p-personal li {
 	margin-left: 0;
 	margin-right: 1em;
@@ -152,11 +139,6 @@
 #p-personal li {
 	float: left;
 }
-/* Fix link icons */
-.external {
-	padding: 0 !important;
-	background: none !important;
-}
 #footer {
 	clear: both;
 }
@@ -191,16 +173,6 @@
 	padding-right: 2em;
 }
 
-/* workaround for moz bug, displayed bullets on left side */
-
-#toc ul {
-	text-align: right;
-}
-
-#toc ul ul {
-	margin: 0 2em 0 0;
-}
-
 input#wpSave, input#wpDiff {
 	margin-right: 0;
 	margin-left: .33em;
--- skins/monobook/content_rtl.css_old	2006-05-26 16:01:20.000000000 +0200
+++ skins/monobook/content_rtl.css	2006-05-26 19:52:06.000000000 +0200
@@ -0,0 +1,100 @@
+/*
+Right-to-left fixes for MonoBook.
+Places sidebar on right, tweaks various alignment issues.
+
+Works mostly ok nicely on Safari 1.2.1; fine in Mozilla.
+
+Safari bugs (1.2.1):
+* Tabs are still appearing in left-to-right order. (Try after localizing)
+
+Opera bugs (7.23 linux):
+* Some bits of ltr text (sidebar box titles) have forward and backward versions overlapping each other
+
+IE/mac bugs:
+* The thing barfs on Hebrew and Arabic anyway, so no point testing.
+
+Missing features due to lack of support:
+* external link icons
+
+To test:
+* Opera6
+* IE 5.0
+* etc
+
+*/
+#realContent {
+	direction: rtl;
+/*    unicode-bidi: bidi-override;*/
+	unicode-bidi: embed;
+}
+
+/* Fix alignment */
+.documentByLine {
+	text-align: left;
+}
+
+div div.thumbcaption {
+	text-align: right;
+}
+
+div.magnify,
+#div.townBox {
+	left: auto;
+	right: 0;
+}
+
+/* Fix margins for non-css2 browsers */
+/* top right bottom left */
+
+ul {
+	margin-left: 0;
+	margin-right: 1.5em;
+}
+ol {
+	margin-left: 0;
+	margin-right: 2.4em;
+}
+dd {
+	margin-left: 0;
+	margin-right: 1.6em;
+}
+/* ??? */
+li { 
+	margin-left: 0;
+	margin-right: 2.4em;
+}
+.tocindent {
+	margin-left: 0;
+	margin-right: 2em;
+}
+div.tright, div.floatright, table.floatright {
+	clear: none;
+}
+div.tleft, div.floatleft, table.floatleft {
+	clear: left;
+}
+div.townBox {
+	margin-left: 0;
+	margin-right: 1em;
+}
+div.townBox dl dd {
+	margin-left: 0;
+	margin-right: 1.1em;
+}
+/* Fix link icons */
+.external {
+	padding: 0 !important;
+	background: none !important;
+}
+
+
+
+/* workaround for moz bug, displayed bullets on left side */
+
+#toc ul {
+	text-align: right;
+}
+
+#toc ul ul {
+	margin: 0 2em 0 0;
+}
--- skins/monobook/main.css_old	2006-05-26 17:38:55.000000000 +0200
+++ skins/monobook/main.css	2006-05-28 21:47:03.000000000 +0200
@@ -569,7 +569,7 @@
 ** keep the whitespace in front of the ^=, hides rule from konqueror
 ** this is css3, the validator doesn't like it when validating as css2
 */
-#bodyContent a.external,
+#bodyContent a.external[DIR="ltr"],
 #bodyContent a[href ^="gopher://"] {
 	background: url(external.png) center right no-repeat;
 	padding-right: 13px;
@@ -676,6 +676,8 @@
 	list-style-type: square;
 	list-style-image: url(bullet.gif);
 	font-size: 95%;
+	margin: .3em 0 0 1.5em;
+	padding: 0;
 }
 .portlet li {
 	padding: 0;
@@ -718,7 +720,7 @@
 }
 
 #p-navigation .pBody {
-	padding-right: 0;
+/*	padding-right: 0; */
 }
 
 #p-navigation a {
--- skins/common/common_content_rtl.css_old	2006-05-26 15:59:42.000000000 +0200
+++ skins/common/common_content_rtl.css	2006-05-26 18:42:41.000000000 +0200
@@ -0,0 +1 @@
+/* RTL specific styles for date content (not layout) go here */
--- skins/MonoBook.php_old	2006-05-25 13:58:46.000000000 +0200
+++ skins/MonoBook.php	2006-05-27 19:24:19.000000000 +0200
@@ -51,7 +51,7 @@
 		wfSuppressWarnings();
 
 ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php $this->text('lang') ?>" lang="<?php $this->text('lang') ?>" dir="<?php $this->text('dir') ?>">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php $this->text('uselang') ?>" lang="<?php $this->text('uselang') ?>" dir="<?php $this->text('dir') ?>">
 	<head>
 		<meta http-equiv="Content-Type" content="<?php $this->text('mimetype') ?>; charset=<?php $this->text('charset') ?>" />
 		<?php $this->html('headlinks') ?>
@@ -93,7 +93,7 @@
 	<div id="content">
 		<a name="top" id="top"></a>
 		<?php if($this->data['sitenotice']) { ?><div id="siteNotice"><?php $this->html('sitenotice') ?></div><?php } ?>
-		<h1 class="firstHeading"><?php $this->data['displaytitle']!=""?$this->text('title'):$this->html('title') ?></h1>
+		<h1 class="firstHeading"<?php $this->text('titledir') ?>><?php $this->data['displaytitle']!=""?$this->text('title'):$this->html('title') ?></h1>
 		<div id="bodyContent">
 			<h3 id="siteSub"><?php $this->msg('tagline') ?></h3>
 			<div id="contentSub"><?php $this->html('subtitle') ?></div>
@@ -124,6 +124,9 @@
 		<h5><?php $this->msg('personaltools') ?></h5>
 		<div class="pBody">
 			<ul>
+<?php 			if ($this->data['rtl'] == "1") 
+				$this->data['personal_urls'] = 
+				array_reverse($this->data['personal_urls'], true); ?>
 <?php 			foreach($this->data['personal_urls'] as $key => $item) { ?>
 				<li id="pt-<?php echo htmlspecialchars($key) ?>"<?php
 					if ($item['active']) { ?> class="active"<?php } ?>><a href="<?php
--- skins/Standard.php_old	2006-05-26 22:37:06.000000000 +0200
+++ skins/Standard.php	2006-05-26 23:45:48.000000000 +0200
@@ -52,16 +52,18 @@
 	 *
 	 */
 	function doGetUserStyles() {
-		global $wgStylePath;
+		global $wgStylePath, $wgLang, $wgUser;
 
 		$s = parent::doGetUserStyles();
 		$qb = $this->qbSetting();
 
-		if ( 2 == $qb ) { # Right
+		if ( (!$wgUser->isLoggedIn() && $wgLang->isRTL() ) ||
+		     ( 2 == $qb ) ) { # Right
 			$s .= "#quickbar { position: absolute; top: 4px; right: 4px; " .
 			  "border-left: 2px solid #000000; }\n" .
 			  "#article { margin-left: 4px; margin-right: 152px; }\n";
-		} else if ( 1 == $qb || 3 == $qb ) {
+		} else if ( (!$wgUser->isLoggedIn()) ||
+		  ( 1 == $qb || 3 == $qb ) ) {
 			$s .= "#quickbar { position: absolute; top: 4px; left: 4px; " .
 			  "border-right: 1px solid gray; }\n" .
 			  "#article { margin-left: 152px; margin-right: 4px; }\n";
@@ -90,7 +92,7 @@
 	}
 
 	function doAfterContent() {
-		global $wgContLang;
+		global $wgLang;
 		$fname =  'SkinStandard::doAfterContent';
 		wfProfileIn( $fname );
 		wfProfileIn( $fname.'-1' );
@@ -105,14 +107,14 @@
 		$qb = $this->qbSetting();
 		$shove = ($qb != 0);
 		$left = ($qb == 1 || $qb == 3);
-		if($wgContLang->isRTL()) $left = !$left;
+		if($wgLang->isRTL()) $left = !$left;
 
 		if ( $shove && $left ) { # Left
 				$s .= $this->getQuickbarCompensator();
 		}
 		wfProfileOut( $fname.'-2' );
 		wfProfileIn( $fname.'-3' );
-		$l = $wgContLang->isRTL() ? 'right' : 'left';
+		$l = $wgLang->isRTL() ? 'right' : 'left';
 		$s .= "<td class='bottom' align='$l' valign='top'>";
 
 		$s .= $this->bottomLinks();
--- skins/CologneBlue.php_old	2006-05-25 05:40:33.000000000 +0200
+++ skins/CologneBlue.php	2006-05-26 23:32:29.000000000 +0200
@@ -98,14 +98,15 @@
 	}
 
 	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
