试图统计用户编辑过的历史字节数,但没能找到相应的api,因此沙盒模块是无法正常运行的。可以手动访问萌娘百科api进行统计。
local p = {}
function p.getTotalBytes(frame)
local username = frame.args[1] or frame:getParent().args[1]
if not username then
return "错误:未提供用户名"
end
local apiUrl = "https://zh.moegirl.org.cn/api.php"
local params = {
action = "query",
list = "usercontribs",
ucuser = username,
ucprop = "size|sizediff",
uclimit = "max",
format = "json"
}
local totalBytes = 0
local continue = true
while continue do
local response = mw.Api.get(apiUrl, params)
if not response or response.error then
return "错误:API请求失败"
end
local data = response.query.usercontribs
for _, contrib in ipairs(data) do
totalBytes = totalBytes + (contrib.sizediff or 0)
end
if response["continue"] then
params.uccontinue = response["continue"].uccontinue
else
continue = false
end
end
return totalBytes
end
return p