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
17 * @ingroup Maintenance
18 * @author Steve Sanbeg
19 * based on nukePage by Rob Church
22 require_once( "Maintenance.php" );
24 class NukeNS
extends Maintenance
{
25 public function __construct() {
26 parent
::__construct();
27 $this->mDescription
= "Remove pages with only 1 revision from any namespace";
28 $this->addParam( 'delete', "Actually delete the page" );
29 $this->addParam( 'ns', 'Namespace to delete from, default NS_MEDIAWIKI', false, true );
32 public function execute() {
33 $ns = $this->getOption( 'ns', NS_MEDIAWIKI
);
34 $delete = $this->getOption( 'delete', false );
35 $dbw = wfGetDB( DB_MASTER
);
38 $tbl_pag = $dbw->tableName( 'page' );
39 $tbl_rev = $dbw->tableName( 'revision' );
40 $res = $dbw->query( "SELECT page_title FROM $tbl_pag WHERE page_namespace = $ns" );
44 while( $row = $dbw->fetchObject( $res ) ) {
45 //echo "$ns_name:".$row->page_title, "\n";
46 $title = Title
::newFromText($row->page_title
, $ns);
47 $id = $title->getArticleID();
49 // Get corresponding revisions
50 $res2 = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_page = $id" );
53 while( $row2 = $dbw->fetchObject( $res2 ) ) {
54 $revs[] = $row2->rev_id
;
56 $count = count( $revs );
58 //skip anything that looks modified (i.e. multiple revs)
60 #echo $title->getPrefixedText(), "\t", $count, "\n";
61 $this->output( "delete: ", $title->getPrefixedText(), "\n" );
63 //as much as I hate to cut & paste this, it's a little different, and
64 //I already have the id & revs
66 $dbw->query( "DELETE FROM $tbl_pag WHERE page_id = $id" );
68 // Delete revisions as appropriate
69 $child = $this->spawnChild( 'NukePage', 'NukePage.php' );
70 $child->deleteRevisions( $revs );
71 $this->purgeRedundantText( true );
75 $this->output( "skip: ", $title->getPrefixedText(), "\n" );
81 #update statistics - better to decrement existing count, or just count
83 $pages = $dbw->selectField('site_stats', 'ss_total_pages');
85 $dbw->update( 'site_stats',
86 array('ss_total_pages' => $pages ),
87 array( 'ss_row_id' => 1),
92 $this->output( "To update the database, run the script with the --delete option.\n" );
97 $maintClass = "NukeNS";
98 require_once( DO_MAINTENANCE
);