4 * Maintenance script to move a batch of pages
6 * @addtogroup Maintenance
9 * USAGE: php moveBatch.php [-u <user>] [-r <reason>] [-i <interval>] <listfile>
11 * <listfile> - file with two titles per line, separated with pipe characters;
12 * the first title is the source, the second is the destination
13 * <user> - username to perform moves as
14 * <reason> - reason to be given for moves
15 * <interval> - number of seconds to sleep after each move
17 * This will print out error codes from Title::moveTo() if something goes wrong,
18 * e.g. immobile_namespace for namespaces which can't be moved
22 $optionsWithArgs = array( 'u', 'r', 'i' );
23 require_once( 'commandLine.inc' );
29 $filename = 'php://stdin';
30 $user = 'Move page script';
34 if ( isset( $args[0] ) ) {
37 if ( isset( $options['u'] ) ) {
38 $user = $options['u'];
40 if ( isset( $options['r'] ) ) {
41 $reason = $options['r'];
43 if ( isset( $options['i'] ) ) {
44 $interval = $options['i'];
47 $wgUser = User
::newFromName( $user );
50 # Setup complete, now start
52 $file = fopen( $filename, 'r' );
54 print "Unable to read file, exiting\n";
58 $dbw =& wfGetDB( DB_MASTER
);
60 for ( $linenum = 1; !feof( $file ); $linenum++
) {
61 $line = fgets( $file );
62 if ( $line === false ) {
65 $parts = array_map( 'trim', explode( '|', $line ) );
66 if ( count( $parts ) != 2 ) {
67 print "Error on line $linenum, no pipe character\n";
70 $source = Title
::newFromText( $parts[0] );
71 $dest = Title
::newFromText( $parts[1] );
72 if ( is_null( $source ) ||
is_null( $dest ) ) {
73 print "Invalid title on line $linenum\n";
78 print $source->getPrefixedText() . ' --> ' . $dest->getPrefixedText();
80 $err = $source->moveTo( $dest, false, $reason );
82 print "\nFAILED: $err";
84 $dbw->immediateCommit();