jenkins-bot has submitted this change and it was merged.

Change subject: RevertAction: Prevent file revert if current version is 
identical
......................................................................


RevertAction: Prevent file revert if current version is identical

There are several reasons for this:

* The file thumbnail shown on the main file page is cached by the
  browser, as images tend to be. This often confuses users into
  thinking their revert did not work, and into attempting it again.
  Recent examples:
  * 
https://commons.wikimedia.org/wiki/Commons:Village_pump/Archive/2016/07#Wrong_SVG_rendering_on_File:DuckDuckGo_logo_and_wordmark.svg
  * 
https://commons.wikimedia.org/w/index.php?title=Commons:Upload_help&oldid=205348523#Reversion_is_not_working_for_me.
  Ideally we'd prevent the caching, but preventing repeated reverts
  should also work.

* Refreshing the success page causes the revert to be attempted again
  (T53383). The usual solution to this is the Post/Redirect/Get
  pattern, but we want to show a success message so that would require
  some more changes (something similar to the post-edit notification).

* It can serve as a "revert conflict" detection mechanism, crude but
  better than none.

In the unlikely case that uploading an identical older version of
the file is necessary, it can still be done using Special:Upload.

Bug: T53383
Change-Id: I37e04a536c5c2fc6cdbe59f6f598bb0c7f25d7a7
---
M includes/actions/RevertAction.php
M languages/i18n/en.json
M languages/i18n/qqq.json
3 files changed, 12 insertions(+), 4 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/actions/RevertAction.php 
b/includes/actions/RevertAction.php
index c800ce7..e466e65 100644
--- a/includes/actions/RevertAction.php
+++ b/includes/actions/RevertAction.php
@@ -112,13 +112,19 @@
        public function onSubmit( $data ) {
                $this->useTransactionalTimeLimit();
 
-               $source = $this->page->getFile()->getArchiveVirtualUrl(
-                       $this->getRequest()->getText( 'oldimage' )
-               );
+               $old = $this->getRequest()->getText( 'oldimage' );
+               $localFile = $this->page->getFile();
+               $oldFile = OldLocalFile::newFromArchiveName( $this->getTitle(), 
$localFile->getRepo(), $old );
+
+               $source = $localFile->getArchiveVirtualUrl( $old );
                $comment = $data['comment'];
 
+               if ( $localFile->getSha1() === $oldFile->getSha1() ) {
+                       return Status::newFatal( 'filerevert-identical' );
+               }
+
                // TODO: Preserve file properties from database instead of 
reloading from file
-               return $this->page->getFile()->upload(
+               return $localFile->upload(
                        $source,
                        $comment,
                        $comment,
diff --git a/languages/i18n/en.json b/languages/i18n/en.json
index dcd3981..bcd740c 100644
--- a/languages/i18n/en.json
+++ b/languages/i18n/en.json
@@ -1682,6 +1682,7 @@
        "filerevert-submit": "Revert",
        "filerevert-success": "<strong>[[Media:$1|$1]]</strong> has been 
reverted to the [$4 version as of $3, $2].",
        "filerevert-badversion": "There is no previous local version of this 
file with the provided timestamp.",
+       "filerevert-identical": "The current version of the file is already 
identical to the selected one.",
        "filedelete": "Delete $1",
        "filedelete-legend": "Delete file",
        "filedelete-intro": "You are about to delete the file 
<strong>[[Media:$1|$1]]</strong> along with all of its history.",
diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json
index 48f2013..655ddfa 100644
--- a/languages/i18n/qqq.json
+++ b/languages/i18n/qqq.json
@@ -1865,6 +1865,7 @@
        "filerevert-submit": "{{Identical|Revert}}",
        "filerevert-success": "Message displayed when you succeed in reverting 
a version of a file.\n* $1 is the name of the media\n* $2 is a date\n* $3 is a 
time\n* $4 is an URL and must follow square bracket: [$4\n{{Identical|Revert}}",
        "filerevert-badversion": "Used as error message.",
+       "filerevert-identical": "Used as error message.",
        "filedelete": "Used as page title. Parameters:\n* $1 - file title\nSee 
also:\n* {{msg-mw|Filedelete-intro}}",
        "filedelete-legend": "Used as fieldset label in the \"Delete file\" 
form.\n{{Identical|Delete file}}",
        "filedelete-intro": "Used as introduction for FileDelete form. 
Parameters:\n* $1 - page title for file\nSee also:\n* {{msg-mw|Filedelete|page 
title}}",

-- 
To view, visit https://gerrit.wikimedia.org/r/308075
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I37e04a536c5c2fc6cdbe59f6f598bb0c7f25d7a7
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Bartosz Dziewoński <matma....@gmail.com>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Matthias Mullie <mmul...@wikimedia.org>
Gerrit-Reviewer: Siebrand <siebr...@kitano.nl>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to