Module:Tag

From TwogPedia
Revision as of 17:38, 23 June 2023 by Couchor (talk | contribs)

Documentation for this module may be created at Module:Tag/doc

local getArgs = require('Module:Arguments').getArgs
local cargo = mw.ext.cargo

local Tag = {}

function Tag.main(frame)
	local args = getArgs(frame)
	
	local tableContainer = mw.html.create('div')
	if args.name == nil then return tableContainer:wikitext('No tag found') end
	
	args.name = mw.uri.decode(args.name)
	
	local tables = 'News'
	local fields = '_pageName, tags'
	local cargoArgs = {
		where = 'tags HOLDS LIKE "%' .. args.name .. '%"',
        orderBy = 'date DESC',
		limit = 50
	}
	local results = cargo.query(tables, fields, cargoArgs)

	if #results > 0 then
		for i = 1, #results do
			local result = results[i]
			local news = mw.html.create('div'):wikitext('[[' .. result._pageName .. ']]')
			tableContainer:node(news)
		end
	else
		return tableContainer:wikitext('No news found with the tag "' .. args.name .. '"') 
	end

	return tableContainer
end

return Tag