46 private $deletePageFactory;
64 parent::__construct( $mainModule, $moduleName );
65 $this->repoGroup = $repoGroup;
66 $this->deletePageFactory = $deletePageFactory;
69 $this->watchlistExpiryEnabled = $this->
getConfig()->get( MainConfigNames::WatchlistExpiry );
70 $this->watchlistMaxDuration =
71 $this->
getConfig()->get( MainConfigNames::WatchlistExpiryMaxDuration );
72 $this->watchlistManager = $watchlistManager;
73 $this->userOptionsLookup = $userOptionsLookup;
89 $titleObj = $pageObj->getTitle();
91 if ( !$pageObj->exists() &&
93 !( $titleObj->getNamespace() ===
NS_FILE && self::canDeleteFile( $pageObj->getFile() ) )
98 $reason = $params[
'reason'];
101 $tags = $params[
'tags'] ?: [];
103 if ( $titleObj->getNamespace() ===
NS_FILE ) {
104 $status = $this->deleteFile(
110 $params[
'deletetalk']
113 $wasScheduled = $status->isOK() && $status->getValue() ===
false;
115 $status = $this->
delete( $pageObj, $reason, $tags, $params[
'deletetalk'] );
116 $wasScheduled = $status->isGood() && $status->getValue() ===
false;
119 if ( !$status->isOK() ) {
123 if ( $wasScheduled ) {
124 $this->
addWarning( [
'delete-scheduled', $titleObj->getPrefixedText() ] );
128 if ( $params[
'watch'] ) {
130 } elseif ( $params[
'unwatch'] ) {
133 $watch = $params[
'watchlist'];
137 $this->
setWatch( $watch, $titleObj, $user,
'watchdeletion', $watchlistExpiry );
140 'title' => $titleObj->getPrefixedText(),
146 if ( $wasScheduled ) {
147 $r[
'scheduled'] =
true;
150 $r[
'logid'] = $status->value;
167 private function delete(
WikiPage $page, &$reason, array $tags,
bool $deleteTalk ):
StatusValue {
171 if ( $reason ===
null ) {
173 if ( $reason ===
false ) {
175 return Status::newFatal(
'cannotdelete',
$title->getPrefixedText() );
179 $deletePage = $this->deletePageFactory->newDeletePage( $page, $this->
getAuthority() );
181 $checkStatus = $deletePage->canProbablyDeleteAssociatedTalk();
182 if ( !$checkStatus->isGood() ) {
183 foreach ( $checkStatus->getErrors() as $error ) {
187 $deletePage->setDeleteAssociatedTalk(
true );
190 $deletionStatus = $deletePage->setTags( $tags )->deleteIfAllowed( $reason );
191 if ( $deletionStatus->isGood() ) {
192 $deletionStatus->value = $deletePage->deletionsWereScheduled()[DeletePage::PAGE_BASE]
194 : $deletePage->getSuccessfulDeletionsIDs()[DeletePage::PAGE_BASE];
196 return $deletionStatus;
216 private function deleteFile(
227 $file = $page->getFile();
228 if ( !self::canDeleteFile(
$file ) ) {
229 return $this->
delete( $page, $reason, $tags, $deleteTalk );
233 $this->checkTitleUserPermissions( $page->
getTitle(),
'delete' );
238 if ( !$tagStatus->isOK() ) {
239 $this->dieStatus( $tagStatus );
244 if ( !FileDeleteForm::isValidOldSpec( $oldimage ) ) {
247 $oldfile = $this->repoGroup->getLocalRepo()->newFromArchiveName(
$title, $oldimage );
248 if ( !$oldfile->exists() || !$oldfile->isLocal() || $oldfile->getRedirected() ) {
253 if ( $reason ===
null ) {
257 return FileDeleteForm::doDelete(
281 ParamValidator::PARAM_TYPE =>
'integer'
285 ParamValidator::PARAM_TYPE =>
'tags',
286 ParamValidator::PARAM_ISMULTI =>
true,
288 'deletetalk' =>
false,
290 ParamValidator::PARAM_DEFAULT =>
false,
291 ParamValidator::PARAM_DEPRECATED =>
true,
301 ParamValidator::PARAM_DEFAULT =>
false,
302 ParamValidator::PARAM_DEPRECATED =>
true,
313 $title = Title::newMainPage()->getPrefixedText();
314 $mp = rawurlencode(
$title );
317 "action=delete&title={$mp}&token=123ABC"
318 =>
'apihelp-delete-example-simple',
319 "action=delete&title={$mp}&token=123ABC&reason=Preparing%20for%20move"
320 =>
'apihelp-delete-example-reason',
325 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)
Get a WikiPage object from a title or pageid param, 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.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
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.