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