3 # Move a batch of pages
4 # Usage: php moveBatch.php [-u <user>] [-r <reason>] [-i <interval>] <listfile>
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
13 $optionsWithArgs = array( 'u', 'r', 'i' );
14 require_once( 'commandLine.inc' );
20 $filename = 'php://stdin';
21 $user = 'Move page script';
25 if ( isset( $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' );
45 print "Unable to read file, exiting\n";
49 $dbw =& wfGetDB( DB_MASTER
);
51 for ( $linenum = 1; !feof( $file ); $linenum++
) {
52 $line = fgets( $file );
53 if ( $line === false ) {
56 $parts = array_map( 'trim', explode( '|', $line ) );
57 if ( count( $parts ) != 2 ) {
58 print "Error on line $linenum, no pipe character\n";
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";
69 print $source->getPrefixedText();
71 $source->moveTo( $dest, false, $reason );
72 $dbw->immediateCommit();