Module:Item: Difference between revisions
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: | ||
end | end | ||
if not item then return '<strong><font color="red">Template error in {{Item}}: missing argument #1 (item)</font></strong>' end | if not item then return '<strong><font color="red">Template error in {{Item}}: missing argument #1 (item)</font></strong>' end | ||
local text = {} | local text = { | ||
'<span style="white-space: nowrap;">', | |||
} | |||
local i = 1 | local i = 1 | ||
if not (args.image or args.img or args['image'..i] or args['img'..i]) then | if not (args.image or args.img or args['image'..i] or args['img'..i]) then | ||
Line 45: | Line 47: | ||
i = i + 1 | i = i + 1 | ||
end | end | ||
table.insert(text, '</span>') | |||
if nolink then | if nolink then | ||
table.insert(text, table.concat{' ', alt}) | table.insert(text, table.concat{' ', alt}) |
Revision as of 19:04, 9 May 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 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
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{' ', alt})
else
table.insert(text, table.concat{' [[', link, '|<span title="', title, '">', alt, '</span>]]'})
end
return tostring(mw.html.create('span'):wikitext(table.concat(text)))
end
return p