Aller au contenu

Module:PingProjet

Une page de Wikipédia, l'encyclopédie libre.

 Documentation[créer] [purger]
local p = {}

local function get_participants_list(frame, project_title)
	project_title = 'Projet:' .. project_title .. '/Participants'
	if not mw.title.new(project_title).exists then
		return nil
	end
	
	local result = ""
	local text = frame:expandTemplate{ title = project_title, args = {}}
	for i,line in ipairs(mw.text.split(text, "\n", true)) do
        result = result .. line:gsub("^[*#]+ *", "") .. " "
    end
    return result
end

function p.get_participants_list(frame)
	return  get_participants_list(frame, project_title or frame.args[1])
end

function p.mention(frame)
	local NB_MAX_PROJECT = 5
	local result = ""
	local hidden_notif_list = ""
	local args = frame:getParent().args
	if args[1] then
		local tmp = get_participants_list(frame, args[1])
		if tmp ~= nil then
			hidden_notif_list = hidden_notif_list .. " " .. tmp
			result = result .. '[[Projet:' .. args[1] .. ']]'
		else
			result = result .. '[[Projet:' .. args[1] .. ']]<span title="Le projet « ' .. args[1] .. ' » n\'a pas de sous-page « Participants »">!</span>'
		end
		local i = 2
		if args[2] then
			while args[i+1] and i < NB_MAX_PROJECT do
				tmp = get_participants_list(frame, args[i])
				if tmp ~= nil then
					hidden_notif_list = hidden_notif_list .. " " .. tmp
					result = result .. ', [[Projet:' .. args[i] .. ']]'
				else
					result = result .. ', [[Projet:' .. args[i] .. ']]<span title="Le projet « ' .. args[i] .. ' » n\'a pas de sous-page « Participants »">!</span>'
				end
				i = i+1
			end
			tmp = get_participants_list(frame, args[i])
			if tmp ~= nil then
				hidden_notif_list = hidden_notif_list .. " " .. tmp
				result = result .. ', [[Projet:' .. args[i] .. ']]'
			else
				result = result .. ', [[Projet:' .. args[i] .. ']]<span title="Le projet « ' .. args[i] .. ' » n\'a pas de sous-page « Participants »">!</span>'
			end
		end
		result = result .. '<div style="display:none;">' .. hidden_notif_list .. '</div>'
	end
	return result
end

return p