Jump to content

📢 Please make sure to read our Style Guide before editing. For questions, suggestions, or technical issues, please contact Noah.

Module:ButtonBox: Difference between revisions

From CrabCraft Wiki
trying again
Tag: Reverted
Undo revision 969 by Max (talk)
Tag: Undo
 
(3 intermediate revisions by 2 users not shown)
Line 3: Line 3:


function p.buttonbox()
function p.buttonbox()
local tables = 'player_data'
    local tables = 'player_data'
local fields = 'username'
    local fields = 'username'
local args = {
    local args = {
orderBy = 'username ASC',
        orderBy = 'username ASC',
limit = 100 -- Optional; remove or increase if needed
        limit   = 100,
}
        groupBy = 'username'
    }


local results = cargo.query(tables, fields, args)
    local results = cargo.query(tables, fields, args)
local out = {}
table.insert(out, '{| class="buttonbox"')


local count = 1
    local out  = { '{| class="buttonbox"' }
    local count = 1


local count = 1
    for _, row in ipairs(results) do
for _, row in ipairs(results) do
        local user = row.username
local username = row.username
        if user ~= '$1'
if username ~= '$1' and username ~= 'MHF_Steve' and username ~= 'BlockKnight32' then
        and user ~= 'MHF_Steve'
if (count - 1) % 7 == 0 then
        and user ~= 'BlockKnight32'
table.insert(out, '|-')
        then
end
            if (count - 1) % 7 == 0 then
                table.insert(out, '|-')
            end


local imageUrl = 'https://mc-heads.net/avatar/' .. username .. '/100.png'
            local image = 'https://mc-heads.net/avatar/' .. user .. '/100.png'
            local link  = '[[' .. user .. ']]'
-- Generate valid HTML <img> tag via #tag parser function
            local cell  = '| <div class="buttonbox-entry">' ..
local imageTag = string.format('{{#tag:img||src=%s|width=100}}', imageUrl)
                            image ..
local parsedImage = mw.getCurrentFrame():preprocess(imageTag)
                            '<div class="buttonbox-label">' .. link .. '</div>' ..
                          ' </div>'


-- Build full HTML button
            table.insert(out, cell)
local box = '<div class="buttonbox-entry">' ..
            count = count + 1
            parsedImage ..
        end
            '<div class="buttonbox-label">' .. username .. '</div>' ..
    end
            '</div>'


-- Wrap entire box in a wikilink
    table.insert(out, '|}')
local link = '[[' .. username .. '|' .. box .. ']]'
    return table.concat(out, '\n')
 
table.insert(out, '| ' .. link)
count = count + 1
end
end
 
table.insert(out, '|}')
return table.concat(out, '\n')
end
end


return p
return p

Latest revision as of 21:19, 11 November 2025

Documentation for this module may be created at Module:ButtonBox/doc

local p = {}
local cargo = mw.ext.cargo

function p.buttonbox()
    local tables = 'player_data'
    local fields = 'username'
    local args = {
        orderBy = 'username ASC',
        limit   = 100,
        groupBy = 'username'
    }

    local results = cargo.query(tables, fields, args)

    local out   = { '{| class="buttonbox"' }
    local count = 1

    for _, row in ipairs(results) do
        local user = row.username
        if user ~= '$1'
        and user ~= 'MHF_Steve'
        and user ~= 'BlockKnight32'
        then
            if (count - 1) % 7 == 0 then
                table.insert(out, '|-')
            end

            local image = 'https://mc-heads.net/avatar/' .. user .. '/100.png'
            local link  = '[[' .. user .. ']]'
            local cell  = '| <div class="buttonbox-entry">' ..
                            image ..
                            '<div class="buttonbox-label">' .. link .. '</div>' ..
                           ' </div>'

            table.insert(out, cell)
            count = count + 1
        end
    end

    table.insert(out, '|}')
    return table.concat(out, '\n')
end

return p