Pet peeve time: reduce clutter from common $wgContLang->isRTL() ? 'x' : 'y' pattern. :)
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 22 Aug 2009 01:24:04 +0000 (01:24 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 22 Aug 2009 01:24:04 +0000 (01:24 +0000)
Introduced helpers:
  $lang->getDir() returns 'ltr' or 'rtl' for HTML 'dir' attrib
  $lang->alignStart() returns 'left' or 'right' for HTML 'align' attrib or CSS 'text-align' property
  $lang->alignEnd() returns 'right' or 'left'

And cleaned up a couple arrays of icons to just reverse the order of items rather than repeating the items twice for each possibility.

includes/Article.php
includes/Linker.php
includes/OutputPage.php
includes/Pager.php
includes/Skin.php
includes/SkinTemplate.php
includes/specials/SpecialFileDuplicateSearch.php
includes/specials/SpecialUpload.php
includes/specials/SpecialVersion.php
languages/Language.php
skins/Standard.php

index 894bf5d..eca3883 100644 (file)
@@ -1292,7 +1292,7 @@ class Article {
                if( !is_array( $target ) ) {
                        $target = array( $target );
                }
-               $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
+               $imageDir = $wgContLang->getDir();
                $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
                $imageUrl2 = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
                $alt2 = $wgContLang->isRTL() ? '&larr;' : '&rarr;'; // should -> and <- be used instead of entities?
index f833fcd..7a86100 100644 (file)
@@ -484,7 +484,7 @@ class Linker {
                        # If  thumbnail width has not been provided, it is set
                        # to the default user option as specified in Language*.php
                        if ( $fp['align'] == '' ) {
-                               $fp['align'] = $wgContLang->isRTL() ? 'left' : 'right';
+                               $fp['align'] = $wgContLang->alignEnd();
                        }
                        return $prefix.$this->makeThumbLink2( $title, $file, $fp, $hp, $time, $query ).$postfix;
                }
index 907b81f..4c68b15 100644 (file)
@@ -1689,7 +1689,7 @@ class OutputPage {
                        $this->setHTMLTitle(  wfMsg( 'pagetitle', $this->getPageTitle() ));
                }
 
-               $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
+               $dir = $wgContLang->getDir();
 
                if ( $wgHtml5 ) {
                        $ret .= "<!doctype html>\n";
@@ -1909,7 +1909,7 @@ class OutputPage {
 
                if( isset( $options['dir'] ) ) {
                        global $wgContLang;
-                       $siteDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
+                       $siteDir = $wgContLang->getDir();
                        if( $siteDir != $options['dir'] )
                                return '';
                }
index 8bd7da2..054ca38 100644 (file)
@@ -837,17 +837,22 @@ abstract class TablePager extends IndexPager {
                        'last' => 'table_pager_last',
                );
                $images = array(
-                       'first' => $wgContLang->isRTL() ? 'arrow_last_25.png' : 'arrow_first_25.png',
-                       'prev' =>  $wgContLang->isRTL() ? 'arrow_right_25.png' : 'arrow_left_25.png',
-                       'next' =>  $wgContLang->isRTL() ? 'arrow_left_25.png' : 'arrow_right_25.png',
-                       'last' =>  $wgContLang->isRTL() ? 'arrow_first_25.png' : 'arrow_last_25.png',
+                       'first' => 'arrow_first_25.png',
+                       'prev' => 'arrow_left_25.png',
+                       'next' => 'arrow_right_25.png',
+                       'last' => 'arrow_last_25.png',
                );
                $disabledImages = array(
-                       'first' => $wgContLang->isRTL() ? 'arrow_disabled_last_25.png' : 'arrow_disabled_first_25.png',
-                       'prev' =>  $wgContLang->isRTL() ? 'arrow_disabled_right_25.png' : 'arrow_disabled_left_25.png',
-                       'next' =>  $wgContLang->isRTL() ? 'arrow_disabled_left_25.png' : 'arrow_disabled_right_25.png',
-                       'last' =>  $wgContLang->isRTL() ? 'arrow_disabled_first_25.png' : 'arrow_disabled_last_25.png',
+                       'first' => 'arrow_disabled_first_25.png',
+                       'prev' => 'arrow_disabled_left_25.png',
+                       'next' => 'arrow_disabled_right_25.png',
+                       'last' => 'arrow_disabled_last_25.png',
                );
+               if( $wgContLang->isRTL() ) {
+                       $keys = array_keys( $labels );
+                       $images = array_combine( $keys, array_reverse( $images ) );
+                       $disabledImages = array_combine( $keys, array_reverse( $disabledImages ) );
+               }
 
                $linkTexts = array();
                $disabledTexts = array();
index d885afb..8d32a04 100644 (file)
@@ -711,7 +711,7 @@ END;
                $a['onload'] = $wgOut->getOnloadHandler();
                $a['class'] =
                        'mediawiki' .
-                       ' '.( $wgContLang->isRTL() ? 'rtl' : 'ltr' ).
+                       ' '.( $wgContLang->getDir() ).
                        ' '.$this->getPageClasses( $this->mTitle ) .
                        ' skin-'. Sanitizer::escapeClass( $this->getSkinName() );
                return $a;
@@ -775,13 +775,13 @@ END;
                } elseif( $left ) {
                        $s .= $this->getQuickbarCompensator( $rows );
                }
-               $l = $wgContLang->isRTL() ? 'right' : 'left';
+               $l = $wgContLang->alignStart();
                $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 = $wgContLang->alignEnd();
                $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
                $s .= $this->nameAndLogin();
                $s .= "\n<br />" . $this->searchForm() . "</td>";
@@ -819,7 +819,7 @@ END;
 
                // Use Unicode bidi embedding override characters,
                // to make sure links don't smash each other up in ugly ways.
-               $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
+               $dir = $wgContLang->getDir();
                $embed = "<span dir='$dir'>";
                $pop = '</span>';
 
index cb260ef..c9bec3b 100644 (file)
@@ -276,7 +276,7 @@ class SkinTemplate extends Skin {
                $tpl->setRef( 'serverurl', $wgServer );
                $tpl->setRef( 'logopath', $wgLogo );
                $tpl->setRef( 'lang', $wgContLanguageCode );
-               $tpl->set( 'dir', $wgContLang->isRTL() ? 'rtl' : 'ltr' );
+               $tpl->set( 'dir', $wgContLang->getDir() );
                $tpl->set( 'rtl', $wgContLang->isRTL() );
                $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
                $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
index b86fcbe..0ed7020 100644 (file)
@@ -99,7 +99,7 @@ function wfSpecialFileDuplicateSearch( $par = null ) {
        );
 
        if( $hash != '' ) {
-               $align = $wgContLang->isRtl() ? 'left' : 'right';
+               $align = $wgContLang->alignEnd();
 
                # Show a thumbnail of the file
                $img = wfFindFile( $title );
index 6d9fd3b..7c51fa1 100644 (file)
@@ -330,14 +330,11 @@ class UploadForm extends SpecialPage {
                global $wgUser, $wgContLang;
                // Check for uppercase extension. We allow these filenames but check if an image
                // with lowercase extension exists already
-               $warning = '';
-               $align = $wgContLang->isRtl() ? 'left' : 'right';
-
                if( $exists === false )
                        return '';
 
                $warning = '';
-               $align = $wgContLang->isRtl() ? 'left' : 'right';
+               $align = $wgContLang->alignEnd();
 
                list( $existsType, $file ) = $exists;
 
index 66c621d..94aff45 100644 (file)
@@ -33,11 +33,8 @@ class SpecialVersion extends SpecialPage {
                $this->setHeaders();
                $this->outputHeader();
 
-               if( $wgContLang->isRTL() ) {
-                       $wgOut->addHTML( '<div dir="rtl">' );
-               } else {
-                       $wgOut->addHTML( '<div dir="ltr">' );
-               }
+               $wgOut->addHTML( Xml::openElement( 'div',
+                       array( 'dir' => $wgContLang->getDir() ) ) );
                $text = 
                        $this->MediaWikiCredits() .
                        $this->softwareInformation() .
index 0836cf6..19520fa 100644 (file)
@@ -1863,6 +1863,38 @@ class Language {
        function isRTL() { 
                return self::$dataCache->getItem( $this->mCode, 'rtl' );
        }
+       
+       /**
+        * Return the correct HTML 'dir' attribute value for this language.
+        * @return String
+        */
+       function getDir() {
+               return $this->isRTL() ? 'rtl' : 'ltr';
+       }
+       
+       /**
+        * Return 'left' or 'right' as appropriate alignment for line-start
+        * for this language's text direction.
+        *
+        * Should be equivalent to CSS3 'start' text-align value....
+        *
+        * @return String
+        */
+       function alignStart() {
+               return $this->isRTL() ? 'right' : 'left';
+       }
+       
+       /**
+        * Return 'right' or 'left' as appropriate alignment for line-end
+        * for this language's text direction.
+        *
+        * Should be equivalent to CSS3 'end' text-align value....
+        *
+        * @return String
+        */
+       function alignEnd() {
+               return $this->isRTL() ? 'left' : 'right';
+       }
 
        /**
         * A hidden direction mark (LRM or RLM), depending on the language direction
index 32455ed..1dc2d48 100644 (file)
@@ -101,7 +101,7 @@ class SkinStandard extends Skin {
                }
                wfProfileOut( __METHOD__ . '-2' );
                wfProfileIn( __METHOD__ . '-3' );
-               $l = $wgContLang->isRTL() ? 'right' : 'left';
+               $l = $wgContLang->alignStart();
                $s .= "<td class='bottom' align='$l' valign='top'>";
 
                $s .= $this->bottomLinks();