r10032 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10031‎ | r10032 | r10033 >
Date:17:06, 9 July 2005
Author:avar
Status:old
Tags:
Comment:
* Moving the contributions limit into a define()
* Changed msg:renameusererrortoomany to show the actual limit
* The User class now has an edit counter, using that
Modified paths:
  • /trunk/extensions/Renameuser/SpecialRenameuser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Renameuser/SpecialRenameuser.php
@@ -13,6 +13,11 @@
1414
1515 $wgExtensionFunctions[] = 'wfSpecialRenameuser';
1616
 17+/**
 18+ * The maximum number of edits a user can have and still be allowed renaming
 19+ */
 20+define( 'RENAMEUSER_CONTRIBLIMIT', 5000 );
 21+
1722 function wfSpecialRenameuser() {
1823 global $IP, $wgMessageCache;
1924
@@ -24,7 +29,8 @@
2530 'renameusererrordoesnotexist' => 'The username "$1" does not exist',
2631 'renameusererrorexists' => 'The username "$1" already exits',
2732 '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',
2935 'renameusersuccess' => 'The user "$1" has been renamed to "$2"',
3036 'renameuserlog' => 'Renamed the user "[[User:$1|$1]]" to "[[User:$2|$2]]"',
3137 )
@@ -37,7 +43,7 @@
3844 }
3945
4046 function execute() {
41 - global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgContLang;
 47+ global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgContLang, $wgLang;
4248 global $wgVersion, $wgMaxNameChars;
4349
4450 $fname = 'Renameuser::execute';
@@ -116,11 +122,14 @@
117123 }
118124
119125 // 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+ );
125134 return;
126135 }
127136
@@ -195,7 +204,9 @@
196205 */
197206 function rename() {
198207 global $wgMemc, $wgDBname;
 208+
199209 $fname = 'RenameuserSQL::rename';
 210+
200211 wfProfileIn( $fname );
201212
202213 $dbw =& wfGetDB( DB_MASTER );
@@ -210,7 +221,6 @@
211222 }
212223
213224 # Update user_touched and clear user cache
214 -
215225 $dbw->update( 'user',
216226 /*SET*/ array( 'user_touched' => $dbw->timestamp() ),
217227 /*WHERE*/ array( 'user_name' => $this->new ),
@@ -218,7 +228,6 @@
219229 );
220230 $wgMemc->delete( "$wgDBname:user:id:{$this->uid}" );
221231
222 -
223232 wfProfileOut( $fname );
224233 }
225234 }

Status & tagging log