Jump to content

Module:STikiLeaderboard

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 00:26, 8 June 2013 (capitalise first letter of username). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

p = {}

-- Get the raw leaderboard content.
local leaderboard = mw.title.new('Wikipedia:STiki/leaderboard')
local leaderboardText
if leaderboard then
    leaderboardText = leaderboard:getContent()
end

-- Get the rank and uses for a given username.
local function findLeaderboardVals(username)
    username = mw.getContentLanguage():ucfirst(mw.text.trim(username or '')) -- Filter out nil values, trim whitespace, and capitalise first letter.
    if username == '' then
        return error('No username specified')
    end
    if not leaderboardText then
        error('Could not find the leaderboard text')
    end
    local rank, uses = mw.ustring.match(leaderboardText, '\n| align=center | (%d+) || align=left | %[%[User:' .. username .. '|' .. username .. '%]%] %(%[%[User_Talk:' .. username .. '|talk%]%] | %[%[Special:Contributions/' .. username .. '|contribs%]%]%) || align=right | (%d+) ||')
    return rank, uses
end

-- Get the username from #invoke and return the rank using findLeaderboardVals().
function p.rank(frame)
    local username = frame.args[1]
    local rank, uses = findLeaderboardVals(username)
    return rank
end

-- Get the username from #invoke and return the uses using findLeaderboardVals().
function p.uses(frame)
    local username = frame.args[1]
    local rank, uses = findLeaderboardVals(username)
    return uses
end

return p