From 6f251c2526004faa55e4bcb9935aad38bfed7a48 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sat, 1 Nov 2014 16:02:31 +0100 Subject: Move file description template into a separate file Move the file description template from the constant `MediaWikiInterface.fileDescriptionPattern` to the file `description.txt` in the main directory of the plug-in. This allows better customization of the file description. - add `MediaWikiInterface.loadFileDescriptionTemplate` that tries to read the file description template from the `description.txt` file - call `MediaWikiInterface.loadFileDescriptionTemplate` before the description preview and before the export Fix https://github.com/ireas/LrMediaWiki/issues/29 --- mediawiki.lrdevplugin/MediaWikiInterface.lua | 40 +++++++++++++++++----------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'mediawiki.lrdevplugin/MediaWikiInterface.lua') diff --git a/mediawiki.lrdevplugin/MediaWikiInterface.lua b/mediawiki.lrdevplugin/MediaWikiInterface.lua index e59b3f4..be874f0 100755 --- a/mediawiki.lrdevplugin/MediaWikiInterface.lua +++ b/mediawiki.lrdevplugin/MediaWikiInterface.lua @@ -27,23 +27,28 @@ local MediaWikiInterface = { username = nil, password = nil, loggedIn = false, - fileDescriptionPattern = [=[== {{int:filedesc}} == -{{Information -|Description=${description} -|Source=${source} -|Date=${timestamp} -|Author=${author} -|Permission= -|other_versions= -|other_fields=${other_fields} -}} -${templates} -== {{int:license-header}} == -${license} -${categories}[[Category:Uploaded with LrMediaWiki]]]=], + fileDescriptionPattern = nil, } +MediaWikiInterface.loadFileDescriptionTemplate = function() + local result, errorMessage = false + local file, message = io.open(_PLUGIN.path .. '/description.txt', 'r') + if file then + MediaWikiInterface.fileDescriptionPattern = file:read('*all') + if not MediaWikiInterface.fileDescriptionPattern then + errorMessage = LOC('$$$/LrMediaWiki/Interface/ReadingDescriptionFailed=Could not read the description template file.') + else + result = true + end + file:close() + else + errorMessage = LOC('$$$/LrMediaWiki/Interface/LoadingDescriptionFailed=Could not load the description template file: ^1', message) + end + return result, errorMessage +end + MediaWikiInterface.prepareUpload = function(username, password, apiPath) + -- MediaWiki login if username and password then MediaWikiInterface.username = username MediaWikiInterface.password = password @@ -56,6 +61,11 @@ MediaWikiInterface.prepareUpload = function(username, password, apiPath) else LrErrors.throwUserError(LOC '$$$/LrMediaWiki/Interface/UsernameOrPasswordMissing=Username or password missing') end + -- file description + result, message = MediaWikiInterface.loadFileDescriptionTemplate() + if not result then + LrErrors.throwUserError(message) + end end MediaWikiInterface.prompt = function(title, label, default) @@ -84,7 +94,7 @@ MediaWikiInterface._prompt = function(functionContext, title, label, default) title = title, contents = contents, }) - local result = nil + local result = nil if dialogResult == 'ok' then result = properties.dialogValue end -- cgit v1.2.1