maintenance script to delete mediawiki messages silently, to upgrade without flooding...
[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
42 if ($delete) echo "delete $ns\n";
43 exit (0);
44
45
46 NukeNS( $ns, $delete);
47
48 function NukeNS($ns_no, $delete) {
49
50 $dbw =& wfGetDB( DB_MASTER );
51 $dbw->begin();
52
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" );
56
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();
61
62 // Get corresponding revisions
63 $res2 = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_page = $id" );
64 $revs = array();
65
66 while( $row2 = $dbw->fetchObject( $res2 ) ) {
67 $revs[] = $row2->rev_id;
68 }
69 $count = count( $revs );
70
71 //skip anything that looks modified (i.e. multiple revs)
72 if (($count == 1)) {
73 #echo $title->getPrefixedText(), "\t", $count, "\n";
74 echo "delete: ", $title->getPrefixedText(), "\n";
75
76 //as much as I hate to cut & paste this, it's a little different, and
77 //I already have the id & revs
78
79 if( $delete ) {
80 $dbw->query( "DELETE FROM $tbl_pag WHERE page_id = $id" );
81 $dbw->commit();
82 // Delete revisions as appropriate
83 DeleteRevisions( $revs );
84 PurgeRedundantText( true );
85 }
86 } else {
87 echo "skip: ", $title->getPrefixedText(), "\n";
88 }
89
90
91 }
92 }
93
94
95 ?>