MediaWiki  1.23.2
moveBatch.php
Go to the documentation of this file.
1 <?php
38 require_once __DIR__ . '/Maintenance.php';
39 
45 class MoveBatch extends Maintenance {
46  public function __construct() {
47  parent::__construct();
48  $this->mDescription = "Moves a batch of pages";
49  $this->addOption( 'u', "User to perform move", false, true );
50  $this->addOption( 'r', "Reason to move page", false, true );
51  $this->addOption( 'i', "Interval to sleep between moves" );
52  $this->addOption( 'noredirects', "Suppress creation of redirects" );
53  $this->addArg( 'listfile', 'List of pages to move, newline delimited', false );
54  }
55 
56  public function execute() {
58 
59  # Change to current working directory
60  $oldCwd = getcwd();
61  chdir( $oldCwd );
62 
63  # Options processing
64  $user = $this->getOption( 'u', 'Move page script' );
65  $reason = $this->getOption( 'r', '' );
66  $interval = $this->getOption( 'i', 0 );
67  $noredirects = $this->getOption( 'noredirects', false );
68  if ( $this->hasArg() ) {
69  $file = fopen( $this->getArg(), 'r' );
70  } else {
71  $file = $this->getStdin();
72  }
73 
74  # Setup
75  if ( !$file ) {
76  $this->error( "Unable to read file, exiting", true );
77  }
78  $wgUser = User::newFromName( $user );
79  if ( !$wgUser ) {
80  $this->error( "Invalid username", true );
81  }
82 
83  # Setup complete, now start
84  $dbw = wfGetDB( DB_MASTER );
85  for ( $linenum = 1; !feof( $file ); $linenum++ ) {
86  $line = fgets( $file );
87  if ( $line === false ) {
88  break;
89  }
90  $parts = array_map( 'trim', explode( '|', $line ) );
91  if ( count( $parts ) != 2 ) {
92  $this->error( "Error on line $linenum, no pipe character" );
93  continue;
94  }
95  $source = Title::newFromText( $parts[0] );
96  $dest = Title::newFromText( $parts[1] );
97  if ( is_null( $source ) || is_null( $dest ) ) {
98  $this->error( "Invalid title on line $linenum" );
99  continue;
100  }
101 
102  $this->output( $source->getPrefixedText() . ' --> ' . $dest->getPrefixedText() );
103  $dbw->begin( __METHOD__ );
104  $err = $source->moveTo( $dest, false, $reason, !$noredirects );
105  if ( $err !== true ) {
106  $msg = array_shift( $err[0] );
107  $this->output( "\nFAILED: " . wfMessage( $msg, $err[0] )->text() );
108  }
109  $dbw->commit( __METHOD__ );
110  $this->output( "\n" );
111 
112  if ( $interval ) {
113  sleep( $interval );
114  }
115  wfWaitForSlaves();
116  }
117  }
118 }
119 
120 $maintClass = "MoveBatch";
121 require_once RUN_MAINTENANCE_IF_MAIN;
$wgUser
$wgUser
Definition: Setup.php:552
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
Maintenance\getStdin
getStdin( $len=null)
Return input from stdin.
Definition: Maintenance.php:287
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
text
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:388
Maintenance\hasArg
hasArg( $argId=0)
Does a given argument exist?
Definition: Maintenance.php:236
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
MoveBatch
Maintenance script to move a batch of pages.
Definition: moveBatch.php:45
wfMessage
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
wfWaitForSlaves
wfWaitForSlaves( $maxLag=false, $wiki=false, $cluster=false)
Modern version of wfWaitForSlaves().
Definition: GlobalFunctions.php:3795
$line
$line
Definition: cdb.php:57
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
$file
if(PHP_SAPI !='cli') $file
Definition: UtfNormalTest2.php:30
MoveBatch\__construct
__construct()
Default constructor.
Definition: moveBatch.php:46
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
MoveBatch\execute
execute()
Do the actual work.
Definition: moveBatch.php:56
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:207
$source
if(PHP_SAPI !='cli') $source
Definition: mwdoc-filter.php:18
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
Maintenance\getArg
getArg( $argId=0, $default=null)
Get an argument.
Definition: Maintenance.php:246
$maintClass
$maintClass
Definition: moveBatch.php:120