Extension:DeletePagePermanently/1.0

From MediaWiki.org

Jump to: navigation, search

         

Manual on MediaWiki Extensions
List of MediaWiki Extensions
Crystal Clear action run.png
DeletePagePermanently

Release status: beta

Implementation  User interface
Description Delete a page permanently from the database
Author(s)  Ludovic MOUTON (LeLorrainTalk)
Last Version  v 1.0
MediaWiki  1.12+
License GPL
Download no link

Contents

[edit] What can this extension do?

The extension DeletePagePermanently adds a new tab that allows you to delete a page permanently from the database. I advise you to test carefully the extension and backup your database as the extension is in beta status.

This extension does NOT delete Template pages.

[edit] Download instructions

Please cut and paste the code found below and place it in $IP/extensions/DeletePagePermanently/DeletePagePermanently.php and DeletePagePermanently.i18n.php. Note: $IP stands for the root directory of your MediaWiki installation, the same directory that holds LocalSettings.php.

[edit] Installation

The extension was designed for MediaWiki 1.13 but it should be compatible with other MediaWiki version as long as the database layout is the same as MediaWiki 13.0 for the tables page_restrictions, revision, text, revision, page and recentchanges. However the extension seems to be compatible with MediaWiki 11.0+ or 1.12+ because of the use of wfLoadExtensionMessages which seems to be introduced in 1.11 or even only 1.12alpha.

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/DeletePagePermanently/DeletePagePermanently.php");
#add configuration parameters here
#setup user rights here

[edit] User rights

The extension introduces a new user rights deleteperm.

Defaults from DeletePagePermanently.php:

$wgGroupPermissions['*']         ['deleteperm'] = false;
$wgGroupPermissions['user']      ['deleteperm'] = false;
$wgGroupPermissions['bureaucrat']['deleteperm'] = false;
$wgGroupPermissions['sysop']     ['deleteperm'] = true;

[edit] Code

<?php
/**
 * DeletePagePermanently.php
 * Ludovic MOUTON	 2008
 * v. 1.0 BETA
 * GPL
*/
 
if ( !defined( 'MEDIAWIKI' ) ) {
	exit( 1 ) ;
}
 
$wgExtensionCredits['other'][] = array(
    'name' => 'DeletePagePermanently',
	'version' => '1.0 BETA',
    'author' => 'Ludovic MOUTON',
    'desciprion' => 'Adds a new delete tab to each page. Pages are deleted permanently from the database.',
	'url'     => 'http://www.mediawiki.org/wiki/Extension:DeletePagePermanently',
);
 
# Default settings
$wgGroupPermissions['*']         ['deleteperm'] = false;
$wgGroupPermissions['user']      ['deleteperm'] = false;
$wgGroupPermissions['bureaucrat']['deleteperm'] = false;
$wgGroupPermissions['sysop']     ['deleteperm'] = true; 
 
$wgExtensionMessagesFiles['DeletePagePermanently'] = dirname( __FILE__ ) . '/DeletePagePermanently.i18n.php';
 
$wgExtensionFunctions[] = 'wfDeletePagePermanently';
 
function wfDeletePagePermanently()
{
	new wfDeletePagePermanently;
	return true;
}
 
class wfDeletePagePermanently
{
	function wfDeletePagePermanently()
	{
		global $wgHooks, $wgMessageCache;
 
		wfLoadExtensionMessages( 'DeletePagePermanently' );
 
		$wgMessageCache->addMessage( 'delete_permanently', wfMsg('tab_label'));
		$wgHooks['SkinTemplateContentActions'][] = array(&$this, 'AddContentHook');
		$wgHooks['UnknownAction'][] = array(&$this, 'AddActionHook');
	}
 
	function AddContentHook( &$content_actions )
	{
		global $wgRequest, $wgRequest, $wgTitle, $wgUser;
 
		if(!$wgUser->isAllowed( 'deleteperm' ) )
			return true;
 
		$action = $wgRequest->getText( 'action' );
 
		if ( $wgTitle->getNamespace() != NS_SPECIAL )
		{
			wfLoadExtensionMessages( 'DeletePagePermanently' );
			$content_actions['delete_permanently'] = array(
				'class' => $action == 'delete_permanently' ? 'selected' : false,
				'text' => wfMsg( 'delete_permanently' ),
				'href' => $wgTitle->getLocalUrl( 'action=delete_permanently' )
			);
		}
 
		return true;
	}
 
	function AddActionHook( $action, &$wgArticle )
	{
		global $wgOut, $wgUser;
 
		if(!$wgUser->isAllowed( 'deleteperm' ))
		{
			$wgOut->permissionRequired('deleteperm');
			return false;
		}
 
		if ($action != 'delete_permanently' )
			return false;
 
		wfLoadExtensionMessages( 'DeletePagePermanently' );
 
		$dbw = wfGetDB( DB_MASTER );
		$ns  = $wgArticle->mTitle->getNamespace();
		$t   = $wgArticle->mTitle->getDBkey();
		$id  = $wgArticle->mTitle->getArticleID();
 
		if ( $t == '' || $id == 0 || $ns != NS_MAIN)
			return false;
 
		# Delete restrictions for the page
		$dbw->delete( 'page_restrictions', array ( 'pr_page' => $id ), __METHOD__ );
 
		# In the table 'revision' : Read all the 'rev_text_id' where 'rev_page' = $id
		$rev_text_id = array();
		$result_rev_text_id = $dbw->select ('revision', 'rev_text_id', "rev_page=$id");
		if(false !== $result_rev_text_id)
			while($row = $dbw->fetchObject($result_rev_text_id))
				$rev_text_id[] = $row->rev_text_id;
 
		# In the table 'text' : Delete the rows where 'old_id' = 'rev_text_id'
		foreach ($rev_text_id as &$value)
			$dbw->delete('text', array('old_id'=>$value), __METHOD__);
 
		# In the table 'revision' : Delete all the revision of the page where 'rev_page' = $id
		$dbw->delete('revision', array('rev_page'=>$id), __METHOD__);
 
		# In the table 'page' : Delete the page entry
		$dbw->delete( 'page', array( 'page_id' => $id ), __METHOD__);
 
		# Clean up recentchanges entries...
		$dbw->delete( 'recentchanges', array( 'rc_namespace' => $ns, 'rc_title' => $t ), __METHOD__ );
 
		$wgOut->addHTML(wfMsgHtml('del_done')); 
 
		return false;
	}
}
<?php
/**
 * DeletePagePermanently.i18n.php
 * Internationalisation file
 * Ludovic MOUTON
 * v. 1.0 BETA
 * GPL
*/
 
$messages = array();
 
$messages['en'] = array (
	'tab_label' => 'Delete permanently',
	'del_done'  => 'The page has been permanently deleted.');
 
$messages['fr'] = array (
	'tab_label' => 'Supprimer définitivement',
	'del_done'  => 'La page a été définitivement effacée.');

[edit] See also