* Make some more messages '*-summary' customizeable through Special:Allmessages or...
[lhc/web/wiklou.git] / maintenance / deleteBatch.php
1 <?php
2
3 # delete a batch of pages
4 # Usage: php deleteBatch.php [-u <user>] [-r <reason>] [-i <interval>] <listfile>
5 # where
6 # <listfile> is a file where each line has two titles separated by a pipe
7 # character. The first title is the source, the second is the destination.
8 # <user> is the username
9 # <reason> is the move reason
10 # <interval> is the number of seconds to sleep for after each move
11
12 $oldCwd = getcwd();
13 $optionsWithArgs = array( 'u', 'r', 'i' );
14 require_once( 'commandLine.inc' );
15
16 chdir( $oldCwd );
17
18 # Options processing
19
20 $filename = 'php://stdin';
21 $user = 'Delete page script';
22 $reason = '';
23 $interval = 0;
24
25 if ( isset( $args[0] ) ) {
26 $filename = $args[0];
27 }
28 if ( isset( $options['u'] ) ) {
29 $user = $options['u'];
30 }
31 if ( isset( $options['r'] ) ) {
32 $reason = $options['r'];
33 }
34 if ( isset( $options['i'] ) ) {
35 $interval = $options['i'];
36 }
37
38 $wgUser = User::newFromName( $user );
39
40
41 # Setup complete, now start
42
43 $file = fopen( $filename, 'r' );
44 if ( !$file ) {
45 print "Unable to read file, exiting\n";
46 exit;
47 }
48
49 $dbw =& wfGetDB( DB_MASTER );
50
51 for ( $linenum = 1; !feof( $file ); $linenum++ ) {
52 $line = trim( fgets( $file ) );
53 if ( $line === false ) {
54 break;
55 }
56 $page = Title::newFromText( $line );
57 if ( is_null( $page ) ) {
58 print "Invalid title '$line' on line $linenum\n";
59 continue;
60 }
61 if( !$page->exists() ) {
62 print "Skipping nonexistent page '$line'\n";
63 continue;
64 }
65
66
67 print $page->getPrefixedText();
68 $dbw->begin();
69 if( $page->getNamespace() == NS_IMAGE ) {
70 $art = new ImagePage( $page );
71 } else {
72 $art = new Article( $page );
73 }
74 $success = $art->doDeleteArticle( $reason );
75 $dbw->immediateCommit();
76 if ( $success ) {
77 print "\n";
78 } else {
79 print " FAILED\n";
80 }
81
82 if ( $interval ) {
83 sleep( $interval );
84 }
85 wfWaitForSlaves( 5 );
86 }
87
88
89 ?>