4 * Maintenance script to move a batch of pages
10 * USAGE: php moveBatch.php [-u <user>] [-r <reason>] [-i <interval>] [listfile]
12 * [listfile] - file with two titles per line, separated with pipe characters;
13 * the first title is the source, the second is the destination.
14 * Standard input is used if listfile is not given.
15 * <user> - username to perform moves as
16 * <reason> - reason to be given for moves
17 * <interval> - number of seconds to sleep after each move
19 * This will print out error codes from Title::moveTo() if something goes wrong,
20 * e.g. immobile_namespace for namespaces which can't be moved
24 $optionsWithArgs = array( 'u', 'r', 'i' );
25 require_once( 'commandLine.inc' );
31 $filename = 'php://stdin';
32 $user = 'Move page script';
36 if ( isset( $args[0] ) ) {
39 if ( isset( $options['u'] ) ) {
40 $user = $options['u'];
42 if ( isset( $options['r'] ) ) {
43 $reason = $options['r'];
45 if ( isset( $options['i'] ) ) {
46 $interval = $options['i'];
49 $wgUser = User
::newFromName( $user );
52 # Setup complete, now start
54 $file = fopen( $filename, 'r' );
56 print "Unable to read file, exiting\n";
60 $dbw = wfGetDB( DB_MASTER
);
62 for ( $linenum = 1; !feof( $file ); $linenum++
) {
63 $line = fgets( $file );
64 if ( $line === false ) {
67 $parts = array_map( 'trim', explode( '|', $line ) );
68 if ( count( $parts ) != 2 ) {
69 print "Error on line $linenum, no pipe character\n";
72 $source = Title
::newFromText( $parts[0] );
73 $dest = Title
::newFromText( $parts[1] );
74 if ( is_null( $source ) ||
is_null( $dest ) ) {
75 print "Invalid title on line $linenum\n";
80 print $source->getPrefixedText() . ' --> ' . $dest->getPrefixedText();
82 $err = $source->moveTo( $dest, false, $reason );
84 print "\nFAILED: $err";
86 $dbw->immediateCommit();