Fixing a variable name, and a PHP warning.
[mediawiki.git] / maintenance / deleteBatch.php
blob62169641c0757a9260b5c84523cbcb7a67c3b63c
1 <?php
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
11 $oldCwd = getcwd();
12 $optionsWithArgs = array( 'u', 'r', 'i' );
13 require_once( 'commandLine.inc' );
15 chdir( $oldCwd );
17 # Options processing
19 $filename = 'php://stdin';
20 $user = 'Delete page script';
21 $reason = '';
22 $interval = 0;
24 if ( isset( $args[0] ) ) {
25 $filename = $args[0];
27 if ( isset( $options['u'] ) ) {
28 $user = $options['u'];
30 if ( isset( $options['r'] ) ) {
31 $reason = $options['r'];
33 if ( isset( $options['i'] ) ) {
34 $interval = $options['i'];
37 $wgUser = User::newFromName( $user );
40 # Setup complete, now start
42 $file = fopen( $filename, 'r' );
43 if ( !$file ) {
44 print "Unable to read file, exiting\n";
45 exit;
48 $dbw = wfGetDB( DB_MASTER );
50 for ( $linenum = 1; !feof( $file ); $linenum++ ) {
51 $line = trim( fgets( $file ) );
52 if ( $line == '' ) {
53 continue;
55 $page = Title::newFromText( $line );
56 if ( is_null( $page ) ) {
57 print "Invalid title '$line' on line $linenum\n";
58 continue;
60 if( !$page->exists() ) {
61 print "Skipping nonexistent page '$line'\n";
62 continue;
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... ";
74 } else {
75 $art = new Article( $page );
77 $success = $art->doDeleteArticle( $reason );
78 $dbw->immediateCommit();
79 if ( $success ) {
80 print "\n";
81 } else {
82 print " FAILED to delete image page\n";
85 if ( $interval ) {
86 sleep( $interval );
88 wfWaitForSlaves( 5 );