Kopumbwa na makambo oyo ezali na kati

Module:Format petscan

Útá Wikipedia.

La documentation pour ce module peut être créée à Module:Format petscan/doc

local p = {}


p.format_paste = function(frame)
	local petscan_text = frame.args[1]
	local tmpl = frame.args[2]
	local newline = ( frame.args["pasretour"] and false ) or true
	
	local format_func 
	
	if tmpl and tmpl ~= "" then
		format_func = function(qid) 
			return frame:expandTemplate{
				title=tmpl, 
				args = {qid} 
			}
		end
	else
		format_func = function(qid) 
			local enart = mw.wikibase.sitelink(qid, "enwiki")
			
			local frart = mw.wikibase.sitelink(qid)
			
			local label = mw.wikibase.label(qid)
			
			if frart == nil and mw.wikibase.getEntityIdForTitle( label ) then
				frart = label .. " (jeu vidéo)"
			end
			
			return "* " .."[[" .. ((frart and frart .. "|") or "") .. mw.wikibase.label(qid) .. "]] " 
			            .. (((enart ~= nil) and "[[:en:" .. enart .. "|(en)]] ") or "")
			            .. "[[:d:" .. qid .. "|(d)]]" 
			            end
	end
	local res = ""
	for match in string.gmatch(petscan_text, "[[]Q[0-9]+[]]") do
		local qid = match:sub(2, #match - 1)
		res = res ..
		tostring(format_func(qid)) .. 
		((newline and "\n") or "") --sous optimal de concaténer comme ça dans une boucle mais c’est pas trop grave
		-- if 
	end	
	return res
end

return p