Merge "mw.notification: fix error on notif. close with $.fx.off=true"
[lhc/web/wiklou.git] / includes / api / ApiUndelete.php
1 <?php
2 /**
3 *
4 *
5 * Created on Jul 3, 2007
6 *
7 * Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
8 *
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.
13 *
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.
18 *
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
23 *
24 * @file
25 */
26
27 /**
28 * @ingroup API
29 */
30 class ApiUndelete extends ApiBase {
31
32 public function __construct( $main, $action ) {
33 parent::__construct( $main, $action );
34 }
35
36 public function execute() {
37 $params = $this->extractRequestParams();
38
39 if ( !$this->getUser()->isAllowed( 'undelete' ) ) {
40 $this->dieUsageMsg( 'permdenied-undelete' );
41 }
42
43 if ( $this->getUser()->isBlocked() ) {
44 $this->dieUsageMsg( 'blockedtext' );
45 }
46
47 $titleObj = Title::newFromText( $params['title'] );
48 if ( !$titleObj ) {
49 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
50 }
51
52 // Convert timestamps
53 if ( !isset( $params['timestamps'] ) ) {
54 $params['timestamps'] = array();
55 }
56 if ( !is_array( $params['timestamps'] ) ) {
57 $params['timestamps'] = array( $params['timestamps'] );
58 }
59 foreach ( $params['timestamps'] as $i => $ts ) {
60 $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
61 }
62
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()
70 );
71 if ( !is_array( $retval ) ) {
72 $this->dieUsageMsg( 'cannotundelete' );
73 }
74
75 if ( $retval[1] ) {
76 wfRunHooks( 'FileUndeleteComplete',
77 array( $titleObj, array(), $this->getUser(), $params['reason'] ) );
78 }
79
80 $this->setWatch( $params['watchlist'], $titleObj );
81
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 );
87 }
88
89 public function mustBePosted() {
90 return true;
91 }
92
93 public function isWriteMode() {
94 return true;
95 }
96
97 public function getAllowedParams() {
98 return array(
99 'title' => array(
100 ApiBase::PARAM_TYPE => 'string',
101 ApiBase::PARAM_REQUIRED => true
102 ),
103 'token' => array(
104 ApiBase::PARAM_TYPE => 'string',
105 ApiBase::PARAM_REQUIRED => true
106 ),
107 'reason' => '',
108 'timestamps' => array(
109 ApiBase::PARAM_TYPE => 'timestamp',
110 ApiBase::PARAM_ISMULTI => true,
111 ),
112 'watchlist' => array(
113 ApiBase::PARAM_DFLT => 'preferences',
114 ApiBase::PARAM_TYPE => array(
115 'watch',
116 'unwatch',
117 'preferences',
118 'nochange'
119 ),
120 ),
121 );
122 }
123
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',
131 );
132 }
133
134 public function getResultProperties() {
135 return array(
136 '' => array(
137 'title' => 'string',
138 'revisions' => 'integer',
139 'filerevisions' => 'integer',
140 'reason' => 'string'
141 )
142 );
143 }
144
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'
149 );
150 }
151
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 ) );
159 }
160
161 public function needsToken() {
162 return true;
163 }
164
165 public function getTokenSalt() {
166 return '';
167 }
168
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'
173 );
174 }
175
176 public function getHelpUrls() {
177 return 'https://www.mediawiki.org/wiki/API:Undelete';
178 }
179
180 public function getVersion() {
181 return __CLASS__ . ': $Id$';
182 }
183 }