escape HTML elements in docblock with double quotes
[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( ( isset( $params['timestamps'] ) ? $params['timestamps'] : array() ), $params['reason'] );
65 if ( !is_array( $retval ) ) {
66 $this->dieUsageMsg( 'cannotundelete' );
67 }
68
69 if ( $retval[1] ) {
70 wfRunHooks( 'FileUndeleteComplete',
71 array( $titleObj, array(), $this->getUser(), $params['reason'] ) );
72 }
73
74 $this->setWatch( $params['watchlist'], $titleObj );
75
76 $info['title'] = $titleObj->getPrefixedText();
77 $info['revisions'] = intval( $retval[0] );
78 $info['fileversions'] = intval( $retval[1] );
79 $info['reason'] = $retval[2];
80 $this->getResult()->addValue( null, $this->getModuleName(), $info );
81 }
82
83 public function mustBePosted() {
84 return true;
85 }
86
87 public function isWriteMode() {
88 return true;
89 }
90
91 public function getAllowedParams() {
92 return array(
93 'title' => array(
94 ApiBase::PARAM_TYPE => 'string',
95 ApiBase::PARAM_REQUIRED => true
96 ),
97 'token' => null,
98 'reason' => '',
99 'timestamps' => array(
100 ApiBase::PARAM_TYPE => 'timestamp',
101 ApiBase::PARAM_ISMULTI => true,
102 ),
103 'watchlist' => array(
104 ApiBase::PARAM_DFLT => 'preferences',
105 ApiBase::PARAM_TYPE => array(
106 'watch',
107 'unwatch',
108 'preferences',
109 'nochange'
110 ),
111 ),
112 );
113 }
114
115 public function getParamDescription() {
116 return array(
117 'title' => 'Title of the page you want to restore',
118 'token' => 'An undelete token previously retrieved through list=deletedrevs',
119 'reason' => 'Reason for restoring (optional)',
120 'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.',
121 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
122 );
123 }
124
125 public function getResultProperties() {
126 return array(
127 '' => array(
128 'title' => 'string',
129 'revisions' => 'integer',
130 'filerevisions' => 'integer',
131 'reason' => 'string'
132 )
133 );
134 }
135
136 public function getDescription() {
137 return array(
138 'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be',
139 'retrieved through list=deletedrevs'
140 );
141 }
142
143 public function getPossibleErrors() {
144 return array_merge( parent::getPossibleErrors(), array(
145 array( 'permdenied-undelete' ),
146 array( 'blockedtext' ),
147 array( 'invalidtitle', 'title' ),
148 array( 'cannotundelete' ),
149 ) );
150 }
151
152 public function needsToken() {
153 return true;
154 }
155
156 public function getTokenSalt() {
157 return '';
158 }
159
160 public function getExamples() {
161 return array(
162 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page',
163 'api.php?action=undelete&title=Main%20Page&token=123ABC&timestamps=20070703220045|20070702194856'
164 );
165 }
166
167 public function getHelpUrls() {
168 return 'https://www.mediawiki.org/wiki/API:Undelete';
169 }
170
171 public function getVersion() {
172 return __CLASS__ . ': $Id$';
173 }
174 }