From 5928b906e94de4ac71057905a845a15ff7388623 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 30 May 2008 17:50:04 +0000 Subject: [PATCH] Perform a duplicate check on upload and throw a warning which can be observed or ignored. --- includes/SpecialUpload.php | 28 ++++++++++++++++++++++++++++ languages/messages/MessagesEn.php | 1 + 2 files changed, 29 insertions(+) diff --git a/includes/SpecialUpload.php b/includes/SpecialUpload.php index ac52d44559..a5096b3ede 100644 --- a/includes/SpecialUpload.php +++ b/includes/SpecialUpload.php @@ -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 = ""; + foreach( $dupes as $file ) { + $title = $file->getTitle(); + $msg .= $title->getPrefixedText() . + "|" . $title->getText() . "\n"; + } + $msg .= ""; + return "
  • " . + wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) . + $wgOut->parse( $msg ) . + "
  • \n"; + } else { + return ''; + } + } /** * Get a list of blacklisted filename prefixes from [[MediaWiki:filename-prefix-blacklist]] diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index d8e220a3a6..1c9004b016 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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', -- 2.20.1