30require_once __DIR__ .
'/Maintenance.php';
41 parent::__construct();
43 "Rollback all edits by a given user or IP provided they're the most recent edit" );
46 'A list of titles, none means all titles where the given user is the most recent',
50 $this->
addOption(
'user',
'A user or IP to rollback all edits for',
true,
true );
51 $this->
addOption(
'summary',
'Edit summary to use',
false,
true );
52 $this->
addOption(
'bot',
'Mark the edits as bot' );
59 $userNameUtils = $services->getUserNameUtils();
60 $user = $userNameUtils->isIP( $user ) ? $user : $userNameUtils->getCanonical( $user );
66 $summary = $this->
getOption(
'summary', $this->mSelf .
' mass rollback' );
69 foreach ( explode(
'|', $this->
getOption(
'titles' ) ) as $text ) {
70 $title = Title::newFromText( $text );
72 $this->
error(
'Invalid title, ' . $text );
78 $titles = $this->getRollbackTitles( $user );
82 $this->
output(
'No suitable titles to be rolled back.' );
87 $doer = User::newSystemUser( User::MAINTENANCE_SCRIPT_USER, [
'steal' =>
true ] );
88 $byUser = $services->getUserIdentityLookup()->getUserIdentityByName( $user );
94 $wikiPageFactory = $services->getWikiPageFactory();
95 $rollbackPageFactory = $services->getRollbackPageFactory();
100 foreach ( $titleBatches as $titleBatch ) {
101 foreach ( $titleBatch as $title ) {
102 $page = $wikiPageFactory->newFromTitle( $title );
103 $this->
output(
'Processing ' . $title->getPrefixedText() .
'...' );
106 $rollbackResult = $rollbackPageFactory
107 ->newRollbackPage( $page, $doer, $byUser )
109 ->setSummary( $summary )
113 if ( $rollbackResult->isGood() ) {
114 $this->
output(
"Done!\n" );
116 $this->
output(
"Failed!\n" );
127 private function getRollbackTitles( $user ) {
131 $results = $dbr->newSelectQueryBuilder()
132 ->select( [
'page_namespace',
'page_title' ] )
134 ->join(
'revision',
null,
'page_latest = rev_id' )
135 ->join(
'actor',
null,
'rev_actor = actor_id' )
136 ->where( [
'actor_name' => $user ] )
137 ->caller( __METHOD__ )->fetchResultSet();
138 foreach ( $results as $row ) {
139 $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
148require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
newBatchIterator( $source)
Wrap an entry iterator into a generator that returns batches of said entries.
commitTransactionRound( $fname)
Commit a transactional batch of DB operations and wait for replica DB servers to catch up.
beginTransactionRound( $fname)
Start a transactional batch of DB operations.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
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.