From: Matthias Mullie Date: Wed, 24 Aug 2016 07:29:24 +0000 (+0200) Subject: Add API warnings when upload is same as older versions X-Git-Tag: 1.31.0-rc.0~5747^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles%22%2C%22id_article=%24ze_article%22%29%20.%20%22?a=commitdiff_plain;h=4e50971b32468339b388fb1015b21058338d2d8f;p=lhc%2Fweb%2Fwiklou.git Add API warnings when upload is same as older versions Bug: T141822 Change-Id: I115d84d865c59200dbb60bd962c093185c9afafe --- diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index 54d3c3c30b..7b44f40993 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -704,6 +704,30 @@ class ApiUpload extends ApiBase { : $warning['file']; $warnings[$warning['warning']] = $localFile->getName(); } + + if ( isset( $warnings['no-change'] ) ) { + /** @var File $file */ + $file = $warnings['no-change']; + unset( $warnings['no-change'] ); + + $warnings['nochange'] = [ + 'timestamp' => wfTimestamp( TS_ISO_8601, $file->getTimestamp() ) + ]; + } + + if ( isset( $warnings['duplicate-version'] ) ) { + $dupes = []; + /** @var File $dupe */ + foreach ( $warnings['duplicate-version'] as $dupe ) { + $dupes[] = [ + 'timestamp' => wfTimestamp( TS_ISO_8601, $dupe->getTimestamp() ) + ]; + } + unset( $warnings['duplicate-version'] ); + + ApiResult::setIndexedTagName( $dupes, 'ver' ); + $warnings['duplicateversions'] = $dupes; + } } return $warnings; diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index 6ca1100a75..305c0e9fff 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -394,6 +394,18 @@ class SpecialUpload extends SpecialPage { } if ( $warning == 'exists' ) { $msg = "\t
  • " . self::getExistsWarning( $args ) . "
  • \n"; + } elseif ( $warning == 'no-change' ) { + $file = $args; + $filename = $file->getTitle()->getPrefixedText(); + $msg = "\t
  • " . wfMessage( 'fileexists-no-change', $filename )->parse() . "
  • \n"; + } elseif ( $warning == 'duplicate-version' ) { + $file = $args[0]; + $count = count( $args ); + $filename = $file->getTitle()->getPrefixedText(); + $message = wfMessage( 'fileexists-duplicate-version' ) + ->params( $filename ) + ->numParams( $count ); + $msg = "\t
  • " . $message->parse() . "
  • \n"; } elseif ( $warning == 'was-deleted' ) { # If the file existed before and was deleted, warn the user of this $ltitle = SpecialPage::getTitleFor( 'Log' ); diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index b37c83104e..1be5c24fe4 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -679,9 +679,23 @@ abstract class UploadBase { $warnings['empty-file'] = true; } + $hash = $this->getTempFileSha1Base36(); $exists = self::getExistsWarning( $localFile ); if ( $exists !== false ) { $warnings['exists'] = $exists; + + // check if file is an exact duplicate of current file version + if ( $hash === $localFile->getSha1() ) { + $warnings['no-change'] = $localFile; + } + + // check if file is an exact duplicate of older versions of this file + $history = $localFile->getHistory(); + foreach ( $history as $oldFile ) { + if ( $hash === $oldFile->getSha1() ) { + $warnings['duplicate-version'][] = $oldFile; + } + } } if ( $localFile->wasDeleted() && !$localFile->exists() ) { @@ -689,7 +703,6 @@ abstract class UploadBase { } // Check dupes against existing files - $hash = $this->getTempFileSha1Base36(); $dupes = RepoGroup::singleton()->findBySha1( $hash ); $title = $this->getTitle(); // Remove all matches against self diff --git a/languages/i18n/en.json b/languages/i18n/en.json index dcd398154e..ecc1f54c13 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -1466,6 +1466,8 @@ "file-thumbnail-no": "The filename begins with $1.\nIt seems to be an image of reduced size (thumbnail).\nIf you have this image in full resolution upload this one, otherwise change the filename please.", "fileexists-forbidden": "A file with this name already exists, and cannot be overwritten.\nIf you still want to upload your file, please go back and use a new name.\n[[File:$1|thumb|center|$1]]", "fileexists-shared-forbidden": "A file with this name exists already in the shared file repository.\nIf you still want to upload your file, please go back and use a new name.\n[[File:$1|thumb|center|$1]]", + "fileexists-no-change": "The upload is an exact duplicate of the current version of [[:$1]].", + "fileexists-duplicate-version": "The upload is an exact duplicate of {{PLURAL:$2|an older version|older versions}} of [[:$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.\nYou should check that file's deletion history before proceeding to re-upload it.", "file-deleted-duplicate-notitle": "A file identical to this file has previously been deleted, and the title has been suppressed.\nYou should ask someone with the ability to view suppressed file data to review the situation before proceeding to re-upload it.", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 48f2013056..3aae0f9cc5 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -1649,6 +1649,8 @@ "file-thumbnail-no": "Error message at [[Special:Upload]]. Parameters:\n* $1 - String (e.g. \"180px-\")", "fileexists-forbidden": "{{doc-important|''thumb'' and ''center'' are magic words. Leave it untranslated!}}\nParameters:\n* $1 - name of the existing file", "fileexists-shared-forbidden": "{{doc-important|''thumb'' and ''center'' are magic words. Leave it untranslated!}}\nError message at [[Special:Upload]].\nParameters:\n* $1 - name of the existing file", + "fileexists-no-change": "Used in [[Special:Upload]] to warn when the upload is an exact duplicate of the current version of the file.\nParameters:\n* $1 - name of the existing file", + "fileexists-duplicate-version": "Used in [[Special:Upload]] to warn when the upload is an exact duplicate of (an) older version(s) of the file\nParameters:\n* $1 - name of the existing file\n* $2 - Amount of matching older versions (PLURAL support)", "file-exists-duplicate": "Used as warning in [[Special:Upload]].\nThis message is followed by the gallery of the duplicate files.\n\nParameters:\n* $1 - number of duplicate files", "file-deleted-duplicate": "Used in [[Special:Upload]. Parameters:\n* $1 - page title of the file\n\nSee also:\n* {{msg-mw|file-deleted-duplicate-notitle}}", "file-deleted-duplicate-notitle": "Used in [[Special:Upload]] when the title of the deleted duplicate is not available.\n\nSee also:\n* {{msg-mw|file-deleted-duplicate}}",