Index: trunk/extensions/Renameuser/SpecialRenameuser_body.php |
— | — | @@ -31,30 +31,33 @@ |
32 | 32 | global $wgVersion, $wgMaxNameChars, $wgCapitalLinks; |
33 | 33 | |
34 | 34 | $this->setHeaders(); |
35 | | - |
36 | 35 | $wgOut->addWikiMsg( 'renameuser-summary' ); |
37 | 36 | |
38 | | - if ( !$wgUser->isAllowed( 'renameuser' ) ) { |
| 37 | + if( !$wgUser->isAllowed( 'renameuser' ) ) { |
39 | 38 | $wgOut->permissionRequired( 'renameuser' ); |
40 | 39 | return; |
41 | 40 | } |
42 | | - |
43 | | - if ( wfReadOnly() ) { |
| 41 | + if( wfReadOnly() ) { |
44 | 42 | $wgOut->readOnlyPage(); |
45 | 43 | return; |
46 | 44 | } |
47 | 45 | |
48 | 46 | $showBlockLog = $wgRequest->getBool( 'submit-showBlockLog' ); |
49 | | - $oldusername = Title::makeTitle( NS_USER, $wgRequest->getText( 'oldusername' ) ); |
50 | | - // Force uppercase of newusername otherweise wikis with wgCapitalLinks=false can create lc usernames |
| 47 | + $oldusername = Title::makeTitle( NS_USER, trim( $wgRequest->getText( 'oldusername' ) ) ); |
| 48 | + // Force uppercase of newusername, otherwise wikis with wgCapitalLinks=false can create lc usernames |
51 | 49 | $newusername = Title::newFromText( $wgContLang->ucfirst( $wgRequest->getText( 'newusername' ) ), NS_USER ); |
52 | 50 | $oun = is_object( $oldusername ) ? $oldusername->getText() : ''; |
53 | 51 | $nun = is_object( $newusername ) ? $newusername->getText() : ''; |
54 | 52 | $token = $wgUser->editToken(); |
55 | 53 | $reason = $wgRequest->getText( 'reason' ); |
56 | | - $is_checked = true; |
57 | | - if ( $wgRequest->wasPosted() && ! $wgRequest->getCheck( 'movepages' ) ) { |
58 | | - $is_checked = false; |
| 54 | + // If nothing given for these flags, assume they are checked |
| 55 | + // unless this is a POST submission. |
| 56 | + $move_checked = $reserve_checked = true; |
| 57 | + if( $wgRequest->wasPosted() ) { |
| 58 | + if( !$wgRequest->getCheck( 'movepages' ) ) |
| 59 | + $move_checked = false; |
| 60 | + if( !$wgRequest->getCheck( 'reservename' ) ) |
| 61 | + $reserve_checked = false; |
59 | 62 | } |
60 | 63 | $warnings = array(); |
61 | 64 | if( $oun && $nun && !$wgRequest->getCheck( 'confirmaction' ) ) { |
— | — | @@ -92,17 +95,28 @@ |
93 | 96 | "</td> |
94 | 97 | </tr>" |
95 | 98 | ); |
96 | | - if ( $wgUser->isAllowed( 'move' ) ) { |
| 99 | + if( $wgUser->isAllowed( 'move' ) ) { |
97 | 100 | $wgOut->addHTML( " |
98 | 101 | <tr> |
99 | 102 | <td> |
100 | 103 | </td> |
101 | 104 | <td class='mw-input'>" . |
102 | | - Xml::checkLabel( wfMsg( 'renameusermove' ), 'movepages', 'movepages', $is_checked, array( 'tabindex' => '4' ) ) . |
| 105 | + Xml::checkLabel( wfMsg( 'renameusermove' ), 'movepages', 'movepages', |
| 106 | + $move_checked, array( 'tabindex' => '4' ) ) . |
103 | 107 | "</td> |
104 | 108 | </tr>" |
105 | 109 | ); |
106 | 110 | } |
| 111 | + $wgOut->addHTML( " |
| 112 | + <tr> |
| 113 | + <td> |
| 114 | + </td> |
| 115 | + <td class='mw-input'>" . |
| 116 | + Xml::checkLabel( wfMsg( 'renameuserreserve' ), 'reservename', 'reservename', |
| 117 | + $reserve_checked, array( 'tabindex' => '4' ) ) . |
| 118 | + "</td> |
| 119 | + </tr>" |
| 120 | + ); |
107 | 121 | if( $warnings ) { |
108 | 122 | $warningsHtml = array(); |
109 | 123 | foreach( $warnings as $warning ) |
— | — | @@ -114,7 +128,8 @@ |
115 | 129 | <td>".wfMsgWikiHtml( 'renameuserwarnings' ) ." |
116 | 130 | </td> |
117 | 131 | <td class='mw-input'>" . |
118 | | - '<ul style="color: red; font-weight: bold"><li>'.implode( '</li><li>', $warningsHtml ).'</li></ul>'. |
| 132 | + '<ul style="color: red; font-weight: bold"><li>'. |
| 133 | + implode( '</li><li>', $warningsHtml ).'</li></ul>'. |
119 | 134 | "</td> |
120 | 135 | </tr>" |
121 | 136 | ); |
— | — | @@ -123,18 +138,19 @@ |
124 | 139 | <td> |
125 | 140 | </td> |
126 | 141 | <td class='mw-input'>" . |
127 | | - Xml::checkLabel( wfMsg( 'renameuserconfirm' ), 'confirmaction', 'confirmaction', false, array( 'tabindex' => '5' ) ) . |
| 142 | + Xml::checkLabel( wfMsg( 'renameuserconfirm' ), 'confirmaction', 'confirmaction', |
| 143 | + false, array( 'tabindex' => '5' ) ) . |
128 | 144 | "</td> |
129 | 145 | </tr>" |
130 | 146 | ); |
131 | 147 | } |
132 | | - |
133 | 148 | $wgOut->addHTML( " |
134 | 149 | <tr> |
135 | 150 | <td> |
136 | 151 | </td> |
137 | 152 | <td class='mw-submit'>" . |
138 | | - Xml::submitButton( wfMsg( 'renameusersubmit' ), array( 'name' => 'submit', 'tabindex' => '6', 'id' => 'submit' ) ) . |
| 153 | + Xml::submitButton( wfMsg( 'renameusersubmit' ), array( 'name' => 'submit', |
| 154 | + 'tabindex' => '6', 'id' => 'submit' ) ) . |
139 | 155 | ' ' . |
140 | 156 | Xml::submitButton( wfMsg( 'blocklogpage' ), array ( 'name' => 'submit-showBlockLog', |
141 | 157 | 'id' => 'submit-showBlockLog', 'tabindex' => '7' ) ) . |
— | — | @@ -147,8 +163,8 @@ |
148 | 164 | ); |
149 | 165 | |
150 | 166 | // Show block log if requested |
151 | | - if ( $showBlockLog && is_object( $oldusername ) ) { |
152 | | - $this->showLogExtract ( $oldusername, 'block', $wgOut ) ; |
| 167 | + if( $showBlockLog && is_object( $oldusername ) ) { |
| 168 | + $this->showLogExtract( $oldusername, 'block', $wgOut ) ; |
153 | 169 | return; |
154 | 170 | } |
155 | 171 | |
— | — | @@ -185,50 +201,47 @@ |
186 | 202 | $newuser = User::newFromName( $newusername->getText() ); |
187 | 203 | |
188 | 204 | // It won't be an object if for instance "|" is supplied as a value |
189 | | - if ( !is_object( $olduser ) ) { |
190 | | - $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrorinvalid', $oldusername->getText() ) . "</div>" ); |
| 205 | + if( !is_object( $olduser ) ) { |
| 206 | + $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrorinvalid', |
| 207 | + $oldusername->getText() ) . "</div>" ); |
191 | 208 | return; |
192 | 209 | } |
193 | | - |
194 | | - if ( !is_object( $newuser ) || !User::isCreatableName( $newuser->getName() ) ) { |
195 | | - $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrorinvalid', $newusername->getText() ) . "</div>" ); |
| 210 | + if( !is_object( $newuser ) || !User::isCreatableName( $newuser->getName() ) ) { |
| 211 | + $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrorinvalid', |
| 212 | + $newusername->getText() ) . "</div>" ); |
196 | 213 | return; |
197 | 214 | } |
198 | 215 | |
199 | 216 | // Check for the existence of lowercase oldusername in database. |
200 | 217 | // Until r19631 it was possible to rename a user to a name with first character as lowercase |
201 | | - if ( $wgRequest->getText( 'oldusername' ) !== $wgContLang->ucfirst( $wgRequest->getText( 'oldusername' ) ) ) { |
| 218 | + if( $oldusername->getText() !== $wgContLang->ucfirst( $oldusername->getText() ) ) { |
202 | 219 | // oldusername was entered as lowercase -> check for existence in table 'user' |
203 | | - $dbr_lc = wfGetDB( DB_SLAVE ); |
204 | | - $s = trim( $wgRequest->getText( 'oldusername' ) ); |
205 | | - $uid = $dbr_lc->selectField( 'user', 'user_id', array( 'user_name' => $s ), __METHOD__ ); |
206 | | - if ( $uid === false ) { |
207 | | - if ( !$wgCapitalLinks ) { |
| 220 | + $dbr = wfGetDB( DB_SLAVE ); |
| 221 | + $uid = $dbr->selectField( 'user', 'user_id', |
| 222 | + array( 'user_name' => $oldusername->getText() ), |
| 223 | + __METHOD__ ); |
| 224 | + if( $uid === false ) { |
| 225 | + if( !$wgCapitalLinks ) { |
208 | 226 | $uid = 0; // We are on a lowercase wiki but lowercase username does not exists |
209 | 227 | } else { |
210 | 228 | $uid = $olduser->idForName(); // We are on a standard uppercase wiki, use normal |
211 | 229 | $oldusername = Title::newFromText( $olduser->getName(), NS_USER ); // uppercase form |
212 | 230 | } |
213 | | - } else { |
214 | | - // username with lowercase exists |
215 | | - // Title::newFromText was nice, but forces uppercase |
216 | | - // for older rename accidents on lowercase wikis we need the lowercase username as entered in the form |
217 | | - $oldusername->mTextform = $wgRequest->getText( 'oldusername' ); |
218 | | - $oldusername->mUrlform = $wgRequest->getText( 'oldusername' ); |
219 | | - $oldusername->mDbkeyform = $wgRequest->getText( 'oldusername' ); |
220 | 231 | } |
221 | 232 | } else { |
222 | 233 | // oldusername was entered as upperase -> standard procedure |
223 | 234 | $uid = $olduser->idForName(); |
224 | 235 | } |
225 | 236 | |
226 | | - if ($uid == 0) { |
227 | | - $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrordoesnotexist' , $oldusername->getText() ) . "</div>" ); |
| 237 | + if( $uid == 0 ) { |
| 238 | + $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrordoesnotexist' , |
| 239 | + $oldusername->getText() ) . "</div>" ); |
228 | 240 | return; |
229 | 241 | } |
230 | 242 | |
231 | | - if ($newuser->idForName() != 0) { |
232 | | - $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrorexists', $newusername->getText() ) . "</div>" ); |
| 243 | + if( $newuser->idForName() != 0 ) { |
| 244 | + $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrorexists', |
| 245 | + $newusername->getText() ) . "</div>" ); |
233 | 246 | return; |
234 | 247 | } |
235 | 248 | |
— | — | @@ -236,7 +249,7 @@ |
237 | 250 | $contribs = User::edits( $uid ); |
238 | 251 | |
239 | 252 | // Check edit count |
240 | | - if ( !$wgUser->isAllowed( 'siteadmin' ) ) { |
| 253 | + if( !$wgUser->isAllowed( 'siteadmin' ) ) { |
241 | 254 | if ( RENAMEUSER_CONTRIBLIMIT != 0 && $contribs > RENAMEUSER_CONTRIBLIMIT ) { |
242 | 255 | $wgOut->addWikiText( "<div class=\"errorbox\">" . |
243 | 256 | wfMsg( 'renameusererrortoomany', |
— | — | @@ -254,6 +267,7 @@ |
255 | 268 | return; |
256 | 269 | } |
257 | 270 | |
| 271 | + // Do the heavy lifting... |
258 | 272 | $rename = new RenameuserSQL( $oldusername->getText(), $newusername->getText(), $uid ); |
259 | 273 | if( !$rename->rename() ) { |
260 | 274 | return; |
— | — | @@ -261,19 +275,24 @@ |
262 | 276 | |
263 | 277 | // If this user is renaming his/herself, make sure that Title::moveTo() |
264 | 278 | // doesn't make a bunch of null move edits under the old name! |
265 | | - global $wgUser; |
266 | 279 | if( $wgUser->getId() == $uid ) { |
267 | 280 | $wgUser->setName( $newusername->getText() ); |
268 | 281 | } |
269 | 282 | |
| 283 | + // Log this rename |
270 | 284 | $log = new LogPage( 'renameuser' ); |
271 | 285 | $log->addEntry( 'renameuser', $oldusername, wfMsgExt( 'renameuser-log', array( 'parsemag', 'content' ), |
272 | 286 | $wgContLang->formatNum( $contribs ), $reason ), $newusername->getText() ); |
273 | 287 | |
274 | | - $wgOut->addWikiText( "<div class=\"successbox\">" . wfMsg( 'renameusersuccess', $oldusername->getText(), |
275 | | - $newusername->getText() ) . "</div><br style=\"clear:both\" />" ); |
| 288 | + // Reserve the old name with a random password |
| 289 | + if( $wgRequest->getCheck( 'reservename' ) ) { |
| 290 | + $p = User::randomPassword(); |
| 291 | + $user = User::createNew( $olduser->getName() ); |
| 292 | + $user->setNewpassword( $p ); |
| 293 | + } |
276 | 294 | |
277 | | - if ( $wgRequest->getCheck( 'movepages' ) && $wgUser->isAllowed( 'move' ) ) { |
| 295 | + // Move any user pages |
| 296 | + if( $wgRequest->getCheck( 'movepages' ) && $wgUser->isAllowed( 'move' ) ) { |
278 | 297 | $dbr = wfGetDB( DB_SLAVE ); |
279 | 298 | $oldkey = $oldusername->getDBkey(); |
280 | 299 | $pages = $dbr->select( |
— | — | @@ -315,22 +334,16 @@ |
316 | 335 | if( $output ) |
317 | 336 | $wgOut->addHtml( '<ul>' . $output . '</ul>' ); |
318 | 337 | } |
| 338 | + |
| 339 | + // Output success message stuff :) |
| 340 | + $wgOut->addWikiText( "<div class=\"successbox\">" . wfMsg( 'renameusersuccess', $oldusername->getText(), |
| 341 | + $newusername->getText() ) . "</div><br style=\"clear:both\" />" ); |
319 | 342 | } |
320 | 343 | |
321 | | - // FIXME: this code is total crap. Should this just use LogEventsList or |
322 | | - // since extensions are branched, or are we keeping the half-ass b/c thing? |
323 | 344 | function showLogExtract( $username, $type, &$out ) { |
324 | | - global $wgOut; |
325 | 345 | # Show relevant lines from the logs: |
326 | | - $wgOut->addHtml( Xml::element( 'h2', null, LogPage::logName( $type ) ) . "\n" ); |
327 | | - |
328 | | - $logViewer = new LogViewer( |
329 | | - new LogReader( |
330 | | - new FauxRequest( |
331 | | - array( 'page' => $username->getPrefixedText(), |
332 | | - 'type' => $type ) ) ) ); |
333 | | - $logViewer->showList( $out ); |
334 | | - |
| 346 | + $out->addHtml( Xml::element( 'h2', null, LogPage::logName( $type ) ) . "\n" ); |
| 347 | + LogEventsList::showLogExtract( $out, $type, $username->getPrefixedText() ); |
335 | 348 | } |
336 | 349 | } |
337 | 350 | |
Index: trunk/extensions/Renameuser/SpecialRenameuser.i18n.php |
— | — | @@ -15,6 +15,7 @@ |
16 | 16 | 'renameusernew' => 'New username:', |
17 | 17 | 'renameuserreason' => 'Reason for rename:', |
18 | 18 | 'renameusermove' => 'Move user and talk pages (and their subpages) to new name', |
| 19 | + 'renameuserreserve' => 'Reserve the old username from further use', |
19 | 20 | 'renameuserwarnings' => 'Warnings:', |
20 | 21 | 'renameuserconfirm' => 'Yes, rename the user', |
21 | 22 | 'renameusersubmit' => 'Submit', |