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. --- mediawiki.lrdevplugin/MediaWikiInterface.lua | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'mediawiki.lrdevplugin/MediaWikiInterface.lua') diff --git a/mediawiki.lrdevplugin/MediaWikiInterface.lua b/mediawiki.lrdevplugin/MediaWikiInterface.lua index dbae6ed..34fc249 100755 --- a/mediawiki.lrdevplugin/MediaWikiInterface.lua +++ b/mediawiki.lrdevplugin/MediaWikiInterface.lua @@ -14,10 +14,10 @@ -- i18n: complete local LrBinding = import 'LrBinding' +local LrDate = import 'LrDate' local LrDialogs = import 'LrDialogs' local LrErrors = import 'LrErrors' local LrFunctionContext = import 'LrFunctionContext' -local LrPathUtils = import 'LrPathUtils' local LrView = import 'LrView' local MediaWikiApi = require 'MediaWikiApi' @@ -101,17 +101,25 @@ MediaWikiInterface._prompt = function(functionContext, title, label, default) return result end -MediaWikiInterface.uploadFile = function(filePath, description, hasDescription, fileName) +MediaWikiInterface.addToGallery = function(fileNames, galleryName) + local currentTimeStamp = LrDate.currentTime() + local currentDate = LrDate.formatShortDate(currentTimeStamp) + local currentTime = LrDate.formatShortTime(currentTimeStamp) + local section = '== ' .. currentDate .. ' ' .. currentTime .. ' =='; + local text = '\n'; + for i, fileName in pairs(fileNames) do + text = text .. fileName .. '\n' + end + text = text .. '' + local comment = 'Uploaded with LrMediaWiki ' .. MediaWikiUtils.getVersionString() + MediaWikiApi.appendToPage(galleryName, section, text, comment) +end + +MediaWikiInterface.uploadFile = function(filePath, description, hasDescription, targetFileName) if not MediaWikiInterface.loggedIn then LrErrors.throwUserError(LOC '$$$/LrMediaWiki/Interface/Internal/NotLoggedIn=Internal error: not logged in before upload.') 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 -- cgit v1.2.1