41 private $undeletePageFactory;
44 private $wikiPageFactory;
62 parent::__construct( $mainModule, $moduleName );
65 $this->watchlistExpiryEnabled = $this->
getConfig()->get( MainConfigNames::WatchlistExpiry );
66 $this->watchlistMaxDuration =
67 $this->
getConfig()->get( MainConfigNames::WatchlistExpiryMaxDuration );
68 $this->watchlistManager = $watchlistManager;
69 $this->userOptionsLookup = $userOptionsLookup;
70 $this->undeletePageFactory = $undeletePageFactory;
71 $this->wikiPageFactory = $wikiPageFactory;
80 $block = $user->getBlock( Authority::READ_LATEST );
81 if ( $block && $block->isSitewide() ) {
85 $titleObj = Title::newFromText( $params[
'title'] );
86 if ( !$titleObj || $titleObj->isExternal() ) {
91 if ( !isset( $params[
'timestamps'] ) ) {
92 $params[
'timestamps'] = [];
94 if ( !is_array( $params[
'timestamps'] ) ) {
95 $params[
'timestamps'] = [ $params[
'timestamps'] ];
97 foreach ( $params[
'timestamps'] as $i => $ts ) {
98 $params[
'timestamps'][$i] =
wfTimestamp( TS_MW, $ts );
101 $undeletePage = $this->undeletePageFactory->newUndeletePage(
102 $this->wikiPageFactory->newFromTitle( $titleObj ),
103 $this->getAuthority()
105 ->setUndeleteOnlyTimestamps( $params[
'timestamps'] ?? [] )
106 ->setUndeleteOnlyFileVersions( $params[
'fileids'] ?: [] )
107 ->setTags( $params[
'tags'] ?: [] );
109 if ( $params[
'undeletetalk'] ) {
110 $undeletePage->setUndeleteAssociatedTalk(
true );
113 $status = $undeletePage->undeleteIfAllowed( $params[
'reason'] );
114 if ( $status->isOK() ) {
121 $restoredRevs = $status->getValue()[UndeletePage::REVISIONS_RESTORED];
122 $restoredFiles = $status->getValue()[UndeletePage::FILES_RESTORED];
124 if ( $restoredRevs === 0 && $restoredFiles === 0 ) {
129 if ( $restoredFiles ) {
131 $titleObj, $params[
'fileids'],
132 $this->
getUser(), $params[
'reason'] );
136 $this->
setWatch( $params[
'watchlist'], $titleObj, $user,
null, $watchlistExpiry );
139 'title' => $titleObj->getPrefixedText(),
140 'revisions' => $restoredRevs,
141 'fileversions' => $restoredFiles,
142 'reason' => $params[
'reason']
158 ParamValidator::PARAM_TYPE =>
'string',
159 ParamValidator::PARAM_REQUIRED =>
true
163 ParamValidator::PARAM_TYPE =>
'tags',
164 ParamValidator::PARAM_ISMULTI =>
true,
167 ParamValidator::PARAM_TYPE =>
'timestamp',
168 ParamValidator::PARAM_ISMULTI =>
true,
171 ParamValidator::PARAM_TYPE =>
'integer',
172 ParamValidator::PARAM_ISMULTI =>
true,
174 'undeletetalk' =>
false,
183 $title = Title::newMainPage()->getPrefixedText();
184 $mp = rawurlencode(
$title );
187 "action=undelete&title={$mp}&token=123ABC&reason=Restoring%20{$mp}"
188 =>
'apihelp-undelete-example-page',
189 "action=undelete&title={$mp}&token=123ABC" .
190 '×tamps=2007-07-03T22:00:45Z|2007-07-02T19:48:56Z'
191 =>
'apihelp-undelete-example-revisions',
196 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.