From 93c667f039ffc19ed47e3eb381a3771e96c24711 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 28 Jun 2015 00:36:09 +0200 Subject: Add option to populate a gallery. If set, a new section of the given page is created with a gallery of the uploaded files. - add MediaWikiApi.appendToPage and MediaWikiInterface.addToGallery - require target file name to be set when calling MediaWikiInterface.uploadFile - calculate file name in MediaWikiExportServiceProvider.processRenderedPhotos insted of in ..., store it and pass it to MediaWikiInterface.addToGallery - add the gallery option to the export dialog in MediaWikiExportServiceProvider - update messages Fix #24. --- .../MediaWikiExportServiceProvider.lua | 34 +++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua') diff --git a/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua b/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua index f2ddfc3..b88e1b0 100755 --- a/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua +++ b/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua @@ -17,6 +17,7 @@ local LrDate = import 'LrDate' local LrDialogs = import 'LrDialogs' local LrErrors = import 'LrErrors' local LrFileUtils = import 'LrFileUtils' +local LrPathUtils = import 'LrPathUtils' local LrView = import 'LrView' local bind = LrView.bind @@ -59,6 +60,9 @@ MediaWikiExportServiceProvider.processRenderedPhotos = function(functionContext, MediaWikiInterface.prepareUpload(exportSettings.username, exportSettings.password, exportSettings.api_path) + -- file names for gallery creation + local fileNames = {} + -- iterate over photos for i, rendition in exportContext:renditions() do -- render photo @@ -108,7 +112,11 @@ MediaWikiExportServiceProvider.processRenderedPhotos = function(functionContext, local fileDescription = MediaWikiInterface.buildFileDescription(description, source, timestamp, author, license, templates, other, categories, additionalCategories, permission) - local message = MediaWikiInterface.uploadFile(pathOrMessage, fileDescription, hasDescription) + -- 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) + local fileName = string.gsub(LrPathUtils.leafName(pathOrMessage), '[ _]+', '_') + local message = MediaWikiInterface.uploadFile(pathOrMessage, fileDescription, hasDescription, fileName) if message then rendition:uploadFailed(message) else @@ -122,6 +130,9 @@ MediaWikiExportServiceProvider.processRenderedPhotos = function(functionContext, photo:createDevelopSnapshot(snapshotTitle, true) end) end + + -- file name for gallery creation + fileNames[#fileNames + 1] = fileName end LrFileUtils.delete(pathOrMessage) else @@ -129,6 +140,10 @@ MediaWikiExportServiceProvider.processRenderedPhotos = function(functionContext, rendition:uploadFailed(pathOrMessage) end end + + if (not MediaWikiUtils.isStringEmpty(exportSettings.gallery)) and fileNames then + MediaWikiInterface.addToGallery(fileNames, exportSettings.gallery) + end end MediaWikiExportServiceProvider.sectionsForTopOfDialog = function(viewFactory, propertyTable) @@ -193,6 +208,22 @@ MediaWikiExportServiceProvider.sectionsForTopOfDialog = function(viewFactory, pr title = LOC '$$$/LrMediaWiki/Section/User/ApiPath/Details=Path to the api.php file', }, }, + + viewFactory:row { + spacing = viewFactory:label_spacing(), + + viewFactory:static_text { + title = LOC '$$$/LrMediaWiki/Section/User/Gallery=Gallery', + alignment = labelAlignment, + width = LrView.share "label_width", + }, + + viewFactory:edit_field { + value = bind 'gallery', + immediate = true, + width_in_chars = widthLong, + }, + }, }, }, { @@ -371,6 +402,7 @@ MediaWikiExportServiceProvider.exportPresetFields = { { key = 'info_templates', default = '' }, { key = 'info_other', default = '' }, { key = 'info_categories', default = '' }, + { key = 'gallery', default = '' }, } return MediaWikiExportServiceProvider -- cgit v1.2.1