X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/api/ApiUndelete.php diff --git a/includes/api/ApiUndelete.php b/includes/api/ApiUndelete.php index 7205d05d..3aa7b608 100644 --- a/includes/api/ApiUndelete.php +++ b/includes/api/ApiUndelete.php @@ -1,10 +1,10 @@ .@home.nl + * Copyright © 2007 Roan Kattouw ".@gmail.com" * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,57 +24,65 @@ * @file */ -if ( !defined( 'MEDIAWIKI' ) ) { - // Eclipse helper - will be ignored in production - require_once( "ApiBase.php" ); -} - /** * @ingroup API */ class ApiUndelete extends ApiBase { - public function __construct( $main, $action ) { - parent::__construct( $main, $action ); - } - public function execute() { - global $wgUser; + $this->useTransactionalTimeLimit(); + $params = $this->extractRequestParams(); - if ( !$wgUser->isAllowed( 'undelete' ) ) { - $this->dieUsageMsg( array( 'permdenied-undelete' ) ); + $user = $this->getUser(); + if ( $user->isBlocked() ) { + $this->dieBlocked( $user->getBlock() ); } - if ( $wgUser->isBlocked() ) { - $this->dieUsageMsg( array( 'blockedtext' ) ); + $titleObj = Title::newFromText( $params['title'] ); + if ( !$titleObj || $titleObj->isExternal() ) { + $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ] ); } - $titleObj = Title::newFromText( $params['title'] ); - if ( !$titleObj ) { - $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); + if ( !$titleObj->userCan( 'undelete', $user, 'secure' ) ) { + $this->dieWithError( 'permdenied-undelete' ); + } + + // Check if user can add tags + if ( !is_null( $params['tags'] ) ) { + $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user ); + if ( !$ableToTag->isOK() ) { + $this->dieStatus( $ableToTag ); + } } // Convert timestamps if ( !isset( $params['timestamps'] ) ) { - $params['timestamps'] = array(); + $params['timestamps'] = []; } if ( !is_array( $params['timestamps'] ) ) { - $params['timestamps'] = array( $params['timestamps'] ); + $params['timestamps'] = [ $params['timestamps'] ]; } foreach ( $params['timestamps'] as $i => $ts ) { $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts ); } - $pa = new PageArchive( $titleObj ); - $retval = $pa->undelete( ( isset( $params['timestamps'] ) ? $params['timestamps'] : array() ), $params['reason'] ); + $pa = new PageArchive( $titleObj, $this->getConfig() ); + $retval = $pa->undelete( + ( isset( $params['timestamps'] ) ? $params['timestamps'] : [] ), + $params['reason'], + $params['fileids'], + false, + $user, + $params['tags'] + ); if ( !is_array( $retval ) ) { - $this->dieUsageMsg( array( 'cannotundelete' ) ); + $this->dieWithError( 'apierror-cantundelete' ); } if ( $retval[1] ) { - wfRunHooks( 'FileUndeleteComplete', - array( $titleObj, array(), $wgUser, $params['reason'] ) ); + Hooks::run( 'FileUndeleteComplete', + [ $titleObj, $params['fileids'], $this->getUser(), $params['reason'] ] ); } $this->setWatch( $params['watchlist'], $titleObj ); @@ -82,7 +90,7 @@ class ApiUndelete extends ApiBase { $info['title'] = $titleObj->getPrefixedText(); $info['revisions'] = intval( $retval[0] ); $info['fileversions'] = intval( $retval[1] ); - $info['reason'] = intval( $retval[2] ); + $info['reason'] = $retval[2]; $this->getResult()->addValue( null, $this->getModuleName(), $info ); } @@ -95,70 +103,51 @@ class ApiUndelete extends ApiBase { } public function getAllowedParams() { - return array( - 'title' => array( + return [ + 'title' => [ ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_REQUIRED => true - ), - 'token' => null, + ], 'reason' => '', - 'timestamps' => array( - ApiBase::PARAM_ISMULTI => true - ), - 'watchlist' => array( + 'tags' => [ + ApiBase::PARAM_TYPE => 'tags', + ApiBase::PARAM_ISMULTI => true, + ], + 'timestamps' => [ + ApiBase::PARAM_TYPE => 'timestamp', + ApiBase::PARAM_ISMULTI => true, + ], + 'fileids' => [ + ApiBase::PARAM_TYPE => 'integer', + ApiBase::PARAM_ISMULTI => true, + ], + 'watchlist' => [ ApiBase::PARAM_DFLT => 'preferences', - ApiBase::PARAM_TYPE => array( + ApiBase::PARAM_TYPE => [ 'watch', 'unwatch', 'preferences', 'nochange' - ), - ), - ); - } - - public function getParamDescription() { - return array( - 'title' => 'Title of the page you want to restore', - 'token' => 'An undelete token previously retrieved through list=deletedrevs', - 'reason' => 'Reason for restoring (optional)', - 'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.', - 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch', - ); - } - - 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' - ); - } - - public function getPossibleErrors() { - return array_merge( parent::getPossibleErrors(), array( - array( 'permdenied-undelete' ), - array( 'blockedtext' ), - array( 'invalidtitle', 'title' ), - array( 'cannotundelete' ), - ) ); + ], + ], + ]; } public function needsToken() { - return true; + return 'csrf'; } - public function getTokenSalt() { - return ''; - } - - protected function getExamples() { - return array( - 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page', - 'api.php?action=undelete&title=Main%20Page&token=123ABC×tamps=20070703220045|20070702194856' - ); + protected function getExamplesMessages() { + return [ + 'action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page' + => 'apihelp-undelete-example-page', + 'action=undelete&title=Main%20Page&token=123ABC' . + '×tamps=2007-07-03T22:00:45Z|2007-07-02T19:48:56Z' + => 'apihelp-undelete-example-revisions', + ]; } - public function getVersion() { - return __CLASS__ . ': $Id$'; + public function getHelpUrls() { + return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Undelete'; } }