12use MediaWiki\Page\UndeletePage;
21use Wikimedia\Timestamp\TimestampFormat as TS;
42 parent::__construct( $mainModule, $moduleName );
46 $this->watchlistMaxDuration =
48 $this->watchlistManager = $watchlistManager;
49 $this->watchedItemStore = $watchedItemStore;
50 $this->userOptionsLookup = $userOptionsLookup;
51 $this->undeletePageFactory = $undeletePageFactory;
52 $this->wikiPageFactory = $wikiPageFactory;
61 $block = $user->getBlock( IDBAccessObject::READ_LATEST );
62 if ( $block && $block->isSitewide() ) {
66 $titleObj = Title::newFromText( $params[
'title'] );
67 if ( !$titleObj || $titleObj->isExternal() ) {
70 if ( !$titleObj->canExist() ) {
75 if ( !isset( $params[
'timestamps'] ) ) {
76 $params[
'timestamps'] = [];
78 if ( !is_array( $params[
'timestamps'] ) ) {
79 $params[
'timestamps'] = [ $params[
'timestamps'] ];
81 foreach ( $params[
'timestamps'] as $i => $ts ) {
82 $params[
'timestamps'][$i] =
wfTimestamp( TS::MW, $ts );
85 $undeletePage = $this->undeletePageFactory->newUndeletePage(
86 $this->wikiPageFactory->newFromTitle( $titleObj ),
89 ->setUndeleteOnlyTimestamps( $params[
'timestamps'] ?? [] )
90 ->setUndeleteOnlyFileVersions( $params[
'fileids'] ?: [] )
91 ->setTags( $params[
'tags'] ?: [] );
93 if ( $params[
'undeletetalk'] ) {
94 $undeletePage->setUndeleteAssociatedTalk(
true );
97 $status = $undeletePage->undeleteIfAllowed( $params[
'reason'] );
98 if ( $status->isOK() ) {
105 $restoredRevs = $status->getValue()[UndeletePage::REVISIONS_RESTORED];
106 $restoredFiles = $status->getValue()[UndeletePage::FILES_RESTORED];
108 if ( $restoredRevs === 0 && $restoredFiles === 0 ) {
113 if ( $restoredFiles ) {
115 $titleObj, $params[
'fileids'],
116 $this->
getUser(), $params[
'reason'] );
120 $this->
setWatch( $params[
'watchlist'], $titleObj, $user,
null, $watchlistExpiry );
123 'title' => $titleObj->getPrefixedText(),
124 'revisions' => $restoredRevs,
125 'fileversions' => $restoredFiles,
126 'reason' => $params[
'reason']
145 ParamValidator::PARAM_TYPE =>
'string',
146 ParamValidator::PARAM_REQUIRED => true
150 ParamValidator::PARAM_TYPE =>
'tags',
151 ParamValidator::PARAM_ISMULTI =>
true,
154 ParamValidator::PARAM_TYPE =>
'timestamp',
155 ParamValidator::PARAM_ISMULTI =>
true,
158 ParamValidator::PARAM_TYPE =>
'integer',
159 ParamValidator::PARAM_ISMULTI =>
true,
161 'undeletetalk' =>
false,
172 $title = Title::newMainPage()->getPrefixedText();
173 $mp = rawurlencode( $title );
176 "action=undelete&title={$mp}&token=123ABC&reason=Restoring%20{$mp}"
177 =>
'apihelp-undelete-example-page',
178 "action=undelete&title={$mp}&token=123ABC" .
179 '×tamps=2007-07-03T22:00:45Z|2007-07-02T19:48:56Z'
180 =>
'apihelp-undelete-example-revisions',
186 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Undelete';
191class_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.