Merge "Add option to expose original sha1 in thumb url"
[lhc/web/wiklou.git] / maintenance / moveBatch.php
index 34e6428..a27a772 100644 (file)
@@ -21,7 +21,7 @@
  * @ingroup Maintenance
  * @author Tim Starling
  *
- * USAGE: php moveBatch.php [-u <user>] [-r <reason>] [-i <interval>] [listfile]
+ * USAGE: php moveBatch.php [-u <user>] [-r <reason>] [-i <interval>] [-noredirects] [listfile]
  *
  * [listfile] - file with two titles per line, separated with pipe characters;
  * the first title is the source, the second is the destination.
@@ -29,6 +29,7 @@
  * <user> - username to perform moves as
  * <reason> - reason to be given for moves
  * <interval> - number of seconds to sleep after each move
+ * <noredirects> - suppress creation of redirects
  *
  * This will print out error codes from Title::moveTo() if something goes wrong,
  * e.g. immobile_namespace for namespaces which can't be moved
@@ -48,6 +49,7 @@ class MoveBatch extends Maintenance {
                $this->addOption( 'u', "User to perform move", false, true );
                $this->addOption( 'r', "Reason to move page", false, true );
                $this->addOption( 'i', "Interval to sleep between moves" );
+               $this->addOption( 'noredirects', "Suppress creation of redirects" );
                $this->addArg( 'listfile', 'List of pages to move, newline delimited', false );
        }
 
@@ -62,6 +64,7 @@ class MoveBatch extends Maintenance {
                $user = $this->getOption( 'u', 'Move page script' );
                $reason = $this->getOption( 'r', '' );
                $interval = $this->getOption( 'i', 0 );
+               $noredirects = $this->getOption( 'noredirects', false );
                if ( $this->hasArg() ) {
                        $file = fopen( $this->getArg(), 'r' );
                } else {
@@ -79,7 +82,9 @@ class MoveBatch extends Maintenance {
 
                # Setup complete, now start
                $dbw = wfGetDB( DB_MASTER );
+               // @codingStandardsIgnoreStart Ignore avoid function calls in a FOR loop test part warning
                for ( $linenum = 1; !feof( $file ); $linenum++ ) {
+                       // @codingStandardsIgnoreEnd
                        $line = fgets( $file );
                        if ( $line === false ) {
                                break;
@@ -96,13 +101,12 @@ class MoveBatch extends Maintenance {
                                continue;
                        }
 
-
                        $this->output( $source->getPrefixedText() . ' --> ' . $dest->getPrefixedText() );
                        $dbw->begin( __METHOD__ );
-                       $err = $source->moveTo( $dest, false, $reason );
-                       if ( $err !== true ) {
-                               $msg = array_shift( $err[0] );
-                               $this->output( "\nFAILED: " . wfMessage( $msg, $err[0] )->text() );
+                       $mp = new MovePage( $source, $dest );
+                       $status = $mp->move( $wgUser, $reason, !$noredirects );
+                       if ( !$status->isOK() ) {
+                               $this->output( "\nFAILED: " . $status->getWikiText() );
                        }
                        $dbw->commit( __METHOD__ );
                        $this->output( "\n" );