Module:Sandbox/Valeriej/Wish
The Wish module is for Wikipedia's Teahouse Wishing Well.
The participants function takes in a list of user names and returns a string that contains links for the usernames.
The _participants function is meant to be called from this module and takes in a string of participants separated by commas (or any non alphanumeric character).
The role function takes in a list of roles and returns an image to represent that role. The images also link to a page of definitions.
Incomplete: The stat function takes in a stat (status) and returns on image to represent that status. The image also links to a page of definitions.
Incomplete: The row function returns a row in the Wishing Well table. Call using the following format: This method has a template wrapper at: Template:WishingWell/Table/RowAlt.
local p = {}
--Takes in a list of role names and returns a string of image links
function p.roles( frame )
--Set up variables
local i = 0
local returnS = ""
local linkBase = "User:Valeriej/WishingWellSandbox/Definitions"
local imageSize = "30px"
local imageLink = ""
if frame.args[i+1] == nil then
return returnS
end
repeat
i = i + 1
if frame.args[i] == "builder" then
imageLink = "Community_Noun_project_2280.svg"
elseif frame.args[i] == "designer" then
imageLink = "Vitruvian_Man_Noun_project_6674.svg"
elseif frame.args[i] == "researcher" then
imageLink = "Noun_project_8974.svg"
else
imageLink = "Question_Noun_project_2185.svg"
end
returnS = returnS .. "[[File:" .. imageLink .."|"..imageSize.."|link="..linkBase.. "#Role|This wish needs a "..frame.args[i]..".]] "
mw.log(returnS)
until frame.args[i+1] == nil
return returnS
end
function p._roles(roleList)
--Set up variables
returnS = ""
linkBase = "User:Valeriej/WishingWellSandbox/Definitions"
imageSize = "30px"
imageLink = ""
for token in mw.ustring.gmatch( roleList, "%w+" ) do
if token == "builder" then
imageLink = "Community_Noun_project_2280.svg"
elseif token == "designer" then
imageLink = "Vitruvian_Man_Noun_project_6674.svg"
elseif token == "researcher" then
imageLink = "Noun_project_8974.svg"
else
imageLink = "Question_Noun_project_2185.svg"
end
returnS = returnS .. "[[File:" .. imageLink .."|"..imageSize.."|link="..linkBase.. "#Role|This wish needs a "..token..".]] "
mw.log(returnS)
end
return returnS
end
--Read in usernames and return a list of links to their user pages.
function p.participants( frame )
--Set up variables
i = 0
userLinks = ""
if frame.args[i+1] ~= nil then
repeat
i = i + 1
userLinks = userLinks .. "[[User:"..frame.args[i].."|"..frame.args[i].."]]"
if frame.args[i+1] ~= nil then
userLinks = userLinks .. ", "
end
mw.log(userLinks)
until frame.args[i+1] == nil
end
return userLinks
end
--Read in usernames and return a list of links to their user pages.
function p._participants( userList )
--Set up variables
i = 0
userLinks = ""
for token in mw.ustring.gmatch( userList, "%w+_*%.*%!*%?*%:*%w*%.*%!*" ) do
if(i ~= 0) then
userLinks = userLinks..", "
end
userLinks = userLinks .. "[[User:"..token.."|"..token.."]]"
i=i+1
mw.log(userLinks)
end
return userLinks
end
function p.stat( frame )
i = 1
statusText = ""
if frame.args[i] == "Open" then statusText = frame.args[i]
elseif frame.args[i] == "In Progress" then statusText = frame.args[i]
elseif frame.args[i] == "Ready to Deploy" then statusText = frame.args[i]
elseif frame.args[i] == "Wish Granted" then statusText = frame.args[i]
elseif frame.args[i] == "Experiment" then statusText = frame.args[i].."in Progress"
elseif frame.args[i] == "Closed" then statusText = frame.args[i]
else statusText = "Invalid Status"
end
return statusText
end
function p.row( frame )
--Builds up a row in the Wishing Well table
tablerow = "|" .. frame.args['wishName'].." ||"..p._participants(frame.args['genies']).." ||"..p._roles(frame.args['geniesNeeded'])
tablerow = tablerow.."||"..frame.args['stat'].."||"..frame.args['createdOn'].."||"..frame.args['lastUpdated'].."\n|-"
return tablerow
end
return p