Index: trunk/extensions/Renameuser/SpecialRenameuser_body.php |
— | — | @@ -4,10 +4,10 @@ |
5 | 5 | function Renameuser() { |
6 | 6 | SpecialPage::SpecialPage('Renameuser', 'renameuser'); |
7 | 7 | } |
8 | | - |
| 8 | + |
9 | 9 | function execute() { |
10 | 10 | global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgContLang, $wgLang; |
11 | | - global $wgVersion, $wgMaxNameChars; |
| 11 | + global $wgVersion, $wgMaxNameChars, $wgCapitalLinks; |
12 | 12 | |
13 | 13 | $fname = 'Renameuser::execute'; |
14 | 14 | |
— | — | @@ -27,10 +27,9 @@ |
28 | 28 | $wgOut->versionRequired( '1.7.0' ); |
29 | 29 | return; |
30 | 30 | } |
31 | | - |
32 | | - $oldusername = Title::newFromText( $wgRequest->getText( 'oldusername' ) ); |
33 | | - $newusername = Title::newFromText( $wgRequest->getText( 'newusername' ) ); |
34 | 31 | |
| 32 | + $oldusername = Title::newFromText( $wgRequest->getText( 'oldusername' ), NS_USER ); |
| 33 | + $newusername = Title::newFromText( $wgContLang->ucfirst( $wgRequest->getText( 'newusername' ) ), NS_USER ); // Force uppercase of newusername otherweise wikis with wgCapitalLinks=false can create lc usernames |
35 | 34 | $action = $wgTitle->escapeLocalUrl(); |
36 | 35 | $renameuserold = wfMsgHtml( 'renameuserold' ); |
37 | 36 | $renameusernew = wfMsgHtml( 'renameusernew' ); |
— | — | @@ -77,32 +76,57 @@ |
78 | 77 | |
79 | 78 | if ( !is_object( $oldusername ) || !is_object( $newusername ) || $oldusername->getText() == $newusername->getText() ) |
80 | 79 | return; |
81 | | - |
| 80 | + |
82 | 81 | $wgOut->addHTML( '<hr />' ); |
83 | | - |
| 82 | + |
84 | 83 | // Suppress username validation of old username |
85 | 84 | $olduser = User::newFromName( $oldusername->getText(), false ); |
86 | 85 | $newuser = User::newFromName( $newusername->getText() ); |
87 | 86 | |
88 | 87 | // It won't be an object if for instance "|" is supplied as a value |
89 | 88 | if ( !is_object( $olduser ) ) { |
90 | | - $wgOut->addWikiText( wfMsg( 'renameusererrorinvalid', $oldusername->getText() ) ); |
| 89 | + $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrorinvalid', $oldusername->getText() ) . "</div>" ); |
91 | 90 | return; |
92 | 91 | } |
93 | 92 | |
94 | 93 | if ( !is_object( $newuser ) ) { |
95 | | - $wgOut->addWikiText( wfMsg( 'renameusererrorinvalid', $newusername->getText() ) ); |
| 94 | + $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrorinvalid', $newusername->getText() ) . "</div>" ); |
96 | 95 | return; |
97 | 96 | } |
98 | | - |
99 | | - $uid = $olduser->idForName(); |
| 97 | + |
| 98 | + // Check for the existence of lowercase oldusername in database. |
| 99 | + // Until r19631 it was possible to rename a user to a name with first character as lowercase |
| 100 | + if ( $wgRequest->getText( 'oldusername' ) !== $wgContLang->ucfirst( $wgRequest->getText( 'oldusername' ) ) ) { |
| 101 | + // oldusername was entered as lowercase -> check for existence in table 'user' |
| 102 | + $dbr_lc = wfGetDB( DB_SLAVE ); |
| 103 | + $s = trim( $wgRequest->getText( 'oldusername' ) ); |
| 104 | + $uid = $dbr_lc->selectField( 'user', 'user_id', array( 'user_name' => $s ), __METHOD__ ); |
| 105 | + if ( $uid === false ) { |
| 106 | + if ( !$wgCapitalLinks ) { |
| 107 | + $uid = 0; // We are on a lowercase wiki but lowercase username does not exists |
| 108 | + } else { |
| 109 | + $uid = $olduser->idForName(); // We are on a standard uppercase wiki, use normal |
| 110 | + } |
| 111 | + } else { |
| 112 | + // username with lowercase exists |
| 113 | + // Title::newFromText was nice, but forces uppercase |
| 114 | + // for older rename accidents on lowercase wikis we need the lowercase username as entered in the form |
| 115 | + $oldusername->mTextform = $wgRequest->getText( 'oldusername' ); |
| 116 | + $oldusername->mUrlform = $wgRequest->getText( 'oldusername' ); |
| 117 | + $oldusername->mDbkeyform = $wgRequest->getText( 'oldusername' ); |
| 118 | + } |
| 119 | + } else { |
| 120 | + // oldusername was entered as upperase -> standard procedure |
| 121 | + $uid = $olduser->idForName(); |
| 122 | + } |
| 123 | + |
100 | 124 | if ($uid == 0) { |
101 | | - $wgOut->addWikiText( wfMsg( 'renameusererrordoesnotexist', $oldusername->getText() ) ); |
| 125 | + $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrordoesnotexist' , $oldusername->getText() ) . "</div>" ); |
102 | 126 | return; |
103 | 127 | } |
104 | | - |
| 128 | + |
105 | 129 | if ($newuser->idForName() != 0) { |
106 | | - $wgOut->addWikiText( wfMsg( 'renameusererrorexists', $newusername->getText() ) ); |
| 130 | + $wgOut->addWikiText( "<div class=\"errorbox\">" . wfMsg( 'renameusererrorexists', $newusername->getText() ) . "</div>" ); |
107 | 131 | return; |
108 | 132 | } |
109 | 133 | |
— | — | @@ -110,13 +134,13 @@ |
111 | 135 | if ( !$wgUser->isAllowed( 'siteadmin' ) ) { |
112 | 136 | $contribs = User::edits( $uid ); |
113 | 137 | if ( RENAMEUSER_CONTRIBLIMIT != 0 && $contribs > RENAMEUSER_CONTRIBLIMIT ) { |
114 | | - $wgOut->addWikiText( |
| 138 | + $wgOut->addWikiText( "<div class=\"errorbox\">" . |
115 | 139 | wfMsg( 'renameusererrortoomany', |
116 | 140 | $oldusername->getText(), |
117 | 141 | $wgLang->formatNum( $contribs ), |
118 | 142 | $wgLang->formatNum( RENAMEUSER_CONTRIBLIMIT ) |
119 | 143 | ) |
120 | | - ); |
| 144 | + . "</div>" ); |
121 | 145 | return; |
122 | 146 | } |
123 | 147 | } |
Index: trunk/extensions/Renameuser/SpecialRenameuser.php |
— | — | @@ -18,7 +18,7 @@ |
19 | 19 | $wgExtensionCredits['specialpage'][] = array( |
20 | 20 | 'name' => 'Renameuser', |
21 | 21 | 'author' => 'Ævar Arnfjörð Bjarmason', |
22 | | - 'url' => 'http://meta.wikimedia.org/wiki/Renameuser', |
| 22 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:Renameuser', |
23 | 23 | 'description' => 'Rename a user (need \'\'renameuser\'\' right)', |
24 | 24 | ); |
25 | 25 | |