26require_once __DIR__ .
'/Maintenance.php';
36 parent::__construct();
37 $this->
addDescription(
'Reassign edits from one user to another' );
38 $this->
addOption(
"force",
"Reassign even if the target user doesn't exist" );
39 $this->
addOption(
"norc",
"Don't update the recent changes table" );
40 $this->
addOption(
"report",
"Print out details of what would be changed, but don't update it" );
41 $this->
addArg(
'from',
'Old user to take edits from' );
42 $this->
addArg(
'to',
'New user to give edits to' );
47 # Set up the users involved
51 # If the target doesn't exist, and --force is not set, stop here
52 if ( $to->getId() || $this->hasOption(
'force' ) ) {
56 # If reporting, and there were items, advise the user to run without --report
58 $this->
output(
"Run the script again without --report to update.\n" );
61 $ton = $to->getName();
62 $this->
error(
"User '{$ton}' not found." );
81 $this->
output(
"Checking current edits..." );
88 $row = $dbw->fetchObject(
$res );
90 $this->
output(
"found {$cur}.\n" );
92 $this->
output(
"Checking deleted edits..." );
99 $row = $dbw->fetchObject(
$res );
101 $this->
output(
"found {$del}.\n" );
103 # Don't count recent changes if we're not supposed to
105 $this->
output(
"Checking recent changes..." );
112 $row = $dbw->fetchObject(
$res );
114 $this->
output(
"found {$rec}.\n" );
119 $total = $cur + $del + $rec;
120 $this->
output(
"\nTotal entries to change: {$total}\n" );
125 $this->
output(
"\nReassigning current edits..." );
126 $dbw->update(
'revision', $this->
userSpecification( $to,
'rev_user',
'rev_user_text' ),
128 $this->
output(
"done.\nReassigning deleted edits..." );
129 $dbw->update(
'archive', $this->
userSpecification( $to,
'ar_user',
'ar_user_text' ),
131 $this->
output(
"done.\n" );
132 # Update recent changes if required
134 $this->
output(
"Updating recent changes..." );
135 $dbw->update(
'recentchanges', $this->
userSpecification( $to,
'rc_user',
'rc_user_text' ),
137 $this->
output(
"done.\n" );
157 return $user->getId()
158 ? [ $idfield =>
$user->getId() ]
159 : [ $utfield =>
$user->getName() ];
172 return [ $idfield =>
$user->getId(), $utfield =>
$user->getName() ];
189 $this->
error(
"Invalid username",
true );
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.
hasArg( $argId=0)
Does a given argument exist?
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular param exists.
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.
Maintenance script that reassigns edits from a user or IP address to another user.
execute()
Do the actual work.
__construct()
Default constructor.
initialiseUser( $username)
Initialise the user object.
doReassignEdits(&$from, &$to, $rc=false, $report=false)
Reassign edits from one user to another.
userConditions(&$user, $idfield, $utfield)
Return the most efficient set of user conditions i.e.
userSpecification(&$user, $idfield, $utfield)
Return user specifications i.e.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
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
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
this hook is for auditing only or null if authentication failed before getting that far $username
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
require_once RUN_MAINTENANCE_IF_MAIN