More profiling sections
[mediawiki.git] / maintenance / deleteBatch.php
blob697dffd7a419132fe74bc961cf06036e60a24e47
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 has two titles separated by a pipe
7 # character. The first title is the source, the second is the destination.
8 # <user> is the username
9 # <reason> is the move reason
10 # <interval> is the number of seconds to sleep for after each move
12 $oldCwd = getcwd();
13 $optionsWithArgs = array( 'u', 'r', 'i' );
14 require_once( 'commandLine.inc' );
16 chdir( $oldCwd );
18 # Options processing
20 $filename = 'php://stdin';
21 $user = 'Delete page script';
22 $reason = '';
23 $interval = 0;
25 if ( isset( $args[0] ) ) {
26 $filename = $args[0];
28 if ( isset( $options['u'] ) ) {
29 $user = $options['u'];
31 if ( isset( $options['r'] ) ) {
32 $reason = $options['r'];
34 if ( isset( $options['i'] ) ) {
35 $interval = $options['i'];
38 $wgUser = User::newFromName( $user );
41 # Setup complete, now start
43 $file = fopen( $filename, 'r' );
44 if ( !$file ) {
45 print "Unable to read file, exiting\n";
46 exit;
49 $dbw =& wfGetDB( DB_MASTER );
51 for ( $linenum = 1; !feof( $file ); $linenum++ ) {
52 $line = trim( fgets( $file ) );
53 if ( $line === false ) {
54 break;
56 $page = Title::newFromText( $line );
57 if ( is_null( $page ) ) {
58 print "Invalid title '$line' on line $linenum\n";
59 continue;
61 if( !$page->exists() ) {
62 print "Skipping nonexistent page '$line'\n";
63 continue;
67 print $page->getPrefixedText();
68 $dbw->begin();
69 if( $page->getNamespace() == NS_IMAGE ) {
70 $art = new ImagePage( $page );
71 } else {
72 $art = new Article( $page );
74 $art->doDelete( $reason );
75 $dbw->immediateCommit();
76 print "\n";
78 if ( $interval ) {
79 sleep( $interval );
81 wfWaitForSlaves( 5 );