MediaWiki
REL1_22
|
00001 <?php 00024 require_once __DIR__ . '/Maintenance.php'; 00025 00032 class DeleteRevision extends Maintenance { 00033 00034 public function __construct() { 00035 parent::__construct(); 00036 $this->mDescription = "Delete one or more revisions by moving them to the archive table"; 00037 } 00038 00039 public function execute() { 00040 if ( count( $this->mArgs ) == 0 ) { 00041 $this->error( "No revisions specified", true ); 00042 } 00043 00044 $this->output( "Deleting revision(s) " . implode( ',', $this->mArgs ) . 00045 " from " . wfWikiID() . "...\n" ); 00046 $dbw = wfGetDB( DB_MASTER ); 00047 00048 $affected = 0; 00049 foreach ( $this->mArgs as $revID ) { 00050 $dbw->insertSelect( 'archive', array( 'page', 'revision' ), 00051 array( 00052 'ar_namespace' => 'page_namespace', 00053 'ar_title' => 'page_title', 00054 'ar_page_id' => 'page_id', 00055 'ar_comment' => 'rev_comment', 00056 'ar_user' => 'rev_user', 00057 'ar_user_text' => 'rev_user_text', 00058 'ar_timestamp' => 'rev_timestamp', 00059 'ar_minor_edit' => 'rev_minor_edit', 00060 'ar_rev_id' => 'rev_id', 00061 'ar_text_id' => 'rev_text_id', 00062 'ar_deleted' => 'rev_deleted', 00063 'ar_len' => 'rev_len', 00064 ), array( 00065 'rev_id' => $revID, 00066 'page_id = rev_page' 00067 ), __METHOD__ 00068 ); 00069 if ( !$dbw->affectedRows() ) { 00070 $this->output( "Revision $revID not found\n" ); 00071 } else { 00072 $affected += $dbw->affectedRows(); 00073 $pageID = $dbw->selectField( 'revision', 'rev_page', array( 'rev_id' => $revID ), __METHOD__ ); 00074 $pageLatest = $dbw->selectField( 'page', 'page_latest', array( 'page_id' => $pageID ), __METHOD__ ); 00075 $dbw->delete( 'revision', array( 'rev_id' => $revID ) ); 00076 if ( $pageLatest == $revID ) { 00077 // Database integrity 00078 $newLatest = $dbw->selectField( 'revision', 'rev_id', array( 'rev_page' => $pageID ), __METHOD__, array( 'ORDER BY' => 'rev_timestamp DESC' ) ); 00079 $dbw->update( 'page', array( 'page_latest' => $newLatest ), array( 'page_id' => $pageID ), __METHOD__ ); 00080 } 00081 } 00082 } 00083 $this->output( "Deleted $affected revisions\n" ); 00084 } 00085 } 00086 00087 $maintClass = "DeleteRevision"; 00088 require_once RUN_MAINTENANCE_IF_MAIN;