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
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,
"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.",
"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}}",