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
changed number per row
testing link as whole button
Tag: Reverted
Line 17: Line 17:
for _, row in ipairs(results) do
for _, row in ipairs(results) do
if row.username ~= '$1' and row.username ~= 'MHF_Steve' and row.username ~= 'BlockKnight32' then
if row.username ~= '$1' and row.username ~= 'MHF_Steve' and row.username ~= 'BlockKnight32' then
local url = mw.title.new(pagename):fullUrl()
if (count - 1) % 7 == 0 then
if (count - 1) % 7 == 0 then
table.insert(out, '|-')
table.insert(out, '|-')
Line 27: Line 27:
local cell = '| <div class="buttonbox-entry">'..image..'<div class="buttonbox-label">'..link..'</div> </div>'
-- local cell = '| <div class="buttonbox-entry">'..image..'<div class="buttonbox-label">'..link..'</div> </div>'
local cell = '| <a class="buttonbox-entry" href="'..url..'">' ..
              '<img src="'..image..'" width="100" />' ..
              '<div class="buttonbox-label">'..label..'</div>' ..
            '</a>'


table.insert(out, cell)
table.insert(out, cell)

Revision as of 15:26, 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
	for _, row in ipairs(results) do
		if row.username ~= '$1' and row.username ~= 'MHF_Steve' and row.username ~= 'BlockKnight32' then
		local url = mw.title.new(pagename):fullUrl()
		if (count - 1) % 7 == 0 then
			table.insert(out, '|-')
		end

		local image = 'https://mc-heads.net/avatar/'..row.username..'/100.png'
		local label = row.username
		local link = "[[" .. row.username .. "]]"
		
		
		-- local cell = '| <div class="buttonbox-entry">'..image..'<div class="buttonbox-label">'..link..'</div> </div>'
		local cell = '| <a class="buttonbox-entry" href="'..url..'">' ..
               '<img src="'..image..'" width="100" />' ..
               '<div class="buttonbox-label">'..label..'</div>' ..
             '</a>'

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

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

return p