summaryrefslogtreecommitdiff
path: root/includes/api/ApiDelete.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/api/ApiDelete.php')
-rw-r--r--includes/api/ApiDelete.php91
1 files changed, 37 insertions, 54 deletions
diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php
index aea10482..abca8245 100644
--- a/includes/api/ApiDelete.php
+++ b/includes/api/ApiDelete.php
@@ -31,7 +31,6 @@
* @ingroup API
*/
class ApiDelete extends ApiBase {
-
/**
* Extracts the title, token, and reason from the request parameters and invokes
* the local delete() function with these as arguments. It does not make use of
@@ -52,7 +51,14 @@ class ApiDelete extends ApiBase {
$user = $this->getUser();
if ( $titleObj->getNamespace() == NS_FILE ) {
- $status = self::deleteFile( $pageObj, $user, $params['token'], $params['oldimage'], $reason, false );
+ $status = self::deleteFile(
+ $pageObj,
+ $user,
+ $params['token'],
+ $params['oldimage'],
+ $reason,
+ false
+ );
} else {
$status = self::delete( $pageObj, $user, $params['token'], $reason );
}
@@ -66,8 +72,10 @@ class ApiDelete extends ApiBase {
// Deprecated parameters
if ( $params['watch'] ) {
+ $this->logFeatureUsage( 'action=delete&watch' );
$watch = 'watch';
} elseif ( $params['unwatch'] ) {
+ $this->logFeatureUsage( 'action=delete&unwatch' );
$watch = 'unwatch';
} else {
$watch = $params['watchlist'];
@@ -83,9 +91,9 @@ class ApiDelete extends ApiBase {
}
/**
- * @param $title Title
- * @param $user User doing the action
- * @param $token String
+ * @param Title $title
+ * @param User $user User doing the action
+ * @param string $token
* @return array
*/
private static function getPermissionsError( $title, $user, $token ) {
@@ -96,10 +104,10 @@ class ApiDelete extends ApiBase {
/**
* We have our own delete() function, since Article.php's implementation is split in two phases
*
- * @param $page Page|WikiPage object to work on
- * @param $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
+ * @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 ) {
@@ -121,20 +129,23 @@ class ApiDelete extends ApiBase {
}
$error = '';
+
// Luckily, Article.php provides a reusable delete function that does the hard work for us
return $page->doDeleteArticleReal( $reason, false, 0, true, $error );
}
/**
- * @param $page WikiPage|Page object to work on
- * @param $user User doing the action
- * @param $token
- * @param $oldimage
- * @param $reason
- * @param $suppress bool
+ * @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, &$reason = null, $suppress = false ) {
+ public static function deleteFile( Page $page, User $user, $token, $oldimage,
+ &$reason = null, $suppress = false
+ ) {
$title = $page->getTitle();
$errors = self::getPermissionsError( $title, $user, $token );
if ( count( $errors ) ) {
@@ -159,6 +170,7 @@ class ApiDelete extends ApiBase {
if ( is_null( $reason ) ) { // Log and RC don't like null reasons
$reason = '';
}
+
return FileDeleteForm::doDelete( $title, $file, $oldimage, $reason, $suppress, $user );
}
@@ -176,10 +188,6 @@ class ApiDelete extends ApiBase {
'pageid' => array(
ApiBase::PARAM_TYPE => 'integer'
),
- 'token' => array(
- ApiBase::PARAM_TYPE => 'string',
- ApiBase::PARAM_REQUIRED => true
- ),
'reason' => null,
'watch' => array(
ApiBase::PARAM_DFLT => false,
@@ -204,58 +212,33 @@ class ApiDelete extends ApiBase {
public function getParamDescription() {
$p = $this->getModulePrefix();
+
return array(
'title' => "Title of the page you want to delete. Cannot be used together with {$p}pageid",
'pageid' => "Page ID of the page you want to delete. Cannot be used together with {$p}title",
- 'token' => 'A delete token previously retrieved through prop=info',
- 'reason' => 'Reason for the deletion. If not set, an automatically generated reason will be used',
+ 'reason'
+ => 'Reason for the deletion. If not set, an automatically generated reason will be used',
'watch' => 'Add the page to your watchlist',
- 'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
+ 'watchlist' => 'Unconditionally add or remove the page from your ' .
+ 'watchlist, use preferences or do not change watch',
'unwatch' => 'Remove the page from your watchlist',
'oldimage' => 'The name of the old image to delete as provided by iiprop=archivename'
);
}
- public function getResultProperties() {
- return array(
- '' => array(
- 'title' => 'string',
- 'reason' => 'string',
- 'logid' => 'integer'
- )
- );
- }
-
public function getDescription() {
- return 'Delete a page';
- }
-
- public function getPossibleErrors() {
- return array_merge( parent::getPossibleErrors(),
- $this->getTitleOrPageIdErrorMessage(),
- array(
- array( 'notanarticle' ),
- array( 'hookaborted', 'error' ),
- array( 'delete-toobig', 'limit' ),
- array( 'cannotdelete', 'title' ),
- array( 'invalidoldimage' ),
- array( 'nodeleteablefile' ),
- )
- );
+ return 'Delete a page.';
}
public function needsToken() {
- return true;
- }
-
- public function getTokenSalt() {
- return '';
+ return 'csrf';
}
public function getExamples() {
return array(
'api.php?action=delete&title=Main%20Page&token=123ABC' => 'Delete the Main Page',
- 'api.php?action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move' => 'Delete the Main Page with the reason "Preparing for move"',
+ 'api.php?action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move'
+ => 'Delete the Main Page with the reason "Preparing for move"',
);
}