32 require_once __DIR__ .
'/Maintenance.php';
41 parent::__construct();
43 $this->
addOption(
'u',
"User to perform move",
false,
true );
44 $this->
addOption(
'r',
"Reason to move page",
false,
true );
45 $this->
addOption(
'i',
"Interval to sleep between moves" );
46 $this->
addOption(
'noredirects',
"Suppress creation of redirects" );
47 $this->
addArg(
'listfile',
'List of pages to move, newline delimited',
false );
52 $username = $this->
getOption(
'u',
false );
55 $noRedirects = $this->
hasOption(
'noredirects' );
56 if ( $this->
hasArg( 0 ) ) {
64 $this->
fatalError(
"Unable to read file, exiting" );
66 if ( $username ===
false ) {
74 StubGlobalUser::setUser( $user );
76 # Setup complete, now start
78 for ( $lineNum = 1; !feof(
$file ); $lineNum++ ) {
79 $line = fgets(
$file );
80 if ( $line ===
false ) {
83 $parts = array_map(
'trim', explode(
'|', $line ) );
84 if ( count( $parts ) !== 2 ) {
85 $this->
error(
"Error on line $lineNum, no pipe character" );
90 if (
$source ===
null || $dest ===
null ) {
91 $this->
error(
"Invalid title on line $lineNum" );
95 $this->
output(
$source->getPrefixedText() .
' --> ' . $dest->getPrefixedText() );
97 $mp = MediaWikiServices::getInstance()->getMovePageFactory()
98 ->newMovePage(
$source, $dest );
99 $status = $mp->move( $user, $reason, !$noRedirects );
100 if ( !$status->isOK() ) {
101 $this->
output(
"\nFAILED: " . $status->getMessage(
false,
false,
'en' )->text() );
114 require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
error( $err, $die=0)
Throw an error to the user.
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
beginTransaction(IDatabase $dbw, $fname)
Begin a transaction on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transaction on a DB handle and wait for replica DBs to catch up.
output( $out, $channel=null)
Throw some output to the user.
getStdin( $len=null)
Return input from stdin.
hasArg( $argId=0)
Does a given argument exist?
hasOption( $name)
Checks to see if a particular option was set.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Maintenance script to move a batch of pages.
execute()
Do the actual work.
__construct()
Default constructor.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
static newFromName( $name, $validate='valid')
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.