summaryrefslogtreecommitdiff
path: root/maintenance/deleteBatch.php
blob: 234744c3d800d9a4567334c84d2d438a4d0f6b68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php

# delete a batch of pages
# Usage: php deleteBatch.php [-u <user>] [-r <reason>] [-i <interval>] <listfile>
# where
# 	<listfile> is a file where each line has two titles separated by a pipe
# character. The first title is the source, the second is the destination.
#	<user> is the username
#	<reason> is the move reason
#	<interval> is the number of seconds to sleep for after each move

$oldCwd = getcwd();
$optionsWithArgs = array( 'u', 'r', 'i' );
require_once( 'commandLine.inc' );

chdir( $oldCwd );

# Options processing

$filename = 'php://stdin';
$user = 'Delete page script';
$reason = '';
$interval = 0;

if ( isset( $args[0] ) ) {
	$filename = $args[0];
}
if ( isset( $options['u'] ) ) {
	$user = $options['u'];
}
if ( isset( $options['r'] ) ) {
	$reason = $options['r'];
}
if ( isset( $options['i'] ) ) {
	$interval = $options['i'];
}

$wgUser = User::newFromName( $user );


# Setup complete, now start

$file = fopen( $filename, 'r' );
if ( !$file ) {
	print "Unable to read file, exiting\n";
	exit;
}

$dbw =& wfGetDB( DB_MASTER );

for ( $linenum = 1; !feof( $file ); $linenum++ ) {
	$line = trim( fgets( $file ) );
	if ( $line === false ) {
		break;
	}
	$page = Title::newFromText( $line );
	if ( is_null( $page ) ) {
		print "Invalid title '$line' on line $linenum\n";
		continue;
	}
	if( !$page->exists() ) {
		print "Skipping nonexistent page '$line'\n";
		continue;
	}


	print $page->getPrefixedText();
	$dbw->begin();
	if( $page->getNamespace() == NS_IMAGE ) {
		$art = new ImagePage( $page );
	} else {
		$art = new Article( $page );
	}
	$success = $art->doDeleteArticle( $reason );
	$dbw->immediateCommit();
	if ( $success ) {
		print "\n";
	} else {
		print " FAILED\n";
	}

	if ( $interval ) {
		sleep( $interval );
	}
	wfWaitForSlaves( 5 );
}


?>