From 621a3f63c150b79c3ca996b4ad96d7267bca7e42 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sat, 27 Jun 2015 14:41:34 +0200 Subject: Avoid multiple spaces or underscores in file names. If the image title contains consecutive spaces or underscores, the upload fails without a proper error message. Therefore LrMediaWiki now replaces all (single or multiple) spaces and underscores by a single underscore. - add replacement rule to MediaWikiInterface.uploadFile Fix #37. --- mediawiki.lrdevplugin/MediaWikiInterface.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mediawiki.lrdevplugin/MediaWikiInterface.lua b/mediawiki.lrdevplugin/MediaWikiInterface.lua index 5c68c1b..f2394cc 100755 --- a/mediawiki.lrdevplugin/MediaWikiInterface.lua +++ b/mediawiki.lrdevplugin/MediaWikiInterface.lua @@ -107,6 +107,12 @@ MediaWikiInterface.uploadFile = function(filePath, description, hasDescription, end local comment = 'Uploaded with LrMediaWiki ' .. MediaWikiUtils.getVersionString() local targetFileName = fileName or LrPathUtils.leafName(filePath) + + -- ensure that the target file name does not contain a series of spaces or + -- underscores (as this would cause the upload to fail without a proper + -- error message) + targetFileName = string.gsub(targetFileName, '[ _]+', '_') + local ignorewarnings = false if MediaWikiApi.existsFile(targetFileName) then local continue = LrDialogs.confirm(LOC '$$$/LrMediaWiki/Interface/InUse=File name already in use', LOC('$$$/LrMediaWiki/Interface/InUse/Details=There already is a file with the name ^1. Overwrite? (File description won\'t be changed.)', targetFileName), LOC '$$$/LrMediaWiki/Interface/InUse/OK=Overwrite', LOC '$$$/LrMediaWiki/Interface/InUse/Cancel=Cancel', LOC '$$$/LrMediaWiki/Interface/InUse/Rename=Rename') -- cgit v1.2.1