From 53cb610bdcbd32a417a58890061b36b2f2f9ea6a Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 24 Aug 2014 03:28:15 +0200 Subject: Add categories field to the file metadata (see #7). --- mediawiki.lrdevplugin/Info.lua | 2 ++ .../MediaWikiExportServiceProvider.lua | 4 +++- mediawiki.lrdevplugin/MediaWikiInterface.lua | 11 +++++++-- .../MediaWikiMetadataProvider.lua | 26 ++++++++++++++++++++++ mediawiki.lrdevplugin/TranslatedStrings_de.txt | 3 ++- 5 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 mediawiki.lrdevplugin/MediaWikiMetadataProvider.lua (limited to 'mediawiki.lrdevplugin') diff --git a/mediawiki.lrdevplugin/Info.lua b/mediawiki.lrdevplugin/Info.lua index 5636a42..1559fe7 100755 --- a/mediawiki.lrdevplugin/Info.lua +++ b/mediawiki.lrdevplugin/Info.lua @@ -19,6 +19,8 @@ return { file = 'MediaWikiExportServiceProvider.lua', }, + LrMetadataProvider = 'MediaWikiMetadataProvider.lua', + VERSION = { major = 0, minor = 1, diff --git a/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua b/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua index 3a6eedd..9b4fa96 100755 --- a/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua +++ b/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua @@ -20,6 +20,7 @@ local LrView = import 'LrView' local bind = LrView.bind +local Info = require 'Info' local MediaWikiInterface = require 'MediaWikiInterface' local MediaWikiExportServiceProvider = {} @@ -87,8 +88,9 @@ MediaWikiExportServiceProvider.processRenderedPhotos = function(functionContext, local license = exportSettings.info_license local other = exportSettings.info_other local categories = exportSettings.info_categories + local additionalCategories = photo:getPropertyForPlugin(Info.LrToolkitIdentifier, 'categories') - local fileDescription = MediaWikiInterface.buildFileDescription(description, source, timestamp, author, license, other, categories) + local fileDescription = MediaWikiInterface.buildFileDescription(description, source, timestamp, author, license, other, categories, additionalCategories) MediaWikiInterface.uploadFile(pathOrMessage, fileDescription) LrFileUtils.delete(pathOrMessage) diff --git a/mediawiki.lrdevplugin/MediaWikiInterface.lua b/mediawiki.lrdevplugin/MediaWikiInterface.lua index 14ef24e..709129d 100755 --- a/mediawiki.lrdevplugin/MediaWikiInterface.lua +++ b/mediawiki.lrdevplugin/MediaWikiInterface.lua @@ -74,10 +74,17 @@ MediaWikiInterface.uploadFile = function(filePath, description) end end -MediaWikiInterface.buildFileDescription = function(description, source, timestamp, author, license, other, categories) +MediaWikiInterface.buildFileDescription = function(description, source, timestamp, author, license, other, categories, additionalCategories) local categoriesString = '' for category in string.gmatch(categories, '[^;]+') do - categoriesString = categoriesString .. string.format('[[Category:%s]]\n', category) + if category then + categoriesString = categoriesString .. string.format('[[Category:%s]]\n', category) + end + end + for category in string.gmatch(additionalCategories, '[^;]+') do + if category then + categoriesString = categoriesString .. string.format('[[Category:%s]]\n', category) + end end return string.format(MediaWikiInterface.fileDescriptionPattern, description, source, timestamp, author, other, license, categoriesString) end diff --git a/mediawiki.lrdevplugin/MediaWikiMetadataProvider.lua b/mediawiki.lrdevplugin/MediaWikiMetadataProvider.lua new file mode 100644 index 0000000..72cdda2 --- /dev/null +++ b/mediawiki.lrdevplugin/MediaWikiMetadataProvider.lua @@ -0,0 +1,26 @@ +-- This file is part of the LrMediaWiki project and distributed under the terms +-- of the MIT license (see LICENSE.txt file in the project root directory or +-- [0]). See [1] for more information about LrMediaWiki. +-- +-- Copyright (C) 2014 by the LrMediaWiki team (see CREDITS.txt file in the +-- project root directory or [2]) +-- +-- [0] +-- [1] +-- [2] + +-- Code status: +-- doc: missing +-- i18n: complete + +return { + metadataFieldsForPhotos = { + { + id = 'categories', + title = LOC '$$$/LrMediaWiki/Metadata/Categories=Categories', + dataType = 'string', + }, + }, + + schemaVersion = 1, +} \ No newline at end of file diff --git a/mediawiki.lrdevplugin/TranslatedStrings_de.txt b/mediawiki.lrdevplugin/TranslatedStrings_de.txt index e5ffbb8..62661ff 100755 --- a/mediawiki.lrdevplugin/TranslatedStrings_de.txt +++ b/mediawiki.lrdevplugin/TranslatedStrings_de.txt @@ -29,4 +29,5 @@ "$$$/LrMediaWiki/Interface/Internal/NotLoggedIn=Interner Fehler: vor dem Upload nicht angemeldet." "$$$/LrMediaWiki/Interface/InUse=Dateiname schon verwendet" "$$$/LrMediaWiki/Interface/InUse/Details=Es gibt bereits eine Datei mit dem Namen ^1. Überschreiben? (Die Dateibeschreibung wird nicht verändert.)" -"$$$/LrMediaWiki/Interface/UploadFailed=Upload fehlgeschlagen: ^1" \ No newline at end of file +"$$$/LrMediaWiki/Interface/UploadFailed=Upload fehlgeschlagen: ^1" +"$$$/LrMediaWiki/Metadata/Categories=Kategorien" \ No newline at end of file -- cgit v1.2.3