Extension talk:SpecialDeleteOldRevisions

Version 1.3 and above
Please use this section for the newer versions.

List of working MediaWiki versions

 * 1.6.x: yes
 * 1.7.x: yes
 * 1.8.2: probably (not tested)
 * 1.9.x: yes
 * 1.10.x: yes
 * 1.12.0rc1: no. This extension depends on the presence of \includes\HTMLForm.php, which was removed in this version.

Delete intermediate revisions
Also I wish for this functionality:

I want to keep the database small. As we use the wiki internally, history is not legally important.

I would like a function which physically deletes old versions restricted to these condition:

"Of all consecutive changes one specific user made to a page in one day, keep only the last one. Do not delete revisions newer than ."

- This would mainly delete working stages. - It will keep all changes different users made. - It will keep all changes that were made on different days.


 * I'm sorry, but I can't promise anything since my free time is very limited. - Marc

Proposed coding:
 * 1) Loop through all revisions, sorted by rev_user, rev_id DESC
 * 2) compare all consequtive entries, if rev_id and rev_user are identical.
 * 3) If comparision is true, delete the older entry (need to remember rev_id and rev_text_id to delete corresponding entries in other tables)
 * 4) delete corresponding entries in text where old_id = rev_text_id
 * 5) delete corresponding entries in recentchanges where rc_this_oldid = revision.rev_id

Since only the older entry is deleted, we do not delete the current revision.

Delete unused images
I would need a script that deletes all unused pictures on the server. The list is generated in Special:Unusedimages.

Thumbnails and pictures in other sizes need to be deleted, too.

Tested in 1.6.7
I would like to thank you, Marc, for this extension.

I have tested it in 1.6.7 and it does work fine in the respect, that all texts of the old revisions are deleted.

At this point, looking at the history of an article, one does still see all revisions, but looking at it fails with an error message.

Is there a script to clean the history log?


 * This is weird, because the tests I have made show that the text and the revisions themselves are deleted (if you look at the script, you can see the two functions that do the actual work). Could you write here the result text that appears on the special page when you delete the history ? - Marc


 * I'm using 1.7.1 and your scripts delete the history of each pages but not Special:Recentchanges - Titooy 11:53, 7 October 2006 (UTC)
 * Tested on 1.6.8 and it works fine, you'll have to refresh page (using SHIFT CTRL R in Firefox) to view only the last edit in history, the others have been deleted :) 82.242.126.103 07:33, 18 November 2006 (UTC)

Update for 1.8.2 ?
The current version is no more fully up to date, I should be grateful (at least) if this function was updated for MW 1.8.2 or if someone could detail a manual process Merci d'avance Armenfrast 23:12, 27 October 2006 (UTC)

can't work at 1.8.2.5555555555,can u give a new version on 1.82???

I was able to use it with MediaWiki 1.8.2 by simply commenting out the following lines: if ( ! $wgUser->isSysop ) { $wgOut->sysopRequired; return; } Of course, if you do that, you should exclude this extension after using it, and include it again only the next time you will use it. 201.7.82.156 13:59, 11 January 2007 (UTC)

Here is a better solution by actually updating the code to work with the new API in 1.8.2: if ( ! $wgUser->isAllowed("protect") ) { $wgOut->sysopRequired; return; } 75.180.27.195 23:05, 4 February 2007 (UTC)

request for more explanation in doc
What this extension does exactly is not made clear in the article. Will this allow you to delete selected revisions, or do you have to delete an entire history?


 * This extension has been made only to replicate the behaviour of a maintenance script found in the MediaWiki distribution (DeleteOldRevisions.php) and will delete all history. - Marc
 * This extension deletes the entire history of all articles. There is no selection on a specific article or revision.


 * Isn't it true that it deletes all revisions prior to the revision presented to the script: "up to date: specify the date of the revisions. All revision before and on that date will be deleted." - Scorpei

MySQL error message
Thank you for this script. I've been looking for something like it!

I get a strange error message when I try it myself, however. After I click on the delete button, this comes up: Error in fetchObject: MySQL server has gone away Backtrace:

GlobalFunctions.php line 602 calls wfbacktrace Database.php line 596 calls wfdebugdiebacktrace Database.php line 1787 calls databasemysql::fetchobject LinkBatch.php line 76 calls resultwrapper::fetchobject LinkBatch.php line 55 calls linkbatch::executeinto Skin.php line 192 calls linkbatch::execute Skin.php line 171 calls skinmonobook::preloadexistence SkinTemplate.php line 108 calls skin::initpage MonoBook.php line 28 calls skintemplate::initpage SkinTemplate.php line 151 calls skinmonobook::initpage OutputPage.php line 577 calls skinmonobook::outputpage OutputPage.php line 794 calls outputpage::output Database.php line 476 calls outputpage::databaseerror Database.php line 419 calls databasemysql::reportqueryerror SpecialDeleteOldRevisions.php line 63 calls databasemysql::query SpecialDeleteOldRevisions.php line 130 calls purgeredundanttext SpecialDeleteOldRevisions.php line 162 calls deleteoldrevisions SpecialDeleteOldRevisions.php line 190 calls deleteoldrevisionsform::execute SpecialPage.php line 276 calls deleteoldrevisionspage::execute Wiki.php line 155 calls specialpage::executepath Wiki.php line 47 calls mediawiki::initializespecialcases index.php line 123 calls mediawiki::initialize
 * Does it appear only on that page ??? Seems to me like it is a Mysql problem. Marc 23:18, 3 July 2006 (UTC)

