4 * Remove pages with only 1 revision from the MediaWiki namespace, without
5 * flooding recent changes, delete logs, etc.
6 * Irreversible (can't use standard undelete) and does not update link tables
8 * This is mainly useful to run before maintenance/update.php when upgrading
9 * to 1.9, to prevent flooding recent changes/deletion logs. It's intended
10 * to be conservative, so it's possible that a few entries will be left for
11 * deletion by the upgrade script. It's also possible that it hasn't been
12 * tested thouroughly enough, and will delete something it shouldn't; so
13 * back up your DB if there's anything in the MediaWiki that is important to
16 * @addtogroup Maintenance
17 * @author Steve Sanbeg
18 * based on nukePage by Rob Church
21 require_once( 'commandLine.inc' );
22 require_once( 'nukePage.inc' );
27 if (isset($options['ns']))
32 if (isset( $options['delete'] ) and $options['delete'])
38 NukeNS( $ns, $delete);
40 function NukeNS($ns_no, $delete) {
42 $dbw = wfGetDB( DB_MASTER
);
45 $tbl_pag = $dbw->tableName( 'page' );
46 $tbl_rev = $dbw->tableName( 'revision' );
47 $res = $dbw->query( "SELECT page_title FROM $tbl_pag WHERE page_namespace = $ns_no" );
51 while( $row = $dbw->fetchObject( $res ) ) {
52 //echo "$ns_name:".$row->page_title, "\n";
53 $title = Title
::newFromText($row->page_title
, $ns_no);
54 $id = $title->getArticleID();
56 // Get corresponding revisions
57 $res2 = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_page = $id" );
60 while( $row2 = $dbw->fetchObject( $res2 ) ) {
61 $revs[] = $row2->rev_id
;
63 $count = count( $revs );
65 //skip anything that looks modified (i.e. multiple revs)
67 #echo $title->getPrefixedText(), "\t", $count, "\n";
68 echo "delete: ", $title->getPrefixedText(), "\n";
70 //as much as I hate to cut & paste this, it's a little different, and
71 //I already have the id & revs
74 $dbw->query( "DELETE FROM $tbl_pag WHERE page_id = $id" );
76 // Delete revisions as appropriate
77 DeleteRevisions( $revs );
78 PurgeRedundantText( true );
82 echo "skip: ", $title->getPrefixedText(), "\n";
90 #update statistics - better to decrement existing count, or just count
92 $pages = $dbw->selectField('site_stats', 'ss_total_pages');
94 $dbw->update( 'site_stats',
95 array('ss_total_pages' => $pages ),
96 array( 'ss_row_id' => 1),
102 echo( "To update the database, run the script with the --delete option.\n" );