Jump to content

Module:Medal tally

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by KEmel49 (talk | contribs) at 17:58, 9 December 2024 (Xperiment3). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}

function p.getEditCount(username)
    local url = "https://en.wikipedia.org/w/api.php"
        .. "?action=query&list=users"
        .. "&ususers=" .. mw.uri.encode(username)
        .. "&usprop=editcount"
        .. "&format=json"

    local response = mw.http.fetch(url)
    if not response then
        return "Error: Unable to fetch data."
    end

    local data = mw.text.jsonDecode(response)
    if not data or not data.query or not data.query.users then
        return "Error: Invalid response format."
    end

    local userInfo = data.query.users[1]
    if userInfo and userInfo.editcount then
        return "User " .. username .. " has " .. userInfo.editcount .. " edits."
    else
        return "Error: Edit count not found."
    end
end

return p