r55462 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55461‎ | r55462 | r55463 >
Date:01:24, 22 August 2009
Author:brion
Status:ok
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Pager.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialFileDuplicateSearch.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialVersion.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/skins/Standard.php (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/Standard.php
@@ -101,7 +101,7 @@
102102 }
103103 wfProfileOut( __METHOD__ . '-2' );
104104 wfProfileIn( __METHOD__ . '-3' );
105 - $l = $wgContLang->isRTL() ? 'right' : 'left';
 105+ $l = $wgContLang->alignStart();
106106 $s .= "<td class='bottom' align='$l' valign='top'>";
107107
108108 $s .= $this->bottomLinks();
Index: trunk/phase3/includes/Article.php
@@ -1292,7 +1292,7 @@
12931293 if( !is_array( $target ) ) {
12941294 $target = array( $target );
12951295 }
1296 - $imageDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
 1296+ $imageDir = $wgContLang->getDir();
12971297 $imageUrl = $wgStylePath . '/common/images/redirect' . $imageDir . '.png';
12981298 $imageUrl2 = $wgStylePath . '/common/images/nextredirect' . $imageDir . '.png';
12991299 $alt2 = $wgContLang->isRTL() ? '&larr;' : '&rarr;'; // should -> and <- be used instead of entities?
Index: trunk/phase3/includes/Linker.php
@@ -484,7 +484,7 @@
485485 # If thumbnail width has not been provided, it is set
486486 # to the default user option as specified in Language*.php
487487 if ( $fp['align'] == '' ) {
488 - $fp['align'] = $wgContLang->isRTL() ? 'left' : 'right';
 488+ $fp['align'] = $wgContLang->alignEnd();
489489 }
490490 return $prefix.$this->makeThumbLink2( $title, $file, $fp, $hp, $time, $query ).$postfix;
491491 }
Index: trunk/phase3/includes/OutputPage.php
@@ -1689,7 +1689,7 @@
16901690 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
16911691 }
16921692
1693 - $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
 1693+ $dir = $wgContLang->getDir();
16941694
16951695 if ( $wgHtml5 ) {
16961696 $ret .= "<!doctype html>\n";
@@ -1909,7 +1909,7 @@
19101910
19111911 if( isset( $options['dir'] ) ) {
19121912 global $wgContLang;
1913 - $siteDir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
 1913+ $siteDir = $wgContLang->getDir();
19141914 if( $siteDir != $options['dir'] )
19151915 return '';
19161916 }
Index: trunk/phase3/includes/SkinTemplate.php
@@ -276,7 +276,7 @@
277277 $tpl->setRef( 'serverurl', $wgServer );
278278 $tpl->setRef( 'logopath', $wgLogo );
279279 $tpl->setRef( 'lang', $wgContLanguageCode );
280 - $tpl->set( 'dir', $wgContLang->isRTL() ? 'rtl' : 'ltr' );
 280+ $tpl->set( 'dir', $wgContLang->getDir() );
281281 $tpl->set( 'rtl', $wgContLang->isRTL() );
282282 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
283283 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
Index: trunk/phase3/includes/specials/SpecialFileDuplicateSearch.php
@@ -99,7 +99,7 @@
100100 );
101101
102102 if( $hash != '' ) {
103 - $align = $wgContLang->isRtl() ? 'left' : 'right';
 103+ $align = $wgContLang->alignEnd();
104104
105105 # Show a thumbnail of the file
106106 $img = wfFindFile( $title );
Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -330,14 +330,11 @@
331331 global $wgUser, $wgContLang;
332332 // Check for uppercase extension. We allow these filenames but check if an image
333333 // with lowercase extension exists already
334 - $warning = '';
335 - $align = $wgContLang->isRtl() ? 'left' : 'right';
336 -
337334 if( $exists === false )
338335 return '';
339336
340337 $warning = '';
341 - $align = $wgContLang->isRtl() ? 'left' : 'right';
 338+ $align = $wgContLang->alignEnd();
342339
343340 list( $existsType, $file ) = $exists;
344341
Index: trunk/phase3/includes/specials/SpecialVersion.php
@@ -33,11 +33,8 @@
3434 $this->setHeaders();
3535 $this->outputHeader();
3636
37 - if( $wgContLang->isRTL() ) {
38 - $wgOut->addHTML( '<div dir="rtl">' );
39 - } else {
40 - $wgOut->addHTML( '<div dir="ltr">' );
41 - }
 37+ $wgOut->addHTML( Xml::openElement( 'div',
 38+ array( 'dir' => $wgContLang->getDir() ) ) );
4239 $text =
4340 $this->MediaWikiCredits() .
4441 $this->softwareInformation() .
Index: trunk/phase3/includes/Skin.php
@@ -711,7 +711,7 @@
712712 $a['onload'] = $wgOut->getOnloadHandler();
713713 $a['class'] =
714714 'mediawiki' .
715 - ' '.( $wgContLang->isRTL() ? 'rtl' : 'ltr' ).
 715+ ' '.( $wgContLang->getDir() ).
716716 ' '.$this->getPageClasses( $this->mTitle ) .
717717 ' skin-'. Sanitizer::escapeClass( $this->getSkinName() );
718718 return $a;
@@ -775,13 +775,13 @@
776776 } elseif( $left ) {
777777 $s .= $this->getQuickbarCompensator( $rows );
778778 }
779 - $l = $wgContLang->isRTL() ? 'right' : 'left';
 779+ $l = $wgContLang->alignStart();
