Index: branches/apiedit/phase3/includes/api/ApiMain.php |
— | — | @@ -56,6 +56,7 @@ |
57 | 57 | 'query' => 'ApiQuery', |
58 | 58 | 'rollback' => 'ApiRollback', |
59 | 59 | 'delete' => 'ApiDelete', |
| 60 | + 'undelete' => 'ApiUndelete', |
60 | 61 | 'opensearch' => 'ApiOpenSearch', |
61 | 62 | 'feedwatchlist' => 'ApiFeedWatchlist', |
62 | 63 | 'help' => 'ApiHelp', |
Index: branches/apiedit/phase3/includes/api/ApiRollback.php |
— | — | @@ -90,7 +90,7 @@ |
91 | 91 | $this->dieDebug(__METHOD__, "rollback() returned an unknown error ($retval)"); |
92 | 92 | } |
93 | 93 | // $retval has to be Article::SUCCESS if we get here |
94 | | - $this->getResult()->addValue(null, 'rollback', $info); |
| 94 | + $this->getResult()->addValue(null, $this->getModuleName(), $info); |
95 | 95 | } |
96 | 96 | |
97 | 97 | protected function getAllowedParams() { |
Index: branches/apiedit/phase3/includes/api/ApiDelete.php |
— | — | @@ -128,7 +128,7 @@ |
129 | 129 | } |
130 | 130 | // $retval has to be self::DELETE_SUCCESS if we get here |
131 | 131 | $r = array('title' => $titleObj->getPrefixedText(), 'reason' => $reason); |
132 | | - $this->getResult()->addValue(null, 'delete', $r); |
| 132 | + $this->getResult()->addValue(null, $this->getModuleName(), $r); |
133 | 133 | } |
134 | 134 | |
135 | 135 | protected function getAllowedParams() { |
— | — | @@ -149,8 +149,8 @@ |
150 | 150 | |
151 | 151 | protected function getDescription() { |
152 | 152 | return array( |
153 | | - 'Deletes a page. You need to be logged in as a sysop to use this function, see also action=login.' |
154 | | - ); |
| 153 | + 'Deletes a page. You need to be logged in as a sysop to use this function, see also action=login.' |
| 154 | + ); |
155 | 155 | } |
156 | 156 | |
157 | 157 | protected function getExamples() { |
Index: branches/apiedit/phase3/includes/api/ApiUndelete.php |
— | — | @@ -0,0 +1,108 @@ |
| 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 ApiUndelete 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['token'])) |
| 48 | + $this->dieUsage('The token parameter must be set', 'notoken'); |
| 49 | + |
| 50 | + if(!$wgUser->isAllowed('delete')) |
| 51 | + $this->dieUsage('You don\'t have permission to restore deleted revisions', 'permissiondenied'); |
| 52 | + if($wgUser->isBlocked()) |
| 53 | + $this->dieUsage('You have been blocked from editing', 'blocked'); |
| 54 | + if(wfReadOnly()) |
| 55 | + $this->dieUsage('The wiki is in read-only mode', 'readonly'); |
| 56 | + if(!$wgUser->matchEditToken($params['token'])) |
| 57 | + $this->dieUsage('Invalid token', 'badtoken'); |
| 58 | + |
| 59 | + $titleObj = Title::newFromText($params['title']); |
| 60 | + if(!$titleObj) |
| 61 | + $this->dieUsage("bad title {$params['title']}", 'invalidtitle'); |
| 62 | + $pa = new PageArchive($titleObj); |
| 63 | + if(!$pa->undelete((isset($params['timestamps']) ? $params['timestamps'] : array()), $params['reason'])) |
| 64 | + $this->dieUsage('Undeletion failed for unknown reason', 'failed'); |
| 65 | + |
| 66 | + $info['title'] = $params['title']; |
| 67 | + $info['reason'] = $params['reason']; // FIXME |
| 68 | + $this->getResult()->addValue(null, $this->getModuleName(), $info); |
| 69 | + } |
| 70 | + |
| 71 | + protected function getAllowedParams() { |
| 72 | + return array ( |
| 73 | + 'title' => null, |
| 74 | + 'token' => null, |
| 75 | + 'reason' => "", |
| 76 | + 'timestamps' => array( |
| 77 | + ApiBase :: PARAM_ISMULTI => true |
| 78 | + ) |
| 79 | + ); |
| 80 | + } |
| 81 | + |
| 82 | + protected function getParamDescription() { |
| 83 | + return array ( |
| 84 | + 'title' => 'Title of the page you want to restore.', |
| 85 | + 'token' => 'An undelete token previously retrieved through list=deletedrevs', |
| 86 | + 'reason' => 'Reason for restoring (optional)', |
| 87 | + 'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.' |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + protected function getDescription() { |
| 92 | + return array( |
| 93 | + 'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be', |
| 94 | + 'retrieved through list=deletedrevs' |
| 95 | + ); |
| 96 | + } |
| 97 | + |
| 98 | + protected function getExamples() { |
| 99 | + return array ( |
| 100 | + 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page', |
| 101 | + 'api.php?action=undelete&title=Main%20Page&token=123ABC×tamps=20070703220045|20070702194856' |
| 102 | + ); |
| 103 | + } |
| 104 | + |
| 105 | + public function getVersion() { |
| 106 | + return __CLASS__ . ': $Id: ApiUndelete.php 22289 2007-05-20 23:31:44Z yurik $'; |
| 107 | + } |
| 108 | +} |
| 109 | +?> |
Property changes on: branches/apiedit/phase3/includes/api/ApiUndelete.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 110 | + native |
Index: branches/apiedit/phase3/includes/SpecialUndelete.php |
— | — | @@ -263,6 +263,8 @@ |
264 | 264 | function undelete( $timestamps, $comment = '', $fileVersions = array() ) { |
265 | 265 | // If both the set of text revisions and file revisions are empty, |
266 | 266 | // restore everything. Otherwise, just restore the requested items. |
| 267 | + $dbw = wfGetDB(DB_MASTER); |
| 268 | + $dbw->begin(); |
267 | 269 | $restoreAll = empty( $timestamps ) && empty( $fileVersions ); |
268 | 270 | |
269 | 271 | $restoreText = $restoreAll || !empty( $timestamps ); |
— | — | @@ -303,7 +305,8 @@ |
304 | 306 | if( trim( $comment ) != '' ) |
305 | 307 | $reason .= ": {$comment}"; |
306 | 308 | $log->addEntry( 'restore', $this->title, $reason ); |
307 | | - |
| 309 | + |
| 310 | + $dbw->commit(); |
308 | 311 | return true; |
309 | 312 | } |
310 | 313 | |
Index: branches/apiedit/phase3/includes/AutoLoader.php |
— | — | @@ -324,7 +324,8 @@ |
325 | 325 | 'ApiQuerySiteinfo' => 'includes/api/ApiQuerySiteinfo.php', |
326 | 326 | 'ApiQueryWatchlist' => 'includes/api/ApiQueryWatchlist.php', |
327 | 327 | 'ApiResult' => 'includes/api/ApiResult.php', |
328 | | - 'ApiRollback' => 'includes/api/ApiRollback.php' |
| 328 | + 'ApiRollback' => 'includes/api/ApiRollback.php', |
| 329 | + 'ApiUndelete' => 'includes/api/ApiUndelete.php' |
329 | 330 | ); |
330 | 331 | |
331 | 332 | wfProfileIn( __METHOD__ ); |