58860bd58739078ae3795588cfa236c1515ca1ff
4 * Created on Jul 3, 2007
5 * API for MediaWiki 1.8+
7 * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * http://www.gnu.org/copyleft/gpl.html
25 if (!defined('MEDIAWIKI')) {
26 // Eclipse helper - will be ignored in production
27 require_once ("ApiBase.php");
33 class ApiUndelete
extends ApiBase
{
35 public function __construct($main, $action) {
36 parent
:: __construct($main, $action);
39 public function execute() {
41 $this->getMain()->requestWriteMode();
42 $params = $this->extractRequestParams();
45 if(!isset($params['title']))
46 $this->dieUsageMsg(array('missingparam', 'title'));
47 if(!isset($params['token']))
48 $this->dieUsageMsg(array('missingparam', 'token'));
50 if(!$wgUser->isAllowed('undelete'))
51 $this->dieUsageMsg(array('permdenied-undelete'));
52 if($wgUser->isBlocked())
53 $this->dieUsageMsg(array('blockedtext'));
55 $this->dieUsageMsg(array('readonlytext'));
56 if(!$wgUser->matchEditToken($params['token']))
57 $this->dieUsageMsg(array('sessionfailure'));
59 $titleObj = Title
::newFromText($params['title']);
61 $this->dieUsageMsg(array('invalidtitle', $params['title']));
64 if(!is_array($params['timestamps']))
65 $params['timestamps'] = array($params['timestamps']);
66 foreach($params['timestamps'] as $i => $ts)
67 $params['timestamps'][$i] = wfTimestamp(TS_MW
, $ts);
69 $pa = new PageArchive($titleObj);
70 $dbw = wfGetDb(DB_MASTER
);
72 $retval = $pa->undelete((isset($params['timestamps']) ?
$params['timestamps'] : array()), $params['reason']);
73 if(!is_array($retval))
74 $this->dieUsageMsg(array('cannotundelete'));
76 $info['title'] = $titleObj->getPrefixedText();
77 $info['revisions'] = $retval[0];
78 $info['fileversions'] = $retval[1];
79 $info['reason'] = $retval[2];
80 $this->getResult()->addValue(null, $this->getModuleName(), $info);
83 public function mustBePosted() { return true; }
85 public function getAllowedParams() {
90 'timestamps' => array(
91 ApiBase
:: PARAM_ISMULTI
=> true
96 public function getParamDescription() {
98 'title' => 'Title of the page you want to restore.',
99 'token' => 'An undelete token previously retrieved through list=deletedrevs',
100 'reason' => 'Reason for restoring (optional)',
101 'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.'
105 public function getDescription() {
107 'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be',
108 'retrieved through list=deletedrevs'
112 protected function getExamples() {
114 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page',
115 'api.php?action=undelete&title=Main%20Page&token=123ABC×tamps=20070703220045|20070702194856'
119 public function getVersion() {
120 return __CLASS__
. ': $Id$';