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