Side effects on Page Titles? (character set)
I run this on MW 1.6.7 and the operation works fine. Except for if I dump export data (mssql40) and import it again, then remaining page titles containing Swedish characters are corrupt! I use character set latin1 (latin1_swedish_ci), but (only) the page titles are corrupted (probably into utf8) and NOT the body text. ... Rolf Lampa 03:10, 18 July 2006 (UTC)
 * Question - does anyone know if there's any manipulation of the page titles involved in the code used by SpecialDeleteOldRevisions, somewhere? (I tried to look for myself, but couldn't find any, but I'm not an expert).
 * Note: If I export and import without using SpecialDeleteOldRevisions, the data is OK.

Same problem, corrupt page titles after restore
I have the same problem as you do. I performed a backup of the database and then a restore and all the article titles that contained special Romanian characters were corrupted. Titles without special characters were not affected, and the body of all articles WITH or WITHOUT special characters were not affected. I'm running Wiki 1.6.3, source system is Linux with My SQL 4.1.19, destination system is Windows with My SQL 4.1.20

As in your case, MySQL server collation is UTF-8, the database collation is latin1_swedish_ci, and columns are latin1_bin.

Any ideas?
 * No, I had to give up. I restored my data without the cleaning up of the old revisions (but I could at least restore the data into the source dbs). Were your data irreversible corrupted? Rolf Lampa 11:46, 29 July 2006 (UTC)

Another Error (fixed?)
Database error A database query syntax error has occurred. This may indicate a bug in the software. The last  attempted database query was: (SQL query hidden) from within function "". MySQL returned error "1064: You have an error in your SQL syntax; check the   manual that corresponds to your MySQL server version for the right  syntax to use near 's',  'Christy_Walton', 'Citation', 'Cocky_Comedy', 'Coco_Chanel',  'Codecasa', 'Co' at line 1 (localhost)".

It breaks at the "Christie's". Perhaps the problem is with ' sign and the code for SQL in php file. (MediaWiki 1.9.1)
 * Viktorados 22:03, 21 February 2007 (UTC)

Should be fixed with Version 1.3. --GunterS 20:55, 24 February 2007 (UTC)


 * I still get this error when a name with a ' sign is used (using v1.3 and MW 1.9.2) --BB70 07:15, 22 March 2007 (UTC)
 * I have the same prob. I have pages with ' in title (using v1.3 and MW 1.9.2). -- Paul.D 20:18, 4 October 2007 (UTC)
 * I'm having the same issue (using v1.3 and MW 1.10.0). -- 206.47.249.251 18:53, 29 October 2007 (UTC)

A few serious errors and security concerns
I'd like to highlight a few problems for developers, but unfortunately I don't have time to submit patches.


 * Use Title::newFromText($pagename)->getDbKey instead of converting spaces to underscores.
 * Use 'where page_title='.$dbw->addQuotes($pagename) instead of "where page_title = '$pagename'", and don't use str_replace to double-up quotes.
 * There is no need to wrap $pagenamespace in quotes since you have ensured that it is an integer
 * $arc[] = "'" . $row->page_title . "'" needs to be replaced with $arc[] = $dbw->addQuotes($row->page_title). This will temporarily fix the bug people are currently stumbling on, with page names with single quotes not working.

I can't comment on other issues, I just looked at correct SQL creation.

Request for PHP/mySQL advice
I would appreciate some advice on how to modify this script (or at least a resource that would point me in the right direction). It is a bit more severe than I need for my purposes. I'm running v. 1.6.7, and I would like to this script in a way that would allow you to: I'd like to base it on the current script, but call it something like "CullRevisions.php" and add that in as a special page. Any ideas for where I should look for help? Thanks, Fungiblename 22:26, 13 July 2006 (UTC)
 * 1) Use the current revision deletion scheme (i.e., delete a page, restore some revisions) and
 * 2) Permanently delete the un-restored revisions

Here's what I figured out I need to do on the back end:

To SELECTIVELY delete old revisions (not just nuke them as this script does):

DELETE FROM tbl_text USING tbl_archive, tbl_text WHERE ((`tbl_archive`.`ar_text_id`>0) AND (`tbl_text`.`old_id` = `tbl_archive`.`ar_text_id`))
 * 1) Delete the page
 * 2) Restore the revisions you want to keep
 * 3) Log into your mySQL server and run the following query, replacing "tbl_" with your table prefix:

