Tell me more ×
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

4 Answers

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

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 should also be possible to do what you want by directly manipulating the database. I haven't tested this, 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) 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

Your Answer

 
discard

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.