Module:Item: Difference between revisions

From Create: Minecraft Mod Wiki
Jump to navigation Jump to search
Create: Minecraft Mod Wiki>Joker876
No edit summary
Create: Minecraft Mod Wiki>Joker876
No edit summary
Line 26: Line 26:
title = 'Minecraft Wiki: '..title
title = 'Minecraft Wiki: '..title
end
end
local ret = mw.html.create('span')
local text
:wikitext(table.concat{
if nolink then
'[[File:', img, '.png|', imgsize, '|link=', (nolink and "" or link), (nolink and "]]" or ']][['), link, (nolink and "|" or '|<span title="'), (nolink and "" or title), (nolink and "" or '">'), alt, (nolink and "" or '</span>]]')
text = table.concat{
})
'[[File:', img, '.png|', imgsize, '|link=]]', alt
return tostring(ret)
}
else
text = table.concat{
'[[File:', img, '.png|', imgsize, '|link=', link, ']][[', link, '|<span title="', title, '">', alt, '</span>]]'
}
end
return tostring(mw.html.create('span'):wikitext(text))
end
end


return p
return p

Revision as of 14:29, 30 April 2021

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 isMCwiki = args.minecraft or args.mc
	local item = args[1] or args.item or args.i
	local img = args.image or args.img or item
	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 isMCwiki then
		link = 'w:c:minecraft:'..link
		title = 'Minecraft Wiki: '..title
	end
	local text
	if nolink then
		text = table.concat{
			'[[File:', img, '.png|', imgsize, '|link=]]', alt
		}
	else
		text = table.concat{
			'[[File:', img, '.png|', imgsize, '|link=', link, ']][[', link, '|<span title="', title, '">', alt, '</span>]]'
		}
	end
	return tostring(mw.html.create('span'):wikitext(text))
end

return p