Index: trunk/phase3/maintenance/rollbackEdits.php |
— | — | @@ -0,0 +1,98 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Rollback all edits by a given user or IP provided they're the most |
| 5 | + * recent edit (just like real rollback) |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License along |
| 18 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | + * http://www.gnu.org/copyleft/gpl.html |
| 21 | + * |
| 22 | + * @ingroup Maintenance |
| 23 | + */ |
| 24 | + |
| 25 | +require_once( dirname(__FILE__) . '/Maintenance.php' ); |
| 26 | + |
| 27 | +class RollbackEdits extends Maintenance { |
| 28 | + public function __construct() { |
| 29 | + parent::__construct(); |
| 30 | + $this->mDescription = "Rollback all edits by a given user or IP provided they're the most recent edit"; |
| 31 | + $this->addOption( 'titles', 'A list of titles, none means all titles where the given user is the most recent', false, true ); |
| 32 | + $this->addOption( 'user', 'A user or IP to rollback all edits for', true, true ); |
| 33 | + $this->addOption( 'summary', 'Edit summary to use', false, true ); |
| 34 | + $this->addOption( 'bot', 'Mark the edits as bot' ); |
| 35 | + } |
| 36 | + |
| 37 | + public function execute() { |
| 38 | + $user = $this->getOption( 'user' ); |
| 39 | + $username = User::isIP( $user ) ? $user : User::getCanonicalName( $user ); |
| 40 | + if( !$username ) { |
| 41 | + $this->error( 'Invalid username', true ); |
| 42 | + } |
| 43 | + |
| 44 | + $bot = $this->hasOption( 'bot' ); |
| 45 | + $summary = $this->getOption( 'summary', $this->mSelf . ' mass rollback' ); |
| 46 | + $titles = array(); |
| 47 | + $results = array(); |
| 48 | + if( $this->hasOption( 'titles' ) ) { |
| 49 | + foreach( explode( '|', $this->getOption( 'titles' ) ) as $title ) { |
| 50 | + $t = Title::newFromText( $title ); |
| 51 | + if( !$t ) { |
| 52 | + $this->error( 'Invalid title, ' . $title ); |
| 53 | + } else { |
| 54 | + $titles[] = $t; |
| 55 | + } |
| 56 | + } |
| 57 | + } else { |
| 58 | + $titles = $this->getRollbackTitles( $user ); |
| 59 | + } |
| 60 | + |
| 61 | + if( !$titles ) { |
| 62 | + $this->output( 'No suitable titles to be rolled back' ); |
| 63 | + return; |
| 64 | + } |
| 65 | + |
| 66 | + foreach( $titles as $t ) { |
| 67 | + $a = new Article( $t ); |
| 68 | + $this->output( 'Processing ' . $t->getPrefixedText() . '...' ); |
| 69 | + if( !$a->commitRollback( $user, $summary, $bot, $results ) ) { |
| 70 | + $this->output( "done\n" ); |
| 71 | + } else { |
| 72 | + $this->output( "failed\n" ); |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Get all pages that should be rolled back for a given user |
| 79 | + * @param $user String a name to check against rev_user_text |
| 80 | + */ |
| 81 | + private function getRollbackTitles( $user ) { |
| 82 | + $dbr = wfGetDB( DB_SLAVE ); |
| 83 | + $titles = array(); |
| 84 | + $results = $dbr->select( |
| 85 | + array( 'page', 'revision' ), |
| 86 | + array( 'page_namespace', 'page_title' ), |
| 87 | + array( 'page.page_latest = revision.rev_id', 'revision.rev_user_text' => $user ), |
| 88 | + __METHOD__ |
| 89 | + ); |
| 90 | + var_dump( __METHOD__ ); |
| 91 | + while( $row = $dbr->fetchObject( $results ) ) { |
| 92 | + $titles[] = Title::makeTitle( $row->page_namespace, $row->page_title ); |
| 93 | + } |
| 94 | + return $titles; |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +$maintClass = 'RollbackEdits'; |
| 99 | +require_once( DO_MAINTENANCE ); |
Property changes on: trunk/phase3/maintenance/rollbackEdits.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 100 | + native |