Topic on Project:Support desk/Flow

Undo or delete everything since a certain date

5
Cmjohannes (talkcontribs)

Is there a maintenance script or extension to delete all changes to a wiki since a certain date?

I recently updated an neglected wiki from 1.16 to 1.23.3. It had been abandoned about four years. During this time, spammers had created thousands of user accounts, created pages and made edits. I currently have the wiki locked down, so no one can make edits. I would simply like to "undo" all of the changes since (for example) Jan. 1, 2010. Only spammers have made changes since that date. I do not care if these page and user deletions are recorded in recent changes or if revision histories are kept.

I have found extensions to block or ban users and IP addresses (but not to automatically delete these same users' page edits). I have found extensions to delete changes made by a particular user or IP address. But are all too time consuming and limited, given the amount of spamming. I would simply like to "revert" the wiki to its 2010 state.

88.130.95.196 (talkcontribs)

Hi!

such a script does not come with the MediaWiki core. There are maintenance scripts to really remove all deleted revisions and there is the UserMerge extension to remove a single user (by merging him with Anonymous), but this is a single action and I don't think you want to do that hundreds of times.

You can try with the extensions Extension:Nuke, Extension:DeletePagePermanently and Extension:BlockAndNuke or with a combination of those. Especially BlockAndNuke looks promising I think as it can batch delete a huge number of pages with just a few commands. Also does BlockAndNuke come with a maintenance script, which allows to delete all revisions, which were not made by users in a specified list. With a few MySQL commands you will be able to create a list of the first n users in your database (of which most or all are "ok") and then make the extension delete everything else. This should already bring you a huge step forward. And(!), if UserMerge is installed as well, it even does merge the users into one single account effectively deleting them as well. Note however that I have not tried the extension and I don't know, which strange behaviours it has. Remember to make a backup before you start!

Ciencia Al Poder (talkcontribs)

The best way to do such "revert" is to restore a backup from those days ;)

If that's not possible, and the amount of spam is extreme, it may be more easy to just query the database directly to get a list of pages with edits before a given date, then you can export those pages with Special:Export, install the wiki from scratch (new database) and import those pages.

You can get them with this SQL query (note I haven't tested it).

SELECT DISTINCT page_namespace, page_title
FROM revison
JOIN page ON page_id = rev_page
WHERE rev_timestamp < CAST('20101231235959' AS BINARY);

You'll have to translate namespace numbers with the correct namespace name.

87.115.71.160 (talkcontribs)

This slight revision of the query does work

SELECT DISTINCT page_namespace, page_title

FROM mw_revision

JOIN mw_page ON page_id = rev_page

WHERE rev_timestamp < CAST('202308245959' AS BINARY);

Ciencia Al Poder (talkcontribs)

Of course, if you have installed MediaWiki with a table prefix, you should append it to the table names