Merge "Added deprecation comment to constant that when used throws deprecation exception"
[lhc/web/wiklou.git] / includes / api / ApiDelete.php
index 91406af..422524d 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Created on Jun 30, 2007
  *
- * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@gmail.com
+ * Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  */
 class ApiDelete extends ApiBase {
 
-       public function __construct( $main, $action ) {
-               parent::__construct( $main, $action );
-       }
-
        /**
         * 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 +48,7 @@ class ApiDelete extends ApiBase {
                }
 
                $titleObj = $pageObj->getTitle();
-               $reason = ( isset( $params['reason'] ) ? $params['reason'] : null );
+               $reason = $params['reason'];
                $user = $this->getUser();
 
                if ( $titleObj->getNamespace() == NS_FILE ) {
@@ -61,8 +57,11 @@ class ApiDelete extends ApiBase {
                        $status = self::delete( $pageObj, $user, $params['token'], $reason );
                }
 
+               if ( is_array( $status ) ) {
+                       $this->dieUsageMsg( $status[0] );
+               }
                if ( !$status->isGood() ) {
-                       $errors = $this->getErrorsArray();
+                       $errors = $status->getErrorsArray();
                        $this->dieUsageMsg( $errors[0] ); // We don't care about multiple errors, just report one of them
                }
 
@@ -98,11 +97,11 @@ class ApiDelete extends ApiBase {
        /**
         * We have our own delete() function, since Article.php's implementation is split in two phases
         *
-        * @param $page WikiPage object to work on
+        * @param $page Page|WikiPage object to work on
         * @param $user User doing the action
-        * @param $token String: delete token (same as edit token)
-        * @param $reason String: reason for the deletion. Autogenerated if NULL
-        * @return Status
+        * @param $token String delete token (same as edit token)
+        * @param $reason String|null reason for the deletion. Autogenerated if NULL
+        * @return Status|array
         */
        public static function delete( Page $page, User $user, $token, &$reason = null ) {
                $title = $page->getTitle();
@@ -128,13 +127,13 @@ class ApiDelete extends ApiBase {
        }
 
        /**
-        * @param $page WikiPage object to work on
+        * @param $page WikiPage|Page object to work on
         * @param $user User doing the action
         * @param $token
         * @param $oldimage
         * @param $reason
         * @param $suppress bool
-        * @return Status
+        * @return Status|array
         */
        public static function deleteFile( Page $page, User $user, $token, $oldimage, &$reason = null, $suppress = false ) {
                $title = $page->getTitle();
@@ -156,14 +155,12 @@ class ApiDelete extends ApiBase {
                        if ( !$oldfile->exists() || !$oldfile->isLocal() || $oldfile->getRedirected() ) {
                                return array( array( 'nodeleteablefile' ) );
                        }
-               } else {
-                       $oldfile = false;
                }
 
                if ( is_null( $reason ) ) { // Log and RC don't like null reasons
                        $reason = '';
                }
-               return FileDeleteForm::doDelete( $title, $file, $oldimage, $reason, $suppress );
+               return FileDeleteForm::doDelete( $title, $file, $oldimage, $reason, $suppress, $user );
        }
 
        public function mustBePosted() {
@@ -180,7 +177,10 @@ class ApiDelete extends ApiBase {
                        'pageid' => array(
                                ApiBase::PARAM_TYPE => 'integer'
                        ),
-                       'token' => null,
+                       'token' => array(
+                               ApiBase::PARAM_TYPE => 'string',
+                               ApiBase::PARAM_REQUIRED => true
+                       ),
                        'reason' => null,
                        'watch' => array(
                                ApiBase::PARAM_DFLT => false,
@@ -221,7 +221,8 @@ class ApiDelete extends ApiBase {
                return array(
                        '' => array(
                                'title' => 'string',
-                               'reason' => 'string'
+                               'reason' => 'string',
+                               'logid' => 'integer'
                        )
                );
        }
@@ -262,8 +263,4 @@ class ApiDelete extends ApiBase {
        public function getHelpUrls() {
                return 'https://www.mediawiki.org/wiki/API:Delete';
        }
-
-       public function getVersion() {
-               return __CLASS__ . ': $Id$';
-       }
 }