aboutsummaryrefslogtreecommitdiff
path: root/mediawiki.lrdevplugin
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2015-06-27 14:41:34 +0200
committerRobin Krahl <me@robin-krahl.de>2015-06-27 14:41:34 +0200
commit621a3f63c150b79c3ca996b4ad96d7267bca7e42 (patch)
treebef29cd2c557612852017c10935222dbc7b2592e /mediawiki.lrdevplugin
parentcfa0bc1bec50e2054403c69997233388e5216e72 (diff)
downloadLrMediaWiki-621a3f63c150b79c3ca996b4ad96d7267bca7e42.tar.gz
LrMediaWiki-621a3f63c150b79c3ca996b4ad96d7267bca7e42.tar.bz2
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.
Diffstat (limited to 'mediawiki.lrdevplugin')
-rwxr-xr-xmediawiki.lrdevplugin/MediaWikiInterface.lua6
1 files changed, 6 insertions, 0 deletions
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')