4 * delete a batch of pages
5 * Usage: php deleteBatch.php [-u <user>] [-r <reason>] [-i <interval>] <listfile>
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
13 * @ingroup Maintenance
17 $optionsWithArgs = array( 'u', 'r', 'i' );
18 require_once( 'commandLine.inc' );
24 $filename = 'php://stdin';
25 $user = 'Delete page script';
29 if ( isset( $args[0] ) ) {
32 if ( isset( $options['u'] ) ) {
33 $user = $options['u'];
35 if ( isset( $options['r'] ) ) {
36 $reason = $options['r'];
38 if ( isset( $options['i'] ) ) {
39 $interval = $options['i'];
42 $wgUser = User
::newFromName( $user );
45 # Setup complete, now start
47 $file = fopen( $filename, 'r' );
49 print "Unable to read file, exiting\n";
53 $dbw = wfGetDB( DB_MASTER
);
55 for ( $linenum = 1; !feof( $file ); $linenum++
) {
56 $line = trim( fgets( $file ) );
60 $page = Title
::newFromText( $line );
61 if ( is_null( $page ) ) {
62 print "Invalid title '$line' on line $linenum\n";
65 if( !$page->exists() ) {
66 print "Skipping nonexistent page '$line'\n";
71 print $page->getPrefixedText();
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... ";
80 $art = new Article( $page );
82 $success = $art->doDeleteArticle( $reason );
83 $dbw->immediateCommit();
87 print " FAILED to delete image page\n";