From 2652dc048899503155de957f2da66df8d311a109 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Mon, 12 Jun 2017 13:09:26 -0400 Subject: [PATCH] API: Allow deleting files without corresponding pages Such a deletion doesn't currently produce a log entry, but that's a different bug that also occurs via the web UI. Bug: T167693 Change-Id: If6e751aa28960243db49ac9b81fe518edba11bd5 --- includes/api/ApiDelete.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index 99065c4fe8..72bbe00482 100644 --- a/includes/api/ApiDelete.php +++ b/includes/api/ApiDelete.php @@ -44,11 +44,13 @@ class ApiDelete extends ApiBase { $params = $this->extractRequestParams(); $pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' ); - if ( !$pageObj->exists() ) { + $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(); @@ -128,6 +130,14 @@ class ApiDelete extends ApiBase { 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(); + } + /** * @param Page $page Object to work on * @param User $user User doing the action @@ -143,7 +153,7 @@ class ApiDelete extends ApiBase { $title = $page->getTitle(); $file = $page->getFile(); - if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) { + if ( !self::canDeleteFile( $file ) ) { return self::delete( $page, $user, $reason, $tags ); } -- 2.20.1