Module:ElementRefs

local p = {}

function p.main(frame) if frame == mw.getCurrentFrame then args = require('Module:ProcessArgs').merge(true) else frame = mw.getCurrentFrame end

-- Currently this is just used to display related skills. If other uses get added, we'll need a 'type' argument in the cargo table or something.

local element = args.element or mw.title.getCurrentTitle.text local fields = '_pageName, element, notes'

local wheres = 'element="' .. element .. '"'

local cargoArgs = { where = wheres, orderBy = 'ElementRefs.element', }

local result = p.doQuery(fields, cargoArgs) if not result then return '' end

local html = mw.html.create local ul = html:tag('ul') for _, row in ipairs(result) do       local li = ul:tag('li') li:wikitext(frame:preprocess( .. row._pageName ..)) if (row.notes ~= nil and row.notes ~= '') then li:wikitext(' (' .. row.notes .. ')')       end end

return html end

function p.doQuery(fields, cargoArgs) local result = mw.ext.cargo.query('ElementRefs', fields, cargoArgs) if not next(result) then return nil else return result end end

return p