Index: trunk/extensions/Renameuser/SpecialRenameuser.php |
— | — | @@ -24,6 +24,7 @@ |
25 | 25 | 'renameusererrordoesnotexist' => 'The username "$1" does not exist', |
26 | 26 | 'renameusererrorexists' => 'The username "$1" already exits', |
27 | 27 | 'renameusererrorinvalid' => 'The username "$1" is invalid', |
| 28 | + 'renameusererrortoomany' => 'The username "$1" has too many contributions, renaming would adversely affect site performance.', |
28 | 29 | 'renameusersuccess' => 'The user "$1" has been renamed to "$2"', |
29 | 30 | 'renameuserlog' => 'Renamed the user "[[User:$1|$1]]" to "[[User:$2|$2]]"', |
30 | 31 | ) |
— | — | @@ -39,6 +40,8 @@ |
40 | 41 | global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgContLang; |
41 | 42 | global $wgVersion, $wgMaxNameChars; |
42 | 43 | |
| 44 | + $fname = 'Renameuser::execute'; |
| 45 | + |
43 | 46 | $this->setHeaders(); |
44 | 47 | |
45 | 48 | if ( ! $wgUser->isAllowed( 'renameuser' ) ) { |
— | — | @@ -101,7 +104,8 @@ |
102 | 105 | return; |
103 | 106 | } |
104 | 107 | |
105 | | - if ($olduser->idForName() == 0) { |
| 108 | + $uid = $olduser->idForName(); |
| 109 | + if ($uid == 0) { |
106 | 110 | $wgOut->addWikiText( wfMsg( 'renameusererrordoesnotexist', $oldusername ) ); |
107 | 111 | return; |
108 | 112 | } |
— | — | @@ -111,7 +115,16 @@ |
112 | 116 | return; |
113 | 117 | } |
114 | 118 | |
115 | | - $rename = new RenameuserSQL($oldusername, $newusername); |
| 119 | + // Check edit count |
| 120 | + $dbr =& wfGetDB( DB_READ ); |
| 121 | + $numEdits = $dbr->selectField( 'revision', 'count(*)', |
| 122 | + array( 'rev_user' => $uid ), $fname ); |
| 123 | + if ( $numEdits > 5000 ) { |
| 124 | + $wgOut->addWikiText( wfMsg( 'renameusererrortoomany', $oldusername ) ); |
| 125 | + return; |
| 126 | + } |
| 127 | + |
| 128 | + $rename = new RenameuserSQL($oldusername, $newusername, $uid ); |
116 | 129 | $rename->rename(); |
117 | 130 | |
118 | 131 | $log = new LogPage( '' ); |
— | — | @@ -140,6 +153,14 @@ |
141 | 154 | var $new; |
142 | 155 | |
143 | 156 | /** |
| 157 | + * The user ID |
| 158 | + * |
| 159 | + * @var integer |
| 160 | + * @access private |
| 161 | + */ |
| 162 | + var $uid; |
| 163 | + |
| 164 | + /** |
144 | 165 | * The the tables => fields to be updated |
145 | 166 | * |
146 | 167 | * @var array |
— | — | @@ -153,9 +174,11 @@ |
154 | 175 | * @param string $old The old username |
155 | 176 | * @param string $new The new username |
156 | 177 | */ |
157 | | - function RenameuserSQL($old, $new) { |
| 178 | + function RenameuserSQL($old, $new, $uid) { |
158 | 179 | $this->old = $old; |
159 | 180 | $this->new = $new; |
| 181 | + $this->uid = $uid; |
| 182 | + |
160 | 183 | $this->tables = array( |
161 | 184 | // 1.5 schema |
162 | 185 | 'user' => 'user_name', |
— | — | @@ -171,6 +194,7 @@ |
172 | 195 | * Do the rename operation |
173 | 196 | */ |
174 | 197 | function rename() { |
| 198 | + global $wgMemc, $wgDBname; |
175 | 199 | $fname = 'RenameuserSQL::rename'; |
176 | 200 | wfProfileIn( $fname ); |
177 | 201 | |
— | — | @@ -184,6 +208,17 @@ |
185 | 209 | $sql = "UPDATE LOW_PRIORITY $table SET $field = $qnew WHERE $field = $qold"; |
186 | 210 | $dbw->query($sql, $fname); |
187 | 211 | } |
| 212 | + |
| 213 | + # Update user_touched and clear user cache |
| 214 | + |
| 215 | + $dbw->update( 'user', |
| 216 | + /*SET*/ array( 'user_touched' => $dbw->timestamp() ), |
| 217 | + /*WHERE*/ array( 'user_name' => $this->new ), |
| 218 | + $fname |
| 219 | + ); |
| 220 | + $wgMemc->delete( "$wgDBname:user:id:{$this->uid}" ); |
| 221 | + |
| 222 | + |
188 | 223 | wfProfileOut( $fname ); |
189 | 224 | } |
190 | 225 | } |