Thread:Extension talk:UserMerge/Powershell script using curl to mege large numbers of users

For those of you who may have to merge large numbers of users - I had over 500 in less than a week after my latex-based captcha succumbed to the robots - the following Powershell script works as of 6/16/2013. I used it on Mediawiki version 1.20.2. Hope it's some help. It took me forever to get this worked out :)

The list of users is in the text file usersfull.txt, one user per line. I used mysql to generate the file. The file with the users should be in the directory that you change to at the beginning of the script.

The various output.html files are useful for debugging.

Each of the users in userfull.txt will be merged with the user DeleteMe and then the old user will be deleted. You should create the user DeleteMe before you run the script.


 * 1) Change the working directory

cd E:\users\bill\Documents\fixwiki


 * 1) Run Curl to get the cookies and the html file with the login token

curl -o output.html --cookie-jar cookie-jar.txt http://WWW.MYWIKI.ORG/wiki/index.php?title=Special:UserLogin

$token = Select-String 'wpLoginToken" value="(.*?)"' output.html $token = $token.Matches|select Groups | foreach {$_.Groups[1].Value}


 * 1) Log in

$myexe= "curl.exe" $myparms = " -L -o output2.html -b cookie-jar.txt -c cookie-jar.txt -d wpLoginToken=$token " + '-d wpName=USERNAME -d wpPassword=PASSWORD -d wpRemember=1 -d wpLoginattempt=`"Log in`"  http://WWW.MYWIKI.ORG/index.php?title=Special:UserLogin"&"action=submitlogin"&"type=login' $result = Invoke-Expression ($myexe + $myparms)


 * 1) Go to the merge page to get an edit token

$mycmd= "curl.exe -o output3.html -b cookie-jar.txt -c cookie-jar.txt http://WWW.MYWIKI.ORG/index.php?title=Special:UserMerge" $result = Invoke-Expression $mycmd


 * 1) Extract the edit token and add the urlencode for +\

$token = Select-String '"hidden" value="(.*?)\+' output3.html $token = $token.Matches|select Groups | foreach {$_.Groups[1].Value} $token = $token + '%2B%5C'


 * 1) Loop through usersfull.txt running the merge on each user

foreach ($user in Get-Content "usersfull.txt") {   Write-Host $user

# Run the merge

$mycmd= "curl.exe -o output.html -b cookie-jar.txt -c cookie-jar.txt -d token=$token -d olduser=$user -d newuser=DeleteMe -d deleteuser=on -d submit=Merge+user http://WWW.MYWIKI.ORG/index.php?title=Special:UserMerge" $result = Invoke-Expression $mycmd

} 