}
/**
- * @addtogroup API
+ * @ingroup API
*/
class ApiUndelete extends ApiBase {
global $wgUser;
$this->getMain()->requestWriteMode();
$params = $this->extractRequestParams();
-
+
$titleObj = NULL;
if(!isset($params['title']))
- $this->dieUsage('The title parameter must be set', 'notitle');
+ $this->dieUsageMsg(array('missingparam', 'title'));
if(!isset($params['token']))
- $this->dieUsage('The token parameter must be set', 'notoken');
+ $this->dieUsageMsg(array('missingparam', 'token'));
if(!$wgUser->isAllowed('undelete'))
- $this->dieUsage('You don\'t have permission to restore deleted revisions', 'permissiondenied');
+ $this->dieUsageMsg(array('permdenied-undelete'));
if($wgUser->isBlocked())
- $this->dieUsage('You have been blocked from editing', 'blocked');
+ $this->dieUsageMsg(array('blockedtext'));
if(wfReadOnly())
- $this->dieUsage('The wiki is in read-only mode', 'readonly');
+ $this->dieUsageMsg(array('readonlytext'));
if(!$wgUser->matchEditToken($params['token']))
- $this->dieUsage('Invalid token', 'badtoken');
+ $this->dieUsageMsg(array('sessionfailure'));
$titleObj = Title::newFromText($params['title']);
if(!$titleObj)
- $this->dieUsage("Bad title ``{$params['title']}''", 'invalidtitle');
+ $this->dieUsageMsg(array('invalidtitle', $params['title']));
// Convert timestamps
+ if(!isset($params['timestamps']))
+ $params['timestamps'] = array();
if(!is_array($params['timestamps']))
$params['timestamps'] = array($params['timestamps']);
foreach($params['timestamps'] as $i => $ts)
$dbw->begin();
$retval = $pa->undelete((isset($params['timestamps']) ? $params['timestamps'] : array()), $params['reason']);
if(!is_array($retval))
- switch($retval)
- {
- case PageArchive::UNDELETE_NOTHINGRESTORED:
- $this->dieUsage('No revisions could be restored', 'norevs');
- case PageArchive::UNDELETE_NOTAVAIL:
- $this->dieUsage('Not all requested revisions could be found', 'revsnotfound');
- case PageArchive::UNDELETE_UNKNOWNERR:
- $this->dieUsage('Undeletion failed with unknown error', 'unknownerror');
- }
- $dbw->commit();
-
+ $this->dieUsageMsg(array('cannotundelete'));
+
+ if($retval[1])
+ wfRunHooks( 'FileUndeleteComplete',
+ array($titleObj, array(), $wgUser, $params['reason']) );
+
$info['title'] = $titleObj->getPrefixedText();
$info['revisions'] = $retval[0];
$info['fileversions'] = $retval[1];
$info['reason'] = $retval[2];
$this->getResult()->addValue(null, $this->getModuleName(), $info);
}
-
- protected function getAllowedParams() {
+
+ public function mustBePosted() { return true; }
+
+ public function getAllowedParams() {
return array (
'title' => null,
'token' => null,
);
}
- protected function getParamDescription() {
+ public function getParamDescription() {
return array (
'title' => 'Title of the page you want to restore.',
'token' => 'An undelete token previously retrieved through list=deletedrevs',
);
}
- protected function getDescription() {
+ public function getDescription() {
return array(
'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be',
'retrieved through list=deletedrevs'