36 parent::__construct( $mainModule, $moduleName, $modulePrefix );
38 $this->watchlistExpiryEnabled = $this->
getConfig()->get(
'WatchlistExpiry' );
39 $this->watchlistMaxDuration = $this->
getConfig()->get(
'WatchlistExpiryMaxDuration' );
55 $titleObj = $pageObj->getTitle();
56 if ( !$pageObj->exists() &&
58 !( $titleObj->getNamespace() ==
NS_FILE && self::canDeleteFile( $pageObj->getFile() ) )
63 $reason = $params[
'reason'];
71 if ( $params[
'tags'] ) {
73 if ( !$tagStatus->isOK() ) {
78 if ( $titleObj->getNamespace() ==
NS_FILE ) {
88 $status =
self::delete( $pageObj, $user, $reason, $params[
'tags'] );
91 if ( !$status->isOK() ) {
97 if ( $params[
'watch'] ) {
99 } elseif ( $params[
'unwatch'] ) {
102 $watch = $params[
'watchlist'];
106 $this->
setWatch( $watch, $titleObj, $user,
'watchdeletion', $watchlistExpiry );
109 'title' => $titleObj->getPrefixedText(),
113 if ( $status->hasMessage(
'delete-scheduled' ) ) {
114 $r[
'scheduled'] =
true;
116 if ( $status->value !==
null ) {
118 $r[
'logid'] = $status->value;
132 private static function delete(
WikiPage $page,
User $user, &$reason =
null, $tags = [] ) {
136 if ( $reason ===
null ) {
141 if ( $reason ===
false ) {
143 return Status::newFatal(
'cannotdelete',
$title->getPrefixedText() );
179 &$reason =
null, $suppress =
false, $tags = []
184 $file = $page->getFile();
185 if ( !self::canDeleteFile(
$file ) ) {
191 return Status::newFatal(
'invalidoldimage' );
193 $oldfile = MediaWikiServices::getInstance()->getRepoGroup()
194 ->getLocalRepo()->newFromArchiveName(
$title, $oldimage );
195 if ( !$oldfile->exists() || !$oldfile->isLocal() || $oldfile->getRedirected() ) {
196 return Status::newFatal(
'nodeleteablefile' );
200 if ( $reason ===
null ) {
251 'action=delete&title=Main%20Page&token=123ABC'
252 =>
'apihelp-delete-example-simple',
253 'action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move'
254 =>
'apihelp-delete-example-reason',
259 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.
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,...
getModuleName()
Get the name of the module being executed by this instance.
checkTitleUserPermissions(LinkTarget $linkTarget, $actions, array $options=[])
Helper function for permission-denied errors.
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.
static delete(WikiPage $page, User $user, &$reason=null, $tags=[])
We have our own delete() function, since Article.php's implementation is split in two phases.
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)
static deleteFile(WikiPage $page, User $user, $oldimage, &$reason=null, $suppress=false, $tags=[])
__construct(ApiMain $mainModule, $moduleName, $modulePrefix='')
Stable to call.
isWriteMode()
Indicates whether this module requires write mode.
mustBePosted()
Indicates whether this module must be called with a POST request Stable to override.
This is the main API class, used for both external and internal processing.
getUser()
Stable to override.
Implements some public methods and some protected utility functions which are required by multiple ch...
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Class representing a MediaWiki article and history.
getAutoDeleteReason(&$hasHistory)
Auto-generates a deletion reason.
doDeleteArticleReal( $reason, $user=false, $suppress=false, $u2=null, &$error='', User $deleter=null, $tags=[], $logsubtype='delete', $immediate=false)
Back-end article deletion Deletes the article with database consistency, writes logs,...
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.