From e75ab2a20d770c23e1bae8b4258640f033f4f7db Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sat, 8 Nov 2014 18:53:29 +0100 Subject: Allow empty descriptions for reuploads There is no need for descriptions if an existing file is overwritten. Therefore the check and the error message are moved at a point where we know whether it is an initial upload or a reupload. - refactor MediaWikiInterface.uploadFile: - add the parameter hasDescription that describes whether there is a valid description - return a string (error message) if there is an error - store description status in MediaWikiExportServiceProvider.prepareUpload - check the return value of MediaWikiInterface.uploadFile in MediaWikiExportServiceProvider.prepareUpload Fix https://github.com/ireas/LrMediaWiki/issues/30 --- mediawiki.lrdevplugin/MediaWikiInterface.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'mediawiki.lrdevplugin/MediaWikiInterface.lua') diff --git a/mediawiki.lrdevplugin/MediaWikiInterface.lua b/mediawiki.lrdevplugin/MediaWikiInterface.lua index 2473406..5c68c1b 100755 --- a/mediawiki.lrdevplugin/MediaWikiInterface.lua +++ b/mediawiki.lrdevplugin/MediaWikiInterface.lua @@ -101,7 +101,7 @@ MediaWikiInterface._prompt = function(functionContext, title, label, default) return result end -MediaWikiInterface.uploadFile = function(filePath, description, fileName) +MediaWikiInterface.uploadFile = function(filePath, description, hasDescription, fileName) if not MediaWikiInterface.loggedIn then LrErrors.throwUserError(LOC '$$$/LrMediaWiki/Interface/Internal/NotLoggedIn=Internal error: not logged in before upload.') end @@ -119,17 +119,22 @@ MediaWikiInterface.uploadFile = function(filePath, description, fileName) 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) + MediaWikiInterface.uploadFile(filePath, description, hasDescription, newFileName) end return else return end + else + if not hasDescription then + return LOC '$$$/LrMediaWiki/Export/NoDescription=No description given for this file!' + end end local uploadResult = MediaWikiApi.upload(targetFileName, filePath, description, comment, ignorewarnings) if uploadResult ~= true then - LrErrors.throwUserError(LOC('$$$/LrMediaWiki/Interface/UploadFailed=Upload failed: ^1', uploadResult)) + return LOC('$$$/LrMediaWiki/Interface/UploadFailed=Upload failed: ^1', uploadResult) end + return nil end MediaWikiInterface.buildFileDescription = function(description, source, timestamp, author, license, templates, other, categories, additionalCategories, permission) -- cgit v1.2.1