Merge "Change 'editfont' default preference to 'monospace'"
[lhc/web/wiklou.git] / includes / api / ApiDelete.php
index 50c24ae..7766acd 100644 (file)
@@ -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 );
                }
 
@@ -218,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';
        }
 }