aboutsummaryrefslogtreecommitdiff
path: root/mediawiki.lrdevplugin
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2015-06-27 19:29:11 +0200
committerRobin Krahl <me@robin-krahl.de>2015-06-27 19:29:11 +0200
commitd3ba117b246a5e6e21c93b94cd40ae460d2d3541 (patch)
tree555efe0c568ff1542711b1d575c2f395229c8515 /mediawiki.lrdevplugin
parent3c028a07fd88db17f94da3c54e9b6f4594e1636a (diff)
downloadLrMediaWiki-d3ba117b246a5e6e21c93b94cd40ae460d2d3541.tar.gz
LrMediaWiki-d3ba117b246a5e6e21c93b94cd40ae460d2d3541.tar.bz2
Add logging support and fix refactoring errors.
The user now may enable logging in MediaWikiUtils. If logging is enabled, a log file is written to the user’s "My Documents" that contains all API requests. Furthermore, bugs introduced by the refactoring in commit 8862341672dc288596d6ef66f92751bba6dfef25 have been fixed. - set up logging in MediaWikiUtils - write to the log in MediaWikiApi.performRequest - fix error in MediaWikiExportServiceProvider.processRenderedPhotos - fix error in MediaWikiApi.parseXmlDom Fix #43.
Diffstat (limited to 'mediawiki.lrdevplugin')
-rwxr-xr-xmediawiki.lrdevplugin/MediaWikiApi.lua12
-rwxr-xr-xmediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua3
-rw-r--r--mediawiki.lrdevplugin/MediaWikiUtils.lua13
3 files changed, 25 insertions, 3 deletions
diff --git a/mediawiki.lrdevplugin/MediaWikiApi.lua b/mediawiki.lrdevplugin/MediaWikiApi.lua
index ea9c396..de432a7 100755
--- a/mediawiki.lrdevplugin/MediaWikiApi.lua
+++ b/mediawiki.lrdevplugin/MediaWikiApi.lua
@@ -19,6 +19,7 @@ local LrPathUtils = import 'LrPathUtils'
local LrXml = import 'LrXml'
local Info = require 'Info'
+local MediaWikiUtils = require 'MediaWikiUtils'
local MediaWikiApi = {
userAgent = string.format('LrMediaWiki %d.%d', Info.VERSION.major, Info.VERSION.minor),
@@ -64,7 +65,7 @@ function MediaWikiApi.parseXmlDom(xmlDomInstance)
end
for i = 1, xmlDomInstance:childCount() do
local child = xmlDomInstance:childAtIndex(i)
- local childName = child:name()[0]
+ local childName = child:name()
if childName then
value[childName] = MediaWikiApi.parseXmlDom(child)
end
@@ -88,15 +89,24 @@ function MediaWikiApi.performRequest(arguments)
value = 'application/x-www-form-urlencoded',
},
}
+ MediaWikiUtils.trace('Performing API request');
+ MediaWikiUtils.trace('Request body:');
+ MediaWikiUtils.trace(requestBody);
local resultBody, resultHeaders = LrHttp.post(MediaWikiApi.apiPath, requestBody, requestHeaders)
+ MediaWikiUtils.trace('Result status:');
+ MediaWikiUtils.trace(resultHeaders.status);
+
if not resultHeaders.status then
LrErrors.throwUserError(LOC('$$$/LrMediaWiki/Api/NoConnection=Cannot connect to the MediaWiki API.'))
elseif resultHeaders.status ~= 200 then
LrErrors.throwUserError(LOC('$$$/LrMediaWiki/Api/HttpError=Received HTTP status ^1.', resultHeaders.status))
end
+ MediaWikiUtils.trace('Result body:');
+ MediaWikiUtils.trace(resultBody);
+
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))
diff --git a/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua b/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua
index 8405cea..accbf88 100755
--- a/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua
+++ b/mediawiki.lrdevplugin/MediaWikiExportServiceProvider.lua
@@ -60,8 +60,7 @@ MediaWikiExportServiceProvider.processRenderedPhotos = function(functionContext,
MediaWikiInterface.prepareUpload(exportSettings.username, exportSettings.password, exportSettings.api_path)
-- iterate over photos
- for item in exportContext:renditions() do
- local rendition = item[1]
+ for i, rendition in exportContext:renditions() do
-- render photo
local success, pathOrMessage = rendition:waitForRender()
if success then
diff --git a/mediawiki.lrdevplugin/MediaWikiUtils.lua b/mediawiki.lrdevplugin/MediaWikiUtils.lua
index 0eeb7a9..7d1dd8d 100644
--- a/mediawiki.lrdevplugin/MediaWikiUtils.lua
+++ b/mediawiki.lrdevplugin/MediaWikiUtils.lua
@@ -13,7 +13,16 @@
-- doc: missing
-- i18n: complete
+local LrLogger = import 'LrLogger'
local Info = require 'Info'
+local myLogger = LrLogger('LrMediaWikiLogger')
+
+-- LOGGING
+-- If enabled, the log file will appear in your "My Documents" folder. Warning:
+-- LrMediaWiki will log all requests sent to MediaWiki, including your password!
+-- If you share a log file, make sure you removed your password.
+-- To enable logging, uncomment the following line:
+-- myLogger:enable("logfile")
local MediaWikiUtils = {}
@@ -36,4 +45,8 @@ MediaWikiUtils.getVersionString = function()
return str
end
+MediaWikiUtils.trace = function(message)
+ myLogger:trace(message)
+end
+
return MediaWikiUtils