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 echo( "found \"$real\" with ID $id.\n" );
30 # Get corresponding revisions
31 echo( "Searching for revisions..." );
32 $res = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_page = $id" );
33 while( $row = $dbw->fetchObject( $res ) ) {
34 $revs[] = $row->rev_id;
36 $count = count( $revs );
37 echo( "found $count.\n" );
39 # Delete the page record and associated recent changes entries
41 echo( "Deleting page record..." );
42 $dbw->query( "DELETE FROM $tbl_pag WHERE page_id = $id" );
44 echo( "Cleaning up recent changes..." );
45 $dbw->query( "DELETE FROM $tbl_rec WHERE rc_cur_id = $id" );
51 # Delete revisions as appropriate
52 if( $delete && $count ) {
53 echo( "Deleting revisions..." );
54 DeleteRevisions( $revs );
56 PurgeRedundantText( true );
60 echo( "not found in database.\n" );
66 function DeleteRevisions( $ids ) {
68 $dbw = wfGetDB( DB_MASTER );
71 $tbl_rev = $dbw->tableName( 'revision' );
73 $set = implode( ', ', $ids );
74 $dbw->query( "DELETE FROM $tbl_rev WHERE rev_id IN ( $set )" );
78 #TODO: see if this is a "good" page, to decrement that as well.
79 $pages = $dbw->selectField('site_stats', 'ss_total_pages');
81 $dbw->update( 'site_stats',
82 array('ss_total_pages' => $pages ),
83 array( 'ss_row_id' => 1),