4 * Support functions for the nukeArticle script
8 * @author Rob Church <robchur@gmail.com>
11 require_once( 'purgeOldText.inc' );
13 function NukePage( $name, $delete = false ) {
15 $dbw = wfGetDB( DB_MASTER );
18 $tbl_pag = $dbw->tableName( 'page' );
19 $tbl_rec = $dbw->tableName( 'recentchanges' );
20 $tbl_rev = $dbw->tableName( 'revision' );
23 echo( "Searching for \"$name\"..." );
24 $title = Title::newFromText( $name );
26 $id = $title->getArticleID();
27 $real = $title->getPrefixedText();
28 $isGoodArticle = $title->isContentPage();
29 echo( "found \"$real\" with ID $id.\n" );
31 # Get corresponding revisions
32 echo( "Searching for revisions..." );
33 $res = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_page = $id" );
34 while( $row = $dbw->fetchObject( $res ) ) {
35 $revs[] = $row->rev_id;
37 $count = count( $revs );
38 echo( "found $count.\n" );
40 # Delete the page record and associated recent changes entries
42 echo( "Deleting page record..." );
43 $dbw->query( "DELETE FROM $tbl_pag WHERE page_id = $id" );
45 echo( "Cleaning up recent changes..." );
46 $dbw->query( "DELETE FROM $tbl_rec WHERE rc_cur_id = $id" );
52 # Delete revisions as appropriate
53 if( $delete && $count ) {
54 echo( "Deleting revisions..." );
55 DeleteRevisions( $revs );
57 PurgeRedundantText( true );
60 # Update stats as appropriate
62 echo( "Updating site stats..." );
63 $ga = $isGoodArticle ? -1 : 0; // if it was good, decrement that too
64 $stats = new SiteStatsUpdate( 0, -$count, $ga, -1 );
71 echo( "not found in database.\n" );
77 function DeleteRevisions( $ids ) {
79 $dbw = wfGetDB( DB_MASTER );
82 $tbl_rev = $dbw->tableName( 'revision' );
84 $set = implode( ', ', $ids );
85 $dbw->query( "DELETE FROM $tbl_rev WHERE rev_id IN ( $set )" );