r24498 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24497‎ | r24498 | r24499 >
Date:20:34, 31 July 2007
Author:catrope
Status:old
Tags:
Comment:
apiedit:
* Re-adding ApiRollback.php which was deleted by the merge
* Tweaking SpecialUndelete.php to use new framework
Modified paths:
  • /branches/apiedit/phase3/includes/SpecialUndelete.php (modified) (history)
  • /branches/apiedit/phase3/includes/api/ApiRollback.php (added) (history)

Diff [purge]

Index: branches/apiedit/phase3/includes/api/ApiRollback.php
@@ -0,0 +1,134 @@
 2+<?php
 3+
 4+/*
 5+ * Created on Jun 20, 2007
 6+ * API for MediaWiki 1.8+
 7+ *
 8+ * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
 9+ *
 10+ * This program is free software; you can redistribute it and/or modify
 11+ * it under the terms of the GNU General Public License as published by
 12+ * the Free Software Foundation; either version 2 of the License, or
 13+ * (at your option) any later version.
 14+ *
 15+ * This program is distributed in the hope that it will be useful,
 16+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 18+ * GNU General Public License for more details.
 19+ *
 20+ * You should have received a copy of the GNU General Public License along
 21+ * with this program; if not, write to the Free Software Foundation, Inc.,
 22+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 23+ * http://www.gnu.org/copyleft/gpl.html
 24+ */
 25+
 26+if (!defined('MEDIAWIKI')) {
 27+ // Eclipse helper - will be ignored in production
 28+ require_once ("ApiBase.php");
 29+}
 30+
 31+/**
 32+ * @addtogroup API
 33+ */
 34+class ApiRollback extends ApiBase {
 35+
 36+ public function __construct($main, $action) {
 37+ parent :: __construct($main, $action);
 38+ }
 39+
 40+ public function execute() {
 41+ global $wgUser;
 42+ $params = $this->extractRequestParams();
 43+
 44+ $titleObj = NULL;
 45+ if(!isset($params['title']))
 46+ $this->dieUsage('The title parameter must be set', 'notarget');
 47+ if(!isset($params['user']))
 48+ $this->dieUsage('The user parameter must be set', 'nouser');
 49+ if(!isset($params['token']))
 50+ $this->dieUsage('The token parameter must be set', 'notoken');
 51+
 52+ // doRollback() also checks for these, but we wanna save some work
 53+ if(!$wgUser->isAllowed('rollback'))
 54+ $this->dieUsage('You don\'t have permission to rollback', 'permissiondenied');
 55+ if($wgUser->isBlocked())
 56+ $this->dieUsage('You have been blocked from editing', 'blocked');
 57+ if(wfReadOnly())
 58+ $this->dieUsage('The wiki is in read-only mode', 'readonly');
 59+
 60+ $titleObj = Title::newFromText($params['title']);
 61+ if(!$titleObj)
 62+ $this->dieUsage("bad title {$params['title']}", 'invalidtitle');
 63+
 64+ $articleObj = new Article($titleObj);
 65+ $summary = (isset($params['summary']) ? $params['summary'] : "");
 66+ $info = array();
 67+ $retval = $articleObj->doRollback($params['user'], $params['token'], isset($params['markbot']), $summary, &$info);
 68+
 69+ switch($retval)
 70+ {
 71+ case Article::SUCCESS:
 72+ break; // We'll deal with that later
 73+ case Article::PERM_DENIED:
 74+ $this->dieUsage("You don't have permission to rollback", 'permissiondenied');
 75+ case Article::BLOCKED: // If we get BLOCKED or PERM_DENIED that's very weird, but it's possible
 76+ $this->dieUsage('You have been blocked from editing', 'blocked');
 77+ case Article::READONLY:
 78+ $this->dieUsage('The wiki is in read-only mode', 'readonly');
 79+ case Article::BAD_TOKEN:
 80+ $this->dieUsage('Invalid token', 'badtoken');
 81+ case Article::BAD_TITLE:
 82+ $this->dieUsage("The article ``{$params['title']}'' doesn't exist", 'missingtitle');
 83+ case Article::ALREADYROLLED:
 84+ $this->dieUsage('The edit(s) you tried to rollback is/are already rolled back', 'alreadyrolled');
 85+ case Article::ONLY_AUTHOR:
 86+ $this->dieUsage("{$params['user']} is the only author of the page", 'onlyauthor');
 87+ case Article::EDIT_FAILED:
 88+ $this->dieDebug(__METHOD__, 'Article::doEdit() failed');
 89+ default:
 90+ // rollback() has apparently invented a new error, which is extremely weird
 91+ $this->dieDebug(__METHOD__, "rollback() returned an unknown error ($retval)");
 92+ }
 93+ // $retval has to be Article::SUCCESS if we get here
 94+ $this->getResult()->addValue(null, $this->getModuleName(), $info);
 95+ }
 96+
 97+ protected function getAllowedParams() {
 98+ return array (
 99+ 'title' => null,
 100+ 'user' => null,
 101+ 'token' => null,
 102+ 'summary' => null,
 103+ 'markbot' => null
 104+ );
 105+ }
 106+
 107+ protected function getParamDescription() {
 108+ return array (
 109+ 'title' => 'Title of the page you want to rollback.',
 110+ 'user' => 'Name of the user whose edits are to be rolled back. If set incorrectly, you\'ll get a badtoken error.',
 111+ 'token' => 'A rollback token previously retrieved through prop=info',
 112+ 'summary' => 'Custom edit summary. If not set, default summary will be used.',
 113+ 'markbot' => 'Mark the reverted edits and the revert as bot edits'
 114+ );
 115+ }
 116+
 117+ protected function getDescription() {
 118+ return array(
 119+ 'Undoes the last edit to the page. If the last user who edited the page made multiple edits in a row,',
 120+ 'they will all be rolled back. You need to be logged in as a sysop to use this function, see also action=login.'
 121+ );
 122+ }
 123+
 124+ protected function getExamples() {
 125+ return array (
 126+ 'api.php?action=rollback&title=Main%20Page&user=Catrope&token=123ABC',
 127+ 'api.php?action=rollback&title=Main%20Page&user=217.121.114.116&token=123ABC&summary=Reverting%20vandalism&markbot=1'
 128+ );
 129+ }
 130+
 131+ public function getVersion() {
 132+ return __CLASS__ . ': $Id: ApiRollback.php 22289 2007-05-20 23:31:44Z yurik $';
 133+ }
 134+}
 135+?>
Property changes on: branches/apiedit/phase3/includes/api/ApiRollback.php
___________________________________________________________________
Added: svn:eol-style
1136 + native
Index: branches/apiedit/phase3/includes/SpecialUndelete.php
@@ -275,8 +275,8 @@
276276
277277 if( $restoreFiles && $this->title->getNamespace() == NS_IMAGE ) {
278278 $img = wfLocalFile( $this->title );
279 - $filesRestored = $img->restore( $fileVersions );
280 - // TODO: includes/filerepo/LocalFile.php
 279+ $this->fileStatus = $img->restore( $fileVersions );
 280+ $filesRestored = $this->fileStatus->successCount;
281281 } else {
282282 $filesRestored = 0;
283283 }

Status & tagging log