r2624 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r2623‎ | r2624 | r2625 >
Date:03:03, 6 March 2004
Author:vibber
Status:old
Tags:
Comment:
Add digit transformation function Language::formatNum() for Arabic and other
languages which need to use localized (decimal) digits. Sample implementation
for Arabic.
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SpecialImagelist.php (modified) (history)
  • /trunk/phase3/includes/SpecialLongpages.php (modified) (history)
  • /trunk/phase3/includes/SpecialNewpages.php (modified) (history)
  • /trunk/phase3/includes/SpecialPopularpages.php (modified) (history)
  • /trunk/phase3/includes/SpecialRecentchanges.php (modified) (history)
  • /trunk/phase3/includes/SpecialShortpages.php (modified) (history)
  • /trunk/phase3/includes/SpecialStatistics.php (modified) (history)
  • /trunk/phase3/includes/SpecialWatchlist.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/languages/LanguageAr.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialNewpages.php
@@ -20,13 +20,12 @@
2121 }
2222
2323 function formatResult( $skin, $result ) {
24 -
2524 global $wgLang;
2625
2726 $u = $result->cur_user;
2827 $ut = $result->cur_user_text;
2928
30 - $length = wfmsg( "nbytes", $result->cur_length );
 29+ $length = wfmsg( "nbytes", $wgLang->formatNum( $result->cur_length ) );
3130 $c = wfEscapeHTML( $result->cur_comment );
3231
3332 if ( 0 == $u ) { # not by a logged-in user
Index: trunk/phase3/includes/SpecialImagelist.php
@@ -36,7 +36,7 @@
3737 if ( 0 == $limit ) {
3838 $lt = wfMsg( "all" );
3939 } else {
40 - $lt = "${limit}";
 40+ $lt = $wgLang->formatNum( "${limit}" );
4141 $sql .= " LIMIT {$limit}";
4242 }
4343 $wgOut->addHTML( "<p>" . wfMsg( "imglegend" ) . "\n" );
@@ -65,7 +65,7 @@
6666 if ( ! $first ) { $fill .= " | "; }
6767 $first = false;
6868
69 - $fill .= $sk->makeKnownLink( $here, "{$num}",
 69+ $fill .= $sk->makeKnownLink( $here, $wgLang->formatNum( $num ),
7070 "sort=bysize&limit={$num}" );
7171 }
7272 $text = wfMsg( "showlast", $fill, $bysize );
@@ -77,7 +77,7 @@
7878 if ( ! $first ) { $fill .= " | "; }
7979 $first = false;
8080
81 - $fill .= $sk->makeKnownLink( $here, $num,
 81+ $fill .= $sk->makeKnownLink( $here, $wgLang->formatNum( $num ),
8282 "sort=bydate&limit={$num}" );
8383 }
8484 $text = wfMsg( "showlast", $fill, $bydate );
@@ -94,7 +94,7 @@
9595 $ilink = "<a href=\"" . wfImageUrl( $name ) .
9696 "\">{$name}</a>";
9797
98 - $nb = wfMsg( "nbytes", $s->img_size );
 98+ $nb = wfMsg( "nbytes", $wgLang->formatNum( $s->img_size ) );
9999 $l = "(" .
100100 $sk->makeKnownLink( $wgLang->getNsText(
101101 Namespace::getImage() ) . ":{$name}", wfMsg( "imgdesc" ) ) .
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -596,19 +596,22 @@
597597
598598 function wfShowingResults( $offset, $limit )
599599 {
600 - return wfMsg( "showingresults", $limit, $offset+1 );
 600+ global $wgLang;
 601+ return wfMsg( "showingresults", $wgLang->formatNum( $limit ), $wgLang->formatNum( $offset+1 ) );
601602 }
602603
603604 function wfShowingResultsNum( $offset, $limit, $num )
604605 {
605 - return wfMsg( "showingresultsnum", $limit, $offset+1, $num );
 606+ global $wgLang;
 607+ return wfMsg( "showingresultsnum", $wgLang->formatNum( $limit ), $wgLang->formatNum( $offset+1 ), $wgLang->formatNum( $num ) );
606608 }
607609
608610 function wfViewPrevNext( $offset, $limit, $link, $query = "", $atend = false )
609611 {
610 - global $wgUser;
611 - $prev = wfMsg( "prevn", $limit );
612 - $next = wfMsg( "nextn", $limit );
 612+ global $wgUser, $wgLang;
 613+ $fmtLimit = $wgLang->formatNum( $limit );
 614+ $prev = wfMsg( "prevn", $fmtLimit );
 615+ $next = wfMsg( "nextn", $fmtLimit );
613616 $link = wfUrlencode( $link );
614617
615618 $sk = $wgUser->getSkin();
@@ -640,12 +643,13 @@
641644
642645 function wfNumLink( $offset, $limit, $link, $query = "" )
643646 {
644 - global $wgUser;
 647+ global $wgUser, $wgLang;
645648 if ( "" == $query ) { $q = ""; }
646649 else { $q = "{$query}&"; }
647650 $q .= "limit={$limit}&offset={$offset}";
648651
649 - $s = "<a href=\"" . wfLocalUrlE( $link, $q ) . "\">{$limit}</a>";
 652+ $fmtLimit = $wgLang->formatNum( $limit );
 653+ $s = "<a href=\"" . wfLocalUrlE( $link, $q ) . "\">{$fmtLimit}</a>";
650654 return $s;
651655 }
652656
Index: trunk/phase3/includes/SpecialStatistics.php
@@ -2,7 +2,7 @@
33
44 function wfSpecialStatistics()
55 {
6 - global $wgUser, $wgOut;
 6+ global $wgUser, $wgOut, $wgLang;
77 $fname = "wfSpecialStatistics";
88
99 $wgOut->addHTML( "<h2>" . wfMsg( "sitestats" ) . "</h2>\n" );
@@ -21,9 +21,12 @@
2222 $good = $row->ss_good_articles;
2323
2424 $text = wfMsg( "sitestatstext",
25 - $total, $good, $views, $edits,
26 - sprintf( "%.2f", $total ? $edits / $total : 0 ),
27 - sprintf( "%.2f", $edits ? $views / $edits : 0 ) );
 25+ $wgLang->formatNum( $total ),
 26+ $wgLang->formatNum( $good ),
 27+ $wgLang->formatNum( $views ),
 28+ $wgLang->formatNum( $edits ),
 29+ $wgLang->formatNum( sprintf( "%.2f", $total ? $edits / $total : 0 ) ),
 30+ $wgLang->formatNum( sprintf( "%.2f", $edits ? $views / $edits : 0 ) ) );
2831
2932 $wgOut->addHTML( $text );
3033 $wgOut->addHTML( "<h2>" . wfMsg( "userstats" ) . "</h2>\n" );
@@ -42,7 +45,9 @@
4346 $sk = $wgUser->getSkin();
4447 $ap = $sk->makeKnownLink( wfMsg( "administrators" ), "" );
4548
46 - $text = wfMsg( "userstatstext", $total, $admins, $ap );
 49+ $text = wfMsg( "userstatstext",
 50+ $wgLang->formatNum( $total ),
 51+ $wgLang->formatNum( $admins ), $ap );
4752 $wgOut->addHTML( $text );
4853 }
4954
Index: trunk/phase3/includes/SpecialPopularpages.php
@@ -19,8 +19,9 @@
2020 }
2121
2222 function formatResult( $skin, $result ) {
 23+ global $wgLang;
2324 $link = $skin->makeKnownLink( $result->cur_title, "" );
24 - $nv = wfMsg( "nviews", $result->cur_counter );
 25+ $nv = wfMsg( "nviews", $wgLang->formatNum( $result->cur_counter ) );
2526 return "{$link} ({$nv})";
2627 }
2728 }
Index: trunk/phase3/includes/SpecialRecentchanges.php
@@ -104,10 +104,10 @@
105105 }
106106
107107 if(isset($from)) {
108 - $note = wfMsg( "rcnotefrom", $limit,
 108+ $note = wfMsg( "rcnotefrom", $wgLang->formatNum( $limit ),
109109 $wgLang->timeanddate( $from, true ) );
110110 } else {
111 - $note = wfMsg( "rcnote", $limit, $days );
 111+ $note = wfMsg( "rcnote", $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
112112 }
113113 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
114114
@@ -142,7 +142,7 @@
143143 global $wgUser, $wgLang;
144144 $sk = $wgUser->getSkin();
145145 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
146 - ($lim ? "{$lim}" : wfMsg( "all" ) ), "{$more}" .
 146+ ($lim ? $wgLang->formatNum( "{$lim}" ) : wfMsg( "all" ) ), "{$more}" .
147147 ($d ? "days={$d}&" : "") . "limit={$lim}" );
148148 return $s;
149149 }
@@ -152,7 +152,7 @@
153153 global $wgUser, $wgLang;
154154 $sk = $wgUser->getSkin();
155155 $s = $sk->makeKnownLink( $wgLang->specialPage( $page ),
156 - ($d ? "{$d}" : wfMsg( "all" ) ), "{$more}days={$d}" .
 156+ ($d ? $wgLang->formatNum( "{$d}" ) : wfMsg( "all" ) ), "{$more}days={$d}" .
157157 ($lim ? "&limit={$lim}" : "") );
158158 return $s;
159159 }
Index: trunk/phase3/includes/SpecialLongpages.php
@@ -19,7 +19,8 @@
2020 }
2121
2222 function formatResult( $skin, $result ) {
23 - $nb = wfMsg( "nbytes", $result->len );
 23+ global $wgLang;
 24+ $nb = wfMsg( "nbytes", $wgLang->formatNum( $result->len ) );
2425 $link = $skin->makeKnownLink( $result->cur_title, "" );
2526 return "{$link} ({$nb})";
2627 }
Index: trunk/phase3/includes/Skin.php
@@ -668,7 +668,7 @@
669669 if ( $wgDisableCounters ) {
670670 $s = "";
671671 } else {
672 - $count = $wgArticle->getCount();
 672+ $count = $wgLang->formatNum( $wgArticle->getCount() );
673673 $s = wfMsg( "viewcount", $count );
674674 }
675675 $s .= $this->lastModified();
Index: trunk/phase3/includes/SpecialShortpages.php
@@ -19,7 +19,8 @@
2020 }
2121
2222 function formatResult( $skin, $result ) {
23 - $nb = wfMsg( "nbytes", $result->len );
 23+ global $wgLang;
 24+ $nb = wfMsg( "nbytes", $wgLang->formatNum( $result->len ) );
2425 $link = $skin->makeKnownLink( $result->cur_title, "" );
2526 return "{$link} ({$nb})";
2627 }
Index: trunk/phase3/includes/SpecialWatchlist.php
@@ -89,7 +89,7 @@
9090 }
9191
9292 if(isset($_REQUEST['magic'])) {
93 - $wgOut->addHTML( wfMsg( "watchlistcontains", $nitems ) .
 93+ $wgOut->addHTML( wfMsg( "watchlistcontains", $wgLang->formatNum( $nitems ) ) .
9494 "<p>" . wfMsg( "watcheditlist" ) . "</p>\n" );
9595
9696 $wgOut->addHTML( "<form action='" .
@@ -133,7 +133,8 @@
134134 }
135135
136136
137 - $wgOut->addHTML( "<i>" . wfMsg( "watchdetails", $nitems, $npages, $y,
 137+ $wgOut->addHTML( "<i>" . wfMsg( "watchdetails",
 138+ $wgLang->formatNum( $nitems ), $wgLang->formatNum( $npages ), $y,
138139 $specialTitle->getURL( "magic=yes", true ) ) . "</i><br>\n" );
139140
140141
@@ -151,9 +152,9 @@
152153 $res = wfQuery( $sql, DB_READ, $fname );
153154
154155 if($days >= 1)
155 - $note = wfMsg( "rcnote", $limit, $days );
 156+ $note = wfMsg( "rcnote", $wgLang->formatNum( $limit ), $wgLang->formatNum( $days ) );
156157 elseif($days > 0)
157 - $note = wfMsg( "wlnote", $limit, round($days*24) );
 158+ $note = wfMsg( "wlnote", $wgLang->formatNum( $limit ), $wgLang->formatNum( round($days*24) ) );
158159 else
159160 $note = "";
160161 $wgOut->addHTML( "\n<hr>\n{$note}\n<br>" );
@@ -189,7 +190,8 @@
190191 $sk = $wgUser->getSkin();
191192 $s = $sk->makeKnownLink(
192193 $wgLang->specialPage( $page ),
193 - $h, "days=" . ($h / 24.0) );
 194+ $wgLang->formatNum( $h ),
 195+ "days=" . ($h / 24.0) );
194196 return $s;
195197 }
196198
@@ -199,7 +201,7 @@
200202 $sk = $wgUser->getSkin();
201203 $s = $sk->makeKnownLink(
202204 $wgLang->specialPage( $page ),
203 - ($d ? $d : wfMsg( "all" ) ), "days=$d" );
 205+ ($d ? $wgLang->formatNum( $d ) : wfMsg( "all" ) ), "days=$d" );
204206 return $s;
205207 }
206208
Index: trunk/phase3/languages/Language.php
@@ -1560,23 +1560,15 @@
15611561 $datePreference = $wgAmericanDates ? 1 : 2;
15621562 }
15631563
1564 - if ( $datePreference == 1 ) {
1565 - # MDY
1566 - $d = $this->getMonthAbbreviation( substr( $ts, 4, 2 ) ) .
1567 - " " . (0 + substr( $ts, 6, 2 )) . ", " .
1568 - substr( $ts, 0, 4 );
1569 - } else if ( $datePreference == 2 ) {
1570 - #DMY
1571 - $d = (0 + substr( $ts, 6, 2 )) . " " .
1572 - $this->getMonthAbbreviation( substr( $ts, 4, 2 ) ) . " " .
1573 - substr( $ts, 0, 4 );
1574 - } else {
1575 - #YMD
1576 - $d = substr( $ts, 0, 4 ) . " " . $this->getMonthAbbreviation( substr( $ts, 4, 2 ) ) .
1577 - " " . (0 + substr( $ts, 6, 2 ));
 1564+ $month = $this->getMonthAbbreviation( substr( $ts, 4, 2 ) );
 1565+ $day = $this->formatNum( 0 + substr( $ts, 6, 2 ) );
 1566+ $year = $this->formatNum( substr( $ts, 0, 4 ) );
 1567+
 1568+ switch( $datePreference ) {
 1569+ case 1: return "$month $day, $year";
 1570+ case 2: return "$day $month $year";
 1571+ default: return "$year $month $day";
15781572 }
1579 -
1580 - return $d;
15811573 }
15821574
15831575 function time( $ts, $adj = false )
@@ -1584,7 +1576,7 @@
15851577 if ( $adj ) { $ts = $this->userAdjust( $ts ); }
15861578
15871579 $t = substr( $ts, 8, 2 ) . ":" . substr( $ts, 10, 2 );
1588 - return $t;
 1580+ return $this->formatNum( $t );
