[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
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 $params = $this->extractRequestParams(); 34 35 if ( !$this->getUser()->isAllowed( 'undelete' ) ) { 36 $this->dieUsageMsg( 'permdenied-undelete' ); 37 } 38 39 if ( $this->getUser()->isBlocked() ) { 40 $this->dieUsageMsg( 'blockedtext' ); 41 } 42 43 $titleObj = Title::newFromText( $params['title'] ); 44 if ( !$titleObj || $titleObj->isExternal() ) { 45 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); 46 } 47 48 // Convert timestamps 49 if ( !isset( $params['timestamps'] ) ) { 50 $params['timestamps'] = array(); 51 } 52 if ( !is_array( $params['timestamps'] ) ) { 53 $params['timestamps'] = array( $params['timestamps'] ); 54 } 55 foreach ( $params['timestamps'] as $i => $ts ) { 56 $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts ); 57 } 58 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() 66 ); 67 if ( !is_array( $retval ) ) { 68 $this->dieUsageMsg( 'cannotundelete' ); 69 } 70 71 if ( $retval[1] ) { 72 wfRunHooks( 'FileUndeleteComplete', 73 array( $titleObj, $params['fileids'], $this->getUser(), $params['reason'] ) ); 74 } 75 76 $this->setWatch( $params['watchlist'], $titleObj ); 77 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 ); 83 } 84 85 public function mustBePosted() { 86 return true; 87 } 88 89 public function isWriteMode() { 90 return true; 91 } 92 93 public function getAllowedParams() { 94 return array( 95 'title' => array( 96 ApiBase::PARAM_TYPE => 'string', 97 ApiBase::PARAM_REQUIRED => true 98 ), 99 'reason' => '', 100 'timestamps' => array( 101 ApiBase::PARAM_TYPE => 'timestamp', 102 ApiBase::PARAM_ISMULTI => true, 103 ), 104 'fileids' => array( 105 ApiBase::PARAM_TYPE => 'integer', 106 ApiBase::PARAM_ISMULTI => true, 107 ), 108 'watchlist' => array( 109 ApiBase::PARAM_DFLT => 'preferences', 110 ApiBase::PARAM_TYPE => array( 111 'watch', 112 'unwatch', 113 'preferences', 114 'nochange' 115 ), 116 ), 117 ); 118 } 119 120 public function getParamDescription() { 121 return array( 122 'title' => 'Title of the page you want to restore', 123 'reason' => 'Reason for restoring', 124 'timestamps' => array( 125 'Timestamps of the revisions to restore.', 126 'If both timestamps and fileids are empty, all will be restored.', 127 ), 128 'fileids' => array( 129 'IDs of the file revisions to restore.', 130 'If both timestamps and fileids are empty, all will be restored.', 131 ), 132 'watchlist' => 'Unconditionally add or remove the page from your ' . 133 'watchlist, use preferences or do not change watch', 134 ); 135 } 136 137 public function getDescription() { 138 return array( 139 'Restore certain revisions of a deleted page. A list of deleted revisions ', 140 '(including timestamps) can be retrieved through list=deletedrevs, and a list', 141 'of deleted file ids can be retrieved through list=filearchive.' 142 ); 143 } 144 145 public function needsToken() { 146 return 'csrf'; 147 } 148 149 public function getExamples() { 150 return array( 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' 153 ); 154 } 155 156 public function getHelpUrls() { 157 return 'https://www.mediawiki.org/wiki/API:Undelete'; 158 } 159 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |