40 private $undeletePageFactory;
43 private $wikiPageFactory;
61 parent::__construct( $mainModule, $moduleName );
64 $this->watchlistExpiryEnabled = $this->
getConfig()->get( MainConfigNames::WatchlistExpiry );
65 $this->watchlistMaxDuration =
66 $this->
getConfig()->get( MainConfigNames::WatchlistExpiryMaxDuration );
67 $this->watchlistManager = $watchlistManager;
68 $this->userOptionsLookup = $userOptionsLookup;
69 $this->undeletePageFactory = $undeletePageFactory;
70 $this->wikiPageFactory = $wikiPageFactory;
79 $block = $user->getBlock( Authority::READ_LATEST );
80 if ( $block && $block->isSitewide() ) {
84 $titleObj = Title::newFromText( $params[
'title'] );
85 if ( !$titleObj || $titleObj->isExternal() ) {
90 if ( !isset( $params[
'timestamps'] ) ) {
91 $params[
'timestamps'] = [];
93 if ( !is_array( $params[
'timestamps'] ) ) {
94 $params[
'timestamps'] = [ $params[
'timestamps'] ];
96 foreach ( $params[
'timestamps'] as $i => $ts ) {
97 $params[
'timestamps'][$i] =
wfTimestamp( TS_MW, $ts );
100 $undeletePage = $this->undeletePageFactory->newUndeletePage(
101 $this->wikiPageFactory->newFromTitle( $titleObj ),
102 $this->getAuthority()
104 ->setUndeleteOnlyTimestamps( $params[
'timestamps'] ?? [] )
105 ->setUndeleteOnlyFileVersions( $params[
'fileids'] ?: [] )
106 ->setTags( $params[
'tags'] ?: [] );
108 if ( $params[
'undeletetalk'] ) {
109 $undeletePage->setUndeleteAssociatedTalk(
true );
112 $status = $undeletePage->undeleteIfAllowed( $params[
'reason'] );
113 if ( $status->isOK() ) {
120 $restoredRevs = $status->getValue()[UndeletePage::REVISIONS_RESTORED];
121 $restoredFiles = $status->getValue()[UndeletePage::FILES_RESTORED];
123 if ( $restoredRevs === 0 && $restoredFiles === 0 ) {
128 if ( $restoredFiles ) {
130 $titleObj, $params[
'fileids'],
131 $this->
getUser(), $params[
'reason'] );
135 $this->
setWatch( $params[
'watchlist'], $titleObj, $user,
null, $watchlistExpiry );
138 'title' => $titleObj->getPrefixedText(),
139 'revisions' => $restoredRevs,
140 'fileversions' => $restoredFiles,
141 'reason' => $params[
'reason']
157 ParamValidator::PARAM_TYPE =>
'string',
158 ParamValidator::PARAM_REQUIRED =>
true
162 ParamValidator::PARAM_TYPE =>
'tags',
163 ParamValidator::PARAM_ISMULTI =>
true,
166 ParamValidator::PARAM_TYPE =>
'timestamp',
167 ParamValidator::PARAM_ISMULTI =>
true,
170 ParamValidator::PARAM_TYPE =>
'integer',
171 ParamValidator::PARAM_ISMULTI =>
true,
173 'undeletetalk' =>
false,
182 $title = Title::newMainPage()->getPrefixedText();
183 $mp = rawurlencode(
$title );
186 "action=undelete&title={$mp}&token=123ABC&reason=Restoring%20{$mp}"
187 =>
'apihelp-undelete-example-page',
188 "action=undelete&title={$mp}&token=123ABC" .
189 '×tamps=2007-07-03T22:00:45Z|2007-07-02T19:48:56Z'
190 =>
'apihelp-undelete-example-revisions',
195 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.
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.
addMessagesFromStatus(StatusValue $status, $types=[ 'warning', 'error'], array $filter=[])
Add warnings and/or errors from a Status.
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.
__construct(ApiMain $mainModule, $moduleName, WatchlistManager $watchlistManager, UserOptionsLookup $userOptionsLookup, UndeletePageFactory $undeletePageFactory, WikiPageFactory $wikiPageFactory)
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.
A class containing constants representing the names of configuration variables.
Backend logic for performing a page undelete action.
Service for creating WikiPage objects.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...
Service for page undelete actions.