Module:Higher education task force: Difference between revisions

Content deleted Content added
try again with magic
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))
 
(139 intermediate revisions by 2 users not shown)
Line 1:
equirerequire("strict")
local yesNo = require("Module:Yesno")
local getArgs = require("Module:Arguments").getArgs
local banner = require("Module:WikiProject_banner")
 
local p = {}
 
--[[------------------------< _main >---------------------------------
-- Determine whether we're being called from a sandbox (not really applicable here, but keeping the structure)
Internal function to retrieve data for a task force.
-- local sandbox = mw.getCurrentFrame():getTitle():find('sandbox', 1, true) and '/sandbox' or ''
]]----------------------------------------------------------------------------
 
-- Implements functionality to retrieve data from Module:Higher education task force/data
function p._main(args, data)
local dataModule = require('Module:Higher education task force/data')
Line 18 ⟶ 17:
taskForceData = dataModule[taskForceCode]
end
 
-- No default needed here, as the module is for retrieving specific data
 
return taskForceData
end
 
--[[------------------------< getNamegetCanonicalCode >---------------------------------
Gets the fullcanonical namecode offor a task force. return tfData.canonicalCode
 
]]----------------------------------------------------------------------------
 
function p.getName(frame)
function p.main(frame)
local args = getArgs(frame, { parentFirst = true })
local tfData =return p._main(args)
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
function p.getNestedName(frame)
local args = getArgs(frame, { parentFirst = true })
trable[x[2] ]=t[2]
local tfData = p._main(args)
return trable
if tfData then
return tfData.nested
end
return nil
end
 
-- Adds an element to a table (syntactic sugar)
--[[------------------------< getImage >---------------------------------
function p.ma1(frame,s1,s2)
Gets the image filename for a task force.
frame[s1]=s2
]]----------------------------------------------------------------------------
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
 
--[[ pulls out our specially named parameter from the list of template-like args, and expands
--[[------------------------< getCategory >---------------------------------
Gets the category name for ait into the appropriate task force. table entries
]]--
]]----------------------------------------------------------------------------
function p.getCategoryfudgeTaskforceParameters(frame)
local args = getArgs(frame, { parentFirst = true })
local tfDatataskforcesStr = p._main(args)""
taskforcesStr = args["HETF_TASKFORCES_TO_EXPAND"]
if tfData then
if not taskforcesStr then
return tfData.category
return "oops"
end
 
local taskforceCodes = mw.text.split(taskforcesStr, ",", true, true) -- Split by comma, trim whitespace, remove empty strings
local tfCounter = 1
local trable=args
 
for _, code in ipairs(taskforceCodes) do
local tfData = p._main({code})
if tfData then
trable = p.tab2arg(trable,string.format("|tf %d=%dyes", tfCounter,tfCounter))
trable = p.tab2arg(trable,string.format("|TF_%d_LINK=%s", tfCounter, tfData.link))
trable = p.tab2arg(trable,string.format("|TF_%d_NAME=%s", tfCounter, tfData.name))
trable = p.tab2arg(trable,string.format("|TF_%d_NESTED=%s", tfCounter, tfData.nested))
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
--[[------------------------< getLink >---------------------------------
function p.hetf_banner(frame)
Gets the project link for a task force.
local oframe=frame
]]----------------------------------------------------------------------------
frame=p.fudgeTaskforceParameters(frame)
function p.getLink(frame)
 
local args = getArgs(frame, { parentFirst = true })
return banner.main(oframe)
local tfData = p._main(args)
if tfData then
return tfData.link
end
return nil
end
 
 
--[[------------------------< getCanonicalCode >---------------------------------
function p.printargs(frame)
Gets the canonical code for a task force.
local str=getArgs(frame, { parentFirst = true })
]]----------------------------------------------------------------------------
return str[1]
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
 
p[''] = function (frame) return p._main(frame.args) end