aboutsummaryrefslogtreecommitdiff
path: root/mediawiki.lrdevplugin
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2015-06-27 15:34:11 +0200
committerRobin Krahl <me@robin-krahl.de>2015-06-27 15:34:11 +0200
commit8862341672dc288596d6ef66f92751bba6dfef25 (patch)
tree2b8ec8eee86ed052e50ec6b01f04d8e5a112723e /mediawiki.lrdevplugin
parent848f6be3a29fb68ef43086ba2c1401162f0f845f (diff)
downloadLrMediaWiki-8862341672dc288596d6ef66f92751bba6dfef25.tar.gz
LrMediaWiki-8862341672dc288596d6ef66f92751bba6dfef25.tar.bz2
Fix coding style and add `luacheck` to Travis CI.
Fix #40.
Diffstat (limited to 'mediawiki.lrdevplugin')
-rwxr-xr-xmediawiki.lrdevplugin/MediaWikiApi.lua28
-rwxr-xr-xmediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua7
-rwxr-xr-xmediawiki.lrdevplugin/MediaWikiInterface.lua2
3 files changed, 19 insertions, 18 deletions
diff --git a/mediawiki.lrdevplugin/MediaWikiApi.lua b/mediawiki.lrdevplugin/MediaWikiApi.lua
index 130fbb5..ea9c396 100755
--- a/mediawiki.lrdevplugin/MediaWikiApi.lua
+++ b/mediawiki.lrdevplugin/MediaWikiApi.lua
@@ -36,7 +36,7 @@ function MediaWikiApi.urlEncode(str)
function(c) return string.format('%%%02X', string.byte(c)) end)
str = string.gsub(str, ' ', '+')
end
- return str
+ return str
end
--- Convert HTTP arguments to a URL-encoded request body.
@@ -64,7 +64,7 @@ function MediaWikiApi.parseXmlDom(xmlDomInstance)
end
for i = 1, xmlDomInstance:childCount() do
local child = xmlDomInstance:childAtIndex(i)
- local childName, childNamespace = child:name()
+ local childName = child:name()[0]
if childName then
value[childName] = MediaWikiApi.parseXmlDom(child)
end
@@ -88,7 +88,7 @@ function MediaWikiApi.performRequest(arguments)
value = 'application/x-www-form-urlencoded',
},
}
-
+
local resultBody, resultHeaders = LrHttp.post(MediaWikiApi.apiPath, requestBody, requestHeaders)
if not resultHeaders.status then
@@ -114,14 +114,14 @@ function MediaWikiApi.login(username, password, token)
arguments.lgtoken = token
end
local xml = MediaWikiApi.performRequest(arguments)
-
+
local loginResult = xml.login.result
if loginResult == 'Success' then
return true
elseif not token and loginResult == 'NeedToken' then
return MediaWikiApi.login(username, password, xml.login.token)
end
-
+
return loginResult
end
@@ -175,30 +175,30 @@ function MediaWikiApi.upload(fileName, sourceFilePath, text, comment, ignoreWarn
filePath = sourceFilePath,
contentType = 'application/octet-stream',
}
-
+
local resultBody, resultHeaders = LrHttp.postMultipart(MediaWikiApi.apiPath, requestBody, requestHeaders)
-
+
if resultHeaders.status ~= 200 then
LrErrors.throwUserError(LOC('$$$/LrMediaWiki/Api/HttpError=Received HTTP status ^1.', resultHeaders.status))
end
-
+
local resultXml = MediaWikiApi.parseXmlDom(LrXml.parseXml(resultBody))
if resultXml.error then
LrErrors.throwUserError(LOC('$$$/LrMediaWiki/Api/MediaWikiError=The MediaWiki error ^1 occured: ^2', resultXml.error.code, resultXml.error.info))
end
-
- local uploadResult = resultXml.upload.result
+
+ local uploadResult = resultXml.upload.result
if uploadResult == 'Success' then
return true
elseif uploadResult == 'Warning' then
- warnings = ''
- for k, v in pairs(resultXml.upload.warnings) do
+ local warnings = ''
+ for pair in pairs(resultXml.upload.warnings) do
if warnings ~= '' then
warnings = warnings .. ', '
end
- warnings = warnings .. k
+ warnings = warnings .. pair[0]
end
- return warnings
+ return warnings
else
return uploadResult
end
diff --git a/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua b/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua
index c9d5a1a..8038ee4 100755
--- a/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua
+++ b/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua
@@ -31,7 +31,7 @@ MediaWikiExportServiceProvider.processRenderedPhotos = function(functionContext,
-- configure progess display
local exportSession = exportContext.exportSession
local photoCount = exportSession:countRenditions()
- local progressScope = exportContext:configureProgress{
+ exportContext:configureProgress{
title = photoCount > 1 and LOC('$$$/LrMediaWiki/Export/Progress=Exporting ^1 photos to a MediaWiki', photoCount) or LOC '$$$/LrMediaWiki/Export/Progress/One=Exporting one photo to a MediaWiki',
}
@@ -60,7 +60,8 @@ MediaWikiExportServiceProvider.processRenderedPhotos = function(functionContext,
MediaWikiInterface.prepareUpload(exportSettings.username, exportSettings.password, exportSettings.api_path)
-- iterate over photos
- for i, rendition in exportContext:renditions() do
+ for item in exportContext:renditions() do
+ local rendition = item[1]
-- render photo
local success, pathOrMessage = rendition:waitForRender()
if success then
@@ -291,7 +292,7 @@ MediaWikiExportServiceProvider.sectionsForTopOfDialog = function(viewFactory, pr
viewFactory:push_button {
title = LOC '$$$/LrMediaWiki/Section/Licensing/Preview=Preview generated wikitext',
action = function(button)
- result, message = MediaWikiInterface.loadFileDescriptionTemplate()
+ local 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 -->', '<!-- permission -->')
LrDialogs.message(LOC '$$$/LrMediaWiki/Section/Licensing/Preview=Preview generated wikitext', wikitext, 'info')
diff --git a/mediawiki.lrdevplugin/MediaWikiInterface.lua b/mediawiki.lrdevplugin/MediaWikiInterface.lua
index f2394cc..dbae6ed 100755
--- a/mediawiki.lrdevplugin/MediaWikiInterface.lua
+++ b/mediawiki.lrdevplugin/MediaWikiInterface.lua
@@ -62,7 +62,7 @@ MediaWikiInterface.prepareUpload = function(username, password, apiPath)
LrErrors.throwUserError(LOC '$$$/LrMediaWiki/Interface/UsernameOrPasswordMissing=Username or password missing')
end
-- file description
- result, message = MediaWikiInterface.loadFileDescriptionTemplate()
+ local result, message = MediaWikiInterface.loadFileDescriptionTemplate()
if not result then
LrErrors.throwUserError(message)
end