4 * Maintenance script to move a batch of pages
7 * @subpackage Maintenance
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 * <user> - username to perform moves as
15 * <reason> - reason to be given for moves
16 * <interval> - number of seconds to sleep after each move
18 * This will print out error codes from Title::moveTo() if something goes wrong,
19 * e.g. immobile_namespace for namespaces which can't be moved
23 $optionsWithArgs = array( 'u', 'r', 'i' );
24 require_once( 'commandLine.inc' );
30 $filename = 'php://stdin';
31 $user = 'Move page script';
35 if ( isset( $args[0] ) ) {
38 if ( isset( $options['u'] ) ) {
39 $user = $options['u'];
41 if ( isset( $options['r'] ) ) {
42 $reason = $options['r'];
44 if ( isset( $options['i'] ) ) {
45 $interval = $options['i'];
48 $wgUser = User
::newFromName( $user );
51 # Setup complete, now start
53 $file = fopen( $filename, 'r' );
55 print "Unable to read file, exiting\n";
59 $dbw =& wfGetDB( DB_MASTER
);
61 for ( $linenum = 1; !feof( $file ); $linenum++
) {
62 $line = fgets( $file );
63 if ( $line === false ) {
66 $parts = array_map( 'trim', explode( '|', $line ) );
67 if ( count( $parts ) != 2 ) {
68 print "Error on line $linenum, no pipe character\n";
71 $source = Title
::newFromText( $parts[0] );
72 $dest = Title
::newFromText( $parts[1] );
73 if ( is_null( $source ) ||
is_null( $dest ) ) {
74 print "Invalid title on line $linenum\n";
79 print $source->getPrefixedText();
81 $err = $source->moveTo( $dest, false, $reason );
83 print "\nFAILED: $err";
85 $dbw->immediateCommit();