Module:Test

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

local h = {} local p = {} function p.main(frame) local output = h.initOutput local result = mw.ext.cargo.query(		'Items_new',		'_pageName=page, itemid, name, image, internalname',		{			groupBy = 'itemid',			orderBy = 'itemid',			where = 'itemid IS NOT NULL AND itemid <=4000 AND internalname <> ""',			limit = 5000		}	) for _, row in ipairs(result) do		h.formatRow(row) h.printRow(output, row) end local result = mw.ext.cargo.query(		'Items_new',		'_pageName=page, itemid, name, image, internalname',		{			groupBy = 'itemid',			orderBy = 'itemid',			where = 'itemid IS NOT NULL AND itemid > 4000 AND internalname <> ""',			limit = 5000		}	) for _, row in ipairs(result) do		h.formatRow(row) 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.itemid row.Name = (row.page == row.name) and ('%s'):format(row.name) or ('%s'):format(row.page, row.name) row.Image = row.image row.InternalName = tostring((mw.html.create('code'):wikitext(row.internalname))) 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