Module:Expanded infobox image: Difference between revisions

From Geometry Dash Expanded Wiki
Jump to navigation Jump to search
Display multi-image profile galleries as labelled image tabs
Tag: Reverted
Check gallery input representation
Tag: Reverted
Line 28: Line 28:
     return '[[File:' .. value .. '|' .. math.floor(width) .. 'px]]'
     return '[[File:' .. value .. '|' .. math.floor(width) .. 'px]]'
end
end
function p.debug(frame) return mw.text.nowiki((frame.args[1] or ""):gsub(string.char(127), "DEL")) .. " EXPANDED=" .. mw.text.nowiki(mw.text.unstrip(frame.args[1] or "")) end
return p
return p

Revision as of 19:06, 12 October 2026

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
function p.debug(frame) return mw.text.nowiki((frame.args[1] or ""):gsub(string.char(127), "DEL")) .. " EXPANDED=" .. mw.text.nowiki(mw.text.unstrip(frame.args[1] or "")) end
return p