MediaWiki  1.23.16
ApiUndelete.php
Go to the documentation of this file.
1 <?php
30 class ApiUndelete extends ApiBase {
31 
32  public function execute() {
33  $params = $this->extractRequestParams();
34 
35  $user = $this->getUser();
36  if ( $user->isBlocked() ) {
37  $this->dieUsageMsg( 'blockedtext' );
38  }
39 
40  $titleObj = Title::newFromText( $params['title'] );
41  if ( !$titleObj || $titleObj->isExternal() ) {
42  $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
43  }
44 
45  if ( !$titleObj->userCan( 'undelete', $user, true ) ) {
46  $this->dieUsageMsg( 'permdenied-undelete' );
47  }
48 
49  // Convert timestamps
50  if ( !isset( $params['timestamps'] ) ) {
51  $params['timestamps'] = array();
52  }
53  if ( !is_array( $params['timestamps'] ) ) {
54  $params['timestamps'] = array( $params['timestamps'] );
55  }
56  foreach ( $params['timestamps'] as $i => $ts ) {
57  $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
58  }
59 
60  $pa = new PageArchive( $titleObj );
61  $retval = $pa->undelete(
62  ( isset( $params['timestamps'] ) ? $params['timestamps'] : array() ),
63  $params['reason'],
64  array(),
65  false,
66  $user
67  );
68  if ( !is_array( $retval ) ) {
69  $this->dieUsageMsg( 'cannotundelete' );
70  }
71 
72  if ( $retval[1] ) {
73  wfRunHooks( 'FileUndeleteComplete',
74  array( $titleObj, array(), $user, $params['reason'] ) );
75  }
76 
77  $this->setWatch( $params['watchlist'], $titleObj );
78 
79  $info['title'] = $titleObj->getPrefixedText();
80  $info['revisions'] = intval( $retval[0] );
81  $info['fileversions'] = intval( $retval[1] );
82  $info['reason'] = $retval[2];
83  $this->getResult()->addValue( null, $this->getModuleName(), $info );
84  }
85 
86  public function mustBePosted() {
87  return true;
88  }
89 
90  public function isWriteMode() {
91  return true;
92  }
93 
94  public function getAllowedParams() {
95  return array(
96  'title' => array(
97  ApiBase::PARAM_TYPE => 'string',
99  ),
100  'token' => array(
101  ApiBase::PARAM_TYPE => 'string',
103  ),
104  'reason' => '',
105  'timestamps' => array(
106  ApiBase::PARAM_TYPE => 'timestamp',
107  ApiBase::PARAM_ISMULTI => true,
108  ),
109  'watchlist' => array(
110  ApiBase::PARAM_DFLT => 'preferences',
112  'watch',
113  'unwatch',
114  'preferences',
115  'nochange'
116  ),
117  ),
118  );
119  }
120 
121  public function getParamDescription() {
122  return array(
123  'title' => 'Title of the page you want to restore',
124  'token' => 'An undelete token previously retrieved through list=deletedrevs',
125  'reason' => 'Reason for restoring',
126  'timestamps' => 'Timestamps of the revisions to restore. If not set, all ' .
127  'revisions will be restored.',
128  'watchlist' => 'Unconditionally add or remove the page from your ' .
129  'watchlist, use preferences or do not change watch',
130  );
131  }
132 
133  public function getResultProperties() {
134  return array(
135  '' => array(
136  'title' => 'string',
137  'revisions' => 'integer',
138  'filerevisions' => 'integer',
139  'reason' => 'string'
140  )
141  );
142  }
143 
144  public function getDescription() {
145  return array(
146  'Restore certain revisions of a deleted page. A list of deleted revisions ',
147  '(including timestamps) can be retrieved through list=deletedrevs.'
148  );
149  }
150 
151  public function getPossibleErrors() {
152  return array_merge( parent::getPossibleErrors(), array(
153  array( 'permdenied-undelete' ),
154  array( 'blockedtext' ),
155  array( 'invalidtitle', 'title' ),
156  array( 'cannotundelete' ),
157  ) );
158  }
159 
160  public function needsToken() {
161  return true;
162  }
163 
164  public function getTokenSalt() {
165  return '';
166  }
167 
168  public function getExamples() {
169  return array(
170  'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page',
171  'api.php?action=undelete&title=Main%20Page&token=123ABC&timestamps=20070703220045|20070702194856'
172  );
173  }
174 
175  public function getHelpUrls() {
176  return 'https://www.mediawiki.org/wiki/API:Undelete';
177  }
178 }
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:189
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ApiBase\PARAM_REQUIRED
const PARAM_REQUIRED
Definition: ApiBase.php:62
ApiUndelete\getAllowedParams
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
Definition: ApiUndelete.php:94
PageArchive
Used to show archived pages and eventually restore them.
Definition: SpecialUndelete.php:29
ApiUndelete\getTokenSalt
getTokenSalt()
Returns the token salt if there is one, '' if the module doesn't require a salt, else false if the mo...
Definition: ApiUndelete.php:164
ApiBase\dieUsageMsg
dieUsageMsg( $error)
Output the error message related to a certain array.
Definition: ApiBase.php:1999
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2530
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:50
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:212
ApiUndelete\getExamples
getExamples()
Returns usage examples for this module.
Definition: ApiUndelete.php:168
$params
$params
Definition: styleTest.css.php:40
ContextSource\getUser
getUser()
Get the User object.
Definition: ContextSource.php:132
ApiBase
This abstract class implements many basic API functions, and is the base of all API classes.
Definition: ApiBase.php:42
ApiUndelete\getParamDescription
getParamDescription()
Returns an array of parameter descriptions.
Definition: ApiUndelete.php:121
ApiUndelete\needsToken
needsToken()
Returns whether this module requires a token to execute It is used to show possible errors in action=...
Definition: ApiUndelete.php:160
ApiUndelete\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiUndelete.php:144
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4066
ApiUndelete\execute
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Definition: ApiUndelete.php:32
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ApiUndelete
Definition: ApiUndelete.php:30
ApiUndelete\isWriteMode
isWriteMode()
Indicates whether this module requires write mode.
Definition: ApiUndelete.php:90
ApiBase\setWatch
setWatch( $watch, $titleObj, $userOption=null)
Set a watch (or unwatch) based the based on a watchlist parameter.
Definition: ApiBase.php:1014
TS_MW
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
Definition: GlobalFunctions.php:2478
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:715
$user
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 account $user
Definition: hooks.txt:237
ApiUndelete\getPossibleErrors
getPossibleErrors()
Returns a list of all possible errors returned by the module.
Definition: ApiUndelete.php:151
ApiBase\PARAM_DFLT
const PARAM_DFLT
Definition: ApiBase.php:46
as
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
Definition: distributors.txt:9
ApiBase\getModuleName
getModuleName()
Get the name of the module being executed by this instance.
Definition: ApiBase.php:155
ApiBase\PARAM_ISMULTI
const PARAM_ISMULTI
Definition: ApiBase.php:48
$retval
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 account incomplete not yet checked for validity & $retval
Definition: hooks.txt:237
ApiUndelete\getResultProperties
getResultProperties()
Returns possible properties in the result, grouped by the value of the prop parameter that shows them...
Definition: ApiUndelete.php:133
ApiUndelete\getHelpUrls
getHelpUrls()
Definition: ApiUndelete.php:175
ApiUndelete\mustBePosted
mustBePosted()
Indicates whether this module must be called with a POST request.
Definition: ApiUndelete.php:86