Warn when re-uploading a file with the same SHA1/extension pair as a file which has been deleted.
This commit is contained in:
parent
c051c32755
commit
9903a86e68
3 changed files with 39 additions and 13 deletions
|
|
@ -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' ) );
|
||||
|
||||
|
|
|
|||
|
|
@ -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 = "<gallery>";
|
||||
|
|
@ -761,8 +762,12 @@ class UploadForm {
|
|||
wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
|
||||
$wgOut->parse( $msg ) .
|
||||
"</li>\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';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Reference in a new issue