Update ApiBase::PARAM_* comments
[mediawiki.git] / includes / api / ApiUndelete.php
blobcd50ee65c721b272d9f0b739b270e722882cfd13
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 execute() {
33 $this->useTransactionalTimeLimit();
35 $params = $this->extractRequestParams();
37 if ( !$this->getUser()->isAllowed( 'undelete' ) ) {
38 $this->dieUsageMsg( 'permdenied-undelete' );
41 if ( $this->getUser()->isBlocked() ) {
42 $this->dieUsage(
43 'You have been blocked from editing',
44 'blocked',
46 array( 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $this->getUser()->getBlock() ) )
50 $titleObj = Title::newFromText( $params['title'] );
51 if ( !$titleObj || $titleObj->isExternal() ) {
52 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
55 // Convert timestamps
56 if ( !isset( $params['timestamps'] ) ) {
57 $params['timestamps'] = array();
59 if ( !is_array( $params['timestamps'] ) ) {
60 $params['timestamps'] = array( $params['timestamps'] );
62 foreach ( $params['timestamps'] as $i => $ts ) {
63 $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
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()
74 if ( !is_array( $retval ) ) {
75 $this->dieUsageMsg( 'cannotundelete' );
78 if ( $retval[1] ) {
79 Hooks::run( 'FileUndeleteComplete',
80 array( $titleObj, $params['fileids'], $this->getUser(), $params['reason'] ) );
83 $this->setWatch( $params['watchlist'], $titleObj );
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 );
92 public function mustBePosted() {
93 return true;
96 public function isWriteMode() {
97 return true;
100 public function getAllowedParams() {
101 return array(
102 'title' => array(
103 ApiBase::PARAM_TYPE => 'string',
104 ApiBase::PARAM_REQUIRED => true
106 'reason' => '',
107 'timestamps' => array(
108 ApiBase::PARAM_TYPE => 'timestamp',
109 ApiBase::PARAM_ISMULTI => true,
111 'fileids' => array(
112 ApiBase::PARAM_TYPE => 'integer',
113 ApiBase::PARAM_ISMULTI => true,
115 'watchlist' => array(
116 ApiBase::PARAM_DFLT => 'preferences',
117 ApiBase::PARAM_TYPE => array(
118 'watch',
119 'unwatch',
120 'preferences',
121 'nochange'
127 public function needsToken() {
128 return 'csrf';
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',
141 public function getHelpUrls() {
142 return 'https://www.mediawiki.org/wiki/API:Undelete';