Then truncate your archive table. It's probably a good idea to leave this operation in mySQL to minimize the potential for accidentally running it. -Fungiblename

Notes on Extension
This extension is really great. It worked like a Charm for me. I did note that it does NOT remove the now-gone pages from whatever database the "Recent Changes" page pulls its results. Thus if you click on the "diff" on the Recent Pages, you get:

Error The database did not find the text of a page that it should have found, named "Exalted Errata (Diff: 1559, 1560)". This is usually caused by following an outdated diff or history link to a page that has been deleted. If this is not the case, you may have found a bug in the software. Please report this to an administrator, making note of the URL.


 * Fix: Run  from under the "maintenance" directory in your install directory to rebuild the histories (anything else?). (this must be run as a command line, it has built in security from being run via request.) --Slithytove2 08:05, 20 August 2006 (UTC)

Fixed with version 1.2. --GunterS 20:59, 24 February 2007 (UTC)

Download location
GunterS, would it be possible that you upload the code archive to mediawiki.org, or to create a subpage with the PHP code directly in it, so it's possible to download it even if your web page goes down ? Thanks by advance. Marc 18:21, 28 February 2007 (UTC)

Well, have not yet bothered to get a user. --GunterS 19:39, 28 February 2007 (UTC)

Mediawiki : 1.11.0
Hi,

I have a 1.11.0 MediaWiki. Can I use this extension ?

Thanks.--YvesProvence 10:52, 21 February 2008 (UTC)

Perfect
Works fine on my 1.8.2. I did the same mistake as everyone talking about special character problems here. It happened to me when I backed up my database and used that copy. The characters like umlauts are destroyed by that backup already and not by thsi extension. Have a close look ;) so i backed up my complete domain instead and run this extension on the untouched database. Works fine.

SOmeone on teh IRC channel explained the mysql dump problem to me. I forgot. It was complicated ;) --Subfader 00:53, 1 March 2008 (UTC)

Fuck u Satan 4 eternity NebulousIris (talk) 00:57, 22 September 2018 (UTC)

Mediawiki : 1.12.0
BUG!!

Warning: require_once(./includes/HTMLForm.php) [function.require-once]: failed to open stream: No such file or directory in C:\Program Files\Development\xampp\htdocs\mw1120\extensions\SpecialDeleteOldRevisions.php on line 76

Fatal error: require_once [function.require]: Failed opening required './includes/HTMLForm.php' (include_path='.;./includes;./languages;.;C:\Program Files\Development\xampp\php\pear\') in C:\Program Files\Development\xampp\htdocs\mw1120\extensions\SpecialDeleteOldRevisions.php on line 76

It seems like the file /includes/HTMLForm.php isn't part of Mediawiki anymore :/

Using this in Mediawiki 1.12.0

 * It seem to nice to use this extension by copying "includes/HTMLForm.php" form MW 1.11.x to MW1.12.0.--Roc michael 09:23, 25 March 2008 (UTC)


 * Did you actually delete old revisions in 1.12.0 or you just think it might work??? --Yakushi.kabuto 16:38, 25 March 2008 (UTC)


 * Yes, I've tried and the result was really nice. Good luck!--Roc michael 15:15, 28 March 2008 (UTC)


 * It doesn't work fork for me.... :/ Delete Rev is not even available in Special Pages list. --Yakushi.kabuto 09:18, 29 March 2008 (UTC)
 * Hrr, excuse me but isn't it included as commandline script in MW 1.12? maintenance/deleteOldRevisions.php. Still I'd prefer it with this extension cos I see what I do ;) --Subfader 17:23, 30 March 2008 (UTC)


 * does not work with 1.12 :-( --79.217.245.155 20:33, 5 May 2008 (UTC)


 * someone should enter this bug to: https://bugzilla.wikimedia.org (?)

The problem with the use of script
I tried to understand himself, read the text, but unfortunately did not understand one thing: "If using MySQL you need to optimize the tables afterwards, you can do that with phpMyAdmin." What does this mean? I must remove any table? What exactly? How to write correct a request to MySQL? --81.200.28.30 20:38, 17 April 2008 (UTC)

Bug & Patch
Hi, as said here : Extension_talk:SpecialDeleteOldRevisions, there are some bugs in this extension : It is may allow SQL injection. --193.251.84.98 08:07, 9 July 2008 (UTC)
 * Line 265 :
 * Old : $arc[] = "'" . $row->ar_title . "'";
 * Patch : $arc[] = $dbw->addQuotes($row->ar_title);
 * Line 274 :
 * Bug : $arc[] = "'" . $row->page_title . "'";
 * Patch : $arc[] = $dbw->addQuotes($row->page_title);

MediaWiki 1.13
Since many users don't have shell access, and probably cannot install "php shell" due to host-restrictions, could anyone make this useful extension runnable for MadiaWiki 1.13?

thx --msmithii 29 July 2008