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
30 class ApiUndelete
extends ApiBase
{
32 public function __construct( $main, $action ) {
33 parent
::__construct( $main, $action );
36 public function execute() {
37 $params = $this->extractRequestParams();
39 if ( !$this->getUser()->isAllowed( 'undelete' ) ) {
40 $this->dieUsageMsg( 'permdenied-undelete' );
43 if ( $this->getUser()->isBlocked() ) {
44 $this->dieUsageMsg( 'blockedtext' );
47 $titleObj = Title
::newFromText( $params['title'] );
49 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
53 if ( !isset( $params['timestamps'] ) ) {
54 $params['timestamps'] = array();
56 if ( !is_array( $params['timestamps'] ) ) {
57 $params['timestamps'] = array( $params['timestamps'] );
59 foreach ( $params['timestamps'] as $i => $ts ) {
60 $params['timestamps'][$i] = wfTimestamp( TS_MW
, $ts );
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' );
70 wfRunHooks( 'FileUndeleteComplete',
71 array( $titleObj, array(), $this->getUser(), $params['reason'] ) );
74 $this->setWatch( $params['watchlist'], $titleObj );
76 $info['title'] = $titleObj->getPrefixedText();
77 $info['revisions'] = intval( $retval[0] );
78 $info['fileversions'] = intval( $retval[1] );
79 $info['reason'] = intval( $retval[2] );
80 $this->getResult()->addValue( null, $this->getModuleName(), $info );
83 public function mustBePosted() {
87 public function isWriteMode() {
91 public function getAllowedParams() {
94 ApiBase
::PARAM_TYPE
=> 'string',
95 ApiBase
::PARAM_REQUIRED
=> true
99 'timestamps' => array(
100 ApiBase
::PARAM_TYPE
=> 'timestamp',
101 ApiBase
::PARAM_ISMULTI
=> true,
103 'watchlist' => array(
104 ApiBase
::PARAM_DFLT
=> 'preferences',
105 ApiBase
::PARAM_TYPE
=> array(
115 public function getParamDescription() {
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',
125 public function getDescription() {
127 'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be',
128 'retrieved through list=deletedrevs'
132 public function getPossibleErrors() {
133 return array_merge( parent
::getPossibleErrors(), array(
134 array( 'permdenied-undelete' ),
135 array( 'blockedtext' ),
136 array( 'invalidtitle', 'title' ),
137 array( 'cannotundelete' ),
141 public function needsToken() {
145 public function getTokenSalt() {
149 public function getExamples() {
151 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page',
152 'api.php?action=undelete&title=Main%20Page&token=123ABC×tamps=20070703220045|20070702194856'
156 public function getHelpUrls() {
157 return 'https://www.mediawiki.org/wiki/API:Undelete';
160 public function getVersion() {
161 return __CLASS__
. ': $Id$';