Header
From Gamedatawiki
(Difference between revisions)
m |
m |
||
Line 17: | Line 17: | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
- | //< | + | //$wgExtensionFunctions[] = "wfExtensionSpecialDeleteOldRevisions"; |
- | <pre>< | + | $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.\ | ||
+ | " ); | ||
+ | |||
+ | # 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.\ | ||
+ | " ); | ||
+ | |||
+ | # 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.\ | ||
+ | " ); | ||
+ | |||
+ | # Inform the user of what we're going to do | ||
+ | $count = count( $old ); | ||
+ | $wgOut->addHTML( "$count inactive items found.\ | ||
+ | " ); | ||
+ | |||
+ | # 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.\ | ||
+ | " ); | ||
+ | } | ||
+ | |||
+ | # 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.\ | ||
+ | " ); | ||
+ | |||
+ | # 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.\ | ||
+ | " ); | ||
+ | |||
+ | # Inform the user of what we're going to do | ||
+ | $count = count( $old ); | ||
+ | $wgOut->addHTML( "$count old revisions found.\ | ||
+ | " ); | ||
+ | |||
+ | # 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.\ | ||
+ | " ); | ||
+ | } | ||
+ | |||
+ | # 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') . "')\\">\ | ||
+ | "); | ||
+ | $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 ?\\\ | ||
+ | Cette 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 ?\\\ | ||
+ | This operation cannot be undone."); | ||
+ | $wgMessageCache->addMessage('deleteoldrevisions-removalok', "The old revisions were successfully deleted."); | ||
+ | |||
+ | } | ||
+ | SpecialPage::addPage(new DeleteOldRevisionsPage()); | ||
+ | } | ||
+ | |||
+ | ?></nowiki></pre> | ||
+ | [[Category:MediaWiki extensions]] | ||
+ | [[Category:Extensions_by_Marc_Noirot]] | ||
+ | [[Category:Special page extensions]] | ||
</script> | </script> |
Revision as of 23:08, 18 November 2006
<style type="text/css"> /* Notes: -You must log as admin to edit this page -Whatever you enter in this page will be added to the html in the header after the standard style sheet, so you can override styles. -if you want your code to look nice on this page, put a space at the beginning of each line -This is the default style sheet that you can override : http://editthis.info/wiki/skins/monobook/main.css For example uncomment this next section to turn all the text green: */ /* body { color: green; } */ </style>
<script type="text/javascript"> //$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.\
" );
# 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.\
" );
# 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.\
" );
# Inform the user of what we're going to do $count = count( $old ); $wgOut->addHTML( "$count inactive items found.\
" );
# 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.\
" );
}
# 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.\
" );
# 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.\
" );
# Inform the user of what we're going to do $count = count( $old ); $wgOut->addHTML( "$count old revisions found.\
" );
# 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.\
" );
}
# 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') . "')\\">\
");
$wgOut->addHTML('' . wfMsg('deleteoldrevisions-label') . '
' );$wgOut->addHTML(wfElement( 'input', array( 'type' => 'submit', 'name' => 'delete', 'value' => wfMsg('deleteoldrevisions-button')))); $wgOut->addHTML("</form>");
if( $this->mPosted ) { global $wgOut;$wgOut->addHTML('
'); 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 ?\\\ Cette 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 ?\\\ This operation cannot be undone."); $wgMessageCache->addMessage('deleteoldrevisions-removalok', "The old revisions were successfully deleted."); } SpecialPage::addPage(new DeleteOldRevisionsPage()); } ?></nowiki>
</script>