Merge "Code style: no space after unary minus operator"
[lhc/web/wiklou.git] / includes / api / ApiDelete.php
index b0bf5dd..50c24ae 100644 (file)
@@ -45,7 +45,7 @@ class ApiDelete extends ApiBase {
 
                $pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' );
                if ( !$pageObj->exists() ) {
-                       $this->dieUsageMsg( 'notanarticle' );
+                       $this->dieWithError( 'apierror-missingtitle' );
                }
 
                $titleObj = $pageObj->getTitle();
@@ -53,10 +53,7 @@ class ApiDelete extends ApiBase {
                $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] );
-               }
+               $this->checkTitleUserPermissions( $titleObj, 'delete' );
 
                // If change tagging was requested, check that the user is allowed to tag,
                // and the tags are valid
@@ -73,15 +70,13 @@ class ApiDelete extends ApiBase {
                                $user,
                                $params['oldimage'],
                                $reason,
-                               false
+                               false,
+                               $params['tags']
                        );
                } else {
-                       $status = self::delete( $pageObj, $user, $reason );
+                       $status = self::delete( $pageObj, $user, $reason, $params['tags'] );
                }
 
-               if ( is_array( $status ) ) {
-                       $this->dieUsageMsg( $status[0] );
-               }
                if ( !$status->isGood() ) {
                        $this->dieStatus( $status );
                }
@@ -96,16 +91,11 @@ class ApiDelete extends ApiBase {
                }
                $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(
+               $r = [
                        'title' => $titleObj->getPrefixedText(),
                        'reason' => $reason,
                        'logid' => $status->value
-               );
+               ];
                $this->getResult()->addValue( null, $this->getModuleName(), $r );
        }
 
@@ -115,9 +105,10 @@ class ApiDelete extends ApiBase {
         * @param Page|WikiPage $page Page or WikiPage object to work on
         * @param User $user User doing the action
         * @param string|null $reason Reason for the deletion. Autogenerated if null
-        * @return Status|array
+        * @param array $tags Tags to tag the deletion with
+        * @return Status
         */
-       protected static function delete( Page $page, User $user, &$reason = null ) {
+       protected static function delete( Page $page, User $user, &$reason = null, $tags = [] ) {
                $title = $page->getTitle();
 
                // Auto-generate a summary, if necessary
@@ -127,14 +118,14 @@ class ApiDelete extends ApiBase {
                        $hasHistory = false;
                        $reason = $page->getAutoDeleteReason( $hasHistory );
                        if ( $reason === false ) {
-                               return array( array( 'cannotdelete', $title->getPrefixedText() ) );
+                               return Status::newFatal( 'cannotdelete', $title->getPrefixedText() );
                        }
                }
 
                $error = '';
 
                // Luckily, Article.php provides a reusable delete function that does the hard work for us
-               return $page->doDeleteArticleReal( $reason, false, 0, true, $error, $user );
+               return $page->doDeleteArticleReal( $reason, false, 0, true, $error, $user, $tags );
        }
 
        /**
@@ -143,25 +134,26 @@ class ApiDelete extends ApiBase {
         * @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
+        * @param array $tags Tags to tag the deletion with
+        * @return Status
         */
        protected static function deleteFile( Page $page, User $user, $oldimage,
-               &$reason = null, $suppress = false
+               &$reason = null, $suppress = false, $tags = []
        ) {
                $title = $page->getTitle();
 
                $file = $page->getFile();
                if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
-                       return self::delete( $page, $user, $reason );
+                       return self::delete( $page, $user, $reason, $tags );
                }
 
                if ( $oldimage ) {
                        if ( !FileDeleteForm::isValidOldSpec( $oldimage ) ) {
-                               return array( array( 'invalidoldimage' ) );
+                               return Status::newFatal( 'invalidoldimage' );
                        }
                        $oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $title, $oldimage );
                        if ( !$oldfile->exists() || !$oldfile->isLocal() || $oldfile->getRedirected() ) {
-                               return array( array( 'nodeleteablefile' ) );
+                               return Status::newFatal( 'nodeleteablefile' );
                        }
                }
 
@@ -169,7 +161,7 @@ class ApiDelete extends ApiBase {
                        $reason = '';
                }
 
-               return FileDeleteForm::doDelete( $title, $file, $oldimage, $reason, $suppress, $user );
+               return FileDeleteForm::doDelete( $title, $file, $oldimage, $reason, $suppress, $user, $tags );
        }
 
        public function mustBePosted() {
@@ -181,35 +173,35 @@ class ApiDelete extends ApiBase {
        }
 
        public function getAllowedParams() {
-               return array(
+               return [
                        'title' => null,
-                       'pageid' => array(
+                       'pageid' => [
                                ApiBase::PARAM_TYPE => 'integer'
-                       ),
+                       ],
                        'reason' => null,
-                       'tags' => array(
+                       'tags' => [
                                ApiBase::PARAM_TYPE => 'tags',
                                ApiBase::PARAM_ISMULTI => true,
-                       ),
-                       'watch' => array(
+                       ],
+                       'watch' => [
                                ApiBase::PARAM_DFLT => false,
                                ApiBase::PARAM_DEPRECATED => true,
-                       ),
-                       'watchlist' => array(
+                       ],
+                       'watchlist' => [
                                ApiBase::PARAM_DFLT => 'preferences',
-                               ApiBase::PARAM_TYPE => array(
+                               ApiBase::PARAM_TYPE => [
                                        'watch',
                                        'unwatch',
                                        'preferences',
                                        'nochange'
-                               ),
-                       ),
-                       'unwatch' => array(
+                               ],
+                       ],
+                       'unwatch' => [
                                ApiBase::PARAM_DFLT => false,
                                ApiBase::PARAM_DEPRECATED => true,
-                       ),
+                       ],
                        'oldimage' => null,
-               );
+               ];
        }
 
        public function needsToken() {
@@ -217,12 +209,12 @@ class ApiDelete extends ApiBase {
        }
 
        protected function getExamplesMessages() {
-               return array(
+               return [
                        'action=delete&title=Main%20Page&token=123ABC'
                                => 'apihelp-delete-example-simple',
                        'action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move'
                                => 'apihelp-delete-example-reason',
-               );
+               ];
        }
 
        public function getHelpUrls() {