X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fapi%2FApiDelete.php;h=7766acd3636966ce703b3ef639ae93ca89d37e09;hp=99065c4fe8554e1b7cf144b747c40dd278720d14;hb=e7720b8f8e09287384ddee271641d1b1721318bb;hpb=55043101b2a89ea1e811b6d35e415f57ed0bf41d diff --git a/includes/api/ApiDelete.php b/includes/api/ApiDelete.php index 99065c4fe8..7766acd363 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(); @@ -104,7 +106,7 @@ 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 + * @param string|null &$reason Reason for the deletion. Autogenerated if null * @param array $tags Tags to tag the deletion with * @return Status */ @@ -128,11 +130,19 @@ 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 * @param string $oldimage Archive name - * @param string $reason Reason for the deletion. Autogenerated if null. + * @param string &$reason Reason for the deletion. Autogenerated if null. * @param bool $suppress Whether to mark all deleted versions as restricted * @param array $tags Tags to tag the deletion with * @return Status @@ -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 ); }