Module:Item

From Eco - English Wiki

Documentation for this module may be created at Module:Item/doc

local p = {}

function p.item(f)
	local origArgs = f
	if f == mw.getCurrentFrame() then
		origArgs = f:getParent().args
	else
		f = mw.getCurrentFrame()
	end
	local args = {}
	for k,v in pairs(origArgs) do
		if type(k) == "string" then k = k:lower() end
		args[k] = v
	end
	
	local item = args[1] or args.item or args.i
	local alt = args[2] or item
	local link = args.link or item
	local nolink = args.nolink
	local title = item
	local imgsize = args.size or "21px"
	if not item then return '<strong><font color="red">Template error in {{Item}}: missing argument #1 (item)</font></strong>' end
	local text = {
		'<span style="white-space: nowrap;">',
	}
	local i = 1
	if not (args.image or args.img or args['image'..i] or args['img'..i]) then 
		if nolink then
			table.insert(text, table.concat{'[[File:', item, '.png|', imgsize, '|link=]]'})
		else
			table.insert(text, table.concat{'[[File:', item, '.png|', imgsize, '|link=', link, ']]'})
		end
	end
	if not (args.image or args.img or args.image1 or args.img1) and (args.image2 or args.img2) then i = 2 end
	while i == 1 and (args.image or args.img or args.image2 or args.img2) or args['image'..i] or args['img'..i] do
		local img = args.image or args['image'..i] or args.img or args['img'..i]
		if nolink then
			table.insert(text, table.concat{'[[File:', img, '.png|', imgsize, '|link=]]'})
		else
			table.insert(text, table.concat{'[[File:', img, '.png|', imgsize, '|link=', link, ']]'})
		end
		i = i + 1
	end
	table.insert(text, '</span>')
	if nolink then
		table.insert(text, table.concat{'&nbsp;', alt})
	else
		table.insert(text, table.concat{'&nbsp;[[', link, '|<span title="', title, '">', alt, '</span>]]'})
	end
	return tostring(mw.html.create('span'):wikitext(table.concat(text)))
end

return p