aboutsummaryrefslogtreecommitdiff
path: root/mediawiki.lrdevplugin
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
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')
-rwxr-xr-xmediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua27
-rwxr-xr-xmediawiki.lrdevplugin/MediaWikiInterface.lua57
-rw-r--r--mediawiki.lrdevplugin/MediaWikiUtils.lua22
-rwxr-xr-xmediawiki.lrdevplugin/TranslatedStrings_de.txt60
4 files changed, 119 insertions, 47 deletions
diff --git a/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua b/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua
index 81f9839..bd903f5 100755
--- a/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua
+++ b/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua
@@ -22,13 +22,10 @@ local bind = LrView.bind
local Info = require 'Info'
local MediaWikiInterface = require 'MediaWikiInterface'
+local MediaWikiUtils = require 'MediaWikiUtils'
local MediaWikiExportServiceProvider = {}
-local isStringEmpty = function(str)
- return str == nil or string.match(str, '^%s*$') ~= nil
-end
-
MediaWikiExportServiceProvider.processRenderedPhotos = function(functionContext, exportContext)
-- configure progess display
local exportSession = exportContext.exportSession
@@ -40,22 +37,22 @@ MediaWikiExportServiceProvider.processRenderedPhotos = function(functionContext,
local exportSettings = assert(exportContext.propertyTable)
-- require username, password, apipath, license, author, source
- if isStringEmpty(exportSettings.username) then
+ if MediaWikiUtils.isStringEmpty(exportSettings.username) then
LrErrors.throwUserError(LOC '$$$/LrMediaWiki/Export/NoUsername=No username given!')
end
- if isStringEmpty(exportSettings.password) then
+ if MediaWikiUtils.isStringEmpty(exportSettings.password) then
LrErrors.throwUserError(LOC '$$$/LrMediaWiki/Export/NoPassword=No password given!')
end
- if isStringEmpty(exportSettings.api_path) then
+ if MediaWikiUtils.isStringEmpty(exportSettings.api_path) then
LrErrors.throwUserError(LOC '$$$/LrMediaWiki/Export/NoApiPath=No API path given!')
end
- if isStringEmpty(exportSettings.info_license) then
+ if MediaWikiUtils.isStringEmpty(exportSettings.info_license) then
LrErrors.throwUserError(LOC '$$$/LrMediaWiki/Export/NoLicense=No license given!')
end
- if isStringEmpty(exportSettings.info_author) then
+ if MediaWikiUtils.isStringEmpty(exportSettings.info_author) then
LrErrors.throwUserError(LOC '$$$/LrMediaWiki/Export/NoAuthor=No author given!')
end
- if isStringEmpty(exportSettings.info_source) then
+ if MediaWikiUtils.isStringEmpty(exportSettings.info_source) then
LrErrors.throwUserError(LOC '$$$/LrMediaWiki/Export/NoSource=No source given!')
end
@@ -73,16 +70,16 @@ MediaWikiExportServiceProvider.processRenderedPhotos = function(functionContext,
local descriptionDe = photo:getPropertyForPlugin(Info.LrToolkitIdentifier, 'description_de')
local descriptionAdditional = photo:getPropertyForPlugin(Info.LrToolkitIdentifier, 'description_additional')
local description = ''
- if not isStringEmpty(descriptionEn) then
+ if not MediaWikiUtils.isStringEmpty(descriptionEn) then
description = '{{en|1=' .. descriptionEn .. '}}\n'
end
- if not isStringEmpty(descriptionDe) then
+ if not MediaWikiUtils.isStringEmpty(descriptionDe) then
description = description .. '{{de|1=' .. descriptionDe .. '}}\n'
end
- if not isStringEmpty(descriptionAdditional) then
+ if not MediaWikiUtils.isStringEmpty(descriptionAdditional) then
description = description .. descriptionAdditional
end
- if isStringEmpty(description) then
+ if MediaWikiUtils.isStringEmpty(description) then
rendition:uploadFailed(LOC '$$$/LrMediaWiki/Export/NoDescription=No description given for this file!')
end
local source = exportSettings.info_source
@@ -95,7 +92,7 @@ MediaWikiExportServiceProvider.processRenderedPhotos = function(functionContext,
local license = exportSettings.info_license
local other = exportSettings.info_other
local categories = exportSettings.info_categories
- local additionalCategories = photo:getPropertyForPlugin(Info.LrToolkitIdentifier, 'categories')
+ local additionalCategories = photo:getPropertyForPlugin(Info.LrToolkitIdentifier, 'categories') or ''
local fileDescription = MediaWikiInterface.buildFileDescription(description, source, timestamp, author, license, other, categories, additionalCategories)
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
diff --git a/mediawiki.lrdevplugin/MediaWikiUtils.lua b/mediawiki.lrdevplugin/MediaWikiUtils.lua
new file mode 100644
index 0000000..6093b8a
--- /dev/null
+++ b/mediawiki.lrdevplugin/MediaWikiUtils.lua
@@ -0,0 +1,22 @@
+-- This file is part of the LrMediaWiki project and distributed under the terms
+-- of the MIT license (see LICENSE.txt file in the project root directory or
+-- [0]). See [1] for more information about LrMediaWiki.
+--
+-- Copyright (C) 2014 by the LrMediaWiki team (see CREDITS.txt file in the
+-- project root directory or [2])
+--
+-- [0] <https://raw.githubusercontent.com/LrMediaWiki/LrMediaWiki/master/LICENSE.txt>
+-- [1] <https://commons.wikimedia.org/wiki/Commons:LrMediaWiki>
+-- [2] <https://raw.githubusercontent.com/LrMediaWiki/LrMediaWiki/master/CREDITS.txt>
+
+-- Code status:
+-- doc: missing
+-- i18n: complete
+
+local MediaWikiUtils = {}
+
+MediaWikiUtils.isStringEmpty = function(str)
+ return str == nil or string.match(str, '^%s*$') ~= nil
+end
+
+return MediaWikiUtils \ No newline at end of file
diff --git a/mediawiki.lrdevplugin/TranslatedStrings_de.txt b/mediawiki.lrdevplugin/TranslatedStrings_de.txt
index 716fba7..a2b574e 100755
--- a/mediawiki.lrdevplugin/TranslatedStrings_de.txt
+++ b/mediawiki.lrdevplugin/TranslatedStrings_de.txt
@@ -1,35 +1,41 @@
-"$$$/LrMediaWiki/PluginName=MediaWiki für Lightroom"
-"$$$/LrMediaWiki/MediaWiki=MediaWiki"
-"$$$/LrMediaWiki/Export/Progress=Exportiere ^1 Bilder in ein MediaWiki"
-"$$$/LrMediaWiki/Export/Progress/One=Exportiere ein Bild in ein MediaWiki"
-"$$$/LrMediaWiki/Export/NoUsername=Kein Benutzername angegeben!"
-"$$$/LrMediaWiki/Export/NoPassword=Keine Passwort angegeben!"
+"$$$/LrMediaWiki/Api/HttpError=HTTP-Status ^1 erhalten."
+"$$$/LrMediaWiki/Api/MediaWikiError=Der MediaWiki-Fehler ^1 ist aufgetreten: ^2"
"$$$/LrMediaWiki/Export/NoApiPath=Kein API-Pfad angegeben!"
-"$$$/LrMediaWiki/Export/NoLicense=Keine Lizenz angegeben!"
"$$$/LrMediaWiki/Export/NoAuthor=Kein Urheber angegeben!"
-"$$$/LrMediaWiki/Export/NoSource=Keine Quelle angegeben!"
"$$$/LrMediaWiki/Export/NoDescription=Für diese Datei ist keine Beschreibung angegeben!"
-"$$$/LrMediaWiki/Section/User/Title=Login-Informationen"
-"$$$/LrMediaWiki/Section/User/Username=Benutzername"
-"$$$/LrMediaWiki/Section/User/Password=Passwort"
-"$$$/LrMediaWiki/Section/User/ApiPath=API-Pfad"
-"$$$/LrMediaWiki/Section/User/ApiPath/Details=Pfad zur api.php-Datei"
-"$$$/LrMediaWiki/Section/Licensing/Title=Upload-Informationen"
-"$$$/LrMediaWiki/Section/Licensing/Source=Quelle"
-"$$$/LrMediaWiki/Section/Licensing/Author=Urheber"
-"$$$/LrMediaWiki/Section/Licensing/License=Lizenz"
-"$$$/LrMediaWiki/Section/Licensing/Other=Andere Felder"
-"$$$/LrMediaWiki/Section/Licensing/Categories=Kategorien"
-"$$$/LrMediaWiki/Section/Licensing/Categories/Details=mit ; trennen"
-"$$$/LrMediaWiki/Api/HttpError=HTTP-Status ^1 erhalten."
-"$$$/LrMediaWiki/Api/MediaWikiError=Der MediaWiki-Fehler ^1 ist aufgetreten: ^2"
-"$$$/LrMediaWiki/Interface/LoginFailed=Login fehlgeschlagen: ^1."
-"$$$/LrMediaWiki/Interface/UsernameOrPasswordMissing=Nutzername oder Password nicht angegeben
+"$$$/LrMediaWiki/Export/NoLicense=Keine Lizenz angegeben!"
+"$$$/LrMediaWiki/Export/NoPassword=Keine Passwort angegeben!"
+"$$$/LrMediaWiki/Export/NoSource=Keine Quelle angegeben!"
+"$$$/LrMediaWiki/Export/NoUsername=Kein Benutzername angegeben!"
+"$$$/LrMediaWiki/Export/Progress/One=Exportiere ein Bild in ein MediaWiki"
+"$$$/LrMediaWiki/Export/Progress=Exportiere ^1 Bilder in ein MediaWiki"
"$$$/LrMediaWiki/Interface/Internal/NotLoggedIn=Interner Fehler: vor dem Upload nicht angemeldet."
-"$$$/LrMediaWiki/Interface/InUse=Dateiname schon verwendet"
+"$$$/LrMediaWiki/Interface/InUse/Cancel=Abbrechen"
"$$$/LrMediaWiki/Interface/InUse/Details=Es gibt bereits eine Datei mit dem Namen ^1. Überschreiben? (Die Dateibeschreibung wird nicht verändert.)"
+"$$$/LrMediaWiki/Interface/InUse/OK=Überschreiben"
+"$$$/LrMediaWiki/Interface/InUse/Rename=Umbenennen"
+"$$$/LrMediaWiki/Interface/InUse=Dateiname schon verwendet"
+"$$$/LrMediaWiki/Interface/LoginFailed=Login fehlgeschlagen: ^1."
+"$$$/LrMediaWiki/Interface/Rename/NewName=Neuer Dateiname"
+"$$$/LrMediaWiki/Interface/Rename=Datei umbenennen"
"$$$/LrMediaWiki/Interface/UploadFailed=Upload fehlgeschlagen: ^1"
+"$$$/LrMediaWiki/Interface/UsernameOrPasswordMissing=Nutzername oder Password nicht angegeben
+"$$$/LrMediaWiki/Interface/VersionComment=Versionskommentar"
+"$$$/LrMediaWiki/MediaWiki=MediaWiki"
"$$$/LrMediaWiki/Metadata/Categories=Kategorien"
-"$$$/LrMediaWiki/Metadata/DescriptionEn=Beschreibung (en)"
+"$$$/LrMediaWiki/Metadata/DescriptionAdditional=Beschreibung (andere)"
"$$$/LrMediaWiki/Metadata/DescriptionDe=Beschreibung (de)"
-"$$$/LrMediaWiki/Metadata/DescriptionAdditional=Beschreibung (andere)" \ No newline at end of file
+"$$$/LrMediaWiki/Metadata/DescriptionEn=Beschreibung (en)"
+"$$$/LrMediaWiki/PluginName=MediaWiki für Lightroom"
+"$$$/LrMediaWiki/Section/Licensing/Author=Urheber"
+"$$$/LrMediaWiki/Section/Licensing/Categories/Details=mit ; trennen"
+"$$$/LrMediaWiki/Section/Licensing/Categories=Kategorien"
+"$$$/LrMediaWiki/Section/Licensing/License=Lizenz"
+"$$$/LrMediaWiki/Section/Licensing/Other=Andere Felder"
+"$$$/LrMediaWiki/Section/Licensing/Source=Quelle"
+"$$$/LrMediaWiki/Section/Licensing/Title=Upload-Informationen"
+"$$$/LrMediaWiki/Section/User/ApiPath/Details=Pfad zur api.php-Datei"
+"$$$/LrMediaWiki/Section/User/ApiPath=API-Pfad"
+"$$$/LrMediaWiki/Section/User/Password=Passwort"
+"$$$/LrMediaWiki/Section/User/Title=Login-Informationen"
+"$$$/LrMediaWiki/Section/User/Username=Benutzername" \ No newline at end of file