/**#@-*/
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;
$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." );
}
/**
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(
'fa_user_text',
'fa_timestamp',
'fa_deleted' ),
- array(
- 'fa_name' => $this->title->getDBkey(),
- $conds ),
+ $conds,
__METHOD__,
array( 'ORDER BY' => 'fa_timestamp DESC' ) );
$warning .= self::getExistsWarning( $this->mLocalFile );
}
- $warning .= $this->getDupeWarning( $this->mTempPath );
+ $warning .= $this->getDupeWarning( $this->mTempPath, $finalExt );
if( $warning != '' ) {
/**
* 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>";
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';
}
}
'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',