3 * Erase a page record from the database
4 * Irreversible (can't use standard undelete) and does not update link tables
8 * @author Rob Church <robchur@gmail.com>
11 require_once( "Maintenance.php" );
13 class NukePage
extends Maintenance
{
14 public function __construct() {
15 parent
::__construct();
16 $this->mDescription
= "Remove a page record from the database";
17 $this->addParam( 'delete', "Actually delete the page" );
18 $this->addArgs( array( 'title' ) );
21 public function execute() {
23 $name = $this->getArg();
24 $delete = $this->getOption( 'delete', false );
26 $dbw = wfGetDB( DB_MASTER
);
29 $tbl_pag = $dbw->tableName( 'page' );
30 $tbl_rec = $dbw->tableName( 'recentchanges' );
31 $tbl_rev = $dbw->tableName( 'revision' );
34 $this->output( "Searching for \"$name\"..." );
35 $title = Title
::newFromText( $name );
37 $id = $title->getArticleID();
38 $real = $title->getPrefixedText();
39 $isGoodArticle = $title->isContentPage();
40 $this->output( "found \"$real\" with ID $id.\n" );
42 # Get corresponding revisions
43 $this->output( "Searching for revisions..." );
44 $res = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_page = $id" );
45 while( $row = $dbw->fetchObject( $res ) ) {
46 $revs[] = $row->rev_id
;
48 $count = count( $revs );
49 $this->output( "found $count.\n" );
51 # Delete the page record and associated recent changes entries
53 $this->output( "Deleting page record..." );
54 $dbw->query( "DELETE FROM $tbl_pag WHERE page_id = $id" );
55 $this->output( "done.\n" );
56 $this->output( "Cleaning up recent changes..." );
57 $dbw->query( "DELETE FROM $tbl_rec WHERE rc_cur_id = $id" );
58 $this->output( "done.\n" );
63 # Delete revisions as appropriate
64 if( $delete && $count ) {
65 $this->output( "Deleting revisions..." );
66 $this->deleteRevisions( $revs );
67 $this->output( "done.\n" );
68 $this->purgeRedundantText( true );
71 # Update stats as appropriate
73 $this->output( "Updating site stats..." );
74 $ga = $isGoodArticle ?
-1 : 0; // if it was good, decrement that too
75 $stats = new SiteStatsUpdate( 0, -$count, $ga, -1 );
77 $this->output( "done.\n" );
80 $this->output( "not found in database.\n" );
85 public function deleteRevisions( $ids ) {
86 $dbw = wfGetDB( DB_MASTER
);
89 $tbl_rev = $dbw->tableName( 'revision' );
91 $set = implode( ', ', $ids );
92 $dbw->query( "DELETE FROM $tbl_rev WHERE rev_id IN ( $set )" );
98 $maintClass = "NukePage";
99 require_once( DO_MAINTENANCE
);