20require_once __DIR__ .
'/Maintenance.php';
30 parent::__construct();
32 $this->
addOption(
'u',
"User to perform move",
false,
true );
33 $this->
addOption(
'r',
"Reason to move page",
false,
true );
34 $this->
addOption(
'i',
"Interval to sleep between moves" );
35 $this->
addOption(
'noredirects',
"Suppress creation of redirects" );
38 'List of pages to move (newline delimited) in the format <existing page name>|<new name>',
45 $username = $this->
getOption(
'u',
false );
48 $noRedirects = $this->
hasOption(
'noredirects' );
49 if ( $this->
hasArg( 0 ) ) {
50 $file = fopen( $this->
getArg( 0 ),
'r' );
57 $this->
fatalError(
"Unable to read file, exiting" );
59 if ( $username ===
false ) {
60 $user = User::newSystemUser(
'Move page script', [
'steal' =>
true ] );
62 $user = User::newFromName( $username );
64 if ( !$user || !$user->isRegistered() ) {
70 # Setup complete, now start
71 for ( $lineNum = 1; !feof( $file ); $lineNum++ ) {
72 $line = fgets( $file );
73 if ( $line ===
false ) {
76 $parts = array_map(
'trim', explode(
'|', $line ) );
77 if ( count( $parts ) !== 2 ) {
78 $this->
error(
"Error on line $lineNum, no pipe character" );
81 $source = Title::newFromText( $parts[0] );
82 $dest = Title::newFromText( $parts[1] );
83 if (
$source ===
null || $dest ===
null ) {
84 $this->
error(
"Invalid title on line $lineNum" );
88 $this->
output(
$source->getPrefixedText() .
' --> ' . $dest->getPrefixedText() );
90 $mp = $movePageFactory->newMovePage(
$source, $dest );
91 $status = $mp->move( $user, $reason, !$noRedirects );
92 if ( !$status->isOK() ) {
93 $this->
output(
" FAILED\n" );
94 $this->
error( $status );
108require_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.
error( $err)
Throw an error 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.
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.