Index: trunk/extensions/Renameuser/SpecialRenameuser.php |
— | — | @@ -13,6 +13,11 @@ |
14 | 14 | |
15 | 15 | $wgExtensionFunctions[] = 'wfSpecialRenameuser'; |
16 | 16 | |
| 17 | +/** |
| 18 | + * The maximum number of edits a user can have and still be allowed renaming |
| 19 | + */ |
| 20 | +define( 'RENAMEUSER_CONTRIBLIMIT', 5000 ); |
| 21 | + |
17 | 22 | function wfSpecialRenameuser() { |
18 | 23 | global $IP, $wgMessageCache; |
19 | 24 | |
— | — | @@ -24,7 +29,8 @@ |
25 | 30 | 'renameusererrordoesnotexist' => 'The username "$1" does not exist', |
26 | 31 | 'renameusererrorexists' => 'The username "$1" already exits', |
27 | 32 | 'renameusererrorinvalid' => 'The username "$1" is invalid', |
28 | | - 'renameusererrortoomany' => 'The username "$1" has too many contributions, renaming would adversely affect site performance.', |
| 33 | + 'renameusererrortoomany' => 'The user "$1" has $2 contributions, renaming a user with ' . |
| 34 | + 'more than $3 contributions would adversely affect site performance', |
29 | 35 | 'renameusersuccess' => 'The user "$1" has been renamed to "$2"', |
30 | 36 | 'renameuserlog' => 'Renamed the user "[[User:$1|$1]]" to "[[User:$2|$2]]"', |
31 | 37 | ) |
— | — | @@ -37,7 +43,7 @@ |
38 | 44 | } |
39 | 45 | |
40 | 46 | function execute() { |
41 | | - global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgContLang; |
| 47 | + global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgContLang, $wgLang; |
42 | 48 | global $wgVersion, $wgMaxNameChars; |
43 | 49 | |
44 | 50 | $fname = 'Renameuser::execute'; |
— | — | @@ -116,11 +122,14 @@ |
117 | 123 | } |
118 | 124 | |
119 | 125 | // 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 ) ); |
| 126 | + if ( ( $contribs = User::edits( $uid ) ) > RENAMEUSER_CONTRIBLIMIT ) { |
| 127 | + $wgOut->addWikiText( |
| 128 | + wfMsg( 'renameusererrortoomany', |
| 129 | + $oldusername, |
| 130 | + $wgLang->formatNum( $contribs ), |
| 131 | + $wgLang->formatNum( RENAMEUSER_CONTRIBLIMIT ) |
| 132 | + ) |
| 133 | + ); |
125 | 134 | return; |
126 | 135 | } |
127 | 136 | |
— | — | @@ -195,7 +204,9 @@ |
196 | 205 | */ |
197 | 206 | function rename() { |
198 | 207 | global $wgMemc, $wgDBname; |
| 208 | + |
199 | 209 | $fname = 'RenameuserSQL::rename'; |
| 210 | + |
200 | 211 | wfProfileIn( $fname ); |
201 | 212 | |
202 | 213 | $dbw =& wfGetDB( DB_MASTER ); |
— | — | @@ -210,7 +221,6 @@ |
211 | 222 | } |
212 | 223 | |
213 | 224 | # Update user_touched and clear user cache |
214 | | - |
215 | 225 | $dbw->update( 'user', |
216 | 226 | /*SET*/ array( 'user_touched' => $dbw->timestamp() ), |
217 | 227 | /*WHERE*/ array( 'user_name' => $this->new ), |
— | — | @@ -218,7 +228,6 @@ |
219 | 229 | ); |
220 | 230 | $wgMemc->delete( "$wgDBname:user:id:{$this->uid}" ); |
221 | 231 | |
222 | | - |
223 | 232 | wfProfileOut( $fname ); |
224 | 233 | } |
225 | 234 | } |