Extension:SpecialDeleteOldRevisions
From MediaWiki.org
If you use mediawiki > 1.12, consider using SpecialDeleteOldRevisions2 extension instead. It is curently maintained and fixed for latest wiki release, and you won't have to apply all patches manually.
| This extension does not work since 1.12.x due to the removal of an included file "includes/HTMLForm.php", but if you upload that file from the latest available package where the file was in 1.11.2, the extension is working again. |
|
SpecialDeleteOldRevisions Release status: beta |
|
|---|---|
| Implementation | Special page |
| Description | Will permanently delete old revisions of all or specified articles. (You cannot specify articles prior to 1.7) |
| Author(s) | Marc Noirot, Gunter Schmidt |
| Last Version | 1.3 (2007-02-24) |
| MediaWiki | 1.6, 1.9 |
| License | No license specified |
| Download | original |
Contents |
[edit] What is this extension good for?
This extension deletes permanently all old revisions of all article(s). If you are using 1.7 or newer you can alternatively specify articles, otherwise it acts on all articles.
What it does not do: You can not choose a certain revision (check Oversight for that functionality).
This extension adds a special page accessible to sysops only.
[edit] Usage (1.7 and newer)
You need to be logged in as sysop. Under special pages you will find the Delete old revision page in the sysop section.
- page: specify the pages to be deleted, % for all pages.
- namespace: specify the namespace for the articles, check all for all namespaces.
- up to date: specify the date of the revisions. All revision before and on that date will be deleted.
- Delete archived articles: If this is checked all already deleted articles will be permanently deleted.
This extension will clear the tables: archive, page, revision, text, recent changes and logging.
Example: If you want to delete all unused MediaWiki-Texts (which have been deleted after upgrading to 1.8), choose namespace MediaWiki and article name: %. The database will be significantly smaller.
If using MySQL you need to optimize the tables afterwards, you can do that with phpMyAdmin.
[edit] Usage (1.6 and older)
You need to be logged in as sysop. Under special pages you will find the Delete old revision page in the sysop section.
You next get a page with a single button to Delete. This will delete all revisions from all pages.
[edit] Installation
- Make a file "SpecialDeleteOldRevisions.php" in /extensions with the code on this page.
- Add the following lines near the end in the LocalSettings.php file:
// Extension DeleteOldRevisions $wgAvailableRights[] = 'DeleteOldRevisions'; //this line only on MediaWiki 1.8.x and below $wgGroupPermissions['sysop']['DeleteOldRevisions'] = true; include_once('extensions/SpecialDeleteOldRevisions.php');
You can now access the Special:DeleteOldRevisions page as a sysop.
[edit] Code from 1.13.2
To use this extension, do the following to make it work:
- create the directory "SpecialDeleteOldRevisions"
- place the HTMLForm.php from 1.11.2, replacing includes/HTMLForm.php
- edited line with quotes problem
Now you can download it here
You just need to put lines
$wgGroupPermissions['sysop']['DeleteOldRevisions'] = true;
include_once('extensions/SpecialDeleteOldRevisions/SpecialDeleteOldRevisions.php');
in LocalSettings.php - and everything will work fine.
[edit] Code from 1.7.x
This code has been tested on MediaWiki 1.9.2.
Warning: This code has extended functionality and is still in beta stage. Test in a safe environment and backup your DB!
Download here.
Please use download, it is up to date.
[edit] Code through 1.6.x
Note: This code is outdated, it does not have the article selection.
This code has been tested on MediaWiki 1.6.7.
Note: Won't work on MediaWiki 1.7 (Call to deprecated (v1.7) User::isSysop() method)
- Fix: If you find the function User::isSysop() in includes/User.php, you will see the new function, albeit commented out. (it is User::isAllowed('protect') on my version.)
History:
- 20 June 2006 -- Version 1.0 -- First release.
<?php /* Special:DeleteOldRevisions Mediawiki Extension By Marc Noirot - marc dot noirot at gmail This extension adds a special page accessible to sysops only to permanently delete the history from the wiki. This extension is adapted from the scripts found in the 'maintenance' folder. WARNING: deleting the old revisions is a permanent operation that cannot be undone. It is strongly recommended that you back up your database before attempting to use this script. */ if (!defined('MEDIAWIKI')) die(); $wgExtensionFunctions[] = "wfExtensionSpecialDeleteOldRevisions"; $wgExtensionCredits['specialpage'][] = array( 'name' => 'Special:DeleteOldRevisions', 'description' => 'adds a special page to delete all history from the wiki', 'url' => 'http://www.mediawiki.org/wiki/Extension:SpecialDeleteOldRevisions', 'author' => 'Marc Noirot', 'version' => '1.0' ); require_once "$IP/includes/HTMLForm.php"; require_once "$IP/includes/SpecialPage.php"; /** * Support function for cleaning up redundant text records */ function PurgeRedundantText( $delete = false ) { global $wgOut; # Data should come off the master, wrapped in a transaction $dbw =& wfGetDB( DB_MASTER ); $dbw->begin(); $tbl_arc = $dbw->tableName( 'archive' ); $tbl_rev = $dbw->tableName( 'revision' ); $tbl_txt = $dbw->tableName( 'text' ); # Get "active" text records from the revisions table $wgOut->addHTML("Searching for active text records in revisions table... "); $res = $dbw->query( "SELECT DISTINCTROW rev_text_id FROM $tbl_rev" ); while( $row = $dbw->fetchObject( $res ) ) { $cur[] = $row->rev_text_id; } $wgOut->addHTML( "done.\n" ); # Get "active" text records from the archive table $wgOut->addHTML( "Searching for active text records in archive table... " ); $res = $dbw->query( "SELECT DISTINCTROW ar_text_id FROM $tbl_arc" ); while( $row = $dbw->fetchObject( $res ) ) { $cur[] = $row->ar_text_id; } $wgOut->addHTML( "done.\n" ); # Get the IDs of all text records not in these sets $wgOut->addHTML( "Searching for inactive text records... " ); $set = implode( ', ', $cur ); $res = $dbw->query( "SELECT old_id FROM $tbl_txt WHERE old_id NOT IN ( $set )" ); while( $row = $dbw->fetchObject( $res ) ) { $old[] = $row->old_id; } $wgOut->addHTML( "done.\n" ); # Inform the user of what we're going to do $count = count( $old ); $wgOut->addHTML( "$count inactive items found.\n" ); # Delete as appropriate if( $delete && $count ) { $wgOut->addHTML( "Deleting... " ); $set = implode( ', ', $old ); $dbw->query( "DELETE FROM $tbl_txt WHERE old_id IN ( $set )" ); $wgOut->addHTML( "done.\n" ); } # Done $dbw->commit(); } /** * Support function for deleting old revisions */ function DeleteOldRevisions( $delete = false ) { global $wgOut; # Data should come off the master, wrapped in a transaction $dbw =& wfGetDB( DB_MASTER ); $dbw->begin(); $tbl_pag = $dbw->tableName( 'page' ); $tbl_rev = $dbw->tableName( 'revision' ); # Get "active" revisions from the page table $wgOut->addHTML( "Searching for active revisions... " ); $res = $dbw->query( "SELECT page_latest FROM $tbl_pag" ); while( $row = $dbw->fetchObject( $res ) ) { $cur[] = $row->page_latest; } $wgOut->addHTML( "done.\n" ); # Get all revisions that aren't in this set $wgOut->addHTML( "Searching for inactive revisions... " ); $set = implode( ', ', $cur ); $res = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_id NOT IN ( $set )" ); while( $row = $dbw->fetchObject( $res ) ) { $old[] = $row->rev_id; } $wgOut->addHTML( "done.\n" ); # Inform the user of what we're going to do $count = count( $old ); $wgOut->addHTML( "$count old revisions found.\n" ); # Delete as appropriate if( $delete && $count ) { $wgOut->addHTML( "Deleting... " ); $set = implode( ', ', $old ); $dbw->query( "DELETE FROM $tbl_rev WHERE rev_id IN ( $set )" ); $wgOut->addHTML( "done.\n" ); } # This bit's done # Purge redundant text records $dbw->commit(); PurgeRedundantText( $delete ); } /** * The simple form used to delete the revisions. */ class DeleteOldRevisionsForm extends HTMLForm { var $mPosted, $mRequest, $mSaveprefs, $action; function DeleteOldRevisionsForm($request) { $this->mPosted = $request->wasPosted(); $this->mRequest =& $request; $this->mName = 'deleteoldrevisions'; $titleObj = Title::makeTitle( NS_SPECIAL, 'DeleteOldRevisions' ); $this->action = $titleObj->escapeLocalURL(); } function execute() { global $wgOut; $wgOut->addHTML("<form name=\"uluser\" action=\"$this->action\" method=\"post\" " . "onsubmit=\"return confirm('" . wfMsg('deleteoldrevisions-confirm') . "')\">\n"); $wgOut->addHTML('<p>' . wfMsg('deleteoldrevisions-label') . '</p>' ); $wgOut->addHTML(wfElement( 'input', array( 'type' => 'submit', 'name' => 'delete', 'value' => wfMsg('deleteoldrevisions-button')))); $wgOut->addHTML("</form>"); if( $this->mPosted ) { global $wgOut; $wgOut->addHTML('<pre>'); DeleteOldRevisions(true); $wgOut->addHTML('</pre>'); $wgOut->addHTML('<p><strong>' . wfMsg('deleteoldrevisions-removalok') . '<strong></p>'); } } } /** * The special page itself. */ class DeleteOldRevisionsPage extends SpecialPage { function DeleteOldRevisionsPage() { SpecialPage::SpecialPage('DeleteOldRevisions', 'userrights'); } function execute() { global $wgUser, $wgOut; if ( ! $wgUser->isSysop() ) { $wgOut->sysopRequired(); return; } $this->setHeaders(); global $wgRequest; $form = new DeleteOldRevisionsForm($wgRequest); $form->execute(); } } /** * The extension entry-point. * Supported languages: french and english. */ function wfExtensionSpecialDeleteOldRevisions() { global $wgMessageCache, $wgLanguageCode; if ($wgLanguageCode == 'fr') { $wgMessageCache->addMessage('deleteoldrevisions', 'Suppression des anciennes revisions'); $wgMessageCache->addMessage('deleteoldrevisions-label', 'Cliquez sur \'Effacer\' pour effacer toutes les anciennes revisions du wiki.'); $wgMessageCache->addMessage('deleteoldrevisions-button', 'Effacer'); $wgMessageCache->addMessage('deleteoldrevisions-confirm', "Etes-vous sûr de vouloir effacer toutes les anciennes révisions ?\\nCette opération ne peut etre annulée."); $wgMessageCache->addMessage('deleteoldrevisions-removalok', "Les anciennes révisions ont été effacées avec succès."); } else { $wgMessageCache->addMessage('deleteoldrevisions', 'Delete old revisions'); $wgMessageCache->addMessage('deleteoldrevisions-label', 'Click on \'Delete\' to delete all the wiki\'s old revisions.'); $wgMessageCache->addMessage('deleteoldrevisions-button', 'Delete'); $wgMessageCache->addMessage('deleteoldrevisions-confirm', "Are you sure you want to delete all the old revisions ?\\nThis operation cannot be undone."); $wgMessageCache->addMessage('deleteoldrevisions-removalok', "The old revisions were successfully deleted."); } SpecialPage::addPage(new DeleteOldRevisionsPage()); }
[edit] Optimizing tables
After the revisions have been deleted, optimize all tables by checking them all in myPhpAdmin and then in the "With selected:" drop down at the bottom of the page, choose "optimize".
[edit] Known issues
If pages have single quotes in their titles, an error will result. This can be fixed:
- In the code (near line 270), replace
- $arc[] = "'" . $row->page_title . "'";
- with
- $arc[] = $dbw->addQuotes($row->page_title);
This will temporarily fix the bug people are currently stumbling on.

