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 * You can also specify --nodelete to see what will get deleted, without
20 * @subpackage Maintenance
21 * @author Steve Sanbeg
22 * based on nukePage by Rob Church
25 require_once( 'commandLine.inc' );
26 require_once( 'nukePage.inc' );
31 if (isset($options['ns']))
36 if (isset( $options['nodelete'] ))
42 if ($delete) echo "delete $ns\n";
46 NukeNS( $ns, $delete);
48 function NukeNS($ns_no, $delete) {
50 $dbw =& wfGetDB( DB_MASTER
);
53 $tbl_pag = $dbw->tableName( 'page' );
54 $tbl_rev = $dbw->tableName( 'revision' );
55 $res = $dbw->query( "SELECT page_title FROM $tbl_pag WHERE page_namespace = $ns_no" );
57 while( $row = $dbw->fetchObject( $res ) ) {
58 //echo "$ns_name:".$row->page_title, "\n";
59 $title = Title
::newFromText($row->page_title
, $ns_no);
60 $id = $title->getArticleID();
62 // Get corresponding revisions
63 $res2 = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_page = $id" );
66 while( $row2 = $dbw->fetchObject( $res2 ) ) {
67 $revs[] = $row2->rev_id
;
69 $count = count( $revs );
71 //skip anything that looks modified (i.e. multiple revs)
73 #echo $title->getPrefixedText(), "\t", $count, "\n";
74 echo "delete: ", $title->getPrefixedText(), "\n";
76 //as much as I hate to cut & paste this, it's a little different, and
77 //I already have the id & revs
80 $dbw->query( "DELETE FROM $tbl_pag WHERE page_id = $id" );
82 // Delete revisions as appropriate
83 DeleteRevisions( $revs );
84 PurgeRedundantText( true );
87 echo "skip: ", $title->getPrefixedText(), "\n";