MediaWiki REL1_28
Go to the documentation of this file.
38require_once __DIR__ . '/Maintenance.php';
45class MoveBatch extends Maintenance {
46 public function __construct() {
47 parent::__construct();
48 $this->addDescription( '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 }
56 public function execute() {
59 # Change to current working directory
60 $oldCwd = getcwd();
61 chdir( $oldCwd );
63 # Options processing
64 $user = $this->getOption( 'u', false );
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 }
74 # Setup
75 if ( !$file ) {
76 $this->error( "Unable to read file, exiting", true );
77 }
78 if ( $user === false ) {
79 $wgUser = User::newSystemUser( 'Move page script', [ 'steal' => true ] );
80 } else {
81 $wgUser = User::newFromName( $user );
82 }
83 if ( !$wgUser ) {
84 $this->error( "Invalid username", true );
85 }
87 # Setup complete, now start
88 $dbw = $this->getDB( DB_MASTER );
89 // @codingStandardsIgnoreStart Ignore avoid function calls in a FOR loop test part warning
90 for ( $linenum = 1; !feof( $file ); $linenum++ ) {
91 // @codingStandardsIgnoreEnd
92 $line = fgets( $file );
93 if ( $line === false ) {
94 break;
95 }
96 $parts = array_map( 'trim', explode( '|', $line ) );
97 if ( count( $parts ) != 2 ) {
98 $this->error( "Error on line $linenum, no pipe character" );
99 continue;
100 }
101 $source = Title::newFromText( $parts[0] );
102 $dest = Title::newFromText( $parts[1] );
103 if ( is_null( $source ) || is_null( $dest ) ) {
104 $this->error( "Invalid title on line $linenum" );
105 continue;
106 }
108 $this->output( $source->getPrefixedText() . ' --> ' . $dest->getPrefixedText() );
109 $this->beginTransaction( $dbw, __METHOD__ );
110 $mp = new MovePage( $source, $dest );
111 $status = $mp->move( $wgUser, $reason, !$noredirects );
112 if ( !$status->isOK() ) {
113 $this->output( "\nFAILED: " . $status->getWikiText( false, false, 'en' ) );
114 }
115 $this->commitTransaction( $dbw, __METHOD__ );
116 $this->output( "\n" );
118 if ( $interval ) {
119 sleep( $interval );
120 }
122 }
123 }
126$maintClass = "MoveBatch";
127require_once RUN_MAINTENANCE_IF_MAIN;
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
Definition Setup.php:806
Definition cdb.php:59
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
addArg( $arg, $description, $required=true)
Add some args that are needed.
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
getStdin( $len=null)
Return input from stdin.
hasArg( $argId=0)
Does a given argument exist?
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
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.
Maintenance script to move a batch of pages.
Definition moveBatch.php:45
Do the actual work.
Definition moveBatch.php:56
Default constructor.
Definition moveBatch.php:46
Handles the backend logic of moving a page from one title to another.
Definition MovePage.php:30
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 in any and then calling output() to send it all. It could be easily changed to send incrementally if that becomes useful
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition hooks.txt:1049
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 local account $user
Definition hooks.txt:249
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
Definition defines.php:23