00001 <?php
00002
00023 $oldCwd = getcwd();
00024 $optionsWithArgs = array( 'u', 'r', 'i' );
00025 require_once( 'commandLine.inc' );
00026
00027 chdir( $oldCwd );
00028
00029 # Options processing
00030
00031 $filename = 'php://stdin';
00032 $user = 'Move page script';
00033 $reason = '';
00034 $interval = 0;
00035
00036 if ( isset( $args[0] ) ) {
00037 $filename = $args[0];
00038 }
00039 if ( isset( $options['u'] ) ) {
00040 $user = $options['u'];
00041 }
00042 if ( isset( $options['r'] ) ) {
00043 $reason = $options['r'];
00044 }
00045 if ( isset( $options['i'] ) ) {
00046 $interval = $options['i'];
00047 }
00048
00049 $wgUser = User::newFromName( $user );
00050
00051
00052 # Setup complete, now start
00053
00054 $file = fopen( $filename, 'r' );
00055 if ( !$file ) {
00056 print "Unable to read file, exiting\n";
00057 exit;
00058 }
00059
00060 $dbw = wfGetDB( DB_MASTER );
00061
00062 for ( $linenum = 1; !feof( $file ); $linenum++ ) {
00063 $line = fgets( $file );
00064 if ( $line === false ) {
00065 break;
00066 }
00067 $parts = array_map( 'trim', explode( '|', $line ) );
00068 if ( count( $parts ) != 2 ) {
00069 print "Error on line $linenum, no pipe character\n";
00070 continue;
00071 }
00072 $source = Title::newFromText( $parts[0] );
00073 $dest = Title::newFromText( $parts[1] );
00074 if ( is_null( $source ) || is_null( $dest ) ) {
00075 print "Invalid title on line $linenum\n";
00076 continue;
00077 }
00078
00079
00080 print $source->getPrefixedText() . ' --> ' . $dest->getPrefixedText();
00081 $dbw->begin();
00082 $err = $source->moveTo( $dest, false, $reason );
00083 if( $err !== true ) {
00084 print "\nFAILED: $err";
00085 }
00086 $dbw->immediateCommit();
00087 print "\n";
00088
00089 if ( $interval ) {
00090 sleep( $interval );
00091 }
00092 wfWaitForSlaves( 5 );
00093 }
00094
00095
00096