X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiDelete.php;h=50c24aeca8b5954af8a04ce34ef0f13cb98414cf;hb=d5a7166771613dfe4ed9fb75fa5efeced6134bd1;hp=77911b04b50d9deb7edfeed1cdf0215d5a735f57;hpb=fc1ca75323b5f424a9f8d28d42d85a311ed2f721;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index 77911b04b5..72bbe00482 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -44,19 +44,18 @@ class ApiDelete extends ApiBase { $params = $this->extractRequestParams(); $pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' ); - if ( !$pageObj->exists() ) { - $this->dieUsageMsg( 'notanarticle' ); + $titleObj = $pageObj->getTitle(); + if ( !$pageObj->exists() && + !( $titleObj->getNamespace() == NS_FILE && self::canDeleteFile( $pageObj->getFile() ) ) + ) { + $this->dieWithError( 'apierror-missingtitle' ); } - $titleObj = $pageObj->getTitle(); $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] ); - } + $this->checkTitleUserPermissions( $titleObj, 'delete' ); // If change tagging was requested, check that the user is allowed to tag, // and the tags are valid @@ -73,15 +72,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,11 +93,6 @@ 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 = [ 'title' => $titleObj->getPrefixedText(), 'reason' => $reason, @@ -115,9 +107,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 +120,22 @@ class ApiDelete extends ApiBase { $hasHistory = false; $reason = $page->getAutoDeleteReason( $hasHistory ); if ( $reason === false ) { - return [ [ '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 ); + } + + /** + * @param File $file + * @return bool + */ + protected static function canDeleteFile( File $file ) { + return $file->exists() && $file->isLocal() && !$file->getRedirected(); } /** @@ -143,25 +144,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 ); + if ( !self::canDeleteFile( $file ) ) { + return self::delete( $page, $user, $reason, $tags ); } if ( $oldimage ) { if ( !FileDeleteForm::isValidOldSpec( $oldimage ) ) { - return [ [ 'invalidoldimage' ] ]; + return Status::newFatal( 'invalidoldimage' ); } $oldfile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $title, $oldimage ); if ( !$oldfile->exists() || !$oldfile->isLocal() || $oldfile->getRedirected() ) { - return [ [ 'nodeleteablefile' ] ]; + return Status::newFatal( 'nodeleteablefile' ); } } @@ -169,7 +171,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() { @@ -226,6 +228,6 @@ class ApiDelete extends ApiBase { } public function getHelpUrls() { - return 'https://www.mediawiki.org/wiki/API:Delete'; + return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Delete'; } }