27 require_once __DIR__ .
'/Maintenance.php';
37 parent::__construct();
39 "Rollback all edits by a given user or IP provided they're the most recent edit" );
42 'A list of titles, none means all titles where the given user is the most recent',
46 $this->
addOption(
'user',
'A user or IP to rollback all edits for',
true,
true );
47 $this->
addOption(
'summary',
'Edit summary to use',
false,
true );
48 $this->
addOption(
'bot',
'Mark the edits as bot' );
53 $services = MediaWikiServices::getInstance();
54 $userNameUtils = $services->getUserNameUtils();
55 $username = $userNameUtils->isIP( $user ) ? $user : $userNameUtils->getCanonical( $user );
61 $summary = $this->
getOption(
'summary', $this->mSelf .
' mass rollback' );
67 $this->
error(
'Invalid title, ' . $title );
73 $titles = $this->getRollbackTitles( $user );
77 $this->
output(
'No suitable titles to be rolled back.' );
83 $byUser = $services->getUserIdentityLookup()->getUserIdentityByName( $username );
89 $wikiPageFactory = $services->getWikiPageFactory();
90 $rollbackPageFactory = $services->getRollbackPageFactory();
91 foreach ( $titles as
$t ) {
92 $page = $wikiPageFactory->newFromTitle(
$t );
93 $this->
output(
'Processing ' . $t->getPrefixedText() .
'...' );
94 $rollbackResult = $rollbackPageFactory
95 ->newRollbackPage( $page, $doer, $byUser )
97 ->setSummary( $summary )
99 if ( $rollbackResult->isGood() ) {
100 $this->
output(
"Done!\n" );
102 $this->
output(
"Failed!\n" );
112 private function getRollbackTitles( $user ) {
117 $results =
$dbr->select(
118 [
'page',
'revision' ] + $actorQuery[
'tables'],
119 [
'page_namespace',
'page_title' ],
120 $actorQuery[
'conds'],
123 [
'revision' => [
'JOIN',
'page_latest = rev_id' ] ] + $actorQuery[
'joins']
125 foreach ( $results as $row ) {
134 require_once RUN_MAINTENANCE_IF_MAIN;
static newMigration()
Static constructor.
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.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
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 rollback all edits by a given user or IP provided they're the most recent edit.
__construct()
Default constructor.
execute()
Do the actual work.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
static newFromName( $name, $validate='valid')
static newSystemUser( $name, $options=[])
Static factory method for creation of a "system" user from username.
const MAINTENANCE_SCRIPT_USER
Username used for various maintenance scripts.