From 71432fb487a9f93a244a9f0761d80a33839d0567 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 22 Aug 2009 01:24:04 +0000 Subject: [PATCH] Pet peeve time: reduce clutter from common $wgContLang->isRTL() ? 'x' : 'y' pattern. :) 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 | 2 +- includes/Linker.php | 2 +- includes/OutputPage.php | 4 +-- includes/Pager.php | 21 +++++++----- includes/Skin.php | 8 ++--- includes/SkinTemplate.php | 2 +- .../specials/SpecialFileDuplicateSearch.php | 2 +- includes/specials/SpecialUpload.php | 5 +-- includes/specials/SpecialVersion.php | 7 ++-- languages/Language.php | 32 +++++++++++++++++++ skins/Standard.php | 2 +- 11 files changed, 59 insertions(+), 28 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 894bf5d9eb..eca3883b73 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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() ? '←' : '→'; // should -> and <- be used instead of entities? diff --git a/includes/Linker.php b/includes/Linker.php index f833fcd01c..7a86100ce0 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -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; } diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 907b81f6d1..4c68b15ee3 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1689,7 +1689,7 @@ class OutputPage { $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() )); } - $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr'; + $dir = $wgContLang->getDir(); if ( $wgHtml5 ) { $ret .= "\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 ''; } diff --git a/includes/Pager.php b/includes/Pager.php index 8bd7da2511..054ca38286 100644 --- a/includes/Pager.php +++ b/includes/Pager.php @@ -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(); diff --git a/includes/Skin.php b/includes/Skin.php index d885afb168..8d32a04dd7 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -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 .= "\n"; $s .= $this->topLinks(); $s .= "

" . $this->pageTitleLinks() . "

\n"; - $r = $wgContLang->isRTL() ? 'left' : 'right'; + $r = $wgContLang->alignEnd(); $s .= "\n"; $s .= $this->nameAndLogin(); $s .= "\n
" . $this->searchForm() . ""; @@ -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 = ""; $pop = ''; diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index cb260ef842..c9bec3b2ce 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -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 ) ); diff --git a/includes/specials/SpecialFileDuplicateSearch.php b/includes/specials/SpecialFileDuplicateSearch.php index b86fcbea6f..0ed7020a2d 100644 --- a/includes/specials/SpecialFileDuplicateSearch.php +++ b/includes/specials/SpecialFileDuplicateSearch.php @@ -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 ); diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 6d9fd3bd82..7c51fa1b59 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -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; diff --git a/includes/specials/SpecialVersion.php b/includes/specials/SpecialVersion.php index 66c621dc7a..94aff45f58 100644 --- a/includes/specials/SpecialVersion.php +++ b/includes/specials/SpecialVersion.php @@ -33,11 +33,8 @@ class SpecialVersion extends SpecialPage { $this->setHeaders(); $this->outputHeader(); - if( $wgContLang->isRTL() ) { - $wgOut->addHTML( '
' ); - } else { - $wgOut->addHTML( '
' ); - } + $wgOut->addHTML( Xml::openElement( 'div', + array( 'dir' => $wgContLang->getDir() ) ) ); $text = $this->MediaWikiCredits() . $this->softwareInformation() . diff --git a/languages/Language.php b/languages/Language.php index 0836cf60d8..19520fa76d 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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 diff --git a/skins/Standard.php b/skins/Standard.php index 32455eddf0..1dc2d48707 100644 --- a/skins/Standard.php +++ b/skins/Standard.php @@ -101,7 +101,7 @@ class SkinStandard extends Skin { } wfProfileOut( __METHOD__ . '-2' ); wfProfileIn( __METHOD__ . '-3' ); - $l = $wgContLang->isRTL() ? 'right' : 'left'; + $l = $wgContLang->alignStart(); $s .= ""; $s .= $this->bottomLinks(); -- 2.20.1