54 parent::__construct( $mainModule, $moduleName );
58 $this->watchlistExpiryEnabled = $this->
getConfig()->get(
'WatchlistExpiry' );
59 $this->watchlistMaxDuration = $this->
getConfig()->get(
'WatchlistExpiryMaxDuration' );
77 $titleObj = $pageObj->getTitle();
79 if ( !$pageObj->exists() &&
81 !( $titleObj->getNamespace() ===
NS_FILE && self::canDeleteFile( $pageObj->getFile() ) )
86 $reason = $params[
'reason'];
94 if ( $params[
'tags'] ) {
96 if ( !$tagStatus->isOK() ) {
101 if ( $titleObj->getNamespace() ===
NS_FILE ) {
111 $status =
self::delete( $pageObj, $user, $reason, $params[
'tags'] );
114 if ( !$status->isOK() ) {
120 if ( $params[
'watch'] ) {
122 } elseif ( $params[
'unwatch'] ) {
125 $watch = $params[
'watchlist'];
129 $this->
setWatch( $watch, $titleObj, $user,
'watchdeletion', $watchlistExpiry );
132 'title' => $titleObj->getPrefixedText(),
136 if ( $status->hasMessage(
'delete-scheduled' ) ) {
137 $r[
'scheduled'] =
true;
139 if ( $status->value !==
null ) {
141 $r[
'logid'] = $status->value;
159 if ( $reason ===
null ) {
164 if ( $reason ===
false ) {
166 return Status::newFatal(
'cannotdelete',
$title->getPrefixedText() );
202 &$reason =
null, $suppress =
false, $tags = []
207 $file = $page->getFile();
208 if ( !self::canDeleteFile(
$file ) ) {
214 return Status::newFatal(
'invalidoldimage' );
216 $oldfile = $this->repoGroup->getLocalRepo()->newFromArchiveName(
$title, $oldimage );
217 if ( !$oldfile->exists() || !$oldfile->isLocal() || $oldfile->getRedirected() ) {
218 return Status::newFatal(
'nodeleteablefile' );
222 if ( $reason ===
null ) {
273 'action=delete&title=Main%20Page&token=123ABC'
274 =>
'apihelp-delete-example-simple',
275 'action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move'
276 =>
'apihelp-delete-example-reason',
281 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.
WatchlistManager $watchlistManager
UserOptionsLookup $userOptionsLookup
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.
addMessagesFromStatus(StatusValue $status, $types=[ 'warning', 'error'], array $filter=[])
Add warnings and/or errors from a Status.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
checkTitleUserPermissions( $pageIdentity, $actions, array $options=[])
Helper function for permission-denied errors.
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.
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.
__construct(ApiMain $mainModule, $moduleName, RepoGroup $repoGroup, WatchlistManager $watchlistManager, UserOptionsLookup $userOptionsLookup)
deleteFile(WikiPage $page, UserIdentity $deleter, $oldimage, &$reason=null, $suppress=false, $tags=[])
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)
static delete(WikiPage $page, UserIdentity $deleter, &$reason=null, $tags=[])
We have our own delete() function, since Article.php's implementation is split in two phases.
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...
Prioritized list of file repositories.
Class representing a MediaWiki article and history.
doDeleteArticleReal( $reason, UserIdentity $deleter, $suppress=false, $u1=null, &$error='', $u2=null, $tags=[], $logsubtype='delete', $immediate=false)
Back-end article deletion Deletes the article with database consistency, writes logs,...
getAutoDeleteReason(&$hasHistory)
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...
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.