MediaWiki REL1_33
ApiUndelete.php
Go to the documentation of this file.
1<?php
26class ApiUndelete extends ApiBase {
27
28 public function execute() {
30
32
33 $user = $this->getUser();
34 $block = $user->getBlock();
35 if ( $block && $block->isSitewide() ) {
36 $this->dieBlocked( $user->getBlock() );
37 }
38
39 $titleObj = Title::newFromText( $params['title'] );
40 if ( !$titleObj || $titleObj->isExternal() ) {
41 $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ] );
42 }
43
44 if ( !$titleObj->userCan( 'undelete', $user, 'secure' ) ) {
45 $this->dieWithError( 'permdenied-undelete' );
46 }
47
48 // Check if user can add tags
49 if ( !is_null( $params['tags'] ) ) {
50 $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user );
51 if ( !$ableToTag->isOK() ) {
52 $this->dieStatus( $ableToTag );
53 }
54 }
55
56 // Convert timestamps
57 if ( !isset( $params['timestamps'] ) ) {
58 $params['timestamps'] = [];
59 }
60 if ( !is_array( $params['timestamps'] ) ) {
61 $params['timestamps'] = [ $params['timestamps'] ];
62 }
63 foreach ( $params['timestamps'] as $i => $ts ) {
64 $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
65 }
66
67 $pa = new PageArchive( $titleObj, $this->getConfig() );
68 $retval = $pa->undelete(
69 ( $params['timestamps'] ?? [] ),
70 $params['reason'],
71 $params['fileids'],
72 false,
73 $user,
74 $params['tags']
75 );
76 if ( !is_array( $retval ) ) {
77 $this->dieWithError( 'apierror-cantundelete' );
78 }
79
80 if ( $retval[1] ) {
81 Hooks::run( 'FileUndeleteComplete',
82 [ $titleObj, $params['fileids'], $this->getUser(), $params['reason'] ] );
83 }
84
85 $this->setWatch( $params['watchlist'], $titleObj );
86
87 $info['title'] = $titleObj->getPrefixedText();
88 $info['revisions'] = (int)$retval[0];
89 $info['fileversions'] = (int)$retval[1];
90 $info['reason'] = $retval[2];
91 $this->getResult()->addValue( null, $this->getModuleName(), $info );
92 }
93
94 public function mustBePosted() {
95 return true;
96 }
97
98 public function isWriteMode() {
99 return true;
100 }
101
102 public function getAllowedParams() {
103 return [
104 'title' => [
105 ApiBase::PARAM_TYPE => 'string',
107 ],
108 'reason' => '',
109 'tags' => [
110 ApiBase::PARAM_TYPE => 'tags',
112 ],
113 'timestamps' => [
114 ApiBase::PARAM_TYPE => 'timestamp',
116 ],
117 'fileids' => [
118 ApiBase::PARAM_TYPE => 'integer',
120 ],
121 'watchlist' => [
122 ApiBase::PARAM_DFLT => 'preferences',
124 'watch',
125 'unwatch',
126 'preferences',
127 'nochange'
128 ],
129 ],
130 ];
131 }
132
133 public function needsToken() {
134 return 'csrf';
135 }
136
137 protected function getExamplesMessages() {
138 return [
139 'action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page'
140 => 'apihelp-undelete-example-page',
141 'action=undelete&title=Main%20Page&token=123ABC' .
142 '&timestamps=2007-07-03T22:00:45Z|2007-07-02T19:48:56Z'
143 => 'apihelp-undelete-example-revisions',
144 ];
145 }
146
147 public function getHelpUrls() {
148 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Undelete';
149 }
150}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:37
const PARAM_REQUIRED
(boolean) Is the parameter required?
Definition ApiBase.php:111
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
Definition ApiBase.php:1990
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
Definition ApiBase.php:87
setWatch( $watch, $titleObj, $userOption=null)
Set a watch (or unwatch) based the based on a watchlist parameter.
Definition ApiBase.php:1726
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition ApiBase.php:48
getResult()
Get the result object.
Definition ApiBase.php:632
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:743
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:512
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
Definition ApiBase.php:2061
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
Definition ApiBase.php:1847
dieBlocked(Block $block)
Throw an ApiUsageException, which will (if uncaught) call the main module's error handler and die wit...
Definition ApiBase.php:2030
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
Definition ApiBase.php:51
needsToken()
Returns the token type this module requires in order to execute.
mustBePosted()
Indicates whether this module must be called with a POST request.
getHelpUrls()
Return links to more detailed help pages about the module.
getExamplesMessages()
Returns usage examples for this module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
isWriteMode()
Indicates whether this module requires write mode.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
static canAddTagsAccompanyingChange(array $tags, User $user=null)
Is it OK to allow the user to apply all the specified tags at the same time as they edit/make the cha...
Used to show archived pages and eventually restore them.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition hooks.txt:2004
$params