Jump to content

Module:Badge display

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by BoonDock (talk | contribs) at 21:47, 18 April 2023 (Test no border // Edit via Wikitext Extension for VSCode). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.DisplayImage(frame)
    -- Usage from a template etc:
    -- {{#invoke:BadgeDisplay|DisplayImage
    -- | image = NameOfImage.jpg
    -- | caption = Caption for the image
    -- | description = Description of the image
    -- | float = left/right/center
    -- | height = height in pixels or other units
    -- | width = width in pixels or other units
    -- | size = size in pixels or other units, e.g. "x25px"
    -- }}

    local args = getArgs(frame)

    -- Set default values for optional parameters
    local float = args.float or 'none'
    local height = args.height or ''
    local width = args.width or ''
    local size = args.size or ''
	local imageName=args.image or ''
	--imageName = "File:" .. imageName
    -- Get the width of the image
    local imageWidth = mw.ustring.match(args.width or '', '%d+')
    if not imageWidth then
        local imageTitle = mw.title.new(imageName)
        local imageInfo = imageTitle and mw.info or {}
        imageWidth = imageInfo.width or '50'
    end

    -- Build the wikitext table
    local wikitext = '{| class="wikitable" style="width:' .. (tonumber(imageWidth) * 1.1) .. 'px; margin:0 auto;border:none;"\n'
    wikitext = wikitext .. '|caption style="text-align:center;"|' .. (args.caption or 'No Caption') .. '\n|-\n'
    wikitext = wikitext .. '|style="text-align:center;border:none;"| [[File:' .. (args.image or 'No Image') .. ']]\n|-\n'
    --wikitext = wikitext .. '|style="text-align:center;"| [[File:' .. (args.image or 'No Image') .. ']]\n|-\n'
    wikitext = wikitext .. '|style="text-align:center;"|' .. (args.description or 'No Description') .. '\n|-\n'
    wikitext = wikitext .. '|}\n'
    wikitext = wikitext .. '=== Debug === \n'
    wikitext = wikitext .. '* float: ' .. float .. '\n'
    wikitext = wikitext .. '* height: ' .. height .. '\n'
    wikitext = wikitext .. '* width: ' .. width .. '\n'
    wikitext = wikitext .. '* size: ' .. size .. '\n'
    wikitext = wikitext .. '* imageName: ' .. imageName .. '\n'
    wikitext = wikitext .. '* imageWidth: ' .. imageWidth .. '\n'

    return wikitext
end

return p