minor improvements
[lhc/web/wiklou.git] / maintenance / moveBatch.php
1 <?php
2
3 # Move a batch of pages
4 # Usage: php moveBatch.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
11
12 $oldCwd = getcwd();
13 $optionsWithArgs = array( 'u', 'r', 'i' );
14 require_once( 'commandLine.inc' );
15
16 chdir( $oldCwd );
17
18 # Options processing
19
20 $filename = 'php://stdin';
21 $user = 'Move page script';
22 $reason = '';
23 $interval = 0;
24
25 if ( isset( $args[0] ) ) {
26 $filename = $args[0];
27 }
28 if ( isset( $options['u'] ) ) {
29 $user = $options['u'];
30 }
31 if ( isset( $options['r'] ) ) {
32 $reason = $options['r'];
33 }
34 if ( isset( $options['i'] ) ) {
35 $interval = $options['i'];
36 }
37
38 $wgUser = User::newFromName( $user );
39
40
41 # Setup complete, now start
42
43 $file = fopen( $filename, 'r' );
44 if ( !$file ) {
45 print "Unable to read file, exiting\n";
46 exit;
47 }
48
49 $dbw =& wfGetDB( DB_MASTER );
50
51 for ( $linenum = 1; !feof( $file ); $linenum++ ) {
52 $line = fgets( $file );
53 if ( $line === false ) {
54 break;
55 }
56 $parts = array_map( 'trim', explode( '|', $line ) );
57 if ( count( $parts ) != 2 ) {
58 print "Error on line $linenum, no pipe character\n";
59 continue;
60 }
61 $source = Title::newFromText( $parts[0] );
62 $dest = Title::newFromText( $parts[1] );
63 if ( is_null( $source ) || is_null( $dest ) ) {
64 print "Invalid title on line $linenum\n";
65 continue;
66 }
67
68
69 print $source->getPrefixedText();
70 $dbw->begin();
71 $source->moveTo( $dest, false, $reason );
72 $dbw->immediateCommit();
73 print "\n";
74
75 if ( $interval ) {
76 sleep( $interval );
77 }
78 wfWaitForSlaves( 5 );
79 }
80
81
82 ?>