Perform a duplicate check on upload and throw a warning which can be observed or...
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 30 May 2008 17:50:04 +0000 (17:50 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 30 May 2008 17:50:04 +0000 (17:50 +0000)
includes/SpecialUpload.php
languages/messages/MessagesEn.php

index ac52d44..a5096b3 100644 (file)
@@ -539,6 +539,9 @@ class UploadForm {
                        if ( !$this->mDestWarningAck ) {
                                $warning .= self::getExistsWarning( $this->mLocalFile );
                        }
+                       
+                       $warning .= $this->getDupeWarning( $this->mTempPath );
+                       
                        if( $warning != '' ) {
                                /**
                                 * Stash the file in a temporary location; the user can choose
@@ -739,6 +742,31 @@ class UploadForm {
 
                return $output->getText();
        }
+       
+       /**
+        * Check for duplicate files and throw up a warning before the upload
+        * completes.
+        */
+       function getDupeWarning( $tempfile ) {
+               $hash = File::sha1Base36( $tempfile );
+               $dupes = RepoGroup::singleton()->findBySha1( $hash );
+               if( $dupes ) {
+                       global $wgOut;
+                       $msg = "<gallery>";
+                       foreach( $dupes as $file ) {
+                               $title = $file->getTitle();
+                               $msg .= $title->getPrefixedText() .
+                                       "|" . $title->getText() . "\n";
+                       }
+                       $msg .= "</gallery>";
+                       return "<li>" .
+                               wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
+                               $wgOut->parse( $msg ) .
+                               "</li>\n";
+               } else {
+                       return '';
+               }
+       }
 
        /**
         * Get a list of blacklisted filename prefixes from [[MediaWiki:filename-prefix-blacklist]]
index d8e220a..1c9004b 100644 (file)
@@ -1631,6 +1631,7 @@ If you have this image in full resolution upload this one, otherwise change the
 please go back and upload this file under a new name. [[Image:$1|thumb|center|$1]]',
 'fileexists-shared-forbidden' => 'A file with this name exists already in the shared file repository;
 please go back and upload this file under a new name. [[Image:$1|thumb|center|$1]]',
+'file-exists-duplicate'       => 'This file seems to be a duplicate of the following {{PLURAL:$1|file|files}}:',
 'successfulupload'            => 'Successful upload',
 'uploadwarning'               => 'Upload warning',
 'savefile'                    => 'Save file',