46 parent::__construct( $mainModule, $moduleName );
50 $this->watchlistMaxDuration =
52 $this->watchlistManager = $watchlistManager;
53 $this->watchedItemStore = $watchedItemStore;
54 $this->userOptionsLookup = $userOptionsLookup;
70 $titleObj = $pageObj->getTitle();
72 if ( !$pageObj->exists() &&
74 !( $titleObj->getNamespace() ===
NS_FILE && self::canDeleteFile( $pageObj->getFile() ) )
79 $reason = $params[
'reason'];
82 $tags = $params[
'tags'] ?: [];
84 if ( $titleObj->getNamespace() ===
NS_FILE ) {
85 $status = $this->deleteFile(
94 $wasScheduled = $status->isOK() && $status->getValue() ===
false;
96 $status = $this->
delete( $pageObj, $reason, $tags, $params[
'deletetalk'] );
97 $wasScheduled = $status->isGood() && $status->getValue() ===
false;
100 if ( !$status->isOK() ) {
104 if ( $wasScheduled ) {
105 $this->
addWarning( [
'delete-scheduled', $titleObj->getPrefixedText() ] );
109 if ( $params[
'watch'] ) {
111 } elseif ( $params[
'unwatch'] ) {
114 $watch = $params[
'watchlist'];
118 $this->
setWatch( $watch, $titleObj, $user,
'watchdeletion', $watchlistExpiry );
121 'title' => $titleObj->getPrefixedText(),
127 if ( $wasScheduled ) {
128 $r[
'scheduled'] =
true;
131 $r[
'logid'] = $status->value;
148 private function delete(
WikiPage $page, &$reason, array $tags,
bool $deleteTalk ):
StatusValue {
152 if ( $reason ===
null ) {
154 if ( $reason ===
false ) {
156 return Status::newFatal(
'cannotdelete', $title->getPrefixedText() );
160 $deletePage = $this->deletePageFactory->newDeletePage( $page, $this->
getAuthority() );
162 $checkStatus = $deletePage->canProbablyDeleteAssociatedTalk();
163 if ( !$checkStatus->isGood() ) {
164 foreach ( $checkStatus->getMessages() as $msg ) {
168 $deletePage->setDeleteAssociatedTalk(
true );
171 $deletionStatus = $deletePage->setTags( $tags )->deleteIfAllowed( $reason );
172 if ( $deletionStatus->isGood() ) {
174 $deletionStatus->value = $deletePage->deletionsWereScheduled()[DeletePage::PAGE_BASE]
176 : $deletePage->getSuccessfulDeletionsIDs()[DeletePage::PAGE_BASE];
178 return $deletionStatus;
198 private function deleteFile(
209 $file = $page->getFile();
210 if ( !self::canDeleteFile( $file ) ) {
211 return $this->
delete( $page, $reason, $tags, $deleteTalk );
215 $this->checkTitleUserPermissions( $page->
getTitle(),
'delete' );
219 $tagStatus = ChangeTags::canAddTagsAccompanyingChange( $tags, $this->
getAuthority() );
220 if ( !$tagStatus->isOK() ) {
221 $this->dieStatus( $tagStatus );
226 if ( !FileDeleteForm::isValidOldSpec( $oldimage ) ) {
227 return Status::newFatal(
'invalidoldimage' );
229 $oldfile = $this->repoGroup->getLocalRepo()->newFromArchiveName( $title, $oldimage );
230 if ( !$oldfile->exists() || !$oldfile->isLocal() || $oldfile->getRedirected() ) {
231 return Status::newFatal(
'nodeleteablefile' );
235 return FileDeleteForm::doDelete(
263 ParamValidator::PARAM_TYPE =>
'integer'
267 ParamValidator::PARAM_TYPE =>
'tags',
268 ParamValidator::PARAM_ISMULTI =>
true,
270 'deletetalk' =>
false,
272 ParamValidator::PARAM_DEFAULT =>
false,
273 ParamValidator::PARAM_DEPRECATED =>
true,
283 ParamValidator::PARAM_DEFAULT =>
false,
284 ParamValidator::PARAM_DEPRECATED =>
true,
297 $title = Title::newMainPage()->getPrefixedText();
298 $mp = rawurlencode( $title );
301 "action=delete&title={$mp}&token=123ABC"
302 =>
'apihelp-delete-example-simple',
303 "action=delete&title={$mp}&token=123ABC&reason=Preparing%20for%20move"
304 =>
'apihelp-delete-example-reason',
310 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Delete';
315class_alias( ApiDelete::class,
'ApiDelete' );
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()
Backend logic for performing a page delete action.
File deletion user interface.
Base representation for an editable wiki page.
getTitle()
Get the title object of the article.
getAutoDeleteReason(&$hasHistory=false)
Auto-generates a deletion reason.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...
Service for page delete actions.