MediaWiki r35609 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r35608‎ | r35609 (on ViewVC)‎ | r35610 >
Date:17:50, 30 May 2008
Author:brion
Status:old
Tags:
Comment:
Perform a duplicate check on upload and throw a warning which can be observed or ignored.
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/SpecialUpload.php
===================================================================
--- trunk/phase3/includes/SpecialUpload.php	(revision 35608)
+++ trunk/phase3/includes/SpecialUpload.php	(revision 35609)
@@ -539,6 +539,9 @@
 			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 @@
 
 		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: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php	(revision 35608)
+++ trunk/phase3/languages/messages/MessagesEn.php	(revision 35609)
@@ -1631,6 +1631,7 @@
 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',

Follow-up revisions

Rev.Commit summaryAuthorDate
r35747Add bug and comment for r35609: * (bug 13434) Show a warning when hash identi...raymond18:45, 2 June 2008

Status & tagging log

  • 15:27, 12 September 2011 Meno25 (Talk | contribs) changed the status of r35609 [removed: ok added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox