61 parent::__construct( $mainModule, $moduleName );
62 $this->repoGroup = $repoGroup;
63 $this->deletePageFactory = $deletePageFactory;
67 $this->watchlistMaxDuration =
69 $this->watchlistManager = $watchlistManager;
70 $this->userOptionsLookup = $userOptionsLookup;
86 $titleObj = $pageObj->getTitle();
88 if ( !$pageObj->exists() &&
90 !( $titleObj->getNamespace() ===
NS_FILE && self::canDeleteFile( $pageObj->getFile() ) )
100 if ( $titleObj->getNamespace() ===
NS_FILE ) {
101 $status = $this->deleteFile(
110 $wasScheduled = $status->isOK() && $status->getValue() ===
false;
112 $status = $this->
delete( $pageObj, $reason, $tags,
$params[
'deletetalk'] );
113 $wasScheduled = $status->isGood() && $status->getValue() ===
false;
116 if ( !$status->isOK() ) {
120 if ( $wasScheduled ) {
121 $this->
addWarning( [
'delete-scheduled', $titleObj->getPrefixedText() ] );
127 } elseif (
$params[
'unwatch'] ) {
134 $this->
setWatch( $watch, $titleObj, $user,
'watchdeletion', $watchlistExpiry );
137 'title' => $titleObj->getPrefixedText(),
143 if ( $wasScheduled ) {
144 $r[
'scheduled'] =
true;
147 $r[
'logid'] = $status->value;
164 private function delete(
WikiPage $page, &$reason, array $tags,
bool $deleteTalk ):
StatusValue {
168 if ( $reason ===
null ) {
170 if ( $reason ===
false ) {
172 return Status::newFatal(
'cannotdelete', $title->getPrefixedText() );
176 $deletePage = $this->deletePageFactory->newDeletePage( $page, $this->
getAuthority() );
178 $checkStatus = $deletePage->canProbablyDeleteAssociatedTalk();
179 if ( !$checkStatus->isGood() ) {
180 foreach ( $checkStatus->getMessages() as $msg ) {
184 $deletePage->setDeleteAssociatedTalk(
true );
187 $deletionStatus = $deletePage->setTags( $tags )->deleteIfAllowed( $reason );
188 if ( $deletionStatus->isGood() ) {
189 $deletionStatus->value = $deletePage->deletionsWereScheduled()[DeletePage::PAGE_BASE]
191 : $deletePage->getSuccessfulDeletionsIDs()[DeletePage::PAGE_BASE];
193 return $deletionStatus;
213 private function deleteFile(
224 $file = $page->getFile();
225 if ( !self::canDeleteFile( $file ) ) {
226 return $this->
delete( $page, $reason, $tags, $deleteTalk );
230 $this->checkTitleUserPermissions( $page->
getTitle(),
'delete' );
235 if ( !$tagStatus->isOK() ) {
236 $this->dieStatus( $tagStatus );
241 if ( !FileDeleteForm::isValidOldSpec( $oldimage ) ) {
242 return Status::newFatal(
'invalidoldimage' );
244 $oldfile = $this->repoGroup->getLocalRepo()->newFromArchiveName( $title, $oldimage );
245 if ( !$oldfile->exists() || !$oldfile->isLocal() || $oldfile->getRedirected() ) {
246 return Status::newFatal(
'nodeleteablefile' );
250 return FileDeleteForm::doDelete(
275 ParamValidator::PARAM_TYPE =>
'integer'
279 ParamValidator::PARAM_TYPE =>
'tags',
280 ParamValidator::PARAM_ISMULTI =>
true,
282 'deletetalk' =>
false,
284 ParamValidator::PARAM_DEFAULT =>
false,
285 ParamValidator::PARAM_DEPRECATED =>
true,
295 ParamValidator::PARAM_DEFAULT =>
false,
296 ParamValidator::PARAM_DEPRECATED =>
true,
307 $title = Title::newMainPage()->getPrefixedText();
308 $mp = rawurlencode( $title );
311 "action=delete&title={$mp}&token=123ABC"
312 =>
'apihelp-delete-example-simple',
313 "action=delete&title={$mp}&token=123ABC&reason=Preparing%20for%20move"
314 =>
'apihelp-delete-example-reason',
319 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Delete';
324class_alias( ApiDelete::class,
'ApiDelete' );
array $params
The job parameters.
Implements some public methods and some protected utility functions which are required by multiple ch...
isLocal()
Returns true if the file comes from the local file repository.
exists()
Returns true if file exists in the repository.
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.
Prioritized list of file repositories.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Base representation for an editable wiki page.
getAutoDeleteReason(&$hasHistory=false)
Auto-generates a deletion reason.
getTitle()
Get the title object of the article.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...
Service for page delete actions.