aboutsummaryrefslogtreecommitdiff
path: root/mediawiki.lrdevplugin
diff options
context:
space:
mode:
Diffstat (limited to 'mediawiki.lrdevplugin')
-rwxr-xr-xmediawiki.lrdevplugin/MediaWikiInterface.lua32
-rw-r--r--mediawiki.lrdevplugin/MediaWikiUtils.lua11
2 files changed, 30 insertions, 13 deletions
diff --git a/mediawiki.lrdevplugin/MediaWikiInterface.lua b/mediawiki.lrdevplugin/MediaWikiInterface.lua
index 8d79974..e59b3f4 100755
--- a/mediawiki.lrdevplugin/MediaWikiInterface.lua
+++ b/mediawiki.lrdevplugin/MediaWikiInterface.lua
@@ -5,9 +5,9 @@
-- Copyright (C) 2014 by the LrMediaWiki team (see CREDITS.txt file in the
-- project root directory or [2])
--
--- [0] <https://raw.githubusercontent.com/LrMediaWiki/LrMediaWiki/master/LICENSE.txt>
+-- [0] <https://raw.githubusercontent.com/ireas/LrMediaWiki/master/LICENSE.txt>
-- [1] <https://commons.wikimedia.org/wiki/Commons:LrMediaWiki>
--- [2] <https://raw.githubusercontent.com/LrMediaWiki/LrMediaWiki/master/CREDITS.txt>
+-- [2] <https://raw.githubusercontent.com/ireas/LrMediaWiki/master/CREDITS.txt>
-- Code status:
-- doc: missing
@@ -29,18 +29,18 @@ local MediaWikiInterface = {
loggedIn = false,
fileDescriptionPattern = [=[== {{int:filedesc}} ==
{{Information
-|Description=%s
-|Source=%s
-|Date=%s
-|Author=%s
+|Description=${description}
+|Source=${source}
+|Date=${timestamp}
+|Author=${author}
|Permission=
|other_versions=
-|other_fields=%s
+|other_fields=${other_fields}
}}
-%s
+${templates}
== {{int:license-header}} ==
-%s
-%s[[Category:Uploaded with LrMediaWiki]]]=],
+${license}
+${categories}[[Category:Uploaded with LrMediaWiki]]]=],
}
MediaWikiInterface.prepareUpload = function(username, password, apiPath)
@@ -134,7 +134,17 @@ MediaWikiInterface.buildFileDescription = function(description, source, timestam
categoriesString = categoriesString .. string.format('[[Category:%s]]\n', category)
end
end
- return string.format(MediaWikiInterface.fileDescriptionPattern, description, source, timestamp, author, other, templates, license, categoriesString)
+ local arguments = {
+ description = description,
+ source = source,
+ timestamp = timestamp,
+ author = author,
+ other_fields = other,
+ templates = templates,
+ license = license,
+ categories = categoriesString,
+ }
+ return MediaWikiUtils.formatString(MediaWikiInterface.fileDescriptionPattern, arguments)
end
return MediaWikiInterface
diff --git a/mediawiki.lrdevplugin/MediaWikiUtils.lua b/mediawiki.lrdevplugin/MediaWikiUtils.lua
index 00dd46d..0eeb7a9 100644
--- a/mediawiki.lrdevplugin/MediaWikiUtils.lua
+++ b/mediawiki.lrdevplugin/MediaWikiUtils.lua
@@ -5,9 +5,9 @@
-- Copyright (C) 2014 by the LrMediaWiki team (see CREDITS.txt file in the
-- project root directory or [2])
--
--- [0] <https://raw.githubusercontent.com/LrMediaWiki/LrMediaWiki/master/LICENSE.txt>
+-- [0] <https://raw.githubusercontent.com/ireas/LrMediaWiki/master/LICENSE.txt>
-- [1] <https://commons.wikimedia.org/wiki/Commons:LrMediaWiki>
--- [2] <https://raw.githubusercontent.com/LrMediaWiki/LrMediaWiki/master/CREDITS.txt>
+-- [2] <https://raw.githubusercontent.com/ireas/LrMediaWiki/master/CREDITS.txt>
-- Code status:
-- doc: missing
@@ -17,6 +17,13 @@ local Info = require 'Info'
local MediaWikiUtils = {}
+-- Allows formatting of strings like "${test} eins zwei drei ${test2}"
+-- Based on a solution by http://lua-users.org/wiki/RiciLake shown here:
+-- http://lua-users.org/wiki/StringInterpolation
+MediaWikiUtils.formatString = function(str, arguments)
+ return (str:gsub('($%b{})', function(w) return arguments[w:sub(3, -2)] or w end))
+end
+
MediaWikiUtils.isStringEmpty = function(str)
return str == nil or string.match(str, '^%s*$') ~= nil
end