12use MediaWiki\Page\UndeletePage;
21use Wikimedia\Timestamp\TimestampFormat as TS;
39 parent::__construct( $mainModule, $moduleName );
43 $this->watchlistMaxDuration =
45 $this->watchlistManager = $watchlistManager;
46 $this->watchedItemStore = $watchedItemStore;
47 $this->userOptionsLookup = $userOptionsLookup;
56 $block = $user->getBlock( IDBAccessObject::READ_LATEST );
57 if ( $block && $block->isSitewide() ) {
61 $titleObj = Title::newFromText( $params[
'title'] );
62 if ( !$titleObj || $titleObj->isExternal() ) {
65 if ( !$titleObj->canExist() ) {
70 if ( !isset( $params[
'timestamps'] ) ) {
71 $params[
'timestamps'] = [];
73 if ( !is_array( $params[
'timestamps'] ) ) {
74 $params[
'timestamps'] = [ $params[
'timestamps'] ];
76 foreach ( $params[
'timestamps'] as $i => $ts ) {
77 $params[
'timestamps'][$i] =
wfTimestamp( TS::MW, $ts );
80 $undeletePage = $this->undeletePageFactory->newUndeletePage(
81 $this->wikiPageFactory->newFromTitle( $titleObj ),
84 ->setUndeleteOnlyTimestamps( $params[
'timestamps'] ?? [] )
85 ->setUndeleteOnlyFileVersions( $params[
'fileids'] ?: [] )
86 ->setTags( $params[
'tags'] ?: [] );
88 if ( $params[
'undeletetalk'] ) {
89 $undeletePage->setUndeleteAssociatedTalk(
true );
92 $status = $undeletePage->undeleteIfAllowed( $params[
'reason'] );
93 if ( $status->isOK() ) {
100 $restoredRevs = $status->getValue()[UndeletePage::REVISIONS_RESTORED];
101 $restoredFiles = $status->getValue()[UndeletePage::FILES_RESTORED];
103 if ( $restoredRevs === 0 && $restoredFiles === 0 ) {
108 if ( $restoredFiles ) {
110 $titleObj, $params[
'fileids'],
111 $this->
getUser(), $params[
'reason'] );
115 $this->
setWatch( $params[
'watchlist'], $titleObj, $user,
null, $watchlistExpiry );
118 'title' => $titleObj->getPrefixedText(),
119 'revisions' => $restoredRevs,
120 'fileversions' => $restoredFiles,
121 'reason' => $params[
'reason']
140 ParamValidator::PARAM_TYPE =>
'string',
141 ParamValidator::PARAM_REQUIRED => true
145 ParamValidator::PARAM_TYPE =>
'tags',
146 ParamValidator::PARAM_ISMULTI =>
true,
149 ParamValidator::PARAM_TYPE =>
'timestamp',
150 ParamValidator::PARAM_ISMULTI =>
true,
153 ParamValidator::PARAM_TYPE =>
'integer',
154 ParamValidator::PARAM_ISMULTI =>
true,
156 'undeletetalk' =>
false,
167 $title = Title::newMainPage()->getPrefixedText();
168 $mp = rawurlencode( $title );
171 "action=undelete&title={$mp}&token=123ABC&reason=Restoring%20{$mp}"
172 =>
'apihelp-undelete-example-page',
173 "action=undelete&title={$mp}&token=123ABC" .
174 '×tamps=2007-07-03T22:00:45Z|2007-07-02T19:48:56Z'
175 =>
'apihelp-undelete-example-revisions',
181 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Undelete';
186class_alias( ApiUndelete::class,
'ApiUndelete' );
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
wfTimestamp( $outputtype=TS::UNIX, $ts=0)
Get a timestamp string in one of various formats.
This is the main API class, used for both external and internal processing.
A class containing constants representing the names of configuration variables.
const WatchlistExpiry
Name constant for the WatchlistExpiry setting, for use with Config::get()
const WatchlistExpiryMaxDuration
Name constant for the WatchlistExpiryMaxDuration setting, for use with Config::get()
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.