39 parent::__construct();
41 "Rollback all edits by a given user or IP provided they're the most recent edit" );
44 'A list of titles, none means all titles where the given user is the most recent',
48 $this->
addOption(
'user',
'A user or IP to rollback all edits for',
true,
true );
49 $this->
addOption(
'summary',
'Edit summary to use',
false,
true );
50 $this->
addOption(
'bot',
'Mark the edits as bot' );
56 $userNameUtils = $services->getUserNameUtils();
57 $username = $userNameUtils->isIP( $user ) ? $user : $userNameUtils->getCanonical( $user );
63 $summary = $this->
getOption(
'summary', $this->mSelf .
' mass rollback' );
66 foreach ( explode(
'|', $this->
getOption(
'titles' ) ) as $title ) {
67 $t = Title::newFromText( $title );
69 $this->
error(
'Invalid title, ' . $title );
75 $titles = $this->getRollbackTitles( $user );
79 $this->
output(
'No suitable titles to be rolled back.' );
84 $doer = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
85 $byUser = $services->getUserIdentityLookup()->getUserIdentityByName( $username );
91 $wikiPageFactory = $services->getWikiPageFactory();
92 $rollbackPageFactory = $services->getRollbackPageFactory();
93 foreach ( $titles as $t ) {
94 $page = $wikiPageFactory->newFromTitle( $t );
95 $this->
output(
'Processing ' . $t->getPrefixedText() .
'...' );
96 $rollbackResult = $rollbackPageFactory
97 ->newRollbackPage( $page, $doer, $byUser )
99 ->setSummary( $summary )
101 if ( $rollbackResult->isGood() ) {
102 $this->
output(
"Done!\n" );
104 $this->
output(
"Failed!\n" );
114 private function getRollbackTitles( $user ) {
117 $actorQuery = ActorMigration::newMigration()
118 ->getWhere( $dbr,
'rev_user', User::newFromName( $user,
false ) );
119 $results = $dbr->select(
120 [
'page',
'revision' ] + $actorQuery[
'tables'],
121 [
'page_namespace',
'page_title' ],
122 $actorQuery[
'conds'],
125 [
'revision' => [
'JOIN',
'page_latest = rev_id' ] ] + $actorQuery[
'joins']
127 foreach ( $results as $row ) {
128 $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
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.
getServiceContainer()
Returns the main service container.
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.