Extension:SpecialDeleteOldRevisions

What is this extension good for?
This extension deletes permanently all old revisions of the specified (or all) article(s).

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.

Usage
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.

Installation
// 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.
 * 1) Make a file "SpecialDeleteOldRevisions.php" in /extensions with the code on this page.
 * 2) Add the following lines near the end in the LocalSettings.php file:

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.

Code till 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://meta.wikimedia.org/wiki/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("action\" method=\"post\" " .                       "onsubmit=\"return confirm('" . wfMsg('deleteoldrevisions-confirm') . "')\">\n"); $wgOut->addHTML(' ' . wfMsg('deleteoldrevisions-label') . ' ' ); $wgOut->addHTML(wfElement( 'input', array(                       'type'  => 'submit',                        'name'  => 'delete',                        'value' => wfMsg('deleteoldrevisions-button')))); $wgOut->addHTML(" ");

if( $this->mPosted ) { global $wgOut; $wgOut->addHTML(' '); DeleteOldRevisions(true); $wgOut->addHTML('&lt;/pre>'); $wgOut->addHTML(' ' . wfMsg('deleteoldrevisions-removalok') . ' '); }   } }

/** * 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&ucirc;r de vouloir effacer toutes les anciennes r&eacute;visions ?\\nCette op&eacute;ration ne peut etre annul&eacute;e."); $wgMessageCache->addMessage('deleteoldrevisions-removalok', "Les anciennes r&eacute;visions ont &eacute;t&eacute; effac&eacute;es avec succ&egrave;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); }

?>