If I drag a file onto the "drop files here", upload it, then I change the name of the file on my computer and drag it again again and upload, I do not get the duplicate file warning I get on the standard Special:Upload page. Would it be possible to enable this check?
Topic on Extension talk:MsUpload
I think you'd need to add a sha1 field to be passed to the imageinfo API [1] in the checkUploadWarning function [2]. In order to do this I think you'd need to compute the sha1 in the browser.
- [1] API docs for imageinfo: https://www.mediawiki.org/wiki/API:Imageinfo
- [2] https://github.com/wikimedia/mediawiki-extensions-MsUpload/blob/master/MsUpload.js#L97
Looking into this a bit more, there are two ways that it would be possible to determine if there are duplicate files on the server.
- Compute the sha1 hash in the browser, then use API:Allimages to find images with the same hash
- Upload the file with API:Upload with the "stash" property set to "1". This prevents it from uploading it to the file repository and keeps it stashed temporarily. It also returns any error messages, including if there are duplicate files. This is what Extension:UploadWizard does to check for duplicates.
Extension:MsUpload uses the Plupload library to handle uploads. I've attempted to generate a sha1 from files handled by Plupload using CryptoJS, but have not been able to accurately generate the hash. See this issue submitted to Plupload and this issue submitted to CrytoJS.
For uploading the file with `stash=1`, Plupload does not appear to have a method to upload a single file and perform a check. It only has the `start()` method (see methods) which uploads all files in the queue. It may be possible to modify MsUpload's onBeforeUpload method to add stash=1 to multipart_params, then run start(), check for errors, then be able to run start() again without stash=1 for the actual upload (assuming no errors). However, running start() once appears to do something to break Plupload. I have not dug deeply into this aspect.
I've forked the github repo for this and created a pull request with the changes required to enable duplicate checking. I'm going to let some people test it, then will submit a patch in gerrit. Github is just easier for me to work with. PR is here: https://github.com/jamesmontalvo3/mediawiki-extensions-MsUpload/pull/1