From StrategyWiki, the video game walkthrough and strategy guide wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Icon/Documentation

local p = {}
 
function p.icon( frame )
	local iconName = frame:getParent().args[1] or ''
	local size = frame:getParent().args[2] or '25'
	local customText = frame:getParent().args[3] or ''

	local sizeStr = size .. "x" .. size .. "px"
	return p._icon(iconName, sizeStr, customText )
end

function p._icon( iconName, sizeStr, customText )
	local iconData = mw.loadData( 'Module:icon/data' )
	local iconString

	iconName = string.lower( iconName )

	if iconData[iconName] then
		iconString = "[[" .. iconData[iconName].flag .. "|" .. sizeStr .. "|" .. iconData[iconName].name .. "|" .. customText .. "]]"
	else
		local syscat = require( "Module:syscat" )

		if mw.title.new( syscat._syscat( iconName ) .. " icon.png", 'File' ).exists == true then
			iconString = "[[File:" .. syscat._syscat( iconName ) .. " icon.png|" .. syscat._syscat( iconName ) .. "|" .. sizeStr .. "|" .. customText .. "]]"
		end
	end
	return iconString or "Deprecated template usage"
end

return p