Jump to content

Module:Sandbox/Theki/profile

From Meta, a Wikimedia project coordination wiki
Module documentation
local p = {}

function p.picture(frame)
	local a = {}
	for el in string.gmatch(frame.args[1], "[^,]+") do
		table.insert(a, el)
	end
	if #a == 1 then
		return "[[File:" .. a[1] .. "|256px]]"
	else
		return frame:preprocess(mw.getCurrentFrame():extensionTag({
			name = "gallery",
			args = { mode = "slideshow", style = "margin:0!important;" },
			content = table.concat(a, "\n")
		}))
	end
end

local sites = {
	commons = { n = "Commons", i = "Commons-logo.svg" },
	metawikimedia = { n = "Meta", i = "Wikimedia Community Logo.svg" },
	wikifunctions = { n = "Wikifunctions", i = "Wikifunctions-logo.svg" },
	wikipedia = { n = "Wikipedia", i = "Wikipedia-logo-v2-square.svg" },
	wikisource = { n = "Wikisource", i = "Wikisource-logo.svg" }
}

function p.sites(frame)
	local o = '<div class="prof-sitelist">'
	local i = 0
	
	local title = mw.title.getCurrentTitle()
	local pagename = "User talk:" .. title.rootText
	for site,timeJoined,description in string.gmatch(frame.args[1], "(%l+)%s+(%d+)%s*([^;]*);?$?") do
		local j = (os.time() - timeJoined) / 60 / 60 / 24
		local unit = "days"
		if j >= 365 then
			j = j / 365;
			unit = "years"
		end
		j = math.floor(j * 10) / 10
		
		o = o
			.. '<div class="prof-site" style="' .. (i ~= 0 and "border-top:0;" or "") .. '"><div class="prof-site-icon">'
			.. "[[File:" .. sites[site].i .. "|32px]]" .. "[[" .. site .. ":" .. pagename .. "|" .. sites[site].n .. "]]"
			.. '</div><div class="prof-site-desc"><div><div>'
			.. description
			.. (site == "wikisource" and frame.args[2] or "")
			.. '</div><span class="prof-site-desc-header">Joined <strong>' .. j .. " " .. unit .. " ago" .. '</strong></span></div></div></div>'
		i = i + 1
	end
	return o .. "</div>"
end

return p