模块:UserlinkUserEditCount:修订间差异
小 (Moqi移动页面模块:Userlink-UserEditCount至模块:UserlinkUserEditCount,不留重定向) |
无编辑摘要 |
||
第1行: | 第1行: | ||
local p = {} | local p = {} | ||
function p. | function p.getUserEditCount(frame) | ||
local username = frame.args[1] | local username = frame.args[1] | ||
if not username then | if not username then | ||
第7行: | 第7行: | ||
end | end | ||
local | local site = mw.site | ||
local apiUrl = site.baseUrl .. "/api.php" | |||
if | local url = apiUrl .. "?action=query&list=usercontribs&ucuser=" .. mw.uri.encode(username) .. "&uclimit=max&ucnamespace=0&format=json" | ||
local result = mw.http.fetch(url) | |||
if result and result.status == 200 then | |||
local data = mw.text.jsonDecode(result.body) | |||
if data and data.query and data.query.usercontribs then | |||
local editCount = #data.query.usercontribs | |||
return "用户 " .. username .. " 的编辑总数为: " .. editCount | |||
end | |||
end | end | ||
return "无法获取用户编辑总数" | |||
return " | |||
end | end | ||
return p | return p |
2024年6月4日 (二) 18:45的版本
可在模块:UserlinkUserEditCount/doc创建此模块的帮助文档
local p = {} function p.getUserEditCount(frame) local username = frame.args[1] if not username then return "没有提供用户名" end local site = mw.site local apiUrl = site.baseUrl .. "/api.php" local url = apiUrl .. "?action=query&list=usercontribs&ucuser=" .. mw.uri.encode(username) .. "&uclimit=max&ucnamespace=0&format=json" local result = mw.http.fetch(url) if result and result.status == 200 then local data = mw.text.jsonDecode(result.body) if data and data.query and data.query.usercontribs then local editCount = #data.query.usercontribs return "用户 " .. username .. " 的编辑总数为: " .. editCount end end return "无法获取用户编辑总数" end return p