diff options
| -rwxr-xr-x | mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua | 9 | ||||
| -rwxr-xr-x | mediawiki.lrdevplugin/MediaWikiInterface.lua | 40 | ||||
| -rwxr-xr-x | mediawiki.lrdevplugin/TranslatedStrings_de.txt | 3 | ||||
| -rw-r--r-- | mediawiki.lrdevplugin/description.txt | 14 | 
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  | 
