]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/nukePage.php
MediaWiki 1.17.0
[autoinstallsdev/mediawiki.git] / maintenance / nukePage.php
1 <?php
2 /**
3  * Erase a page record from the database
4  * Irreversible (can't use standard undelete) and does not update link tables
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  * http://www.gnu.org/copyleft/gpl.html
20  *
21  * @ingroup Maintenance
22  * @author Rob Church <robchur@gmail.com>
23  */
24
25 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
26
27 class NukePage extends Maintenance {
28         public function __construct() {
29                 parent::__construct();
30                 $this->mDescription = "Remove a page record from the database";
31                 $this->addOption( 'delete', "Actually delete the page" );
32                 $this->addArg( 'title', 'Title to delete' );
33         }
34
35         public function execute() {
36
37                 $name = $this->getArg();
38                 $delete = $this->getOption( 'delete', false );
39
40                 $dbw = wfGetDB( DB_MASTER );
41                 $dbw->begin();
42
43                 $tbl_pag = $dbw->tableName( 'page' );
44                 $tbl_rec = $dbw->tableName( 'recentchanges' );
45                 $tbl_rev = $dbw->tableName( 'revision' );
46
47                 # Get page ID
48                 $this->output( "Searching for \"$name\"..." );
49                 $title = Title::newFromText( $name );
50                 if ( $title ) {
51                         $id   = $title->getArticleID();
52                         $real = $title->getPrefixedText();
53                         $isGoodArticle = $title->isContentPage();
54                         $this->output( "found \"$real\" with ID $id.\n" );
55
56                         # Get corresponding revisions
57                         $this->output( "Searching for revisions..." );
58                         $res = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_page = $id" );
59                         foreach ( $res as $row ) {
60                                 $revs[] = $row->rev_id;
61                         }
62                         $count = count( $revs );
63                         $this->output( "found $count.\n" );
64
65                         # Delete the page record and associated recent changes entries
66                         if ( $delete ) {
67                                 $this->output( "Deleting page record..." );
68                                 $dbw->query( "DELETE FROM $tbl_pag WHERE page_id = $id" );
69                                 $this->output( "done.\n" );
70                                 $this->output( "Cleaning up recent changes..." );
71                                 $dbw->query( "DELETE FROM $tbl_rec WHERE rc_cur_id = $id" );
72                                 $this->output( "done.\n" );
73                         }
74
75                         $dbw->commit();
76
77                         # Delete revisions as appropriate
78                         if ( $delete && $count ) {
79                                 $this->output( "Deleting revisions..." );
80                                 $this->deleteRevisions( $revs );
81                                 $this->output( "done.\n" );
82                                 $this->purgeRedundantText( true );
83                         }
84
85                         # Update stats as appropriate
86                         if ( $delete ) {
87                                 $this->output( "Updating site stats..." );
88                                 $ga = $isGoodArticle ? -1 : 0; // if it was good, decrement that too
89                                 $stats = new SiteStatsUpdate( 0, -$count, $ga, -1 );
90                                 $stats->doUpdate();
91                                 $this->output( "done.\n" );
92                         }
93                 } else {
94                         $this->output( "not found in database.\n" );
95                         $dbw->commit();
96                 }
97         }
98
99         public function deleteRevisions( $ids ) {
100                 $dbw = wfGetDB( DB_MASTER );
101                 $dbw->begin();
102
103                 $tbl_rev = $dbw->tableName( 'revision' );
104
105                 $set = implode( ', ', $ids );
106                 $dbw->query( "DELETE FROM $tbl_rev WHERE rev_id IN ( $set )" );
107
108                 $dbw->commit();
109         }
110 }
111
112 $maintClass = "NukePage";
113 require_once( RUN_MAINTENANCE_IF_MAIN );