Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mediawiki rollback bot (Mass undo troll actions!)

Tags:

php

mediawiki

I want to rollback every page a certain IP address has edited, and delete any pages they've made.

How can I do this with either a bot or a plugin or even default functionality to do this? I've found the bot documentation (here) but haven't been able to find any source codes with getting user contributions and rolling back.

Thanks for your help! This should preferably be in PHP.

like image 878
Cyclone Avatar asked Dec 22 '10 00:12

Cyclone


2 Answers

We had the same problem and I ended up creating a SQL script. See here. I tried it only two times and it worked for me. Below is the link to script.

http://www.gc-k.org/index.php/Cleaning_up_after_Vandals_%28Media_Wiki_Mass_Rollback%29

And here is the script itself. Change database properties before to use it. First command line argument should be name or IP of the user.

echo off
clear
USER=$1
DB_USR=XXX
DB_PWD=XXX
DB_NAME=XXX

echo "For all pages affected by $USER activities set  last revision to the last untouched one"
mysql $DB_NAME --user=$DB_USR --password=$DB_PWD  --execute="update page p set p.page_latest=( SELECT max(r.rev_id) FROM revision r WHERE r.rev_page=p.page_id and r.rev_user_text!='$USER' ) where p.page_id in (select distinct  r2.rev_page from revision r2 where r2.rev_user_text='$USER')"

echo "For all pages make sure that page len is set equal to revision len"
mysql $DB_NAME --user=$DB_USR --password=$DB_PWD  --execute="update page p set p.page_len=( SELECT r.rev_len FROM revision r WHERE r.rev_page=p.page_id and r.rev_id=p.page_latest )"

echo "Delete revisions done by $USER"
mysql $DB_NAME --user=$DB_USR --password=$DB_PWD --execute="delete from revision where rev_user_text='$USER'"

echo Delete $USER from the recent changes
mysql $DB_NAME --user=$DB_USR --password=$DB_PWD --execute="delete from recentchanges where rc_user_text='$USER'"

# Optional - clear cache
# mysql $DB_NAME --user=$DB_USR --password=$DB_PWD --execute="delete FROM `objectcache`"
# mysql $DB_NAME --user=$DB_USR --password=$DB_PWD --execute="delete FROM `querycache`"
# mysql $DB_NAME --user=$DB_USR --password=$DB_PWD --execute="delete FROM `querycachetwo`"

After script is run you have to hold SHIFT key when reloading page in the browser. Otherwise cached version will be rendered and you will not notice that rollback actually happened.

like image 181
Stan Sokolov Avatar answered Oct 16 '22 22:10

Stan Sokolov


The Extension:Nuke is explicitly written to delete all pages created by a given user in one click.

I don't think there's a tool to delete or revert all contributions made by one user, but there are scripts to rollback edits with one click. See also Manual:Combating vandalism.

like image 37
Bergi Avatar answered Oct 16 '22 21:10

Bergi