Extension:UserMerge

User Merge and Delete extension allows Wiki users with the 'userrights' permission (Bureaucrat by default) to merge one Wiki user's account with another Wiki user's account - deleting following merge is also supported. You may not delete a user without merging first - omitting the "New User" field will auto-populate the New User as User ID 1 (Usually WikiSysop) and ask you to confirm merge to Admin. Merging to Anonymous (ID0) is not supported.

Installation

 * 1) Copy the Source Code (below) create the three required files: UserMerge_body.php, UserMerge.i18n.php, and UserMerge.php
 * 2) Create a new folder (directory) in the following location: wiki-install-folder/extensions/UserMerge
 * 3) Copy the three files in to the new UserMerge folder
 * 4) Add the following code to your LocalSettings.php (at the bottom, before the closing "?>")

UserMerge_body.php
 ");

if ($validNewUser && $validOldUser) { //go time, baby if (!$wgUser->matchEditToken( $wgRequest->getVal( 'token' ) ) ) { //bad editToken $wgOut->addHTML( "Invalid Edit Token. \n" ); } else { //good editToken $this->mergeUser($newuser_text,$newuserID,$olduser_text,$olduserID); if ($wgRequest->getText( 'deleteuser' )) { $this->deleteUser($olduserID, $olduser_text); }                 }                }        }

function deleteUser ($olduserID, $olduser_text) { global $wgOut; $dbw =& wfGetDB( DB_MASTER ); $dbw->delete( 'user_groups', array( 'ug_user' => $olduserID )); $dbw->delete( 'user', array( 'user_id' => $olduserID )); $wgOut->addHTML("$olduser_text($olduserID) has been deleted."); }       function mergeUser ($newuser_text, $newuserID, $olduser_text, $olduserID) { global $wgOut; $textUpdateFields = array(array('archive','ar_user_text'),                                         array('revision','rev_user_text'),                                          array('filearchive','fa_user_text'),                                          array('image','img_user_text'),                                          array('oldimage','oi_user_text'),                                          array('recentchanges','rc_user_text'),                                          array('ipblocks','ipb_address'));

$idUpdateFields = array(array('archive','ar_user'),                                         array('revision','rev_user'),                                          array('filearchive','fa_user'),                                          array('image','img_user'),                                          array('oldimage','oi_user'),                                          array('recentchanges','rc_user'),                                          array('logging','log_user'));

$dbw =& wfGetDB( DB_MASTER ); foreach ($idUpdateFields as $idUpdateField) { $dbw->update($idUpdateField[0], array( $idUpdateField[1] => $newuserID ), array( $idUpdateField[1] => $olduserID )); $wgOut->addHTML("Updating $idUpdateField[0] table ($olduserID to $newuserID) \n"); }               foreach ($textUpdateFields as $textUpdateField) { $dbw->update($textUpdateField[0], array( $textUpdateField[1] => $newuser_text ), array( $textUpdateField[1] => $olduser_text )); $wgOut->addHTML("Updating $textUpdateField[0] table ($olduser_text to $newuser_text) \n"); }

$dbw->delete( 'user_newtalk', array( 'user_ip' => $olduserID ));

$wgOut->addHTML(" \nMerge from $olduser_text($olduserID) to $newuser_text($newuserID) is complete.\n "); }       function loadMessages { static $messagesLoaded = false; global $wgMessageCache; if ( $messagesLoaded ) return true; $messagesLoaded = true;

require( dirname( __FILE__ ) . '/UserMerge.i18n.php' ); foreach ( $allMessages as $lang => $langMessages ) { $wgMessageCache->addMessages( $langMessages, $lang ); }

return true; } }

Usage

 * 1) Follow Installation Instructions
 * 2) You will have a new Restricted Special Page titled User Merge and Delete