Module:AuthorContent

local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local util_html = require('Module:HtmlUtil') local util_time = require('Module:TimeUtil')

local COLUMNS = { 'Date', 'Content', 'Publication', 'Content Type' }

local h = {}

local i18n = { ContentType = 'Content Type', Author = 'Author', }

function h.query(author, limit) local tbl = { tables = 'ExternalContent', fields = { 'Title', 'URL', 'ContentType', 'Publication', 'Date', },		where = ('Authors HOLDS "%s"'):format(author), orderBy = 'Date DESC', limit = limit or 200, }	return tbl end

function h.processData(result, author) local processed = {} for i, row in ipairs(result) do		processed[i] = h.processRow(row, author) end return processed end

function h.processRow(row, author) local tbl = { Date = util_time.dateInLocal(row.Date), Content = ('[%s %s]'):format(row.URL, row.Title or ''), Publication = row.Publication or '', ['Content Type'] = row.ContentType or '', }	return tbl end

function h.makeOutput(processed, author) local output = mw.html.create output:wikitext(("The following query shows all the media content authored by: %s"):format(author)) h.printTable(output, processed, author) return output end

function h.printTable(output, processed, author) local tbl = output:tag('table') :addClass('wikitable hoverable-rows') :attr('id', 'teamschedule-history-table') h.addHeading(tbl) for _, row in ipairs(processed) do		local tr = tbl:tag('tr') for _, col in ipairs(COLUMNS) do			tr:tag('td') :wikitext(row[col]) end end end

function h.addHeading(tbl) local tr = tbl:tag('tr') for _, col in ipairs(COLUMNS) do		tbl:tag('th'):wikitext(col) end return end

local p = {} function p.main(frame) local args = util_args.merge(true) local author = args[1] local query = h.query(author, args.limit) local result = util_cargo.queryAndCast(query) local processed = h.processData(result, author) return h.makeOutput(processed, author) end return p