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 $params = $this->extractRequestParams();
44 if(!isset($params['title']))
45 $this->dieUsageMsg(array('missingparam', 'title'));
46 if(!isset($params['token']))
47 $this->dieUsageMsg(array('missingparam', 'token'));
49 if(!$wgUser->isAllowed('undelete'))
50 $this->dieUsageMsg(array('permdenied-undelete'));
51 if($wgUser->isBlocked())
52 $this->dieUsageMsg(array('blockedtext'));
53 if(!$wgUser->matchEditToken($params['token']))
54 $this->dieUsageMsg(array('sessionfailure'));
56 $titleObj = Title
::newFromText($params['title']);
58 $this->dieUsageMsg(array('invalidtitle', $params['title']));
61 if(!isset($params['timestamps']))
62 $params['timestamps'] = array();
63 if(!is_array($params['timestamps']))
64 $params['timestamps'] = array($params['timestamps']);
65 foreach($params['timestamps'] as $i => $ts)
66 $params['timestamps'][$i] = wfTimestamp(TS_MW
, $ts);
68 $pa = new PageArchive($titleObj);
69 $dbw = wfGetDB(DB_MASTER
);
71 $retval = $pa->undelete((isset($params['timestamps']) ?
$params['timestamps'] : array()), $params['reason']);
72 if(!is_array($retval))
73 $this->dieUsageMsg(array('cannotundelete'));
76 wfRunHooks( 'FileUndeleteComplete',
77 array($titleObj, array(), $wgUser, $params['reason']) );
79 $info['title'] = $titleObj->getPrefixedText();
80 $info['revisions'] = intval($retval[0]);
81 $info['fileversions'] = intval($retval[1]);
82 $info['reason'] = intval($retval[2]);
83 $this->getResult()->addValue(null, $this->getModuleName(), $info);
86 public function mustBePosted() { return true; }
88 public function isWriteMode() {
92 public function getAllowedParams() {
97 'timestamps' => array(
98 ApiBase
:: PARAM_ISMULTI
=> true
103 public function getParamDescription() {
105 'title' => 'Title of the page you want to restore.',
106 'token' => 'An undelete token previously retrieved through list=deletedrevs',
107 'reason' => 'Reason for restoring (optional)',
108 'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.'
112 public function getDescription() {
114 'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be',
115 'retrieved through list=deletedrevs'
119 protected function getExamples() {
121 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page',
122 'api.php?action=undelete&title=Main%20Page&token=123ABC×tamps=20070703220045|20070702194856'
126 public function getVersion() {
127 return __CLASS__
. ': $Id$';