Module:LuaLink2

local utils={}

local function emptyCheck(value) if value==nil then return false elseif value=="" then return false elseif value=={} then return false else return true end end

local function parseIcons(params, link) local left, right, i = "", "", 1 while emptyCheck(params["icon"..i]) do       local icon = "]" if i % 2 == 0 then left = left .. icon else right = icon .. right end i = i + 1 end return {left,right} end

local function createElement(name, params, page, disp) local color, style = "#000", ""

if emptyCheck(params["color"]) then color = params["color"] end

if emptyCheck(params["style"]) then style = params["style"] end local icons = parseIcons(params, page)

local coreLink = " ' .. disp .. " "

return "'''" .. icons[1] .. coreLink .. icons[2] .. "'''"

end

function utils.user(frame) local name = frame.args[1] or frame:getParent.args[1] local users = mw.loadData("Module:LuaLink/users")

local params = users[name] if emptyCheck(params) then local page, disp

if emptyCheck(frame.args[2]) or emptyCheck(frame:getParent.args[2]) then page = frame.args[2] or frame:getParent.args[2] else page = "User:" .. name end

if emptyCheck(frame.args[3]) or emptyCheck(frame:getParent.args[3]) then disp = frame.args[3] or frame:getParent.args[3] elseif emptyCheck(frame.args[2]) or emptyCheck(frame:getParent.args[2]) then disp = page elseif emptyCheck(params["nick"]) then disp = params["nick"] else disp = name end

return createElement(name, params, page, disp) else return "Invalid user" end end

function utils.category(frame) local name = frame.args[1] or frame:getParent.args[1] local cats = mw.loadData("Module:LuaLink/categories")

local params = cats[name] if emptyCheck(params) then local disp, page = nil,":Category:" .. name

if emptyCheck(frame.args[2]) or emptyCheck(frame:getParent.args[2]) then disp = frame.args[2] or frame:getParent.args[2] elseif emptyCheck(params["nick"]) then disp = params["nick"] else disp = name end

return createElement(name, params, page, disp) else return "Invalid category" end end

function utils.ideologies(frame) local name = frame.args[1] or frame:getParent.args[1] local ideo = mw.loadData("Module:LuaLink/ideologies")

local params = ideo[name] if emptyCheck(params) then local disp if emptyCheck(frame.args[2]) or emptyCheck(frame:getParent.args[2]) then disp = frame.args[2] or frame:getParent.args[2] elseif emptyCheck(params["nick"]) then disp = params["nick"] else disp = name end

return createElement(name, params, name, disp) else return "Invalid ideology" end end

return utils