Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Basically my 'private' mediawiki instance was about as secure as a toddlers piggybank. I've tightened it up now, but am left with about a hundred or so new pages and revisions generated by hundreds of randomly generated users.

2 part question; Is there a way to delete all orphaned pages? Can I say to roll back all revisions NOT made by a particular user (me)?

share|improve this question

7 Answers 7

If you don't want to use the export-and-reinstall method suggested by danlefree, you might also find the Nuke extension useful. Once installed, visiting the special page Special:Nuke as an administrator gives you a form like this:

Screenshot of MediaWiki Nuke extension interface

There are also several built-in MediaWiki maintenance scripts that could be useful, including:

  • cleanupSpam.php, which can be used to rollback and/or delete all revisions containing a link to a particular hostname,

  • deleteBatch.php, which can be used to delete all pages listed in a file, and

  • rollbackEdits.php (which doesn't currently seem to have proper on-wiki documentation), which can be used to roll back all edits of a specified user.

Spam cleanup using direct database access

It's also be possible to do what you want by directly manipulating the database. There details can vary a bit depending on your situation, but the basic steps would go something like this:

  1. Set your wiki to read-only mode. You do not want someone to try editing the wiki while you're messing with the database.

  2. Make a backup of your wiki. (This is highly recommended before any irreversible mass deletions anyway.)

  3. Delete all revisions that were not made by you:

    DELETE FROM revision WHERE rev_user != YOUR_USER_ID;

    This will get rid of the spam revisions (although their content will still remain in the text table), but will leave the page_latest field of any affected pages pointing to a nonexistent revision. This could cause confusion, so we'd better fix it:

  4. Wipe out the page_latest column for all pages:

    UPDATE page SET page_latest = 0;
  5. Rebuild the column, either by running the attachLatest.php maintenance script (recommended; remember to use the --fix parameter so that the script actually changes the database) or with a manual SQL query:

    UPDATE page SET page_latest =
        (SELECT MAX(rev_id) FROM revision WHERE rev_page = page_id);
  6. Delete all pages for which no revisions could be found:

    DELETE FROM page WHERE page_latest = 0;
  7. For a final touch, rebuild the links, text index and recent changes tables by running the rebuildall.php maintenance script. You may also want to remove the content of the deleted spam revisions from the database, so that they won't take up unnecessary space there, by running the purgeOldText.php maintenance script.

Once that's all done, check that everything looks good, and if so, turn off read-only mode — hopefully after installing some anti-spam features to keep the problem from reoccurring.

For small wikis, I highly recommend the QuestyCaptcha extension, which allows you to configure a simple custom text-based CAPTCHA. The trick is that, with every wiki having its own set of questions, programming a spambot to answer them correctly would be a lot of work for very little gain. I installed it on my own wiki after getting hit by XRumer a couple of times, and have seen no spam ever since.

Update: I just used these instructions to nuke about 35,000 spam revisions created by equally many users from a small wiki. Everything went fine. In this particular case, I started (after making a backup, of course) by finding the user ID of the last legitimate user (20) and deleting every user above that along with their contributions:

DELETE FROM user WHERE user_id > 20;
DELETE FROM user_groups WHERE ug_user > 20;
DELETE FROM user_properties WHERE up_user > 20;
DELETE FROM user_newtalk WHERE user_id > 20;
DELETE FROM revision WHERE rev_user > 20;

and then proceeded from step 4 above.

share|improve this answer

The easiest way to handle this situation (if you don't mind a nuke'n'pave) would be to export all wiki pages created or edited by your username, reinstall the wiki, and import the export file you'd generated.

"Reinstall" in this context would mean:

  1. Export articles created by you (presumably logged in as the WikiSysop user or similar)
  2. Drop the MW database
  3. Create an empty MW database
  4. Copy your LocalSettings.php file to a safe location
  5. Re-upload the /config/ directory
  6. Run the installation process on the new MW database (note that you will want to re-create your old admin user)
  7. Delete the /config/ directory and move your old LocalSettings.php file back to the MW root
  8. Import the file created at Step #1

Edit: You may want to pull down a database backup (including spam revisions) in case you encounter any problems with this process or would like to experiment with alternate ways to purge the spam.

share|improve this answer

In theory, you could write a MediaWiki extension to do whatever you like to a MediaWiki instance, including to do the things you mentioned.

Short of that, and short of the "nuke'n'pave" suggested by danlefree, you might find the User Merge and Delete extension useful: you can use it to consolidate multiple spambot accounts into a single account whose edits can then be addressed more easily.

share|improve this answer

The easiest way to handle this situation is to install extension DeleteBatch. Use Special:AllPages on your wiki to get a script file of the page names you want deleted, and load it into Special:DeleteBatch.

share|improve this answer

I took over an installation and found over 47,000 spam entries in the user table and almost 900,000 spam externallinks. I used Sequel Pro and visited each table and deleted entries not made by authentic users. I found spam in externallinks,page,searchindex,user,watchlist. It was fairly time-efficient; the bulk of my time was waiting for delete queries to run. I was lucky because most of the authentic edits happened early in the order of things.

share|improve this answer
There's no point in trying to delete spam links from externallinks, since that's a redundant metadata table that's basically only used for things like Special:LinkSearch; once you've cleaned up the actual pages, you can just run rebuildall.php to wipe and rebuild it. Ditto for searchindex. –  Ilmari Karonen Jan 10 at 3:08

If it's only one hundred spammy pages you're not doing too badly. I had to clean up a wiki which had thousands of spammed pages. I came across some good tips by User:Halz on this page: https://www.mediawiki.org/wiki/User:Halz/Mass_despamming including a breakdown of the limitations of the various tools.

At the bottom he's provided a useful SQL query which runs a bit slowly but helps you find pages which are most likely spam, particularly if you can identify the time period when the wiki got taken over by spammers. Halz also has a hacked version of Extension:Nuke which presents these kinds of query-able parameters for easy mass-deletion. He gave me a copy to use, but I don't think he's published it.

share|improve this answer

I strongly recommend not to mess with MediaWiki's SQL! MediaWiki is a complex beast, very optimized for Wikipedia. There are some weird things going on in SQL and if you simply DELETE rows things might loose consistency. (Meta: But I don't even have comment rights yet on this SO, so I can't comment on the answers that tell you to do this. I hate that part about SO.)

If you have some programming skills, go through the API. Pywikibot could be a good choice.

Otherwise, check the tools in the maintenance/ directory. You could try my own tool, mewsh to help with that (and I just added "anti-spam tools" as a todo there).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.