ecbe04442e905e42e6bf4064bf9c8df113a28657
[lhc/web/wiklou.git] / maintenance / nukeNS.php
1 <?php
2
3 /**
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
7 *
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
14 * you.
15 *
16 * You can also specify --nodelete to see what will get deleted, without
17 * deleting anything.
18 *
19 * @package MediaWiki
20 * @subpackage Maintenance
21 * @author Steve Sanbeg
22 * based on nukePage by Rob Church
23 */
24
25 require_once( 'commandLine.inc' );
26 require_once( 'nukePage.inc' );
27
28 $ns = NS_MEDIAWIKI;
29 $delete = true;
30
31 if (isset($options['ns']))
32 {
33 $ns = $options['ns'];
34 }
35
36 if (isset( $options['nodelete'] ))
37 {
38 $delete = false;
39 }
40
41 NukeNS( $ns, $delete);
42
43 function NukeNS($ns_no, $delete) {
44
45 $dbw =& wfGetDB( DB_MASTER );
46 $dbw->begin();
47
48 $tbl_pag = $dbw->tableName( 'page' );
49 $tbl_rev = $dbw->tableName( 'revision' );
50 $res = $dbw->query( "SELECT page_title FROM $tbl_pag WHERE page_namespace = $ns_no" );
51
52 while( $row = $dbw->fetchObject( $res ) ) {
53 //echo "$ns_name:".$row->page_title, "\n";
54 $title = Title::newFromText($row->page_title, $ns_no);
55 $id = $title->getArticleID();
56
57 // Get corresponding revisions
58 $res2 = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_page = $id" );
59 $revs = array();
60
61 while( $row2 = $dbw->fetchObject( $res2 ) ) {
62 $revs[] = $row2->rev_id;
63 }
64 $count = count( $revs );
65
66 //skip anything that looks modified (i.e. multiple revs)
67 if (($count == 1)) {
68 #echo $title->getPrefixedText(), "\t", $count, "\n";
69 echo "delete: ", $title->getPrefixedText(), "\n";
70
71 //as much as I hate to cut & paste this, it's a little different, and
72 //I already have the id & revs
73
74 if( $delete ) {
75 $dbw->query( "DELETE FROM $tbl_pag WHERE page_id = $id" );
76 $dbw->commit();
77 // Delete revisions as appropriate
78 DeleteRevisions( $revs );
79 PurgeRedundantText( true );
80 }
81 } else {
82 echo "skip: ", $title->getPrefixedText(), "\n";
83 }
84
85
86 }
87 }
88
89
90 ?>