6623de1a3d3bbf0cde83c551ce23d8470c9cd294
[lhc/web/wiklou.git] / maintenance / deleteRevision.php
1 <?php
2 /**
3 * Delete one or more revisions by moving them to the archive table.
4 *
5 * @file
6 * @ingroup Maintenance
7 */
8
9 require_once( "Maintenance.php" );
10
11 class DeleteRevision extends Maintenance {
12
13 public function __construct() {
14 parent::__construct();
15 $this->mDescription = "Delete one or more revisions by moving them to the archive table";
16 }
17
18 public function execute() {
19 if( count( $this->mArgs ) == 0 ) {
20 $this->error( "No revisions specified", true );
21 }
22
23 $this->output( "Deleting revision(s) " . implode( ',', $this->mArgs ) .
24 " from " . wfWikiID() . "...\n" );
25 $dbw = wfGetDB( DB_MASTER );
26
27 $affected = 0;
28 foreach ( $this->mArgs as $revID ) {
29 $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
30 array(
31 'ar_namespace' => 'page_namespace',
32 'ar_title' => 'page_title',
33 'ar_comment' => 'rev_comment',
34 'ar_user' => 'rev_user',
35 'ar_user_text' => 'rev_user_text',
36 'ar_timestamp' => 'rev_timestamp',
37 'ar_minor_edit' => 'rev_minor_edit',
38 'ar_rev_id' => 'rev_id',
39 'ar_text_id' => 'rev_text_id',
40 ), array(
41 'rev_id' => $revID,
42 'page_id = rev_page'
43 ), __METHOD__
44 );
45 if ( !$dbw->affectedRows() ) {
46 $this->output( "Revision $revID not found\n" );
47 } else {
48 $affected += $dbw->affectedRows();
49 $dbw->delete( 'revision', array( 'rev_id' => $revID ) );
50 }
51 }
52 $this->output( "Deleted $affected revisions\n" );
53 }
54 }
55
56 $maintClass = "DeleteRevision";
57 require_once( DO_MAINTENANCE );