Merge "Fix method declaration in UploadFromStash"
[mediawiki.git] / includes / api / ApiUndelete.php
blob2ee86411c47a51332c2128b7a9d18ef4fd2344dd
1 <?php
2 /**
5 * Created on Jul 3, 2007
7 * Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
24 * @file
27 /**
28 * @ingroup API
30 class ApiUndelete extends ApiBase {
32 public function __construct( $main, $action ) {
33 parent::__construct( $main, $action );
36 public function execute() {
37 $params = $this->extractRequestParams();
39 if ( !$this->getUser()->isAllowed( 'undelete' ) ) {
40 $this->dieUsageMsg( 'permdenied-undelete' );
43 if ( $this->getUser()->isBlocked() ) {
44 $this->dieUsageMsg( 'blockedtext' );
47 $titleObj = Title::newFromText( $params['title'] );
48 if ( !$titleObj ) {
49 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
52 // Convert timestamps
53 if ( !isset( $params['timestamps'] ) ) {
54 $params['timestamps'] = array();
56 if ( !is_array( $params['timestamps'] ) ) {
57 $params['timestamps'] = array( $params['timestamps'] );
59 foreach ( $params['timestamps'] as $i => $ts ) {
60 $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
63 $pa = new PageArchive( $titleObj );
64 $retval = $pa->undelete(
65 ( isset( $params['timestamps'] ) ? $params['timestamps'] : array() ),
66 $params['reason'],
67 array(),
68 false,
69 $this->getUser()
71 if ( !is_array( $retval ) ) {
72 $this->dieUsageMsg( 'cannotundelete' );
75 if ( $retval[1] ) {
76 wfRunHooks( 'FileUndeleteComplete',
77 array( $titleObj, array(), $this->getUser(), $params['reason'] ) );
80 $this->setWatch( $params['watchlist'], $titleObj );
82 $info['title'] = $titleObj->getPrefixedText();
83 $info['revisions'] = intval( $retval[0] );
84 $info['fileversions'] = intval( $retval[1] );
85 $info['reason'] = $retval[2];
86 $this->getResult()->addValue( null, $this->getModuleName(), $info );
89 public function mustBePosted() {
90 return true;
93 public function isWriteMode() {
94 return true;
97 public function getAllowedParams() {
98 return array(
99 'title' => array(
100 ApiBase::PARAM_TYPE => 'string',
101 ApiBase::PARAM_REQUIRED => true
103 'token' => array(
104 ApiBase::PARAM_TYPE => 'string',
105 ApiBase::PARAM_REQUIRED => true
107 'reason' => '',
108 'timestamps' => array(
109 ApiBase::PARAM_TYPE => 'timestamp',
110 ApiBase::PARAM_ISMULTI => true,
112 'watchlist' => array(
113 ApiBase::PARAM_DFLT => 'preferences',
114 ApiBase::PARAM_TYPE => array(
115 'watch',
116 'unwatch',
117 'preferences',
118 'nochange'
124 public function getParamDescription() {
125 return array(
126 'title' => 'Title of the page you want to restore',
127 'token' => 'An undelete token previously retrieved through list=deletedrevs',
128 'reason' => 'Reason for restoring',
129 'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.',
130 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
134 public function getResultProperties() {
135 return array(
136 '' => array(
137 'title' => 'string',
138 'revisions' => 'integer',
139 'filerevisions' => 'integer',
140 'reason' => 'string'
145 public function getDescription() {
146 return array(
147 'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be',
148 'retrieved through list=deletedrevs'
152 public function getPossibleErrors() {
153 return array_merge( parent::getPossibleErrors(), array(
154 array( 'permdenied-undelete' ),
155 array( 'blockedtext' ),
156 array( 'invalidtitle', 'title' ),
157 array( 'cannotundelete' ),
158 ) );
161 public function needsToken() {
162 return true;
165 public function getTokenSalt() {
166 return '';
169 public function getExamples() {
170 return array(
171 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page',
172 'api.php?action=undelete&title=Main%20Page&token=123ABC&timestamps=20070703220045|20070702194856'
176 public function getHelpUrls() {
177 return 'https://www.mediawiki.org/wiki/API:Undelete';
180 public function getVersion() {
181 return __CLASS__ . ': $Id$';