62 parent::__construct( $mainModule, $moduleName );
63 $this->repoGroup = $repoGroup;
64 $this->deletePageFactory = $deletePageFactory;
67 $this->watchlistExpiryEnabled = $this->
getConfig()->get( MainConfigNames::WatchlistExpiry );
68 $this->watchlistMaxDuration =
69 $this->
getConfig()->get( MainConfigNames::WatchlistExpiryMaxDuration );
70 $this->watchlistManager = $watchlistManager;
71 $this->userOptionsLookup = $userOptionsLookup;
87 $titleObj = $pageObj->getTitle();
89 if ( !$pageObj->exists() &&
91 !( $titleObj->getNamespace() ===
NS_FILE && self::canDeleteFile( $pageObj->getFile() ) )
96 $reason = $params[
'reason'];
99 $tags = $params[
'tags'] ?: [];
101 if ( $titleObj->getNamespace() ===
NS_FILE ) {
102 $status = $this->deleteFile(
108 $params[
'deletetalk']
111 $wasScheduled = $status->isOK() && $status->getValue() ===
false;
113 $status = $this->
delete( $pageObj, $reason, $tags, $params[
'deletetalk'] );
114 $wasScheduled = $status->isGood() && $status->getValue() ===
false;
117 if ( !$status->isOK() ) {
121 if ( $wasScheduled ) {
122 $this->
addWarning( [
'delete-scheduled', $titleObj->getPrefixedText() ] );
126 if ( $params[
'watch'] ) {
128 } elseif ( $params[
'unwatch'] ) {
131 $watch = $params[
'watchlist'];
135 $this->
setWatch( $watch, $titleObj, $user,
'watchdeletion', $watchlistExpiry );
138 'title' => $titleObj->getPrefixedText(),
144 if ( $wasScheduled ) {
145 $r[
'scheduled'] =
true;
148 $r[
'logid'] = $status->value;
165 private function delete(
WikiPage $page, &$reason, array $tags,
bool $deleteTalk ):
StatusValue {
169 if ( $reason ===
null ) {
171 if ( $reason ===
false ) {
173 return Status::newFatal(
'cannotdelete', $title->getPrefixedText() );
177 $deletePage = $this->deletePageFactory->newDeletePage( $page, $this->
getAuthority() );
179 $checkStatus = $deletePage->canProbablyDeleteAssociatedTalk();
180 if ( !$checkStatus->isGood() ) {
181 foreach ( $checkStatus->getErrors() as $error ) {
185 $deletePage->setDeleteAssociatedTalk(
true );
188 $deletionStatus = $deletePage->setTags( $tags )->deleteIfAllowed( $reason );
189 if ( $deletionStatus->isGood() ) {
190 $deletionStatus->value = $deletePage->deletionsWereScheduled()[DeletePage::PAGE_BASE]
192 : $deletePage->getSuccessfulDeletionsIDs()[DeletePage::PAGE_BASE];
194 return $deletionStatus;
214 private function deleteFile(
225 $file = $page->getFile();
226 if ( !self::canDeleteFile(
$file ) ) {
227 return $this->
delete( $page, $reason, $tags, $deleteTalk );
231 $this->checkTitleUserPermissions( $page->
getTitle(),
'delete' );
236 if ( !$tagStatus->isOK() ) {
237 $this->dieStatus( $tagStatus );
242 if ( !FileDeleteForm::isValidOldSpec( $oldimage ) ) {
243 return Status::newFatal(
'invalidoldimage' );
245 $oldfile = $this->repoGroup->getLocalRepo()->newFromArchiveName( $title, $oldimage );
246 if ( !$oldfile->exists() || !$oldfile->isLocal() || $oldfile->getRedirected() ) {
247 return Status::newFatal(
'nodeleteablefile' );
251 if ( $reason ===
null ) {
255 return FileDeleteForm::doDelete(
279 ParamValidator::PARAM_TYPE =>
'integer'
283 ParamValidator::PARAM_TYPE =>
'tags',
284 ParamValidator::PARAM_ISMULTI =>
true,
286 'deletetalk' =>
false,
288 ParamValidator::PARAM_DEFAULT =>
false,
289 ParamValidator::PARAM_DEPRECATED =>
true,
299 ParamValidator::PARAM_DEFAULT =>
false,
300 ParamValidator::PARAM_DEPRECATED =>
true,
311 $title = Title::newMainPage()->getPrefixedText();
312 $mp = rawurlencode( $title );
315 "action=delete&title={$mp}&token=123ABC"
316 =>
'apihelp-delete-example-simple',
317 "action=delete&title={$mp}&token=123ABC&reason=Preparing%20for%20move"
318 =>
'apihelp-delete-example-reason',
323 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Delete';
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.
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.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
getModuleName()
Get the name of the module being executed by this instance.
getTitleOrPageId( $params, $load=false)
Attempts to load a WikiPage object from a title or pageid parameter, if possible.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
API module that facilitates deleting pages.
__construct(ApiMain $mainModule, $moduleName, RepoGroup $repoGroup, WatchlistManager $watchlistManager, UserOptionsLookup $userOptionsLookup, DeletePageFactory $deletePageFactory)
execute()
Extracts the title and reason from the request parameters and invokes the local delete() function wit...
needsToken()
Returns the token type this module requires in order to execute.
getExamplesMessages()
Returns usage examples for this module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getHelpUrls()
Return links to more detailed help pages about the module.
static canDeleteFile(File $file)
isWriteMode()
Indicates whether this module requires write mode.
mustBePosted()
Indicates whether this module must be called with a POST request.
This is the main API class, used for both external and internal processing.
Implements some public methods and some protected utility functions which are required by multiple ch...
A class containing constants representing the names of configuration variables.
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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.