Module:ItemIDs

local util_cargo = require('Module:CargoUtil')

local COLUMNS = { 'Id', 'Name', 'InternalName' } local i18n = { Id = 'ID', Name = 'Name', Image = 'Image', InternalName = 'Internal name', }

local h = {} local p = {} function p.main(frame) local query = { fields = 'itemid, name, internalname', tables = 'Items', groupBy = 'itemid', orderBy = 'itemid', where = 'itemid IS NOT NULL', continue = true }	local result = util_cargo.query(query) for _, row in ipairs(result) do		h.formatRow(row) end local output = h.initOutput for _, row in ipairs(result) do		h.printRow(output, row) end return output end

function h.initOutput local output = mw.html.create('table') :addClass('terraria') :addClass('sortable') :css('text-align', 'center') local header = output:tag('tr') for _, key in ipairs(COLUMNS) do		header:tag('th') :wikitext(i18n[key]) end return output end

function h.formatRow(row) row.Id = row.itemid2 and row.itemid2 * -1 or row.itemid row.Name = ('%s'):format(row.name) row.Image = row.image row.InternalName = tostring(h.makeInternalName(row)) end

function h.makeInternalName(row) local ret = mw.html.create('code') :wikitext(row.internalname) return ret end

function h.printRow(output, row) local tr = output:tag('tr') for _, key in ipairs(COLUMNS) do		tr:tag('td') :wikitext(row[key]) end end

return p