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