aboutsummaryrefslogtreecommitdiff
path: root/mediawiki.lrdevplugin/MediaWikiInterface.lua
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2014-08-25 20:07:24 +0200
committerRobin Krahl <me@robin-krahl.de>2014-08-25 20:07:24 +0200
commit8deeb71274124b2c93a64b49dc3581cee4453cd9 (patch)
tree2bfd56057c0e1a5e0ab14ee8fe505e126d7c298f /mediawiki.lrdevplugin/MediaWikiInterface.lua
parentbec94fdb41dbb479b1128c864d9ccf736fa20bfc (diff)
downloadLrMediaWiki-8deeb71274124b2c93a64b49dc3581cee4453cd9.tar.gz
LrMediaWiki-8deeb71274124b2c93a64b49dc3581cee4453cd9.tar.bz2
Fix #5: Ask for comment for reuploads and #6: Allow new filenames for duplicates.
Diffstat (limited to 'mediawiki.lrdevplugin/MediaWikiInterface.lua')
-rwxr-xr-xmediawiki.lrdevplugin/MediaWikiInterface.lua57
1 files changed, 52 insertions, 5 deletions
diff --git a/mediawiki.lrdevplugin/MediaWikiInterface.lua b/mediawiki.lrdevplugin/MediaWikiInterface.lua
index 709129d..5201b2d 100755
--- a/mediawiki.lrdevplugin/MediaWikiInterface.lua
+++ b/mediawiki.lrdevplugin/MediaWikiInterface.lua
@@ -13,12 +13,15 @@
-- doc: missing
-- i18n: complete
+local LrBinding = import 'LrBinding'
local LrDialogs = import 'LrDialogs'
local LrErrors = import 'LrErrors'
+local LrFunctionContext = import 'LrFunctionContext'
local LrPathUtils = import 'LrPathUtils'
+local LrView = import 'LrView'
local MediaWikiApi = require 'MediaWikiApi'
-
+local MediaWikiUtils = require 'MediaWikiUtils'
local MediaWikiInterface = {
username = nil,
@@ -54,21 +57,65 @@ MediaWikiInterface.prepareUpload = function(username, password, apiPath)
end
end
-MediaWikiInterface.uploadFile = function(filePath, description)
+MediaWikiInterface.prompt = function(title, label, default)
+ return LrFunctionContext.callWithContext('MediaWikiInterface.prompt', function(context)
+ return MediaWikiInterface._prompt(context, title, label, default)
+ end)
+end
+
+MediaWikiInterface._prompt = function(functionContext, title, label, default)
+ local factory = LrView.osFactory()
+ local properties = LrBinding.makePropertyTable(functionContext)
+ properties.dialogValue = default
+ local contents = factory:row {
+ spacing = factory:label_spacing(),
+ bind_to_object = properties,
+ factory:static_text {
+ title = label,
+ },
+ factory:edit_field {
+ fill_horizontal = 1,
+ value = LrView.bind('dialogValue'),
+ width_in_chars = 20,
+ },
+ }
+ local dialogResult = LrDialogs.presentModalDialog({
+ title = title,
+ contents = contents,
+ })
+ local result = nil
+ if dialogResult == 'ok' then
+ result = properties.dialogValue
+ end
+ return result
+end
+
+MediaWikiInterface.uploadFile = function(filePath, description, fileName)
if not MediaWikiInterface.loggedIn then
LrErrors.throwUserError(LOC '$$$/LrMediaWiki/Interface/Internal/NotLoggedIn=Internal error: not logged in before upload.')
end
- local targetFileName = LrPathUtils.leafName(filePath)
+ local comment = 'Uploaded with LrMediaWiki'
+ local targetFileName = fileName or LrPathUtils.leafName(filePath)
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))
+ 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')
if continue == 'ok' then
+ local newComment = MediaWikiInterface.prompt(LOC '$$$/LrMediaWiki/Interface/VersionComment=Version comment', LOC '$$$/LrMediaWiki/Interface/VersionComment=Version comment')
+ if not MediaWikiUtils.isStringEmpty(newComment) then
+ comment = newComment .. ' (LrMediaWiki)'
+ end
ignorewarnings = true
+ elseif continue == 'other' then
+ local newFileName = MediaWikiInterface.prompt(LOC '$$$/LrMediaWiki/Interface/Rename=Rename file', LOC '$$$/LrMediaWiki/Interface/Rename/NewName=New file name', targetFileName)
+ if not MediaWikiUtils.isStringEmpty(newFileName) and newFileName ~= targetFileName then
+ MediaWikiInterface.uploadFile(filePath, description, newFileName)
+ end
+ return
else
return
end
end
- local uploadResult = MediaWikiApi.upload(targetFileName, filePath, description, 'Uploaded with LrMediaWiki', ignorewarnings)
+ local uploadResult = MediaWikiApi.upload(targetFileName, filePath, description, comment, ignorewarnings)
if uploadResult ~= true then
LrErrors.throwUserError(LOC('$$$/LrMediaWiki/Interface/UploadFailed=Upload failed: ^1', uploadResult))
end