46 parent::__construct( $mainModule, $moduleName );
49 $this->watchlistExpiryEnabled = $this->
getConfig()->get(
'WatchlistExpiry' );
50 $this->watchlistMaxDuration = $this->
getConfig()->get(
'WatchlistExpiryMaxDuration' );
61 $block = $user->getBlock( Authority::READ_LATEST );
62 if ( $block && $block->isSitewide() ) {
66 $titleObj = Title::newFromText( $params[
'title'] );
67 if ( !$titleObj || $titleObj->isExternal() ) {
71 if ( !$this->
getAuthority()->authorizeWrite(
'undelete', $titleObj ) ) {
76 if ( $params[
'tags'] !==
null ) {
78 if ( !$ableToTag->isOK() ) {
84 if ( !isset( $params[
'timestamps'] ) ) {
85 $params[
'timestamps'] = [];
87 if ( !is_array( $params[
'timestamps'] ) ) {
88 $params[
'timestamps'] = [ $params[
'timestamps'] ];
90 foreach ( $params[
'timestamps'] as $i => $ts ) {
91 $params[
'timestamps'][$i] =
wfTimestamp( TS_MW, $ts );
95 $retval = $pa->undeleteAsUser(
96 ( $params[
'timestamps'] ?? [] ),
103 if ( !is_array( $retval ) ) {
109 $titleObj, $params[
'fileids'],
110 $this->
getUser(), $params[
'reason'] );
114 $this->
setWatch( $params[
'watchlist'], $titleObj, $user,
null, $watchlistExpiry );
117 'title' => $titleObj->getPrefixedText(),
118 'revisions' => (int)$retval[0],
119 'fileversions' => (
int)$retval[1],
120 'reason' => $retval[2]
161 'action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page'
162 =>
'apihelp-undelete-example-page',
163 'action=undelete&title=Main%20Page&token=123ABC' .
164 '×tamps=2007-07-03T22:00:45Z|2007-07-02T19:48:56Z'
165 =>
'apihelp-undelete-example-revisions',
170 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Undelete';
getExpiryFromParams(array $params)
Get formatted expiry from the given parameters, or null if no expiry was provided.
setWatch(string $watch, Title $title, User $user, ?string $userOption=null, ?string $expiry=null)
Set a watch (or unwatch) based the based on a watchlist parameter.
getWatchlistParams(array $watchOptions=[])
Get additional allow params specific to watchlisting.
WatchlistManager $watchlistManager
UserOptionsLookup $userOptionsLookup
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.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getModuleName()
Get the name of the module being executed by this instance.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
getHookRunner()
Get an ApiHookRunner for running core API hooks.
dieBlocked(Block $block)
Throw an ApiUsageException, which will (if uncaught) call the main module's error handler and die wit...
This is the main API class, used for both external and internal processing.
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.
__construct(ApiMain $mainModule, $moduleName, WatchlistManager $watchlistManager, UserOptionsLookup $userOptionsLookup)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
Used to show archived pages and eventually restore them.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...