Merge "Support all values for exif PhotometricInterpretation"
[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 execute() {
33 $this->useTransactionalTimeLimit();
34
35 $params = $this->extractRequestParams();
36
37 if ( !$this->getUser()->isAllowed( 'undelete' ) ) {
38 $this->dieUsageMsg( 'permdenied-undelete' );
39 }
40
41 if ( $this->getUser()->isBlocked() ) {
42 $this->dieUsage(
43 'You have been blocked from editing',
44 'blocked',
45 0,
46 array( 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $this->getUser()->getBlock() ) )
47 );
48 }
49
50 $titleObj = Title::newFromText( $params['title'] );
51 if ( !$titleObj || $titleObj->isExternal() ) {
52 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
53 }
54
55 // Convert timestamps
56 if ( !isset( $params['timestamps'] ) ) {
57 $params['timestamps'] = array();
58 }
59 if ( !is_array( $params['timestamps'] ) ) {
60 $params['timestamps'] = array( $params['timestamps'] );
61 }
62 foreach ( $params['timestamps'] as $i => $ts ) {
63 $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
64 }
65
66 $pa = new PageArchive( $titleObj, $this->getConfig() );
67 $retval = $pa->undelete(
68 ( isset( $params['timestamps'] ) ? $params['timestamps'] : array() ),
69 $params['reason'],
70 $params['fileids'],
71 false,
72 $this->getUser()
73 );
74 if ( !is_array( $retval ) ) {
75 $this->dieUsageMsg( 'cannotundelete' );
76 }
77
78 if ( $retval[1] ) {
79 Hooks::run( 'FileUndeleteComplete',
80 array( $titleObj, $params['fileids'], $this->getUser(), $params['reason'] ) );
81 }
82
83 $this->setWatch( $params['watchlist'], $titleObj );
84
85 $info['title'] = $titleObj->getPrefixedText();
86 $info['revisions'] = intval( $retval[0] );
87 $info['fileversions'] = intval( $retval[1] );
88 $info['reason'] = $retval[2];
89 $this->getResult()->addValue( null, $this->getModuleName(), $info );
90 }
91
92 public function mustBePosted() {
93 return true;
94 }
95
96 public function isWriteMode() {
97 return true;
98 }
99
100 public function getAllowedParams() {
101 return array(
102 'title' => array(
103 ApiBase::PARAM_TYPE => 'string',
104 ApiBase::PARAM_REQUIRED => true
105 ),
106 'reason' => '',
107 'timestamps' => array(
108 ApiBase::PARAM_TYPE => 'timestamp',
109 ApiBase::PARAM_ISMULTI => true,
110 ),
111 'fileids' => array(
112 ApiBase::PARAM_TYPE => 'integer',
113 ApiBase::PARAM_ISMULTI => true,
114 ),
115 'watchlist' => array(
116 ApiBase::PARAM_DFLT => 'preferences',
117 ApiBase::PARAM_TYPE => array(
118 'watch',
119 'unwatch',
120 'preferences',
121 'nochange'
122 ),
123 ),
124 );
125 }
126
127 public function needsToken() {
128 return 'csrf';
129 }
130
131 protected function getExamplesMessages() {
132 return array(
133 'action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page'
134 => 'apihelp-undelete-example-page',
135 'action=undelete&title=Main%20Page&token=123ABC' .
136 '&timestamps=2007-07-03T22:00:45Z|2007-07-02T19:48:56Z'
137 => 'apihelp-undelete-example-revisions',
138 );
139 }
140
141 public function getHelpUrls() {
142 return 'https://www.mediawiki.org/wiki/API:Undelete';
143 }
144 }