MediaWiki  1.23.8
Go to the documentation of this file.
1 <?php
25 require_once __DIR__ . '/Maintenance.php';
33 class RollbackEdits extends Maintenance {
34  public function __construct() {
35  parent::__construct();
36  $this->mDescription = "Rollback all edits by a given user or IP provided they're the most recent edit";
37  $this->addOption( 'titles', 'A list of titles, none means all titles where the given user is the most recent', false, true );
38  $this->addOption( 'user', 'A user or IP to rollback all edits for', true, true );
39  $this->addOption( 'summary', 'Edit summary to use', false, true );
40  $this->addOption( 'bot', 'Mark the edits as bot' );
41  }
43  public function execute() {
44  $user = $this->getOption( 'user' );
45  $username = User::isIP( $user ) ? $user : User::getCanonicalName( $user );
46  if ( !$username ) {
47  $this->error( 'Invalid username', true );
48  }
50  $bot = $this->hasOption( 'bot' );
51  $summary = $this->getOption( 'summary', $this->mSelf . ' mass rollback' );
52  $titles = array();
53  $results = array();
54  if ( $this->hasOption( 'titles' ) ) {
55  foreach ( explode( '|', $this->getOption( 'titles' ) ) as $title ) {
56  $t = Title::newFromText( $title );
57  if ( !$t ) {
58  $this->error( 'Invalid title, ' . $title );
59  } else {
60  $titles[] = $t;
61  }
62  }
63  } else {
64  $titles = $this->getRollbackTitles( $user );
65  }
67  if ( !$titles ) {
68  $this->output( 'No suitable titles to be rolled back' );
69  return;
70  }
72  $doer = User::newFromName( 'Maintenance script' );
74  foreach ( $titles as $t ) {
75  $page = WikiPage::factory( $t );
76  $this->output( 'Processing ' . $t->getPrefixedText() . '... ' );
77  if ( !$page->commitRollback( $user, $summary, $bot, $results, $doer ) ) {
78  $this->output( "done\n" );
79  } else {
80  $this->output( "failed\n" );
81  }
82  }
83  }
90  private function getRollbackTitles( $user ) {
91  $dbr = wfGetDB( DB_SLAVE );
92  $titles = array();
93  $results = $dbr->select(
94  array( 'page', 'revision' ),
95  array( 'page_namespace', 'page_title' ),
96  array( 'page_latest = rev_id', 'rev_user_text' => $user ),
97  __METHOD__
98  );
99  foreach ( $results as $row ) {
100  $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title );
101  }
102  return $titles;
103  }
104 }
106 $maintClass = 'RollbackEdits';
107 require_once RUN_MAINTENANCE_IF_MAIN;
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3659
Definition: rollbackEdits.php:106
getRollbackTitles( $user)
Get all pages that should be rolled back for a given user.
Definition: rollbackEdits.php:90
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
Definition: maintenance.txt:50
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:389
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
Maintenance script to rollback all edits by a given user or IP provided they're the most recent edit.
Definition: rollbackEdits.php:33
Default constructor.
Definition: rollbackEdits.php:34
Definition: testCompression.php:48
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:103
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition: linkcache.txt:17
static isIP( $name)
Does the string match an anonymous IPv4 address?
Definition: User.php:555
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
Do the actual work.
Definition: rollbackEdits.php:43
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
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 account $user
Definition: hooks.txt:237
Definition: importImages.php:120
const DB_SLAVE
Definition: Defines.php:55
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
static getCanonicalName( $name, $validate='valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid.
Definition: User.php:884
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:333
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
Definition: testCompression.php:65
hasOption( $name)
Checks to see if a particular param exists.
Definition: Maintenance.php:181