FANDOM


local Link = {}
local HF = require('Module:HF')
local getArgs = require('Dev:Arguments').getArgs
 
local function FileLink( page, ... )
    -- get the extra arguments as a table
    local args = { ... }
    -- get the count of extra arguments, correctly
    local n = select( '#', ... )
    local placeholder = table.concat( args, '|', 1, n )
    return HF.Link( 'File:' .. page .. (n > 0 and '|' .. placeholder or ''))
end
 
function Link.main(frame)
	local args = getArgs(frame)
	return Link._main(args)
end
 
function Link._main(args)
    local img = args['img'] and FileLink( args['img'], 'x30px' ) or nil
    if not args[1] then return nil end
    local primary = args[1]
    local type_values = {
        item = FileLink(
            primary .. '.png',
            ('alt=Item image of %s, %s'):format(
                mw.uri.encode( '{{:'..primary..'}}'), -- This doesn't seem right
                'File:' .. primary .. '.png'
            )
        ),
        npc = FileLink(
            primary .. '.png',
            'x30px',
            ('alt=NPC image of %s, %s'):format(
                primary,
                'File:' .. primary .. '.png'
            )
        ),
        chat = FileLink(
            primary .. ' chathead.png',
            'x30px',
            ('alt=Chat head image of %s, %s'):format(
                primary,
                'File:' .. primary .. ' chathead.png'
            )
        ),
        music = FileLink('Music.png'),
        skill = FileLink(
            primary .. ' icon.png',
            ('alt=Skill icon of %s, %s'):format(
                primary,
                'File:' .. primary .. ' icon.png'
            )
        )
    }
    local _type = args['type'] and (type_values[args['type']] or nil) or nil
 
    local image = img or _type or FileLink('Placeholder.png',('alt=Link to %s'):format(primary))
    local link = HF.Link(primary, args[2] or nil)
    return table.concat({image, link}, ' ')
end
 
return Link
Community content is available under CC-BY-SA unless otherwise noted.