Module:Expanded infobox image

From Geometry Dash Expanded Wiki
Revision as of 19:04, 12 October 2026 by Bot994 (talk | contribs) (Display multi-image profile galleries as labelled image tabs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Expanded infobox image/doc

local p = {}
function p.render(frame)
    local value = mw.text.trim(frame.args[1] or '')
    if value == '' then return '' end
    local width = tonumber(frame.args.width) or 300
    if width < 1 or width > 2000 then width = 300 end
    local expanded = mw.text.unstrip(value)
    if expanded:find('class="gallery', 1, true) then
        local tabs = {}
        for box in expanded:gmatch('<li class="gallerybox"(.-)</li>') do
            local url = box:match('href="([^"]+)"')
            local label = box:match('<div class="gallerytext">(.-)</div>')
            local file = url and mw.uri.decode(url):match('/[Ff]ile:(.+)')
            if not file then return value end
            file = mw.text.decode(file):gsub('_', ' ')
            label = mw.text.trim(mw.text.decode((label or ''):gsub('<[^>]+>', '')))
            label = label:gsub('[\r\n=|]', ' ')
            if label == '' then label = 'Image ' .. (#tabs + 1) end
            tabs[#tabs + 1] = label .. '=\n[[File:' .. file .. '|' .. math.floor(width) .. 'px]]'
        end
        if #tabs > 1 then
            return '<div class="expanded-profile-image-tabs">' .. frame:extensionTag('tabber', table.concat(tabs, '\n|-|\n')) .. '</div>'
        end
    end
    if value:find(string.char(127), 1, true) or value:find('[[', 1, true) or value:find('<', 1, true) then return value end
    value = value:gsub('^[Ff][Ii][Ll][Ee]:', ''):gsub('^[Ii][Mm][Aa][Gg][Ee]:', '')
    if mw.text.trim(value) == '' then return '' end
    return '[[File:' .. value .. '|' .. math.floor(width) .. 'px]]'
end
return p