No point in fetching the result in Database::unlock() if we're not using it anyway.
[lhc/web/wiklou.git] / maintenance / deleteBatch.php
1 <?php
2
3 /**
4 * delete a batch of pages
5 * Usage: php deleteBatch.php [-u <user>] [-r <reason>] [-i <interval>] <listfile>
6 * where
7 * <listfile> is a file where each line contains the title of a page to be deleted.
8 * <user> is the username
9 * <reason> is the delete reason
10 * <interval> is the number of seconds to sleep for after each delete
11 *
12 * @file
13 * @ingroup Maintenance
14 */
15
16 $oldCwd = getcwd();
17 $optionsWithArgs = array( 'u', 'r', 'i' );
18 require_once( 'commandLine.inc' );
19
20 chdir( $oldCwd );
21
22 # Options processing
23
24 $filename = 'php://stdin';
25 $user = 'Delete page script';
26 $reason = '';
27 $interval = 0;
28
29 if ( isset( $args[0] ) ) {
30 $filename = $args[0];
31 }
32 if ( isset( $options['u'] ) ) {
33 $user = $options['u'];
34 }
35 if ( isset( $options['r'] ) ) {
36 $reason = $options['r'];
37 }
38 if ( isset( $options['i'] ) ) {
39 $interval = $options['i'];
40 }
41
42 $wgUser = User::newFromName( $user );
43
44
45 # Setup complete, now start
46
47 $file = fopen( $filename, 'r' );
48 if ( !$file ) {
49 print "Unable to read file, exiting\n";
50 exit;
51 }
52
53 $dbw = wfGetDB( DB_MASTER );
54
55 for ( $linenum = 1; !feof( $file ); $linenum++ ) {
56 $line = trim( fgets( $file ) );
57 if ( $line == '' ) {
58 continue;
59 }
60 $page = Title::newFromText( $line );
61 if ( is_null( $page ) ) {
62 print "Invalid title '$line' on line $linenum\n";
63 continue;
64 }
65 if( !$page->exists() ) {
66 print "Skipping nonexistent page '$line'\n";
67 continue;
68 }
69
70
71 print $page->getPrefixedText();
72 $dbw->begin();
73 if( $page->getNamespace() == NS_IMAGE ) {
74 $art = new ImagePage( $page );
75 $img = wfFindFile( $art->mTitle );
76 if( !$img || !$img->delete( $reason ) ) {
77 print "FAILED to delete image file... ";
78 }
79 } else {
80 $art = new Article( $page );
81 }
82 $success = $art->doDeleteArticle( $reason );
83 $dbw->immediateCommit();
84 if ( $success ) {
85 print "\n";
86 } else {
87 print " FAILED to delete image page\n";
88 }
89
90 if ( $interval ) {
91 sleep( $interval );
92 }
93 wfWaitForSlaves( 5 );
94 }
95
96
97