00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 if (!defined('MEDIAWIKI')) {
00026
00027 require_once ("ApiBase.php");
00028 }
00029
00033 class ApiUndelete extends ApiBase {
00034
00035 public function __construct($main, $action) {
00036 parent :: __construct($main, $action);
00037 }
00038
00039 public function execute() {
00040 global $wgUser;
00041 $params = $this->extractRequestParams();
00042
00043 $titleObj = NULL;
00044 if(!isset($params['title']))
00045 $this->dieUsageMsg(array('missingparam', 'title'));
00046 if(!isset($params['token']))
00047 $this->dieUsageMsg(array('missingparam', 'token'));
00048
00049 if(!$wgUser->isAllowed('undelete'))
00050 $this->dieUsageMsg(array('permdenied-undelete'));
00051 if($wgUser->isBlocked())
00052 $this->dieUsageMsg(array('blockedtext'));
00053 if(!$wgUser->matchEditToken($params['token']))
00054 $this->dieUsageMsg(array('sessionfailure'));
00055
00056 $titleObj = Title::newFromText($params['title']);
00057 if(!$titleObj)
00058 $this->dieUsageMsg(array('invalidtitle', $params['title']));
00059
00060
00061 if(!isset($params['timestamps']))
00062 $params['timestamps'] = array();
00063 if(!is_array($params['timestamps']))
00064 $params['timestamps'] = array($params['timestamps']);
00065 foreach($params['timestamps'] as $i => $ts)
00066 $params['timestamps'][$i] = wfTimestamp(TS_MW, $ts);
00067
00068 $pa = new PageArchive($titleObj);
00069 $dbw = wfGetDB(DB_MASTER);
00070 $dbw->begin();
00071 $retval = $pa->undelete((isset($params['timestamps']) ? $params['timestamps'] : array()), $params['reason']);
00072 if(!is_array($retval))
00073 $this->dieUsageMsg(array('cannotundelete'));
00074
00075 if($retval[1])
00076 wfRunHooks( 'FileUndeleteComplete',
00077 array($titleObj, array(), $wgUser, $params['reason']) );
00078
00079 $info['title'] = $titleObj->getPrefixedText();
00080 $info['revisions'] = intval($retval[0]);
00081 $info['fileversions'] = intval($retval[1]);
00082 $info['reason'] = intval($retval[2]);
00083 $this->getResult()->addValue(null, $this->getModuleName(), $info);
00084 }
00085
00086 public function mustBePosted() { return true; }
00087
00088 public function isWriteMode() {
00089 return true;
00090 }
00091
00092 public function getAllowedParams() {
00093 return array (
00094 'title' => null,
00095 'token' => null,
00096 'reason' => "",
00097 'timestamps' => array(
00098 ApiBase :: PARAM_ISMULTI => true
00099 )
00100 );
00101 }
00102
00103 public function getParamDescription() {
00104 return array (
00105 'title' => 'Title of the page you want to restore.',
00106 'token' => 'An undelete token previously retrieved through list=deletedrevs',
00107 'reason' => 'Reason for restoring (optional)',
00108 'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.'
00109 );
00110 }
00111
00112 public function getDescription() {
00113 return array(
00114 'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be',
00115 'retrieved through list=deletedrevs'
00116 );
00117 }
00118
00119 protected function getExamples() {
00120 return array (
00121 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page',
00122 'api.php?action=undelete&title=Main%20Page&token=123ABC×tamps=20070703220045|20070702194856'
00123 );
00124 }
00125
00126 public function getVersion() {
00127 return __CLASS__ . ': $Id: ApiUndelete.php 48091 2009-03-06 13:49:44Z catrope $';
00128 }
00129 }