]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - maintenance/deleteRevision.php
MediaWiki 1.17.4
[autoinstalls/mediawiki.git] / maintenance / deleteRevision.php
1 <?php
2 /**
3  * Delete one or more revisions by moving them to the archive table.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  * http://www.gnu.org/copyleft/gpl.html
19  *
20  * @ingroup Maintenance
21  */
22
23 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
24
25 class DeleteRevision extends Maintenance {
26
27         public function __construct() {
28                 parent::__construct();
29                 $this->mDescription = "Delete one or more revisions by moving them to the archive table";
30         }
31
32         public function execute() {
33                 if ( count( $this->mArgs ) == 0 ) {
34                         $this->error( "No revisions specified", true );
35                 }
36
37                 $this->output( "Deleting revision(s) " . implode( ',', $this->mArgs ) .
38                                                 " from " . wfWikiID() . "...\n" );
39                 $dbw = wfGetDB( DB_MASTER );
40
41                 $affected = 0;
42                 foreach ( $this->mArgs as $revID ) {
43                         $dbw->insertSelect( 'archive', array( 'page', 'revision' ),
44                                 array(
45                                         'ar_namespace'  => 'page_namespace',
46                                         'ar_title'      => 'page_title',
47                                         'ar_page_id'    => 'page_id',
48                                         'ar_comment'    => 'rev_comment',
49                                         'ar_user'       => 'rev_user',
50                                         'ar_user_text'  => 'rev_user_text',
51                                         'ar_timestamp'  => 'rev_timestamp',
52                                         'ar_minor_edit' => 'rev_minor_edit',
53                                         'ar_rev_id'     => 'rev_id',
54                                         'ar_text_id'    => 'rev_text_id',
55                                         'ar_deleted'    => 'rev_deleted',
56                                         'ar_len'        => 'rev_len',
57                                 ), array(
58                                         'rev_id' => $revID,
59                                         'page_id = rev_page'
60                                 ), __METHOD__
61                         );
62                         if ( !$dbw->affectedRows() ) {
63                                 $this->output( "Revision $revID not found\n" );
64                         } else {
65                                 $affected += $dbw->affectedRows();
66                                 $pageID = $dbw->selectField( 'revision', 'rev_page', array( 'rev_id' => $revID ), __METHOD__ );
67                                 $pageLatest = $dbw->selectField( 'page', 'page_latest', array( 'page_id' => $pageID ), __METHOD__ );
68                                 $dbw->delete( 'revision', array( 'rev_id' => $revID ) );
69                                 if ( $pageLatest == $revID ) {
70                                         // Database integrity
71                                         $newLatest = $dbw->selectField( 'revision', 'rev_id', array( 'rev_page' => $pageID ), __METHOD__, array( 'ORDER BY' => 'rev_timestamp DESC' ) );
72                                         $dbw->update( 'page', array( 'page_latest' => $newLatest ), array( 'page_id' => $pageID ), __METHOD__ );
73                                 }
74                         }
75                 }
76                 $this->output( "Deleted $affected revisions\n" );
77         }
78 }
79
80 $maintClass = "DeleteRevision";
81 require_once( RUN_MAINTENANCE_IF_MAIN );