35require_once __DIR__ .
'/Maintenance.php';
45 parent::__construct();
47 $this->
addOption(
'u',
"User to perform move",
false,
true );
48 $this->
addOption(
'r',
"Reason to move page",
false,
true );
49 $this->
addOption(
'i',
"Interval to sleep between moves" );
50 $this->
addOption(
'noredirects',
"Suppress creation of redirects" );
51 $this->
addArg(
'listfile',
'List of pages to move, newline delimited',
false );
56 $username = $this->
getOption(
'u',
false );
59 $noRedirects = $this->
hasOption(
'noredirects' );
60 if ( $this->
hasArg( 0 ) ) {
61 $file = fopen( $this->
getArg( 0 ),
'r' );
68 $this->
fatalError(
"Unable to read file, exiting" );
70 if ( $username ===
false ) {
71 $user = User::newSystemUser(
'Move page script', [
'steal' =>
true ] );
73 $user = User::newFromName( $username );
75 if ( !$user || !$user->isRegistered() ) {
78 StubGlobalUser::setUser( $user );
82 # Setup complete, now start
83 for ( $lineNum = 1; !feof( $file ); $lineNum++ ) {
84 $line = fgets( $file );
85 if ( $line ===
false ) {
88 $parts = array_map(
'trim', explode(
'|', $line ) );
89 if ( count( $parts ) !== 2 ) {
90 $this->
error(
"Error on line $lineNum, no pipe character" );
93 $source = Title::newFromText( $parts[0] );
94 $dest = Title::newFromText( $parts[1] );
95 if (
$source ===
null || $dest ===
null ) {
96 $this->
error(
"Invalid title on line $lineNum" );
100 $this->
output(
$source->getPrefixedText() .
' --> ' . $dest->getPrefixedText() );
102 $mp = $movePageFactory->newMovePage(
$source, $dest );
103 $status = $mp->move( $user, $reason, !$noRedirects );
104 if ( !$status->isOK() ) {
105 $this->
output(
" FAILED\n" );
106 $this->
error( $status );
120require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
getArg( $argId=0, $default=null)
Get an argument.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
commitTransactionRound( $fname)
Commit a transactional batch of DB operations and wait for replica DB servers to catch up.
hasArg( $argId=0)
Does a given argument exist?
beginTransactionRound( $fname)
Start a transactional batch of DB operations.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
getStdin( $len=null)
Return input from stdin.
addDescription( $text)
Set the description text.
Maintenance script to move a batch of pages.
execute()
Do the actual work.
__construct()
Default constructor.