aboutsummaryrefslogtreecommitdiff
path: root/mediawiki.lrdevplugin/MediaWikiInterface.lua
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2014-11-01 16:02:31 +0100
committerRobin Krahl <me@robin-krahl.de>2014-11-01 16:02:31 +0100
commit6f251c2526004faa55e4bcb9935aad38bfed7a48 (patch)
tree9e774fe95a9ba02aa85af595e199203249bcf1e9 /mediawiki.lrdevplugin/MediaWikiInterface.lua
parent0d2d08472aa09dd001b532698e04b0f02e0a44c6 (diff)
downloadLrMediaWiki-6f251c2526004faa55e4bcb9935aad38bfed7a48.tar.gz
LrMediaWiki-6f251c2526004faa55e4bcb9935aad38bfed7a48.tar.bz2
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
Diffstat (limited to 'mediawiki.lrdevplugin/MediaWikiInterface.lua')
-rwxr-xr-xmediawiki.lrdevplugin/MediaWikiInterface.lua40
1 files changed, 25 insertions, 15 deletions
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