*/
class ApiDelete extends ApiBase {
/**
- * Extracts the title, token, and reason from the request parameters and invokes
+ * Extracts the title and reason from the request parameters and invokes
* the local delete() function with these as arguments. It does not make use of
* the delete function specified by Article.php. If the deletion succeeds, the
* details of the article deleted and the reason for deletion are added to the
$reason = $params['reason'];
$user = $this->getUser();
+ // Check that the user is allowed to carry out the deletion
+ $errors = $titleObj->getUserPermissionsErrors( 'delete', $user );
+ if ( count( $errors ) ) {
+ $this->dieUsageMsg( $errors[0] );
+ }
+
+ // If change tagging was requested, check that the user is allowed to tag,
+ // and the tags are valid
+ if ( count( $params['tags'] ) ) {
+ $tagStatus = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user );
+ if ( !$tagStatus->isOK() ) {
+ $this->dieStatus( $tagStatus );
+ }
+ }
+
if ( $titleObj->getNamespace() == NS_FILE ) {
$status = self::deleteFile(
$pageObj,
$user,
- $params['token'],
$params['oldimage'],
$reason,
false
);
} else {
- $status = self::delete( $pageObj, $user, $params['token'], $reason );
+ $status = self::delete( $pageObj, $user, $reason );
}
if ( is_array( $status ) ) {
}
$this->setWatch( $watch, $titleObj, 'watchdeletion' );
+ // Apply change tags to the log entry, if requested
+ if ( count( $params['tags'] ) ) {
+ ChangeTags::addTags( $params['tags'], null, null, $status->value, null, $user );
+ }
+
$r = array(
'title' => $titleObj->getPrefixedText(),
'reason' => $reason,
$this->getResult()->addValue( null, $this->getModuleName(), $r );
}
- /**
- * @param Title $title
- * @param User $user User doing the action
- * @param string $token
- * @return array
- */
- private static function getPermissionsError( $title, $user, $token ) {
- // Check permissions
- return $title->getUserPermissionsErrors( 'delete', $user );
- }
-
/**
* We have our own delete() function, since Article.php's implementation is split in two phases
*
* @param Page|WikiPage $page Page or WikiPage object to work on
* @param User $user User doing the action
- * @param string $token Delete token (same as edit token)
* @param string|null $reason Reason for the deletion. Autogenerated if null
* @return Status|array
*/
- public static function delete( Page $page, User $user, $token, &$reason = null ) {
+ protected static function delete( Page $page, User $user, &$reason = null ) {
$title = $page->getTitle();
- $errors = self::getPermissionsError( $title, $user, $token );
- if ( count( $errors ) ) {
- return $errors;
- }
// Auto-generate a summary, if necessary
if ( is_null( $reason ) ) {
/**
* @param Page $page Object to work on
* @param User $user User doing the action
- * @param string $token Delete token (same as edit token)
* @param string $oldimage Archive name
* @param string $reason Reason for the deletion. Autogenerated if null.
* @param bool $suppress Whether to mark all deleted versions as restricted
* @return Status|array
*/
- public static function deleteFile( Page $page, User $user, $token, $oldimage,
+ protected static function deleteFile( Page $page, User $user, $oldimage,
&$reason = null, $suppress = false
) {
$title = $page->getTitle();
- $errors = self::getPermissionsError( $title, $user, $token );
- if ( count( $errors ) ) {
- return $errors;
- }
$file = $page->getFile();
if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
- return self::delete( $page, $user, $token, $reason );
+ return self::delete( $page, $user, $reason );
}
if ( $oldimage ) {
ApiBase::PARAM_TYPE => 'integer'
),
'reason' => null,
+ 'tags' => array(
+ ApiBase::PARAM_TYPE => ChangeTags::listExplicitlyDefinedTags(),
+ ApiBase::PARAM_ISMULTI => true,
+ ),
'watch' => array(
ApiBase::PARAM_DFLT => false,
ApiBase::PARAM_DEPRECATED => true,