aboutsummaryrefslogtreecommitdiff
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
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
-rwxr-xr-xmediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua9
-rwxr-xr-xmediawiki.lrdevplugin/MediaWikiInterface.lua40
-rwxr-xr-xmediawiki.lrdevplugin/TranslatedStrings_de.txt3
-rw-r--r--mediawiki.lrdevplugin/description.txt14
4 files changed, 49 insertions, 17 deletions
diff --git a/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua b/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua
index 52f45d3..079225e 100755
--- a/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua
+++ b/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua
@@ -266,8 +266,13 @@ MediaWikiExportServiceProvider.sectionsForTopOfDialog = function(viewFactory, pr
viewFactory:push_button {
title = LOC '$$$/LrMediaWiki/Section/Licensing/Preview=Preview generated wikitext',
action = function(button)
- local wikitext = MediaWikiInterface.buildFileDescription('<!-- description -->', propertyTable.info_source, '<!-- date -->', propertyTable.info_author, propertyTable.info_license, '<!-- {{Location}} if GPS metadata is available -->\n' .. propertyTable.info_templates, propertyTable.info_other, propertyTable.info_categories, '<!-- per-file categories -->')
- LrDialogs.message(LOC '$$$/LrMediaWiki/Section/Licensing/Preview=Preview generated wikitext', wikitext, 'info')
+ result, message = MediaWikiInterface.loadFileDescriptionTemplate()
+ if result then
+ local wikitext = MediaWikiInterface.buildFileDescription('<!-- description -->', propertyTable.info_source, '<!-- date -->', propertyTable.info_author, propertyTable.info_license, '<!-- {{Location}} if GPS metadata is available -->\n' .. propertyTable.info_templates, propertyTable.info_other, propertyTable.info_categories, '<!-- per-file categories -->')
+ LrDialogs.message(LOC '$$$/LrMediaWiki/Section/Licensing/Preview=Preview generated wikitext', wikitext, 'info')
+ else
+ LrDialogs.message(LOC '$$$/LrMediaWiki/Export/DescriptionError=Error reading the file description', message, 'error')
+ end
end,
},
},
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
diff --git a/mediawiki.lrdevplugin/TranslatedStrings_de.txt b/mediawiki.lrdevplugin/TranslatedStrings_de.txt
index 06420d5..2585861 100755
--- a/mediawiki.lrdevplugin/TranslatedStrings_de.txt
+++ b/mediawiki.lrdevplugin/TranslatedStrings_de.txt
@@ -1,5 +1,6 @@
"$$$/LrMediaWiki/Api/HttpError=HTTP-Status ^1 erhalten."
"$$$/LrMediaWiki/Api/MediaWikiError=Der MediaWiki-Fehler ^1 ist aufgetreten: ^2"
+"$$$/LrMediaWiki/Export/DescriptionError=Fehler beim Lesen der Dateibeschreibung"
"$$$/LrMediaWiki/Export/NoApiPath=Kein API-Pfad angegeben!"
"$$$/LrMediaWiki/Export/NoAuthor=Kein Urheber angegeben!"
"$$$/LrMediaWiki/Export/NoDescription=Für diese Datei ist keine Beschreibung angegeben!"
@@ -15,7 +16,9 @@
"$$$/LrMediaWiki/Interface/InUse/OK=Überschreiben"
"$$$/LrMediaWiki/Interface/InUse/Rename=Umbenennen"
"$$$/LrMediaWiki/Interface/InUse=Dateiname schon verwendet"
+"$$$/LrMediaWiki/Interface/LoadingDescriptionFailed=Die Datei mit der Vorlage für die Bildbeschreibung konnte nicht geöffnet werden: ^1"
"$$$/LrMediaWiki/Interface/LoginFailed=Login fehlgeschlagen: ^1."
+"$$$/LrMediaWiki/Interface/ReadingDescriptionFailed=Die Datei mit der Vorlage für die Bildbeschreibung konnte nicht gelesen werden."
"$$$/LrMediaWiki/Interface/Rename/NewName=Neuer Dateiname"
"$$$/LrMediaWiki/Interface/Rename=Datei umbenennen"
"$$$/LrMediaWiki/Interface/UploadFailed=Upload fehlgeschlagen: ^1"
diff --git a/mediawiki.lrdevplugin/description.txt b/mediawiki.lrdevplugin/description.txt
new file mode 100644
index 0000000..69818f0
--- /dev/null
+++ b/mediawiki.lrdevplugin/description.txt
@@ -0,0 +1,14 @@
+== {{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]] \ No newline at end of file