Module:Higher education task force

This is an old revision of this page, as edited by Tduk (talk | contribs) at 13:51, 14 April 2025. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

require("strict")
local yesNo = require("Module:Yesno")
local getArgs = require("Module:Arguments").getArgs

local p = {}

--[[------------------------< _main >---------------------------------
Internal function to retrieve data for a task force.
]]----------------------------------------------------------------------------
function p._main(args, data)
	local dataModule = require('Module:Higher education task force/data')
	local taskForceCode = args.code or args[1]
	local taskForceData

	if taskForceCode then
		taskForceCode = taskForceCode:match('^%s*(.-)%s*$'):lower() -- trim whitespace and put in lower case
		taskForceData = dataModule[taskForceCode]
	end

	return taskForceData
end

--[[------------------------< getName >---------------------------------
Gets the full name of a task force.
]]----------------------------------------------------------------------------
function p.getName(frame)
	local args = getArgs(frame, { parentFirst = true })
	local tfData = p._main(args)
	if tfData then
		return tfData.name
	end
	return nil
end

--[[------------------------< getNestedName >---------------------------------
Gets the nested name of a task force.
]]----------------------------------------------------------------------------
function p.getNestedName(frame)
	local args = getArgs(frame, { parentFirst = true })
	local tfData = p._main(args)
	if tfData then
		return tfData.nested
	end
	return nil
end

--[[------------------------< getImage >---------------------------------
Gets the image filename for a task force.
]]----------------------------------------------------------------------------
function p.getImage(frame)
	local args = getArgs(frame, { parentFirst = true })
	local tfData = p._main(args)
	if tfData then
		return tfData.image
	end
	return nil
end

--[[------------------------< getCategory >---------------------------------
Gets the category name for a task force.
]]----------------------------------------------------------------------------
function p.getCategory(frame)
	local args = getArgs(frame, { parentFirst = true })
	local tfData = p._main(args)
	if tfData then
		return tfData.category
	end
	return nil
end

--[[------------------------< getLink >---------------------------------
Gets the project link for a task force.
]]----------------------------------------------------------------------------
function p.getLink(frame)
	local args = getArgs(frame, { parentFirst = true })
	local tfData = p._main(args)
	if tfData then
		return tfData.link
	end
	return nil
end

--[[------------------------< getCanonicalCode >---------------------------------
Gets the canonical code for a task force.
]]----------------------------------------------------------------------------
function p.getCanonicalCode(frame)
	local args = getArgs(frame, { parentFirst = true })
	local tfData = p._main(args)
	if tfData then
		return tfData.canonicalCode
	end
	return nil
end

function p.main(frame)
	local args = getArgs(frame, { parentFirst = true })
	return p._main(args)
end

--[[------------------------< generateTaskforceParameters >---------------------------------
Generates the WikiProject banner parameters for a comma-separated list of task force codes.

Parameters:
* frame: The frame object.

Returns:
* A string containing the WikiProject banner parameters for the task forces.
]]----------------------------------------------------------------------------
function p.generateTaskforceParameters(frame)
	local taskforcesStr = frame.args.taskforces
	if not taskforcesStr then
		return ""
 	end

	local taskforceCodes = mw.text.split(taskforcesStr, ",", true, true) -- Split by comma, trim whitespace, remove empty strings
	local paramsStr = ""
	local tfCounter = 1

	for _, code in ipairs(taskforceCodes) do
		local tfData = p.getTaskForceData(code)
		if tfData then
			paramsStr = paramsStr .. string.format("\n|tf %d=yes", tfCounter)
			paramsStr = paramsStr .. string.format("\n|TF_%d_LINK=%s", tfCounter, tfData.link)
			paramsStr = paramsStr .. string.format("\n|TF_%d_NAME=%s", tfCounter, tfData.name)
			paramsStr = paramsStr .. string.format("\n|TF_%d_NESTED=%s", tfCounter, tfData.nested)
			paramsStr = paramsStr .. string.format("\n|TF_%d_IMAGE=%s", tfCounter, tfData.image)
			paramsStr = paramsStr .. string.format("\n|TF_%d_MAIN_CAT=%s", tfCounter, tfData.category)
			tfCounter = tfCounter + 1
		end
	end

	return paramsStr
end

p[''] = function (frame) return p._main(frame.args) end

return p