ba0fe5da5db3d63f5ba0d6b355c9f36a76591bc3
3 * Erase a page record from the database
4 * Irreversible (can't use standard undelete) and does not update link tables
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.
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.
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
22 * @ingroup Maintenance
23 * @author Rob Church <robchur@gmail.com>
26 require_once __DIR__
. '/Maintenance.php';
29 * Maintenance script that erases a page record from the database.
31 * @ingroup Maintenance
33 class NukePage
extends Maintenance
{
34 public function __construct() {
35 parent
::__construct();
36 $this->addDescription( 'Remove a page record from the database' );
37 $this->addOption( 'delete', "Actually delete the page" );
38 $this->addArg( 'title', 'Title to delete' );
41 public function execute() {
42 $name = $this->getArg( 0 );
43 $delete = $this->hasOption( 'delete' );
45 $dbw = $this->getDB( DB_MASTER
);
46 $this->beginTransaction( $dbw, __METHOD__
);
48 $tbl_pag = $dbw->tableName( 'page' );
49 $tbl_rec = $dbw->tableName( 'recentchanges' );
50 $tbl_rev = $dbw->tableName( 'revision' );
53 $this->output( "Searching for \"$name\"..." );
54 $title = Title
::newFromText( $name );
56 $id = $title->getArticleID();
57 $real = $title->getPrefixedText();
58 $isGoodArticle = $title->isContentPage();
59 $this->output( "found \"$real\" with ID $id.\n" );
61 # Get corresponding revisions
62 $this->output( "Searching for revisions..." );
63 $res = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_page = $id" );
65 foreach ( $res as $row ) {
66 $revs[] = $row->rev_id
;
68 $count = count( $revs );
69 $this->output( "found $count.\n" );
71 # Delete the page record and associated recent changes entries
73 $this->output( "Deleting page record..." );
74 $dbw->query( "DELETE FROM $tbl_pag WHERE page_id = $id" );
75 $this->output( "done.\n" );
76 $this->output( "Cleaning up recent changes..." );
77 $dbw->query( "DELETE FROM $tbl_rec WHERE rc_cur_id = $id" );
78 $this->output( "done.\n" );
81 $this->commitTransaction( $dbw, __METHOD__
);
83 # Delete revisions as appropriate
84 if ( $delete && $count ) {
85 $this->output( "Deleting revisions..." );
86 $this->deleteRevisions( $revs );
87 $this->output( "done.\n" );
88 $this->purgeRedundantText( true );
91 # Update stats as appropriate
93 $this->output( "Updating site stats..." );
94 $ga = $isGoodArticle ?
-1 : 0; // if it was good, decrement that too
95 $stats = new SiteStatsUpdate( 0, -$count, $ga, -1 );
97 $this->output( "done.\n" );
100 $this->output( "not found in database.\n" );
101 $this->commitTransaction( $dbw, __METHOD__
);
105 public function deleteRevisions( $ids ) {
106 $dbw = $this->getDB( DB_MASTER
);
107 $this->beginTransaction( $dbw, __METHOD__
);
109 $tbl_rev = $dbw->tableName( 'revision' );
111 $set = implode( ', ', $ids );
112 $dbw->query( "DELETE FROM $tbl_rev WHERE rev_id IN ( $set )" );
114 $this->commitTransaction( $dbw, __METHOD__
);
118 $maintClass = NukePage
::class;
119 require_once RUN_MAINTENANCE_IF_MAIN
;