From 9903a86e687c2b3fc6232cf6fef1d62feff23d0c Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Tue, 18 Nov 2008 02:20:55 +0000 Subject: [PATCH] Warn when re-uploading a file with the same SHA1/extension pair as a file which has been deleted. --- includes/filerepo/ArchivedFile.php | 40 +++++++++++++++++++++-------- includes/specials/SpecialUpload.php | 11 +++++--- languages/messages/MessagesEn.php | 1 + 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/includes/filerepo/ArchivedFile.php b/includes/filerepo/ArchivedFile.php index f6bbda306b..16b939f830 100644 --- a/includes/filerepo/ArchivedFile.php +++ b/includes/filerepo/ArchivedFile.php @@ -30,12 +30,9 @@ class ArchivedFile /**#@-*/ function ArchivedFile( $title, $id=0, $key='' ) { - if( !is_object($title) ) { - throw new MWException( 'ArchivedFile constructor given bogus title.' ); - } $this->id = -1; - $this->title = $title; - $this->name = $title->getDBkey(); + $this->title = false; + $this->name = false; $this->group = ''; $this->key = ''; $this->size = 0; @@ -51,6 +48,20 @@ class ArchivedFile $this->timestamp = NULL; $this->deleted = 0; $this->dataLoaded = false; + + if( is_object($title) ) { + $this->title = $title; + $this->name = $title->getDBkey(); + } + + if ($id) + $this->id = $id; + + if ($key) + $this->key = $key; + + if (!$id && !$key && !is_object($title)) + throw new MWException( "No specifications provided to ArchivedFile constructor." ); } /** @@ -61,8 +72,19 @@ class ArchivedFile if ( $this->dataLoaded ) { return true; } - $conds = ($this->id) ? "fa_id = {$this->id}" : "fa_storage_key = '{$this->key}'"; - if( $this->title->getNamespace() == NS_IMAGE ) { + $conds = array(); + + if ($this->id>0) + $conds['fa_id'] = $this->id; + if ($this->key) + $conds['fa_storage_key'] = $this->key; + if ($this->title) + $conds['fa_name'] = $this->title->getDBkey(); + + if (!count($conds)) + throw new MWException( "No specific information for retrieving archived file" ); + + if( !$this->title || $this->title->getNamespace() == NS_IMAGE ) { $dbr = wfGetDB( DB_SLAVE ); $res = $dbr->select( 'filearchive', array( @@ -84,9 +106,7 @@ class ArchivedFile 'fa_user_text', 'fa_timestamp', 'fa_deleted' ), - array( - 'fa_name' => $this->title->getDBkey(), - $conds ), + $conds, __METHOD__, array( 'ORDER BY' => 'fa_timestamp DESC' ) ); diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 1624e13b2a..e56883b498 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -538,7 +538,7 @@ class UploadForm { $warning .= self::getExistsWarning( $this->mLocalFile ); } - $warning .= $this->getDupeWarning( $this->mTempPath ); + $warning .= $this->getDupeWarning( $this->mTempPath, $finalExt ); if( $warning != '' ) { /** @@ -745,9 +745,10 @@ class UploadForm { * Check for duplicate files and throw up a warning before the upload * completes. */ - function getDupeWarning( $tempfile ) { + function getDupeWarning( $tempfile, $extension ) { $hash = File::sha1Base36( $tempfile ); $dupes = RepoGroup::singleton()->findBySha1( $hash ); + $archivedImage = new ArchivedFile( null, 0, $hash.".$extension" ); if( $dupes ) { global $wgOut; $msg = ""; @@ -761,8 +762,12 @@ class UploadForm { wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) . $wgOut->parse( $msg ) . "\n"; + } elseif ( $archivedImage->getID() > 0 ) { + global $wgOut; + $name = Title::makeTitle( NS_IMAGE, $archivedImage->getName() )->getPrefixedText(); + return Xml::tags( 'li', null, wfMsgExt( 'file-deleted-duplicate', array( 'parseinline' ), array( $name ) ) ); } else { - return ''; + return 'FOOO'; } } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 124879b350..6b86e66178 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -1826,6 +1826,7 @@ If you still want to upload your file, please go back and use a new name. [[Imag 'fileexists-shared-forbidden' => 'A file with this name exists already in the shared file repository. If you still want to upload your file, please go back and use a new name. [[Image:$1|thumb|center|$1]]', 'file-exists-duplicate' => 'This file is a duplicate of the following {{PLURAL:$1|file|files}}:', +'file-deleted-duplicate' => "A file identical to this file ([[$1]]) has previously been deleted. You should check that file's deletion history before proceeding to re-upload it.", 'successfulupload' => 'Successful upload', 'uploadwarning' => 'Upload warning', 'savefile' => 'Save file', -- 2.20.1