r10410 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10409‎ | r10410 | r10411 >
Date:00:28, 9 August 2005
Author:avar
Status:old
Tags:
Comment:
* Using the Title:: instead of my own stuff
Modified paths:
  • /trunk/extensions/Renameuser/SpecialRenameuser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Renameuser/SpecialRenameuser.php
@@ -33,8 +33,8 @@
3434 'renameusernew' => 'New username: ',
3535 'renameusersubmit' => 'Submit',
3636
37 - 'renameusererrordoesnotexist' => 'The username "<nowiki>$1</nowiki>" does not exist',
38 - 'renameusererrorexists' => 'The username "<nowiki>$1</nowiki>" already exits',
 37+ 'renameusererrordoesnotexist' => 'The user "<nowiki>$1</nowiki>" does not exist',
 38+ 'renameusererrorexists' => 'The user "<nowiki>$1</nowiki>" already exits',
3939 'renameusererrorinvalid' => 'The username "<nowiki>$1</nowiki>" is invalid',
4040 'renameusererrortoomany' => 'The user "<nowiki>$1</nowiki>" has $2 contributions, renaming a user with more ' .
4141 'than $3 contributions could adversely affect site performance',
@@ -64,7 +64,7 @@
6565
6666 $this->setHeaders();
6767
68 - if ( ! $wgUser->isAllowed( 'renameuser' ) ) {
 68+ if ( !$wgUser->isAllowed( 'renameuser' ) ) {
6969 $wgOut->permissionRequired( 'renameuser' );
7070 return;
7171 }
@@ -79,12 +79,14 @@
8080 return;
8181 }
8282
83 - $oldusername = $wgContLang->ucfirst( strtr( trim( $wgRequest->getText( 'oldusername' ) ), '_', ' ' ) );
84 - $newusername = $wgContLang->ucfirst( strtr( trim( $wgRequest->getText( 'newusername' ) ), '_', ' ' ) );
 83+ $oldusername = Title::newFromText( $wgRequest->getText( 'oldusername' ) );
 84+ $newusername = Title::newFromText( $wgRequest->getText( 'newusername' ) );
8585
8686 $action = $wgTitle->escapeLocalUrl();
8787 $renameuserold = wfMsgHtml( 'renameuserold' );
8888 $renameusernew = wfMsgHtml( 'renameusernew' );
 89+ $oun = is_object( $oldusername ) ? $oldusername->getText() : '';
 90+ $nun = is_object( $newusername ) ? $newusername->getText() : '';
8991 $submit = wfMsgHtml( 'renameusersubmit' );
9092 $token = $wgUser->editToken();
9193
@@ -93,11 +95,11 @@
9496 <table>
9597 <tr>
9698 <td align='right'>$renameuserold</td>
97 - <td align='left'><input tabindex='1' type='text' size='20' name='oldusername' value=\"" . htmlspecialchars($oldusername) . "\" /></td>
 99+ <td align='left'><input tabindex='1' type='text' size='20' name='oldusername' value=\"$oun\" /></td>
98100 </tr>
99101 <tr>
100102 <td align='right'>$renameusernew</td>
101 - <td align='left'><input tabindex='1' type='text' size='20' name='newusername' value=\"" . htmlspecialchars($newusername) . "\"/></td>
 103+ <td align='left'><input tabindex='1' type='text' size='20' name='newusername' value=\"$nun\"/></td>
102104 </tr>
103105 <tr>
104106 <td>&nbsp;</td>
@@ -110,33 +112,33 @@
111113 if ( !$wgRequest->wasPosted() || !$wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) )
112114 return;
113115
114 - if ($oldusername == '' || $newusername == '' || $oldusername == $newusername)
 116+ if ( !is_object( $oldusername ) || !is_object( $newusername ) || $oldusername->getText() == $newusername->getText() )
115117 return;
116118
117119 $wgOut->addHTML( '<hr />' );
118120
119 - $olduser = User::newFromName( $oldusername );
120 - $newuser = User::newFromName( $newusername );
 121+ $olduser = User::newFromName( $oldusername->getText() );
 122+ $newuser = User::newFromName( $newusername->getText() );
121123
122124 // It won't be an object if for instance "|" is supplied as a value
123125 if ( !is_object( $olduser ) ) {
124 - $wgOut->addWikiText( wfMsg( 'renameusererrorinvalid', $oldusername ) );
 126+ $wgOut->addWikiText( wfMsg( 'renameusererrorinvalid', $oldusername->getText() ) );
125127 return;
126128 }
127129
128130 if ( !is_object( $newuser ) ) {
129 - $wgOut->addWikiText( wfMsg( 'renameusererrorinvalid', $newusername ) );
 131+ $wgOut->addWikiText( wfMsg( 'renameusererrorinvalid', $newusername->getText() ) );
130132 return;
131133 }
132134
133135 $uid = $olduser->idForName();
134136 if ($uid == 0) {
135 - $wgOut->addWikiText( wfMsg( 'renameusererrordoesnotexist', $oldusername ) );
 137+ $wgOut->addWikiText( wfMsg( 'renameusererrordoesnotexist', $oldusername->getText() ) );
136138 return;
137139 }
138140
139141 if ($newuser->idForName() != 0) {
140 - $wgOut->addWikiText( wfMsg( 'renameusererrorexists', $newusername ) );
 142+ $wgOut->addWikiText( wfMsg( 'renameusererrorexists', $newusername->getText() ) );
141143 return;
142144 }
143145
@@ -145,7 +147,7 @@
146148 if ( RENAMEUSER_CONTRIBLIMIT != 0 && $contribs > RENAMEUSER_CONTRIBLIMIT ) {
147149 $wgOut->addWikiText(
148150 wfMsg( 'renameusererrortoomany',
149 - $oldusername,
 151+ $oldusername->getText(),
150152 $wgLang->formatNum( $contribs ),
151153 $wgLang->formatNum( RENAMEUSER_CONTRIBLIMIT )
152154 )
@@ -153,13 +155,13 @@
154156 return;
155157 }
156158
157 - $rename = new RenameuserSQL( $oldusername, $newusername, $uid );
 159+ $rename = new RenameuserSQL( $oldusername->getText(), $newusername->getText(), $uid );
158160 $rename->rename();
159161
160162 $log = new LogPage( 'renameuser' );
161 - $log->addEntry( 'renameuser', $wgTitle, wfMsg( 'renameuserlog', $oldusername, $newusername, $contribs ) );
 163+ $log->addEntry( 'renameuser', $wgTitle, wfMsg( 'renameuserlog', $oldusername->getText(), $newusername->getText(), $contribs ) );
162164
163 - $wgOut->addWikiText( wfMsg( 'renameusersuccess', $oldusername, $newusername ) );
 165+ $wgOut->addWikiText( wfMsg( 'renameusersuccess', $oldusername->getText(), $newusername->getText() ) );
164166 }
165167 }
166168
@@ -240,13 +242,13 @@
241243 );
242244 }
243245
244 - # Update user_touched and clear user cache
245246 $dbw->update( 'user',
246247 array( 'user_touched' => $dbw->timestamp() ),
247248 array( 'user_name' => $this->new ),
248249 $fname
249250 );
250251
 252+ // Clear the user cache
251253 $wgMemc->delete( "$wgDBname:user:id:{$this->uid}" );
252254
253255 wfProfileOut( $fname );

Status & tagging log