diff options
| author | Robin Krahl <me@robin-krahl.de> | 2015-06-28 00:36:09 +0200 | 
|---|---|---|
| committer | Robin Krahl <me@robin-krahl.de> | 2015-06-28 00:36:09 +0200 | 
| commit | 93c667f039ffc19ed47e3eb381a3771e96c24711 (patch) | |
| tree | 98cf6b4a5f879db7046db69ed27fd46c7a1c022d | |
| parent | a673ab08731494f4541f2c9a70ccd3695b747624 (diff) | |
| download | LrMediaWiki-93c667f039ffc19ed47e3eb381a3771e96c24711.tar.gz LrMediaWiki-93c667f039ffc19ed47e3eb381a3771e96c24711.tar.bz2 | |
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.
| -rwxr-xr-x | mediawiki.lrdevplugin/MediaWikiApi.lua | 13 | ||||
| -rwxr-xr-x | mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua | 34 | ||||
| -rwxr-xr-x | mediawiki.lrdevplugin/MediaWikiInterface.lua | 24 | ||||
| -rwxr-xr-x | mediawiki.lrdevplugin/TranslatedStrings_de.txt | 1 | 
4 files changed, 63 insertions, 9 deletions
| diff --git a/mediawiki.lrdevplugin/MediaWikiApi.lua b/mediawiki.lrdevplugin/MediaWikiApi.lua index e54e973..3b1723d 100755 --- a/mediawiki.lrdevplugin/MediaWikiApi.lua +++ b/mediawiki.lrdevplugin/MediaWikiApi.lua @@ -175,6 +175,19 @@ function MediaWikiApi.getEditToken()  	return xml.tokens.edittoken  end +function MediaWikiApi.appendToPage(page, section, text, comment) +	local arguments = { +		action = 'edit', +		title = page, +		section = 'new', +		sectiontitle = section, +		text = text, +		summary = comment, +		token = MediaWikiApi.getEditToken(), +	} +	MediaWikiApi.performRequest(arguments) +end +  function MediaWikiApi.existsFile(fileName)  	local arguments = {  		action = 'query', 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
 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 = '<gallery>\n';
 +	for i, fileName in pairs(fileNames) do
 +		text = text .. fileName .. '\n'
 +	end
 +	text = text .. '</gallery>'
 +	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
 diff --git a/mediawiki.lrdevplugin/TranslatedStrings_de.txt b/mediawiki.lrdevplugin/TranslatedStrings_de.txt index f4b8c33..61d2c8b 100755 --- a/mediawiki.lrdevplugin/TranslatedStrings_de.txt +++ b/mediawiki.lrdevplugin/TranslatedStrings_de.txt @@ -54,6 +54,7 @@  "$$$/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/Gallery=Galerie"
  "$$$/LrMediaWiki/Section/User/Password=Passwort"
  "$$$/LrMediaWiki/Section/User/Title=Login-Informationen"
  "$$$/LrMediaWiki/Section/User/Username=Benutzername"
 | 
