X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/?a=blobdiff_plain;f=includes%2Fapi%2FApiDelete.php;h=b5079a2813410c155a00dfb4a3de5c795a5604b9;hb=e6faa2fd76040d1cbadc6e439ecf51f8f4e52bd4;hp=cefdaac7832d6514ceca379092f5223989e80188;hpb=9b98d3f637f9d24f3e460da1fd4ccfe4a954685f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index cefdaac783..b5079a2813 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -4,7 +4,7 @@ * * Created on Jun 30, 2007 * - * Copyright © 2007 Roan Kattouw .@gmail.com + * Copyright © 2007 Roan Kattouw ".@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 @@ -52,17 +52,18 @@ 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 ) { - $retval = self::deleteFile( $pageObj, $user, $params['token'], $params['oldimage'], $reason, false ); + $status = self::deleteFile( $pageObj, $user, $params['token'], $params['oldimage'], $reason, false ); } else { - $retval = self::delete( $pageObj, $user, $params['token'], $reason ); + $status = self::delete( $pageObj, $user, $params['token'], $reason ); } - if ( count( $retval ) ) { - $this->dieUsageMsg( reset( $retval ) ); // We don't care about multiple errors, just report one of them + if ( !$status->isGood() ) { + $errors = $status->getErrorsArray(); + $this->dieUsageMsg( $errors[0] ); // We don't care about multiple errors, just report one of them } // Deprecated parameters @@ -75,7 +76,11 @@ class ApiDelete extends ApiBase { } $this->setWatch( $watch, $titleObj, 'watchdeletion' ); - $r = array( 'title' => $titleObj->getPrefixedText(), 'reason' => $reason ); + $r = array( + 'title' => $titleObj->getPrefixedText(), + 'reason' => $reason, + 'logid' => $status->value + ); $this->getResult()->addValue( null, $this->getModuleName(), $r ); } @@ -97,7 +102,7 @@ class ApiDelete extends ApiBase { * @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 Title::getUserPermissionsErrors()-like array + * @return Status */ public static function delete( Page $page, User $user, $token, &$reason = null ) { $title = $page->getTitle(); @@ -119,11 +124,7 @@ class ApiDelete extends ApiBase { $error = ''; // Luckily, Article.php provides a reusable delete function that does the hard work for us - if ( $page->doDeleteArticle( $reason, false, 0, true, $error ) ) { - return array(); - } else { - return array( array( 'cannotdelete', $title->getPrefixedText() ) ); - } + return $page->doDeleteArticleReal( $reason, false, 0, true, $error ); } /** @@ -133,7 +134,7 @@ class ApiDelete extends ApiBase { * @param $oldimage * @param $reason * @param $suppress bool - * @return array|Title + * @return Status */ public static function deleteFile( Page $page, User $user, $token, $oldimage, &$reason = null, $suppress = false ) { $title = $page->getTitle(); @@ -162,12 +163,7 @@ class ApiDelete extends ApiBase { if ( is_null( $reason ) ) { // Log and RC don't like null reasons $reason = ''; } - $status = FileDeleteForm::doDelete( $title, $file, $oldimage, $reason, $suppress ); - if ( !$status->isGood() ) { - return array( array( 'cannotdelete', $title->getPrefixedText() ) ); - } - - return array(); + return FileDeleteForm::doDelete( $title, $file, $oldimage, $reason, $suppress ); } public function mustBePosted() { @@ -221,6 +217,15 @@ class ApiDelete extends ApiBase { ); } + public function getResultProperties() { + return array( + '' => array( + 'title' => 'string', + 'reason' => 'string' + ) + ); + } + public function getDescription() { return 'Delete a page'; }