MediaWiki  1.23.8
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  if ( !$this->getUser()->isAllowed( 'undelete' ) ) {
36  $this->dieUsageMsg( 'permdenied-undelete' );
37  }
38 
39  if ( $this->getUser()->isBlocked() ) {
40  $this->dieUsageMsg( 'blockedtext' );
41  }
42 
43  $titleObj = Title::newFromText( $params['title'] );
44  if ( !$titleObj || $titleObj->isExternal() ) {
45  $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
46  }
47 
48  // Convert timestamps
49  if ( !isset( $params['timestamps'] ) ) {
50  $params['timestamps'] = array();
51  }
52  if ( !is_array( $params['timestamps'] ) ) {
53  $params['timestamps'] = array( $params['timestamps'] );
54  }
55  foreach ( $params['timestamps'] as $i => $ts ) {
56  $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
57  }
58 
59  $pa = new PageArchive( $titleObj );
60  $retval = $pa->undelete(
61  ( isset( $params['timestamps'] ) ? $params['timestamps'] : array() ),
62  $params['reason'],
63  array(),
64  false,
65  $this->getUser()
66  );
67  if ( !is_array( $retval ) ) {
68  $this->dieUsageMsg( 'cannotundelete' );
69  }
70 
71  if ( $retval[1] ) {
72  wfRunHooks( 'FileUndeleteComplete',
73  array( $titleObj, array(), $this->getUser(), $params['reason'] ) );
74  }
75 
76  $this->setWatch( $params['watchlist'], $titleObj );
77 
78  $info['title'] = $titleObj->getPrefixedText();
79  $info['revisions'] = intval( $retval[0] );
80  $info['fileversions'] = intval( $retval[1] );
81  $info['reason'] = $retval[2];
82  $this->getResult()->addValue( null, $this->getModuleName(), $info );
83  }
84 
85  public function mustBePosted() {
86  return true;
87  }
88 
89  public function isWriteMode() {
90  return true;
91  }
92 
93  public function getAllowedParams() {
94  return array(
95  'title' => array(
96  ApiBase::PARAM_TYPE => 'string',
98  ),
99  'token' => array(
100  ApiBase::PARAM_TYPE => 'string',
102  ),
103  'reason' => '',
104  'timestamps' => array(
105  ApiBase::PARAM_TYPE => 'timestamp',
106  ApiBase::PARAM_ISMULTI => true,
107  ),
108  'watchlist' => array(
109  ApiBase::PARAM_DFLT => 'preferences',
111  'watch',
112  'unwatch',
113  'preferences',
114  'nochange'
115  ),
116  ),
117  );
118  }
119 
120  public function getParamDescription() {
121  return array(
122  'title' => 'Title of the page you want to restore',
123  'token' => 'An undelete token previously retrieved through list=deletedrevs',
124  'reason' => 'Reason for restoring',
125  'timestamps' => 'Timestamps of the revisions to restore. If not set, all ' .
126  'revisions will be restored.',
127  'watchlist' => 'Unconditionally add or remove the page from your ' .
128  'watchlist, use preferences or do not change watch',
129  );
130  }
131 
132  public function getResultProperties() {
133  return array(
134  '' => array(
135  'title' => 'string',
136  'revisions' => 'integer',
137  'filerevisions' => 'integer',
138  'reason' => 'string'
139  )
140  );
141  }
142 
143  public function getDescription() {
144  return array(
145  'Restore certain revisions of a deleted page. A list of deleted revisions ',
146  '(including timestamps) can be retrieved through list=deletedrevs.'
147  );
148  }
149 
150  public function getPossibleErrors() {
151  return array_merge( parent::getPossibleErrors(), array(
152  array( 'permdenied-undelete' ),
153  array( 'blockedtext' ),
154  array( 'invalidtitle', 'title' ),
155  array( 'cannotundelete' ),
156  ) );
157  }
158 
159  public function needsToken() {
160  return true;
161  }
162 
163  public function getTokenSalt() {
164  return '';
165  }
166 
167  public function getExamples() {
168  return array(
169  'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page',
170  'api.php?action=undelete&title=Main%20Page&token=123ABC&timestamps=20070703220045|20070702194856'
171  );
172  }
173 
174  public function getHelpUrls() {
175  return 'https://www.mediawiki.org/wiki/API:Undelete';
176  }
177 }
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:93
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:163
ApiBase\dieUsageMsg
dieUsageMsg( $error)
Output the error message related to a certain array.
Definition: ApiBase.php:1933
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2483
ApiBase\PARAM_TYPE
const PARAM_TYPE
Definition: ApiBase.php:50
ApiBase\getResult
getResult()
Get the result object.
Definition: ApiBase.php:205
ApiUndelete\getExamples
getExamples()
Returns usage examples for this module.
Definition: ApiUndelete.php:167
$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:120
ApiUndelete\needsToken
needsToken()
Returns whether this module requires a token to execute It is used to show possible errors in action=...
Definition: ApiUndelete.php:159
ApiUndelete\getDescription
getDescription()
Returns the description string for this module.
Definition: ApiUndelete.php:143
wfRunHooks
wfRunHooks( $event, array $args=array(), $deprecatedVersion=null)
Call hook functions defined in $wgHooks.
Definition: GlobalFunctions.php:4010
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:89
ApiBase\setWatch
setWatch( $watch, $titleObj, $userOption=null)
Set a watch (or unwatch) based the based on a watchlist parameter.
Definition: ApiBase.php:952
TS_MW
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
Definition: GlobalFunctions.php:2431
ApiBase\extractRequestParams
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition: ApiBase.php:687
ApiUndelete\getPossibleErrors
getPossibleErrors()
Returns a list of all possible errors returned by the module.
Definition: ApiUndelete.php:150
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:148
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:132
ApiUndelete\getHelpUrls
getHelpUrls()
Definition: ApiUndelete.php:174
ApiUndelete\mustBePosted
mustBePosted()
Indicates whether this module must be called with a POST request.
Definition: ApiUndelete.php:85