r10024 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10023‎ | r10024 | r10025 >
Date:09:18, 9 July 2005
Author:timstarling
Status:old
Tags:
Comment:
miscellaneous improvements
Modified paths:
  • /trunk/extensions/Renameuser/SpecialRenameuser.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Renameuser/SpecialRenameuser.php
@@ -24,6 +24,7 @@
2525 'renameusererrordoesnotexist' => 'The username "$1" does not exist',
2626 'renameusererrorexists' => 'The username "$1" already exits',
2727 'renameusererrorinvalid' => 'The username "$1" is invalid',
 28+ 'renameusererrortoomany' => 'The username "$1" has too many contributions, renaming would adversely affect site performance.',
2829 'renameusersuccess' => 'The user "$1" has been renamed to "$2"',
2930 'renameuserlog' => 'Renamed the user "[[User:$1|$1]]" to "[[User:$2|$2]]"',
3031 )
@@ -39,6 +40,8 @@
4041 global $wgOut, $wgUser, $wgTitle, $wgRequest, $wgContLang;
4142 global $wgVersion, $wgMaxNameChars;
4243
 44+ $fname = 'Renameuser::execute';
 45+
4346 $this->setHeaders();
4447
4548 if ( ! $wgUser->isAllowed( 'renameuser' ) ) {
@@ -101,7 +104,8 @@
102105 return;
103106 }
104107
105 - if ($olduser->idForName() == 0) {
 108+ $uid = $olduser->idForName();
 109+ if ($uid == 0) {
106110 $wgOut->addWikiText( wfMsg( 'renameusererrordoesnotexist', $oldusername ) );
107111 return;
108112 }
@@ -111,7 +115,16 @@
112116 return;
113117 }
114118
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 );
116129 $rename->rename();
117130
118131 $log = new LogPage( '' );
@@ -140,6 +153,14 @@
141154 var $new;
142155
143156 /**
 157+ * The user ID
 158+ *
 159+ * @var integer
 160+ * @access private
 161+ */
 162+ var $uid;
 163+
 164+ /**
144165 * The the tables => fields to be updated
145166 *
146167 * @var array
@@ -153,9 +174,11 @@
154175 * @param string $old The old username
155176 * @param string $new The new username
156177 */
157 - function RenameuserSQL($old, $new) {
 178+ function RenameuserSQL($old, $new, $uid) {
158179 $this->old = $old;
159180 $this->new = $new;
 181+ $this->uid = $uid;
 182+
160183 $this->tables = array(
161184 // 1.5 schema
162185 'user' => 'user_name',
@@ -171,6 +194,7 @@
172195 * Do the rename operation
173196 */
174197 function rename() {
 198+ global $wgMemc, $wgDBname;
175199 $fname = 'RenameuserSQL::rename';
176200 wfProfileIn( $fname );
177201
@@ -184,6 +208,17 @@
185209 $sql = "UPDATE LOW_PRIORITY $table SET $field = $qnew WHERE $field = $qold";
186210 $dbw->query($sql, $fname);
187211 }
 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+
188223 wfProfileOut( $fname );
189224 }
190225 }

Status & tagging log