MediaWiki REL1_31
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 if ( $user->isBlocked() ) {
35 $this->dieBlocked( $user->getBlock() );
36 }
37
38 $titleObj = Title::newFromText( $params['title'] );
39 if ( !$titleObj || $titleObj->isExternal() ) {
40 $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ] );
41 }
42
43 if ( !$titleObj->userCan( 'undelete', $user, 'secure' ) ) {
44 $this->dieWithError( 'permdenied-undelete' );
45 }
46
47 // Check if user can add tags
48 if ( !is_null( $params['tags'] ) ) {
50 if ( !$ableToTag->isOK() ) {
51 $this->dieStatus( $ableToTag );
52 }
53 }
54
55 // Convert timestamps
56 if ( !isset( $params['timestamps'] ) ) {
57 $params['timestamps'] = [];
58 }
59 if ( !is_array( $params['timestamps'] ) ) {
60 $params['timestamps'] = [ $params['timestamps'] ];
61 }
62 foreach ( $params['timestamps'] as $i => $ts ) {
63 $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
64 }
65
66 $pa = new PageArchive( $titleObj, $this->getConfig() );
67 $retval = $pa->undelete(
68 ( isset( $params['timestamps'] ) ? $params['timestamps'] : [] ),
69 $params['reason'],
70 $params['fileids'],
71 false,
72 $user,
73 $params['tags']
74 );
75 if ( !is_array( $retval ) ) {
76 $this->dieWithError( 'apierror-cantundelete' );
77 }
78
79 if ( $retval[1] ) {
80 Hooks::run( 'FileUndeleteComplete',
81 [ $titleObj, $params['fileids'], $this->getUser(), $params['reason'] ] );
82 }
83
84 $this->setWatch( $params['watchlist'], $titleObj );
85
86 $info['title'] = $titleObj->getPrefixedText();
87 $info['revisions'] = intval( $retval[0] );
88 $info['fileversions'] = intval( $retval[1] );
89 $info['reason'] = $retval[2];
90 $this->getResult()->addValue( null, $this->getModuleName(), $info );
91 }
92
93 public function mustBePosted() {
94 return true;
95 }
96
97 public function isWriteMode() {
98 return true;
99 }
100
101 public function getAllowedParams() {
102 return [
103 'title' => [
104 ApiBase::PARAM_TYPE => 'string',
106 ],
107 'reason' => '',
108 'tags' => [
109 ApiBase::PARAM_TYPE => 'tags',
111 ],
112 'timestamps' => [
113 ApiBase::PARAM_TYPE => 'timestamp',
115 ],
116 'fileids' => [
117 ApiBase::PARAM_TYPE => 'integer',
119 ],
120 'watchlist' => [
121 ApiBase::PARAM_DFLT => 'preferences',
123 'watch',
124 'unwatch',
125 'preferences',
126 'nochange'
127 ],
128 ],
129 ];
130 }
131
132 public function needsToken() {
133 return 'csrf';
134 }
135
136 protected function getExamplesMessages() {
137 return [
138 'action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page'
139 => 'apihelp-undelete-example-page',
140 'action=undelete&title=Main%20Page&token=123ABC' .
141 '&timestamps=2007-07-03T22:00:45Z|2007-07-02T19:48:56Z'
142 => 'apihelp-undelete-example-revisions',
143 ];
144 }
145
146 public function getHelpUrls() {
147 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Undelete';
148 }
149}
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:1895
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:1656
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
Definition ApiBase.php:48
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:749
getResult()
Get the result object.
Definition ApiBase.php:641
getModuleName()
Get the name of the module being executed by this instance.
Definition ApiBase.php:521
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
Definition ApiBase.php:1960
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
Definition ApiBase.php:2643
dieBlocked(Block $block)
Throw an ApiUsageException, which will (if uncaught) call the main module's error handler and die wit...
Definition ApiBase.php:1935
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.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
Definition hooks.txt:266
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:2006
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition hooks.txt:247
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
$params