• Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

Module:Sandbox/Shawpaw/UserEditByte

萌娘百科,万物皆可萌的百科全书!转载请标注来源页面的网页链接,并声明引自萌娘百科。内容不可商用。
跳转到导航 跳转到搜索
Template-info.svg 模块文档  [查看] [编辑] [历史] [刷新]

试图统计用户编辑过的历史字节数,但没能找到相应的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