r43658 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43657‎ | r43658 | r43659 >
Date:02:20, 18 November 2008
Author:werdna
Status:ok
Tags:
Comment:
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 (modified) (history)
  • /trunk/phase3/includes/specials/SpecialUpload.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/ArchivedFile.php
@@ -30,12 +30,9 @@
3131 /**#@-*/
3232
3333 function ArchivedFile( $title, $id=0, $key='' ) {
34 - if( !is_object($title) ) {
35 - throw new MWException( 'ArchivedFile constructor given bogus title.' );
36 - }
3734 $this->id = -1;
38 - $this->title = $title;
39 - $this->name = $title->getDBkey();
 35+ $this->title = false;
 36+ $this->name = false;
4037 $this->group = '';
4138 $this->key = '';
4239 $this->size = 0;
@@ -51,6 +48,20 @@
5249 $this->timestamp = NULL;
5350 $this->deleted = 0;
5451 $this->dataLoaded = false;
 52+
 53+ if( is_object($title) ) {
 54+ $this->title = $title;
 55+ $this->name = $title->getDBkey();
 56+ }
 57+
 58+ if ($id)
 59+ $this->id = $id;
 60+
 61+ if ($key)
 62+ $this->key = $key;
 63+
 64+ if (!$id && !$key && !is_object($title))
 65+ throw new MWException( "No specifications provided to ArchivedFile constructor." );
5566 }
5667
5768 /**
@@ -61,8 +72,19 @@
6273 if ( $this->dataLoaded ) {
6374 return true;
6475 }
65 - $conds = ($this->id) ? "fa_id = {$this->id}" : "fa_storage_key = '{$this->key}'";
66 - if( $this->title->getNamespace() == NS_IMAGE ) {
 76+ $conds = array();
 77+
 78+ if ($this->id>0)
 79+ $conds['fa_id'] = $this->id;
 80+ if ($this->key)
 81+ $conds['fa_storage_key'] = $this->key;
 82+ if ($this->title)
 83+ $conds['fa_name'] = $this->title->getDBkey();
 84+
 85+ if (!count($conds))
 86+ throw new MWException( "No specific information for retrieving archived file" );
 87+
 88+ if( !$this->title || $this->title->getNamespace() == NS_IMAGE ) {
6789 $dbr = wfGetDB( DB_SLAVE );
6890 $res = $dbr->select( 'filearchive',
6991 array(
@@ -84,9 +106,7 @@
85107 'fa_user_text',
86108 'fa_timestamp',
87109 'fa_deleted' ),
88 - array(
89 - 'fa_name' => $this->title->getDBkey(),
90 - $conds ),
 110+ $conds,
91111 __METHOD__,
92112 array( 'ORDER BY' => 'fa_timestamp DESC' ) );
93113
Index: trunk/phase3/includes/specials/SpecialUpload.php
@@ -538,7 +538,7 @@
539539 $warning .= self::getExistsWarning( $this->mLocalFile );
540540 }
541541
542 - $warning .= $this->getDupeWarning( $this->mTempPath );
 542+ $warning .= $this->getDupeWarning( $this->mTempPath, $finalExt );
543543
544544 if( $warning != '' ) {
545545 /**
@@ -745,9 +745,10 @@
746746 * Check for duplicate files and throw up a warning before the upload
747747 * completes.
748748 */
749 - function getDupeWarning( $tempfile ) {
 749+ function getDupeWarning( $tempfile, $extension ) {
750750 $hash = File::sha1Base36( $tempfile );
751751 $dupes = RepoGroup::singleton()->findBySha1( $hash );
 752+ $archivedImage = new ArchivedFile( null, 0, $hash.".$extension" );
752753 if( $dupes ) {
753754 global $wgOut;
754755 $msg = "<gallery>";
@@ -761,8 +762,12 @@
762763 wfMsgExt( "file-exists-duplicate", array( "parse" ), count( $dupes ) ) .
763764 $wgOut->parse( $msg ) .
764765 "</li>\n";
 766+ } elseif ( $archivedImage->getID() > 0 ) {
 767+ global $wgOut;
 768+ $name = Title::makeTitle( NS_IMAGE, $archivedImage->getName() )->getPrefixedText();
 769+ return Xml::tags( 'li', null, wfMsgExt( 'file-deleted-duplicate', array( 'parseinline' ), array( $name ) ) );
765770 } else {
766 - return '';
 771+ return 'FOOO';
767772 }
768773 }
769774
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -1826,6 +1826,7 @@
18271827 'fileexists-shared-forbidden' => 'A file with this name exists already in the shared file repository.
18281828 If you still want to upload your file, please go back and use a new name. [[Image:$1|thumb|center|$1]]',
18291829 'file-exists-duplicate' => 'This file is a duplicate of the following {{PLURAL:$1|file|files}}:',
 1830+'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.",
18301831 'successfulupload' => 'Successful upload',
18311832 'uploadwarning' => 'Upload warning',
18321833 'savefile' => 'Save file',

Follow-up revisions

RevisionCommit summaryAuthorDate
r43666Update per r43658 and r43661raymond08:11, 18 November 2008

Status & tagging log