r48185 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48184‎ | r48185 | r48186 >
Date:20:42, 8 March 2009
Author:siebrand
Status:resolved
Tags:
Comment:
* Use Language::commaList( array ) or Language::listToText( array) instead of implode( ', ', array ) where possible
* use Language::formatNum() in a few places
* add some FIXMEs
Modified paths:
  • /trunk/extensions/CheckUser/CheckUser_body.php (modified) (history)
  • /trunk/extensions/Configure/Configure.page.php (modified) (history)
  • /trunk/extensions/Configure/SpecialViewConfig.php (modified) (history)
  • /trunk/extensions/Contributors/Contributors.page.php (modified) (history)
  • /trunk/extensions/EditMessages/EditMessages_body.php (modified) (history)
  • /trunk/extensions/EmergencyDeSysop/SpecialEmergencyDeSysop.php (modified) (history)
  • /trunk/extensions/GlobalBlocking/SpecialGlobalBlockList.php (modified) (history)
  • /trunk/extensions/SharedUserRights/SharedUserRights_body.php (modified) (history)
  • /trunk/extensions/UserRightsNotif/UserRightsNotif.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UserRightsNotif/UserRightsNotif.php
@@ -34,11 +34,11 @@
3535 }
3636
3737 function efUserRightsNotifier( &$user, $added, $removed ) {
38 - global $wgUserRightsNotif;
 38+ global $wgUserRightsNotif, $wgContentLang;
3939 if( $user->canReceiveEmail() ) {
4040 global $wgUser, $wgSitename, $wgContLang;
41 - $added = is_array( $added ) ? implode( ', ', $added ) : '';
42 - $removed = is_array( $removed ) ? implode( ', ', $removed ) : '';
 41+ $added = is_array( $added ) ? $wgContentLang->commaList( $added ) : '';
 42+ $removed = is_array( $removed ) ? $wgContentLang->commaList( $removed ) : '';
4343 $subject = wfMsg( 'userrightsnotifysubject', $wgSitename );
4444 $message = wfMsg( 'userrightsnotifybody', $user->getName(), $wgSitename, $wgUser->getName(), $wgContLang->timeAndDate( wfTimestampNow() ), $added, $removed );
4545 $user->sendMail( $subject, $message, $wgUserRightsNotif['sender'] );
Index: trunk/extensions/CheckUser/CheckUser_body.php
@@ -227,7 +227,7 @@
228228 * @param string $tag
229229 */
230230 protected function doMassUserBlock( $users, $reason = '', $tag = '', $talkTag = '' ) {
231 - global $wgOut, $wgUser, $wgCheckUserMaxBlocks;
 231+ global $wgOut, $wgUser, $wgCheckUserMaxBlocks, $wgLang;
232232 if( empty($users) || $wgUser->isBlocked(false) ) {
233233 $wgOut->addWikiText( wfMsgExt('checkuser-block-failure',array('parsemag')) );
234234 return;
@@ -239,12 +239,12 @@
240240 return;
241241 }
242242 $safeUsers = IPBlockForm::doMassUserBlock( $users, $reason, $tag, $talkTag );
243 - if( !empty($safeUsers) ) {
244 - $n = count($safeUsers);
245 - $ulist = implode(', ',$safeUsers);
246 - $wgOut->addWikiText( wfMsgExt('checkuser-block-success',array('parsemag'),$ulist,$n) );
 243+ if( !empty( $safeUsers ) ) {
 244+ $n = count( $safeUsers );
 245+ $ulist = $wgLang->listToText( $safeUsers );
 246+ $wgOut->addWikiText( wfMsgExt( 'checkuser-block-success', 'parsemag', $ulist, $wgLang->formatNum( $n ) ) );
247247 } else {
248 - $wgOut->addWikiText( wfMsgExt('checkuser-block-failure',array('parsemag')) );
 248+ $wgOut->addWikiText( wfMsgExt( 'checkuser-block-failure', 'parsemag' ) );
249249 }
250250 }
251251
@@ -884,7 +884,7 @@
885885 foreach( $user->getGroups() as $group ) {
886886 $list[] = self::buildGroupLink( $group );
887887 }
888 - $groups = implode( ', ', $list );
 888+ $groups = $wgLang->commaList( $list );
889889 if( $groups ) {
890890 $flags[] = '<i>(' . $groups . ')</i>';
891891 }
@@ -894,7 +894,7 @@
895895 $key = wfMemcKey( 'acctcreate', 'ip', $ip );
896896 $count = intval( $wgMemc->get( $key ) );
897897 if( $count ) {
898 - $flags[] = '<strong>[' . wfMsgExt('checkuser-accounts',array('parsemag'),$count) . ']</strong>';
 898+ $flags[] = '<strong>[' . wfMsgExt( 'checkuser-accounts', 'parsemag', $wgLang->formatNum( $count ) . ']</strong>';
899899 }
900900 }
901901 $s .= implode(' ',$flags);
Index: trunk/extensions/EmergencyDeSysop/SpecialEmergencyDeSysop.php
@@ -96,10 +96,12 @@
9797 * @param array groups an array of user groups
9898 */
9999 function formatGroups ( $groups ) {
 100+ global $wgContentLang;
 101+
100102 if( empty( $groups ) ) {
101103 $groups = wfMsg( 'emergencydesysop-nogroups' );
102104 } else {
103 - $groups = implode( ', ', $groups );
 105+ $groups = $wgContentLang->commaList( $groups );
104106 }
105107 return $groups;
106108 }
@@ -175,12 +177,14 @@
176178
177179 //Log it
178180 $log = new LogPage( "rights" );
 181+ // FIXME: Contains non-localisable text
179182 $log->addEntry(
180183 "rights",
181 - $targetUser->getUserPage( ),
182 - 'Emergency Desysop: ' . $wgRequest->getText( 'reason' ),
 184+ $targetUser->getUserPage( ),
 185+ 'Emergency Desysop: ' . $wgRequest->getText( 'reason' ),
183186 array( $this->formatGroups( $targetUserGroupsOld ), $this->formatGroups( $targetUserGroupsNew ) ) );
184187
 188+ // FIXME: Contains non-localisable text
185189 $log->addEntry(
186190 "rights",
187191 $wgUser->getUserPage( ),
Index: trunk/extensions/SharedUserRights/SharedUserRights_body.php
@@ -288,10 +288,12 @@
289289 }
290290
291291 function makeGroupNameList( $ids ) {
 292+ global $wgContentLang;
 293+
292294 if ( empty( $ids ) ) {
293295 return wfMsgForContent( 'rightsnone' );
294296 } else {
295 - return implode( ', ', $ids );
 297+ return $wgContentLang->commaList( $ids );
296298 }
297299 }
298300
Index: trunk/extensions/Contributors/Contributors.page.php
@@ -38,16 +38,18 @@
3939
4040 private function showInclude() {
4141 wfProfileIn( __METHOD__ );
42 - global $wgOut;
 42+
 43+ global $wgOut, $wgContentLang;
 44+
4345 if( is_object( $this->target ) ) {
4446 if( $this->target->exists() ) {
4547 $names = array();
4648 list( $contributors, $others ) = $this->getMainContributors();
4749 foreach( $contributors as $username => $info )
4850 $names[] = $username;
49 - $output = implode( ', ', $names );
 51+ $output = $wgContentLang->listToText( $names );
5052 if( $others > 0 )
51 - $output .= ' ' . wfMsgForContent( 'contributors-others', $others );
 53+ $output .= wgMsgForContent( 'word-separator' ) . wfMsgForContent( 'contributors-others', $wgContentLang->formatNum( $others ) );
5254 $wgOut->addHTML( htmlspecialchars( $output ) );
5355 } else {
5456 $wgOut->addHTML( '<p>' . htmlspecialchars( wfMsgForContent( 'contributors-nosuchpage', $this->target->getPrefixedText() ) ) . '</p>' );
Index: trunk/extensions/EditMessages/EditMessages_body.php
@@ -223,8 +223,10 @@
224224
225225 foreach ( $warnings as $warningType => $warnings2 ) {
226226 if ( $warningsCount = count( $warnings2 ) ) {
 227+ global $wgLang;
 228+
227229 $wgOut->addWikiMsg( 'editmsg-warning-' . $warningType,
228 - implode( ', ', $warnings2 ), $warningsCount );
 230+ $wgLang->commaList( $warnings2 ), $warningsCount );
229231 // is this really needed?
230232 $warningsCount = 0;
231233 }
Index: trunk/extensions/Configure/SpecialViewConfig.php
@@ -202,7 +202,7 @@
203203 foreach ( $wikis as $wiki ) {
204204 $viewWikis[] = $skin->makeKnownLinkObj( $self, htmlspecialchars( $wiki ), "version={$ts}&wiki={$wiki}" );
205205 }
206 - $view .= ' (' . implode( ', ', $viewWikis ) . ')';
 206+ $view .= ' (' . $wgLang->commaList( $viewWikis ) . ')';
207207 }
208208
209209 if( $view )
@@ -222,7 +222,7 @@
223223 foreach ( $wikis as $wiki ) {
224224 $viewWikis[] = $skin->makeKnownLinkObj( $configTitle, htmlspecialchars( $wiki ), "version={$ts}&wiki={$wiki}" );
225225 }
226 - $editCore .= ' (' . implode( ', ', $viewWikis ) . ')';
 226+ $editCore .= ' (' . $wgLang->commaList( $viewWikis ) . ')';
227227 }
228228 $actions[] = $editCore;
229229 }
@@ -240,7 +240,7 @@
241241 foreach ( $wikis as $wiki ) {
242242 $viewWikis[] = $skin->makeKnownLinkObj( $extTitle, htmlspecialchars( $wiki ), "version={$ts}&wiki={$wiki}" );
243243 }
244 - $editExt .= ' (' . implode( ', ', $viewWikis ) . ')';
 244+ $editExt .= ' (' . $wgLang->commaList( $viewWikis ) . ')';
245245 }
246246 $actions[] = $editExt;
247247 }
@@ -262,7 +262,7 @@
263263
264264 $comment = $arr['reason'] ? $skin->commentBlock( $arr['reason'] ) : '';
265265
266 - $action = implode( ', ', $actions );
 266+ $action = $wgLang->commaList( $actions );
267267 return Xml::tags( 'li', null, wfMsgExt( 'configure-viewconfig-line', array( 'parseinline', 'replaceafter' ), array( $buttons, $time, $userLink, $action, $comment ) ) )."\n";
268268 }
269269
Index: trunk/extensions/Configure/Configure.page.php
@@ -30,7 +30,7 @@
3131 * @param $par Mixed: parameter passed to the page or null
3232 */
3333 public function execute( $par ) {
34 - global $wgUser, $wgRequest, $wgOut, $wgConf, $wgConfigureWikis;
 34+ global $wgUser, $wgRequest, $wgOut, $wgConf, $wgConfigureWikis, $wgLang;
3535
3636 $this->setHeaders();
3737
@@ -63,7 +63,7 @@
6464 }
6565 if ( is_array( $wgConfigureWikis ) && !in_array( $wiki, $wgConfigureWikis ) ) {
6666 $wgOut->wrapWikiMsg( '<div class="errorbox"><strong>$1</strong></div>',
67 - array( 'configure-transwiki-not-in-range', $wiki, implode( ', ', $wgConfigureWikis ) ) );
 67+ array( 'configure-transwiki-not-in-range', $wiki, $wgLang->commaList( $wgConfigureWikis ) ) );
6868 return;
6969 }
7070 }
Index: trunk/extensions/GlobalBlocking/SpecialGlobalBlockList.php
@@ -126,7 +126,7 @@
127127 }
128128
129129 function formatRow( $row ) {
130 - global $wgLang,$wgUser;
 130+ global $wgLang, $wgUser;
131131
132132 ## One-time setup
133133 static $sk=null;
@@ -198,11 +198,15 @@
199199
200200 ## Put it all together.
201201 return Xml::openElement( 'li' ) .
202 - wfMsgExt( 'globalblocking-list-blockitem', array( 'parseinline' ), $timestamp,
203 - $user_display, $display_wiki, $row->gb_address,
204 - implode( ', ', $options) ) .
205 - ' ' .
206 - implode( ' ', $info ) .
 202+ wfMsgExt( 'globalblocking-list-blockitem', array( 'parseinline' ),
 203+ $timestamp,
 204+ $user_display,
 205+ $display_wiki,
 206+ $row->gb_address,
 207+ $wgLang->commaList( $options)
 208+ ) .
 209+ ' ' .
 210+ implode( ' ', $info ) .
207211 Xml::closeElement( 'li' );
208212 }
209213

Follow-up revisions

RevisionCommit summaryAuthorDate
r48199Fix syntax error introduced in r48185. Reported by 'anomie' on IRC.siebrand00:27, 9 March 2009

Status & tagging log