API: Log all deprecated parameter uses to api-feature-usage.log
[lhc/web/wiklou.git] / includes / api / ApiDelete.php
index bdf02bf..edcee86 100644 (file)
@@ -32,7 +32,7 @@
  */
 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
@@ -52,17 +52,31 @@ class ApiDelete extends ApiBase {
                $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 ) ) {
@@ -74,16 +88,19 @@ 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'];
                }
                $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 );
+               }
+
                $r = array(
                        'title' => $titleObj->getPrefixedText(),
                        'reason' => $reason,
@@ -92,32 +109,16 @@ class ApiDelete extends ApiBase {
                $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 ) ) {
@@ -139,24 +140,19 @@ class ApiDelete extends ApiBase {
        /**
         * @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 ) {
@@ -191,6 +187,10 @@ class ApiDelete extends ApiBase {
                                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,