UploadBase: Return 'was-deleted' warning in addition to 'exists-normalized', not...
authorBartosz Dziewoński <matma.rex@gmail.com>
Fri, 11 Sep 2015 18:49:36 +0000 (20:49 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Mon, 12 Oct 2015 12:22:11 +0000 (14:22 +0200)
The 'was-deleted' warning was generated by getExistsWarning(), which
was returning immediately if this was found to be the case. A bunch of
later checks were incorrectly skipped, in particular 'exists-normalized',
which was resulting in UploadWizard incorrectly ignoring that problem.

I'm not sure why that was part of getExistsWarning() at all, it
doesn't seem very relevant. For that matter, neither do the 'thumb',
'thumb-name' and 'bad-prefix' warnings that it also generates, but
this should not be a problem in practice and so I'm leaving them alone.

Other than by allowing some more warning types to appear together or
in different order, this should not affect action=upload API output or
Special:Upload (which was updated appropriately). It does affect
'action=query&prop=imageinfo' output's 'html' property (used for AJAX
checks on Special:Upload), which no longer includes the 'was-deleted'
warning; this was never specified anywhere and just a side-effect.

Bug: T48741
Change-Id: I3686ee8ffd635f5f06f51971b6f16e3e66f33a9e

RELEASE-NOTES-1.27
includes/specials/SpecialUpload.php
includes/upload/UploadBase.php

index 06feb4d..e4793b3 100644 (file)
@@ -52,6 +52,8 @@ production.
 * ApiPageSet::setRedirectMergePolicy() was added. This allows generator
   modules to define how generator data for a redirect source gets merged
   into the redirect destination.
+* prop=imageinfo&iiprop=uploadwarning will no longer include the possibility of
+  "was-deleted" warning.
 
 === Action API internal changes in 1.27 ===
 
index 10d55b2..ad44076 100644 (file)
@@ -263,7 +263,7 @@ class SpecialUpload extends SpecialPage {
                }
 
                # Give a notice if the user is uploading a file that has been deleted or moved
-               # Note that this is independent from the message 'filewasdeleted' that requires JS
+               # Note that this is independent from the message 'filewasdeleted'
                $desiredTitleObj = Title::makeTitleSafe( NS_FILE, $this->mDesiredDestName );
                $delNotice = ''; // empty by default
                if ( $desiredTitleObj instanceof Title && !$desiredTitleObj->exists() ) {
@@ -366,6 +366,19 @@ class SpecialUpload extends SpecialPage {
                        }
                        if ( $warning == 'exists' ) {
                                $msg = "\t<li>" . self::getExistsWarning( $args ) . "</li>\n";
+                       } elseif ( $warning == 'was-deleted' ) {
+                               # If the file existed before and was deleted, warn the user of this
+                               $ltitle = SpecialPage::getTitleFor( 'Log' );
+                               $llink = Linker::linkKnown(
+                                       $ltitle,
+                                       wfMessage( 'deletionlog' )->escaped(),
+                                       array(),
+                                       array(
+                                               'type' => 'delete',
+                                               'page' => Title::makeTitle( NS_FILE, $args )->getPrefixedText(),
+                                       )
+                               );
+                               $msg = "\t<li>" . wfMessage( 'filewasdeleted' )->rawParams( $llink )->parse() . "</li>\n";
                        } elseif ( $warning == 'duplicate' ) {
                                $msg = $this->getDupeWarning( $args );
                        } elseif ( $warning == 'duplicate-archive' ) {
@@ -711,19 +724,6 @@ class SpecialUpload extends SpecialPage {
                        $warning = wfMessage( 'file-thumbnail-no', $badPart )->parse();
                } elseif ( $exists['warning'] == 'bad-prefix' ) {
                        $warning = wfMessage( 'filename-bad-prefix', $exists['prefix'] )->parse();
-               } elseif ( $exists['warning'] == 'was-deleted' ) {
-                       # If the file existed before and was deleted, warn the user of this
-                       $ltitle = SpecialPage::getTitleFor( 'Log' );
-                       $llink = Linker::linkKnown(
-                               $ltitle,
-                               wfMessage( 'deletionlog' )->escaped(),
-                               array(),
-                               array(
-                                       'type' => 'delete',
-                                       'page' => $filename
-                               )
-                       );
-                       $warning = wfMessage( 'filewasdeleted' )->rawParams( $llink )->parseAsBlock();
                }
 
                return $warning;
index 5193a7f..8514187 100644 (file)
@@ -643,6 +643,10 @@ abstract class UploadBase {
                        $warnings['exists'] = $exists;
                }
 
+               if ( $localFile->wasDeleted() && !$localFile->exists() ) {
+                       $warnings['was-deleted'] = $filename;
+               }
+
                // Check dupes against existing files
                $hash = $this->getTempFileSha1Base36();
                $dupes = RepoGroup::singleton()->findBySha1( $hash );
@@ -1745,10 +1749,6 @@ abstract class UploadBase {
                        return array( 'warning' => 'page-exists', 'file' => $file );
                }
 
-               if ( $file->wasDeleted() && !$file->exists() ) {
-                       return array( 'warning' => 'was-deleted', 'file' => $file );
-               }
-
                if ( strpos( $file->getName(), '.' ) == false ) {
                        $partname = $file->getName();
                        $extension = '';