Nenda kwa yaliyomo

Module:TopEditors

Kutoka Wikipedia, kamusi elezo huru
(Elekezwa kutoka Module:BlockedUsers)

Hati za moduli hii zinaweza kuanzishwa kwenye Moduli:TopEditors/hati

local p = {}

function p.getTopEditors()
    -- Load the data page
    local page = mw.title.new("EditorDataPage")
    if not page then
        return "Error: Data page does not exist. Please create 'EditorDataPage'."
    end

    -- Get the content of the data page
    local content = page:getContent()
    if not content or content == "" then
        return "Error: No data found on the data page. Ensure it contains valid JSON."
    end

    -- Parse the content as JSON
    local success, editors = pcall(mw.text.jsonDecode, content)
    if not success or type(editors) ~= "table" then
        return "Error: Failed to parse data. Ensure the page contains valid JSON."
    end

    -- Sort editors by edit count in descending order
    table.sort(editors, function(a, b)
        return a.editcount > b.editcount
    end)

    -- Create a table to display the top 20 editors
    local output = "{| class='wikitable sortable'\n! Rank !! Username !! Edit Count\n"
    for i = 1, math.min(20, #editors) do
        output = output .. string.format("|-\n| %d || %s || %d\n", i, editors[i].name, editors[i].editcount)
    end
    output = output .. "|}"

    return output
end

return p