Module:Higher education task force: Difference between revisions

Content deleted Content added
highly experimental test page, do not use yet
 
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))
 
(141 intermediate revisions by 2 users not shown)
Line 1:
require("strict")
local HigherEducationTaskForce = {}
local yesNo = require("Module:Yesno")
local getArgs = require("Module:Arguments").getArgs
local banner = require("Module:WikiProject_banner")
local p = {}
 
--[[------------------------< _main >---------------------------------
local wikidata_items = {
Internal function to retrieve data for a task force.
student = 'Q132302671', -- Wikidata item for WikiProject Students
]]----------------------------------------------------------------------------
cuny = 'Q132192407', -- Wikidata item for CUNY WikiProject
function p._main(args, data)
uva = 'Q21831051' -- Wikidata item for UVA WikiProject
local dataModule = require('Module:Higher education task force/data')
}
local taskForceCode = args.code or args[1]
local taskForceData
 
if taskForceCode then
local p = {}
taskForceCode = taskForceCode:match('^%s*(.-)%s*$'):lower() -- trim whitespace and put in lower case
taskForceData = dataModule[taskForceCode]
end
 
return taskForceData
function p.getData( frame )
end
local keyword = frame.args[1]
if not keyword then
return nil -- No keyword provided
end
 
--[[------------------------< getCanonicalCode >---------------------------------
local wikidata_item_id = wikidata_items[keyword]
Gets the canonical code for a task force. return tfData.canonicalCode
if not wikidata_item_id then
return nil -- Keyword not found
end
 
]]----------------------------------------------------------------------------
local data = {}
data.wikidata_item = wikidata_item_id
 
function p.main(frame)
local entity = mw.wikibase.getEntity( wikidata_item_id )
local args = getArgs(frame, { parentFirst = true })
if not entity then
return p._main(args)
return nil -- Could not fetch entity from Wikidata
end
 
-- Takes an input string "r" in the form "|a=b" (no spaces around the =) used in templates and adds it to the table
-- TF_1_NAME (P1476 - title)
function p.tab2arg(trable,r)
if entity.claims and entity.claims.P1476 then
local t = mw.text.split(r, "=", true, true) -- Split by comma, trim whitespace, remove empty strings
local titleClaim = entity.claims.P1476[1] -- Assuming only one title
local x = mw.text.split(t[1], "|", true, true) -- Split by comma, trim whitespace, remove empty strings
if titleClaim.mainsnak.datavalue and titleClaim.mainsnak.datavalue.value then
data.tf_1_name = titleClaim.mainsnak.datavalue.value.text
trable[x[2] ]=t[2]
end
return trable
end
end
 
-- Adds an element to a table (syntactic sugar)
-- TF_1_NESTED (P1813 - short name)
function p.ma1(frame,s1,s2)
if entity.claims and entity.claims.P1813 then
frame[s1]=s2
local shortNameClaim = entity.claims.P1813[1] -- Assuming only one short name
end
if shortNameClaim.mainsnak.datavalue and shortNameClaim.mainsnak.datavalue.value then
data.tf_1_nested = shortNameClaim.mainsnak.datavalue.value.text
end
end
 
--[[ pulls out our specially named parameter from the list of template-like args, and expands
-- TF_1_IMAGE (P154 - logo image)
it into the appropriate task force table entries
if entity.claims and entity.claims.P154 then
]]--
local imageClaim = entity.claims.P154[1] -- Assuming only one logo image
function p.fudgeTaskforceParameters(frame)
if imageClaim.mainsnak.datavalue and imageClaim.mainsnak.datavalue.value then
local args = getArgs(frame, { parentFirst = true })
local imageName = imageClaim.mainsnak.datavalue.value.value -- Get the filename
local taskforcesStr = ""
data.tf_1_image = imageName
taskforcesStr = args["HETF_TASKFORCES_TO_EXPAND"]
end
if not taskforcesStr then
end
return "oops"
end
 
local taskforceCodes = mw.text.split(taskforcesStr, ",", true, true) -- Split by comma, trim whitespace, remove empty strings
-- TF_1_MAIN_CAT (P910 - topic category)
local tfCounter = 1
if entity.claims and entity.claims.P910 then
local trable=args
local mainCatClaim = entity.claims.P910[1] -- Assuming only one topic category
if mainCatClaim.mainsnak.datavalue and mainCatClaim.mainsnak.datavalue.value then
local categoryItemId = mainCatClaim.mainsnak.datavalue.value['entity-type'] == 'item' and mainCatClaim.mainsnak.datavalue.value.id
if categoryItemId then
local categoryEntity = mw.wikibase.getEntity( categoryItemId )
if categoryEntity and categoryEntity.labels and categoryEntity.labels.en then
data.tf_1_main_cat = categoryEntity.labels.en.value .. " articles" -- Append " articles" as per example
end
end
end
end
 
for _, code in ipairs(taskforceCodes) do
 
local tfData = p._main({code})
return data
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 frame
end
 
-- More or less a wrapper for WikiProject Banner with some argument sweetening
function p.hetf_banner(frame)
local oframe=frame
frame=p.fudgeTaskforceParameters(frame)
 
return banner.main(oframe)
function p.getWikidataItem( frame )
local data = p.getData( frame )
if data then
return data.wikidata_item
else
return nil
end
end
 
function p.getTFName( frame )
local data = p.getData( frame )
if data then
return data.tf_1_name
else
return nil
end
end
 
function p.getTFNestedprintargs( frame )
local data str= p.getDatagetArgs( frame, { parentFirst = true })
if datareturn thenstr[1]
return data.tf_1_nested
else
return nil
end
end
 
function p.getTFImage( frame )
local data = p.getData( frame )
local imageName = data and data.tf_1_image
if imageName then
return imageName
else
return nil
end
end
 
 
p[''] = function (frame) return p.getTFMainCat_main( frame .args) end
local data = p.getData( frame )
if data then
return data.tf_1_main_cat
else
return nil
end
end
 
 
return p