Module:Higher education task force: Difference between revisions

Content deleted Content added
try again with AI, this time not wikidata-based
m Protected "Module:Higher education task force": High-risk template or module: 5198 transclusions (more info) ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))
 
(140 intermediate revisions by 2 users not shown)
Line 1:
require("strict")
-- This module provides access to data for WikiProject Higher education task forces.
local yesNo = require("Module:Yesno")
-- It uses the data defined in [[Module:Higher education task force/data]].
local getArgs = require("Module:Arguments").getArgs
 
local dataModulebanner = require('"Module:Higher education task force/data'WikiProject_banner")
 
local p = {}
 
--[[------------------------< getTaskForceData_main >---------------------------------
GetsInternal thefunction to retrieve data for a specific 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
Parameters:
taskForceCode = taskForceCode:match('^%s*(.-)%s*$'):lower() -- trim whitespace and put in lower case
* taskForceCode: The code of the task force (e.g., "student", "cuny", "uva").
taskForceData = dataModule[taskForceCode]
end
 
return taskForceData
Returns:
* A table containing the data for the task force, or nil if the code is invalid.
]]----------------------------------------------------------------------------
function p.getTaskForceData(taskForceCode)
return dataModule[taskForceCode]
end
 
--[[------------------------< getNamegetCanonicalCode >---------------------------------
Gets the fullcanonical namecode offor a task force. return tfData.canonicalCode
 
]]----------------------------------------------------------------------------
Parameters:
* taskForceCode: The code of the task force.
 
function p.main(frame)
Returns:
local args = getArgs(frame, { parentFirst = true })
* The full name of the task force, or nil if the code is invalid.
return p._main(args)
]]----------------------------------------------------------------------------
function p.getName(taskForceCode)
local tfData = p.getTaskForceData(taskForceCode)
if tfData then
return tfData.name
end
return nil
end
 
-- Takes an input string "r" in the form "|a=b" (no spaces around the =) used in templates and adds it to the table
--[[------------------------< getNestedName >---------------------------------
function p.tab2arg(trable,r)
Gets the nested name of a task force.
local t = mw.text.split(r, "=", true, true) -- Split by comma, trim whitespace, remove empty strings
local x = mw.text.split(t[1], "|", true, true) -- Split by comma, trim whitespace, remove empty strings
trable[x[2] ]=t[2]
return trable
end
 
-- Adds an element to a table (syntactic sugar)
Parameters:
function p.ma1(frame,s1,s2)
* taskForceCode: The code of the task force.
frame[s1]=s2
 
Returns:
* The nested name of the task force, or nil if the code is invalid.
]]----------------------------------------------------------------------------
function p.getNestedName(taskForceCode)
local tfData = p.getTaskForceData(taskForceCode)
if tfData then
return tfData.nested
end
return nil
end
 
--[[ pulls out our specially named parameter from the list of template-like args, and expands
--[[------------------------< getImage >---------------------------------
Gets the image filename for ait into the appropriate task force. table entries
]]--
function p.fudgeTaskforceParameters(frame)
local args = getArgs(frame, { parentFirst = true })
local taskforcesStr = ""
taskforcesStr = args["HETF_TASKFORCES_TO_EXPAND"]
if not taskforcesStr then
return "oops"
end
 
local taskforceCodes = mw.text.split(taskforcesStr, ",", true, true) -- Split by comma, trim whitespace, remove empty strings
Parameters:
local tfCounter = 1
* taskForceCode: The code of the task force.
local trable=args
 
for _, code in ipairs(taskforceCodes) do
Returns:
local tfData = p._main({code})
* The image filename for the task force, or nil if the code is invalid.
if tfData then
]]----------------------------------------------------------------------------
trable = p.tab2arg(trable,string.format("|tf %d=%dyes", tfCounter,tfCounter))
function p.getImage(taskForceCode)
trable = p.tab2arg(trable,string.format("|TF_%d_LINK=%s", tfCounter, tfData.link))
local tfData = p.getTaskForceData(taskForceCode)
trable = p.tab2arg(trable,string.format("|TF_%d_NAME=%s", tfCounter, tfData.name))
if tfData then
trable = p.tab2arg(trable,string.format("|TF_%d_NESTED=%s", tfCounter, tfData.nested))
return tfData.image
trable = p.tab2arg(trable,string.format("|TF_%d_IMAGE=%s", tfCounter, tfData.image))
trable = p.tab2arg(trable,string.format("|TF_%d_MAIN_CAT=%s", tfCounter, tfData.category))
tfCounter = tfCounter + 1
end
end
frame.args=trable
return nil
return frame
end
 
-- More or less a wrapper for WikiProject Banner with some argument sweetening
--[[------------------------< getCategory >---------------------------------
function p.hetf_banner(frame)
Gets the category name for a task force.
local oframe=frame
frame=p.fudgeTaskforceParameters(frame)
 
return banner.main(oframe)
Parameters:
* taskForceCode: The code of the task force.
 
Returns:
* The category name for the task force, or nil if the code is invalid.
]]----------------------------------------------------------------------------
function p.getCategory(taskForceCode)
local tfData = p.getTaskForceData(taskForceCode)
if tfData then
return tfData.category
end
return nil
end
 
--[[------------------------< getLink >---------------------------------
Gets the project link for a task force.
 
function p.printargs(frame)
Parameters:
local str=getArgs(frame, { parentFirst = true })
* taskForceCode: The code of the task force.
return str[1]
 
Returns:
* The project link for the task force, or nil if the code is invalid.
]]----------------------------------------------------------------------------
function p.getLink(taskForceCode)
local tfData = p.getTaskForceData(taskForceCode)
if tfData then
return tfData.link
end
return nil
end
 
--[[------------------------< getCanonicalCode >---------------------------------
Gets the canonical code for a task force.
 
Parameters:
* taskForceCode: The code of the task force (can be an alias).
 
p[''] = function (frame) return p._main(frame.args) end
Returns:
* The canonical code for the task force, or nil if the code is invalid.
]]----------------------------------------------------------------------------
function p.getCanonicalCode(taskForceCode)
local tfData = p.getTaskForceData(taskForceCode)
if tfData then
return tfData.canonicalCode
end
return nil
end
 
return p