13dd40a4595e1b587999b5e96de8f13418c4e3cd
3 * Maintenance script to move a batch of pages
8 * USAGE: php moveBatch.php [-u <user>] [-r <reason>] [-i <interval>] [listfile]
10 * [listfile] - file with two titles per line, separated with pipe characters;
11 * the first title is the source, the second is the destination.
12 * Standard input is used if listfile is not given.
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
21 require_once( "Maintenance.php" );
23 class MoveBatch
extends Maintenance
{
24 public function __construct() {
25 parent
::__construct();
26 $this->mDescription
= "Moves a batch of pages";
27 $this->addParam( 'u', "User to perform move", false, true );
28 $this->addParam( 'r', "Reason to move page", false, true );
29 $this->addParam( 'i', "Interval to sleep between moves" );
30 $this->addArgs( array( 'listfile' ) );
33 public function execute() {
36 # Change to current working directory
41 $user = $this->getOption( 'u', 'Move page script' );
42 $reason = $this->getOption( 'r', '' );
43 $interval = $this->getOption( 'i', 0 );
44 if( $this->hasArg() ) {
45 $file = fopen( $this->getArg(), 'r' );
47 $file = $this->getStdin();
52 $this->error( "Unable to read file, exiting\n", true );
54 $wgUser = User
::newFromName( $user );
56 # Setup complete, now start
57 $dbw = wfGetDB( DB_MASTER
);
58 for ( $linenum = 1; !feof( $file ); $linenum++
) {
59 $line = fgets( $file );
60 if ( $line === false ) {
63 $parts = array_map( 'trim', explode( '|', $line ) );
64 if ( count( $parts ) != 2 ) {
65 $this->error( "Error on line $linenum, no pipe character\n" );
68 $source = Title
::newFromText( $parts[0] );
69 $dest = Title
::newFromText( $parts[1] );
70 if ( is_null( $source ) ||
is_null( $dest ) ) {
71 $this->error( "Invalid title on line $linenum\n" );
76 $this->output( $source->getPrefixedText() . ' --> ' . $dest->getPrefixedText() );
78 $err = $source->moveTo( $dest, false, $reason );
80 $this->output( "\nFAILED: $err" );
82 $dbw->immediateCommit();
83 $this->output( "\n" );
93 $maintClass = "MoveBatch";
94 require_once( DO_MAINTENANCE
);