X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/maintenance/rollbackEdits.php diff --git a/maintenance/rollbackEdits.php b/maintenance/rollbackEdits.php index e1c126e1..5ad7d4e1 100644 --- a/maintenance/rollbackEdits.php +++ b/maintenance/rollbackEdits.php @@ -18,16 +18,29 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * + * @file * @ingroup Maintenance */ -require_once( dirname( __FILE__ ) . '/Maintenance.php' ); +require_once __DIR__ . '/Maintenance.php'; +/** + * Maintenance script to rollback all edits by a given user or IP provided + * they're the most recent edit. + * + * @ingroup Maintenance + */ class RollbackEdits extends Maintenance { public function __construct() { parent::__construct(); - $this->mDescription = "Rollback all edits by a given user or IP provided they're the most recent edit"; - $this->addOption( 'titles', 'A list of titles, none means all titles where the given user is the most recent', false, true ); + $this->addDescription( + "Rollback all edits by a given user or IP provided they're the most recent edit" ); + $this->addOption( + 'titles', + 'A list of titles, none means all titles where the given user is the most recent', + false, + true + ); $this->addOption( 'user', 'A user or IP to rollback all edits for', true, true ); $this->addOption( 'summary', 'Edit summary to use', false, true ); $this->addOption( 'bot', 'Mark the edits as bot' ); @@ -42,8 +55,8 @@ class RollbackEdits extends Maintenance { $bot = $this->hasOption( 'bot' ); $summary = $this->getOption( 'summary', $this->mSelf . ' mass rollback' ); - $titles = array(); - $results = array(); + $titles = []; + $results = []; if ( $this->hasOption( 'titles' ) ) { foreach ( explode( '|', $this->getOption( 'titles' ) ) as $title ) { $t = Title::newFromText( $title ); @@ -59,13 +72,16 @@ class RollbackEdits extends Maintenance { if ( !$titles ) { $this->output( 'No suitable titles to be rolled back' ); + return; } + $doer = User::newSystemUser( 'Maintenance script', [ 'steal' => true ] ); + foreach ( $titles as $t ) { - $a = new Article( $t ); - $this->output( 'Processing ' . $t->getPrefixedText() . '...' ); - if ( !$a->commitRollback( $user, $summary, $bot, $results ) ) { + $page = WikiPage::factory( $t ); + $this->output( 'Processing ' . $t->getPrefixedText() . '... ' ); + if ( !$page->commitRollback( $user, $summary, $bot, $results, $doer ) ) { $this->output( "done\n" ); } else { $this->output( "failed\n" ); @@ -75,23 +91,25 @@ class RollbackEdits extends Maintenance { /** * Get all pages that should be rolled back for a given user - * @param $user String a name to check against rev_user_text + * @param string $user A name to check against rev_user_text + * @return array */ private function getRollbackTitles( $user ) { - $dbr = wfGetDB( DB_SLAVE ); - $titles = array(); + $dbr = $this->getDB( DB_REPLICA ); + $titles = []; $results = $dbr->select( - array( 'page', 'revision' ), - array( 'page_namespace', 'page_title' ), - array( 'page_latest = rev_id', 'rev_user_text' => $user ), + [ 'page', 'revision' ], + [ 'page_namespace', 'page_title' ], + [ 'page_latest = rev_id', 'rev_user_text' => $user ], __METHOD__ ); foreach ( $results as $row ) { $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title ); } + return $titles; } } $maintClass = 'RollbackEdits'; -require_once( RUN_MAINTENANCE_IF_MAIN ); +require_once RUN_MAINTENANCE_IF_MAIN;