Remove score display from search engine
[mediawiki.git] / includes / api / ApiUndelete.php
blob349297218010e9073221fe83364f22d0278cf372
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 $params = $this->extractRequestParams();
35 if ( !$this->getUser()->isAllowed( 'undelete' ) ) {
36 $this->dieUsageMsg( 'permdenied-undelete' );
39 if ( $this->getUser()->isBlocked() ) {
40 $this->dieUsageMsg( 'blockedtext' );
43 $titleObj = Title::newFromText( $params['title'] );
44 if ( !$titleObj || $titleObj->isExternal() ) {
45 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
48 // Convert timestamps
49 if ( !isset( $params['timestamps'] ) ) {
50 $params['timestamps'] = array();
52 if ( !is_array( $params['timestamps'] ) ) {
53 $params['timestamps'] = array( $params['timestamps'] );
55 foreach ( $params['timestamps'] as $i => $ts ) {
56 $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
59 $pa = new PageArchive( $titleObj, $this->getConfig() );
60 $retval = $pa->undelete(
61 ( isset( $params['timestamps'] ) ? $params['timestamps'] : array() ),
62 $params['reason'],
63 $params['fileids'],
64 false,
65 $this->getUser()
67 if ( !is_array( $retval ) ) {
68 $this->dieUsageMsg( 'cannotundelete' );
71 if ( $retval[1] ) {
72 wfRunHooks( 'FileUndeleteComplete',
73 array( $titleObj, $params['fileids'], $this->getUser(), $params['reason'] ) );
76 $this->setWatch( $params['watchlist'], $titleObj );
78 $info['title'] = $titleObj->getPrefixedText();
79 $info['revisions'] = intval( $retval[0] );
80 $info['fileversions'] = intval( $retval[1] );
81 $info['reason'] = $retval[2];
82 $this->getResult()->addValue( null, $this->getModuleName(), $info );
85 public function mustBePosted() {
86 return true;
89 public function isWriteMode() {
90 return true;
93 public function getAllowedParams() {
94 return array(
95 'title' => array(
96 ApiBase::PARAM_TYPE => 'string',
97 ApiBase::PARAM_REQUIRED => true
99 'token' => array(
100 ApiBase::PARAM_TYPE => 'string',
101 ApiBase::PARAM_REQUIRED => true
103 'reason' => '',
104 'timestamps' => array(
105 ApiBase::PARAM_TYPE => 'timestamp',
106 ApiBase::PARAM_ISMULTI => true,
108 'fileids' => array(
109 ApiBase::PARAM_TYPE => 'integer',
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' => array(
128 'An undelete token previously retrieved through list=deletedrevs, or ',
129 'a delete token retrieved through action=tokens.'
131 'reason' => 'Reason for restoring',
132 'timestamps' => array(
133 'Timestamps of the revisions to restore.',
134 'If both timestamps and fileids are empty, all will be restored.',
136 'fileids' => array(
137 'IDs of the file revisions to restore.',
138 'If both timestamps and fileids are empty, all will be restored.',
140 'watchlist' => 'Unconditionally add or remove the page from your ' .
141 'watchlist, use preferences or do not change watch',
145 public function getResultProperties() {
146 return array(
147 '' => array(
148 'title' => 'string',
149 'revisions' => 'integer',
150 'filerevisions' => 'integer',
151 'reason' => 'string'
156 public function getDescription() {
157 return array(
158 'Restore certain revisions of a deleted page. A list of deleted revisions ',
159 '(including timestamps) can be retrieved through list=deletedrevs, and a list',
160 'of deleted file ids can be retrieved through list=filearchive.'
164 public function getPossibleErrors() {
165 return array_merge( parent::getPossibleErrors(), array(
166 array( 'permdenied-undelete' ),
167 array( 'blockedtext' ),
168 array( 'invalidtitle', 'title' ),
169 array( 'cannotundelete' ),
170 ) );
173 public function needsToken() {
174 return true;
177 public function getTokenSalt() {
178 return '';
181 public function getExamples() {
182 return array(
183 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page',
184 'api.php?action=undelete&title=Main%20Page&token=123ABC&timestamps=20070703220045|20070702194856'
188 public function getHelpUrls() {
189 return 'https://www.mediawiki.org/wiki/API:Undelete';