jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/358402 )

Change subject: API: Allow deleting files without corresponding pages
......................................................................


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
---
M includes/api/ApiDelete.php
1 file changed, 13 insertions(+), 3 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php
index 99065c4..72bbe00 100644
--- a/includes/api/ApiDelete.php
+++ b/includes/api/ApiDelete.php
@@ -44,11 +44,13 @@
                $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();
 
@@ -129,6 +131,14 @@
        }
 
        /**
+        * @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
         * @param string $oldimage Archive name
@@ -143,7 +153,7 @@
                $title = $page->getTitle();
 
                $file = $page->getFile();
-               if ( !$file->exists() || !$file->isLocal() || 
$file->getRedirected() ) {
+               if ( !self::canDeleteFile( $file ) ) {
                        return self::delete( $page, $user, $reason, $tags );
                }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/358402
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If6e751aa28960243db49ac9b81fe518edba11bd5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Zhuyifei1999 <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to