Module:VanillaImage
From Vault Hunters Official Wiki
More actions
Documentation for this module may be created at Module:VanillaImage/doc
-- Module:MinecraftImage
-- Links to images from minecraft.wiki
local p = {}
function p.item(frame)
-- Get the image name from the template parameter
local imageName = frame.args[1] or frame.args.name or ""
local size = frame.args.size or frame.args[2] or "32px"
local alt = frame.args.alt or imageName
local link = frame.args.link or ""
local prefix = frame.args.prefix or "auto"
-- Remove any file extension if provided
imageName = imageName:gsub("%.png$", ""):gsub("%.gif$", "")
-- Clean up the image name (replace spaces with underscores)
imageName = imageName:gsub(" ", "_")
-- Add Invicon_ prefix automatically if not already present
if prefix == "auto" and not imageName:match("^Invicon_") then
imageName = "Invicon_" .. imageName
elseif prefix ~= "auto" and prefix ~= "" then
imageName = prefix .. imageName
end
-- Construct the URL to minecraft.wiki
local imageUrl = "https://minecraft.wiki/w/Special:Redirect/file/" .. mw.uri.encode(imageName .. ".png", "PATH")
-- Make sure size has 'px' suffix
if not size:match("px$") then
size = size .. "px"
end
-- Build the wikitext for external image
local wikitext = "[" .. imageUrl .. " " .. size .. "]"
-- Wrap in link if specified
if link ~= "" then
wikitext = "[[" .. link .. "|" .. wikitext .. "]]"
end
return wikitext
end
-- Alias 'direct' to 'item' for backwards compatibility
p.direct = p.item
return p