780780 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
781781
782782 $s .= $this->topLinks();
783783 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
784784
785 - $r = $wgContLang->isRTL() ? 'left' : 'right';
 785+ $r = $wgContLang->alignEnd();
786786 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
787787 $s .= $this->nameAndLogin();
788788 $s .= "\n<br />" . $this->searchForm() . "</td>";
@@ -819,7 +819,7 @@
820820
821821 // Use Unicode bidi embedding override characters,
822822 // to make sure links don't smash each other up in ugly ways.
823 - $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
 823+ $dir = $wgContLang->getDir();
824824 $embed = "<span dir='$dir'>";
825825 $pop = '</span>';
826826
Index: trunk/phase3/includes/Pager.php
@@ -837,17 +837,22 @@
838838 'last' => 'table_pager_last',
839839 );
840840 $images = array(
841 - 'first' => $wgContLang->isRTL() ? 'arrow_last_25.png' : 'arrow_first_25.png',
842 - 'prev' => $wgContLang->isRTL() ? 'arrow_right_25.png' : 'arrow_left_25.png',
843 - 'next' => $wgContLang->isRTL() ? 'arrow_left_25.png' : 'arrow_right_25.png',
844 - 'last' => $wgContLang->isRTL() ? 'arrow_first_25.png' : 'arrow_last_25.png',
 841+ 'first' => 'arrow_first_25.png',
 842+ 'prev' => 'arrow_left_25.png',
 843+ 'next' => 'arrow_right_25.png',
 844+ 'last' => 'arrow_last_25.png',
845845 );
846846 $disabledImages = array(
847 - 'first' => $wgContLang->isRTL() ? 'arrow_disabled_last_25.png' : 'arrow_disabled_first_25.png',
848 - 'prev' => $wgContLang->isRTL() ? 'arrow_disabled_right_25.png' : 'arrow_disabled_left_25.png',
849 - 'next' => $wgContLang->isRTL() ? 'arrow_disabled_left_25.png' : 'arrow_disabled_right_25.png',
850 - 'last' => $wgContLang->isRTL() ? 'arrow_disabled_first_25.png' : 'arrow_disabled_last_25.png',
 847+ 'first' => 'arrow_disabled_first_25.png',
 848+ 'prev' => 'arrow_disabled_left_25.png',
 849+ 'next' => 'arrow_disabled_right_25.png',
 850+ 'last' => 'arrow_disabled_last_25.png',
851851 );
 852+ if( $wgContLang->isRTL() ) {
 853+ $keys = array_keys( $labels );
 854+ $images = array_combine( $keys, array_reverse( $images ) );
 855+ $disabledImages = array_combine( $keys, array_reverse( $disabledImages ) );
 856+ }
852857
853858 $linkTexts = array();
854859 $disabledTexts = array();
Index: trunk/phase3/languages/Language.php
@@ -1863,6 +1863,38 @@
18641864 function isRTL() {
18651865 return self::$dataCache->getItem( $this->mCode, 'rtl' );
18661866 }
 1867+
 1868+ /**
 1869+ * Return the correct HTML 'dir' attribute value for this language.
 1870+ * @return String
 1871+ */
 1872+ function getDir() {
 1873+ return $this->isRTL() ? 'rtl' : 'ltr';
 1874+ }
 1875+
 1876+ /**
 1877+ * Return 'left' or 'right' as appropriate alignment for line-start
 1878+ * for this language's text direction.
 1879+ *
 1880+ * Should be equivalent to CSS3 'start' text-align value....
 1881+ *
 1882+ * @return String
 1883+ */
 1884+ function alignStart() {
 1885+ return $this->isRTL() ? 'right' : 'left';
 1886+ }
 1887+
 1888+ /**
 1889+ * Return 'right' or 'left' as appropriate alignment for line-end
 1890+ * for this language's text direction.
 1891+ *
 1892+ * Should be equivalent to CSS3 'end' text-align value....
 1893+ *
 1894+ * @return String
 1895+ */
 1896+ function alignEnd() {
 1897+ return $this->isRTL() ? 'left' : 'right';
 1898+ }
18671899
18681900 /**
18691901 * A hidden direction mark (LRM or RLM), depending on the language direction

Status & tagging log