Module:Render/Memento

local render_icon = require('Module:Render').icon local model local linkUtils = require('Module:LinkUtils')

local p = {}

function p.icon(frame) local args = require('Module:Arguments').getArgs(frame, {		parentFirst = true,		wrappers = {			'Template:Memento/Icon',		},	}) return p._icon(args) end

function p._icon(args) local iname = args[1] or '' local data = args.data if not data then if iname == '' then return end local server = args.server or 'gl' local lang = args.lang or 'english' local rows = require('Module:CargoUtil').query{ tables = {'ConceptCard=CC', 'ConceptCardLoc=CCLoc', 'Pages'}, join = { 'CC.iname = CCLoc.iname', 'CC.iname = Pages.iname', },			fields = { 'Pages._pageName = _pageName', 'CC.iname = iname', 'CC.server = server', 'CC.rare = rare', 'CC.icon = icon', 'CCLoc.name = name', },			where = { ('"%s" IN (CC.iname, Pages._pageName)'):format(iname), ('CC.server = "%s"'):format(server), ('CCLoc.lang = "%s"'):format(lang), 'Pages._pageName IS NULL OR Pages.type = "Memento"', },		}		data = rows[1] if not data then return end end iname = data.iname data.name = linkUtils.wikiSafeName(data.name)

local link = nil if args.link ~= 'none' then if args.jplink then link = linkUtils.acdbLink(iname, true) else link = data._pageName or data.name end end

-- TODO Get the correct server local renderArgs = { (data.icon or ) ~=  and ('ConceptCardIcon,'..data.icon) or 'ItemIcon,IT_UNKNOWN', data.name, link, tonumber(data.rare), 4,		64,		(args.count or ) ~=  and args.count or nil, args.classes, nil, false, }	local name if args.name ~= 'none' then if (renderArgs[3] or ) ~=  then if args.jplink then name = ('[%s %s]'):format(renderArgs[3], renderArgs[2]) else name = ('%s'):format(renderArgs[3], renderArgs[2]) end else name = renderArgs[2] end end

if args.size == 'large' then renderArgs[6] = 128 elseif args.size == 'small' then renderArgs[6] = 24 renderArgs[9] = name and ' '..name..' ' renderArgs[10] = true elseif args['size'] == 'compact' then renderArgs[9] = name and ' '..renderArgs[2]..' ' else renderArgs[9] = name and ''..name..' ' end return render_icon(unpack(renderArgs)) end

-- Non cargo version function p._icon2(args) local data = args.data or {} local iname = data.iname if not iname then return end

data.name = linkUtils.wikiSafeName(data.name)

local link = nil if args.link ~= 'none' then if args.jplink then link = linkUtils.acdbLink(iname, true) else link = data._pageName or data.name end end

-- TODO Get the correct server local renderArgs = { (data.icon or ) ~=  and ('ConceptCardIcon,'..data.icon) or 'ItemIcon,IT_UNKNOWN', data.name, link, tonumber(data.rare), 4,		64,		tonumber(args.count), args.classes, nil, false, }	local name if args.name ~= 'none' then if (renderArgs[3] or ) ~=  then if args.jplink then name = ('[%s %s]'):format(renderArgs[3], renderArgs[2]) else name = ('%s'):format(renderArgs[3], renderArgs[2]) end else name = renderArgs[2] end end

if args.size == 'large' then renderArgs[6] = 128 elseif args.size == 'small' then renderArgs[6] = 24 renderArgs[9] = name and ' '..name..' ' renderArgs[10] = true elseif args['size'] == 'compact' then renderArgs[9] = name and ' '..renderArgs[2]..' ' else renderArgs[9] = name and ''..name..' ' end return render_icon(unpack(renderArgs)) end

function p._pageName(args) local iname = args[1] model = model or require('Module:Data').model local data = args.data or model.query('ConceptCard','_pageName,server',{where='iname="'..iname..'"'})[1] or {}

local name = model.getLoc(data._pageName, 'name') local link = nil if data._pageName ~= nil then link = (mw.ext.cargo.query('Pages','_pageName',{where='type="Memento" and iname="'..iname..'"'})[1] or {linkUtils.wikiSafeName(name)})._pageName or nil end

local displayName = (name and name ~=  and (link and ..name..'') or name) or iname return displayName end

return p