* Use double quoted consistently on attributes in linker output; preparing for new...
[mediawiki.git] / maintenance / moveBatch.php
blobae47008482498257686f701e72b48b8952cb8fa1
1 <?php
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
12 $oldCwd = getcwd();
13 $optionsWithArgs = array( 'u', 'r', 'i' );
14 require_once( 'commandLine.inc' );
16 chdir( $oldCwd );
18 # Options processing
20 $filename = 'php://stdin';
21 $user = 'Move page script';
22 $reason = '';
23 $interval = 0;
25 if ( isset( $args[0] ) ) {
26 $filename = $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' );
44 if ( !$file ) {
45 print "Unable to read file, exiting\n";
46 exit;
49 $dbw =& wfGetDB( DB_MASTER );
51 for ( $linenum = 1; !feof( $file ); $linenum++ ) {
52 $line = fgets( $file );
53 if ( $line === false ) {
54 break;
56 $parts = array_map( 'trim', explode( '|', $line ) );
57 if ( count( $parts ) != 2 ) {
58 print "Error on line $linenum, no pipe character\n";
59 continue;
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;
69 print $source->getPrefixedText();
70 $dbw->begin();
71 $source->moveTo( $dest, false, $reason );
72 $dbw->immediateCommit();
73 print "\n";
75 if ( $interval ) {
76 sleep( $interval );
78 wfWaitForSlaves( 5 );