Module:ButtonBox: Difference between revisions
Appearance
perhaps fixed again Tag: Reverted |
trying again Tag: Reverted |
||
| Line 13: | Line 13: | ||
local out = {} | local out = {} | ||
table.insert(out, '{| class="buttonbox"') | table.insert(out, '{| class="buttonbox"') | ||
local count = 1 | |||
local count = 1 | local count = 1 | ||
for _, row in ipairs(results) do | for _, row in ipairs(results) do | ||
local username = row.username | local username = row.username | ||
if | if username ~= '$1' and username ~= 'MHF_Steve' and username ~= 'BlockKnight32' then | ||
if (count - 1) % 7 == 0 then | |||
table.insert(out, '|-') | |||
end | |||
local imageUrl = 'https://mc-heads.net/avatar/' .. username .. '/100.png' | |||
-- Generate valid HTML <img> tag via #tag parser function | |||
local imageTag = string.format('{{#tag:img||src=%s|width=100}}', imageUrl) | |||
local parsedImage = mw.getCurrentFrame():preprocess(imageTag) | |||
-- Build full HTML button | |||
local box = '<div class="buttonbox-entry">' .. | |||
parsedImage .. | |||
'<div class="buttonbox-label">' .. username .. '</div>' .. | |||
'</div>' | |||
-- Wrap entire box in a wikilink | |||
local link = '[[' .. username .. '|' .. box .. ']]' | |||
table.insert(out, '| ' .. link) | |||
count = count + 1 | |||
end | end | ||
end | end | ||
Revision as of 15:44, 24 June 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 -- Optional; remove or increase if needed
}
local results = cargo.query(tables, fields, args)
local out = {}
table.insert(out, '{| class="buttonbox"')
local count = 1
local count = 1
for _, row in ipairs(results) do
local username = row.username
if username ~= '$1' and username ~= 'MHF_Steve' and username ~= 'BlockKnight32' then
if (count - 1) % 7 == 0 then
table.insert(out, '|-')
end
local imageUrl = 'https://mc-heads.net/avatar/' .. username .. '/100.png'
-- Generate valid HTML <img> tag via #tag parser function
local imageTag = string.format('{{#tag:img||src=%s|width=100}}', imageUrl)
local parsedImage = mw.getCurrentFrame():preprocess(imageTag)
-- Build full HTML button
local box = '<div class="buttonbox-entry">' ..
parsedImage ..
'<div class="buttonbox-label">' .. username .. '</div>' ..
'</div>'
-- Wrap entire box in a wikilink
local link = '[[' .. username .. '|' .. box .. ']]'
table.insert(out, '| ' .. link)
count = count + 1
end
end
table.insert(out, '|}')
return table.concat(out, '\n')
end
return p