15891581 }
15901582
15911583 function timeanddate( $ts, $adj = false )
@@ -1748,6 +1740,13 @@
17491741 {
17501742 return NULL;
17511743 }
 1744+
 1745+ # Normally we use the plain ASCII digits. Some languages such as Arabic will
 1746+ # want to output numbers using script-appropriate characters: override this
 1747+ # function with a translator. See LanguageAr.php for an example.
 1748+ function formatNum( $number ) {
 1749+ return $number;
 1750+ }
17521751
17531752 }
17541753
Index: trunk/phase3/languages/LanguageAr.php
@@ -3,18 +3,18 @@
44 include_once("LanguageUtf8.php");
55
66 /* private */ $wgNamespaceNamesAr = array(
7 - "-2" => "ملف",
8 - "-1" => "خاص",
9 - "0" => "",
10 - "1" => "نقاش",
11 - "2" => "مستخدم",
12 - "3" => "نقاش_المستخدم",
13 - "4" => "ويكيبيديا",
14 - "5" => "ويكيبيديا_نقاش",
15 - "6" => "صورة",
16 - "7" => "نقاش_الصورة",
17 - "8" => "MediaWiki",
18 - "9" => "MediaWiki_talk",
 7+ -2 => "ملف",
 8+ -1 => "خاص",
 9+ 0 => "",
 10+ 1 => "نقاش",
 11+ 2 => "مستخدم",
 12+ 3 => "نقاش_المستخدم",
 13+ 4 => "ويكيبيديا",
 14+ 5 => "ويكيبيديا_نقاش",
 15+ 6 => "صورة",
 16+ 7 => "نقاش_الصورة",
 17+ 8 => "MediaWiki",
 18+ 9 => "MediaWiki_talk",
1919 );
2020
2121 /* private */ $wgWeekdayNamesAr = array(
@@ -29,6 +29,22 @@
3030 );
3131
3232 class LanguageAr extends LanguageUtf8 {
 33+ var $digitTransTable = array(
 34+ "0" => "٠",
 35+ "1" => "١",
 36+ "2" => "٢",
 37+ "3" => "٣",
 38+ "4" => "٤",
 39+ "5" => "٥",
 40+ "6" => "٦",
 41+ "7" => "٧",
 42+ "8" => "٨",
 43+ "9" => "٩",
 44+ "%" => "٪",
 45+ "." => "٫",
 46+ "," => "٬"
 47+ );
 48+
3349 # TODO: TRANSLATION!
3450
3551 # Inherit everything except...
@@ -101,7 +117,10 @@
102118
103119 return $s;
104120 }
105 -
 121+
 122+ function formatNum( $number ) {
 123+ return strtr( $number, $this->digitTransTable );
 124+ }
106125 }
107126
108127 ?>

Status & tagging log