Revision: 43658
Author: werdna
Date: 2008-11-18 02:20:55 +0000 (Tue, 18 Nov 2008)
Log Message:
-----------
Warn when re-uploading a file with the same SHA1/extension pair as a file which
has been deleted.
Modified Paths:
--------------
trunk/phase3/includes/filerepo/ArchivedFile.php
trunk/phase3/includes/specials/SpecialUpload.php
trunk/phase3/languages/messages/MessagesEn.php
Modified: trunk/phase3/includes/filerepo/ArchivedFile.php
===================================================================
--- trunk/phase3/includes/filerepo/ArchivedFile.php 2008-11-18 02:03:44 UTC
(rev 43657)
+++ trunk/phase3/includes/filerepo/ArchivedFile.php 2008-11-18 02:20:55 UTC
(rev 43658)
@@ -30,12 +30,9 @@
/[EMAIL PROTECTED]/
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 @@
$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 @@
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 @@
'fa_user_text',
'fa_timestamp',
'fa_deleted' ),
- array(
- 'fa_name' => $this->title->getDBkey(),
- $conds ),
+ $conds,
__METHOD__,
array( 'ORDER BY' => 'fa_timestamp DESC' ) );
Modified: trunk/phase3/includes/specials/SpecialUpload.php
===================================================================
--- trunk/phase3/includes/specials/SpecialUpload.php 2008-11-18 02:03:44 UTC
(rev 43657)
+++ trunk/phase3/includes/specials/SpecialUpload.php 2008-11-18 02:20:55 UTC
(rev 43658)
@@ -538,7 +538,7 @@
$warning .= self::getExistsWarning(
$this->mLocalFile );
}
- $warning .= $this->getDupeWarning( $this->mTempPath );
+ $warning .= $this->getDupeWarning( $this->mTempPath,
$finalExt );
if( $warning != '' ) {
/**
@@ -745,9 +745,10 @@
* 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 @@
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';
}
}
Modified: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php 2008-11-18 02:03:44 UTC
(rev 43657)
+++ trunk/phase3/languages/messages/MessagesEn.php 2008-11-18 02:20:55 UTC
(rev 43658)
@@ -1826,6 +1826,7 @@
'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',
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs