Module:Sandbox/Jikat2/reigntemplate

From Wikipedia, the free encyclopedia
--Google Code in 2017, Update code of the "Reign" template on English Wikipedia
local p = {}

p.reign = function(frame)
	local startdate = frame.args.startdate or "?"
	local enddate = frame.args.enddate or "present"
	local secondstart = frame.args.secondstart or ""
	local secondend = frame.args.secondend or ""
	if #startdate == 0 then startdate = "?"
	end
	if #enddate == 0 then enddate = "present"
	end
	local wrap = frame.args.wrap or ""
	if secondstart == "" and secondend ~= "" then secondstart = "?"
	end
	if secondend == "" and secondstart ~= "" then secondend = "present"
	end
	local era = frame.args.era or ""
	if era ~= "" then era = " "..era
	end
	local single = frame.args.single or ""
	local postdate = frame.args.postdate or ""
	if postdate ~= "" then postdate = ","..postdate
	end
	local predate = frame.args.predate or ""
	if predate ~= "" then predate = predate..", "
	end
	local middate = frame.args.middate or ""
	if middate ~= "" then middate = middate..", "
	end
	local label = frame.args.label or ""
	if single ~= "" then 
		startdate = single
		enddate = ""
	end
	if postdate ~= "" then
		postdate = postdate..era
	elseif secondend ~= "" then
		secondend = secondend..era
	else
		enddate = enddate..era
	end
	local dash =""
	local dash2 =""
	local r = ""
	local cap = frame.args.cap or "n"
	local show = frame.args.show or "normal"
	if show == "normal" then r = "<abbr title='reign'>".."r.".."</abbr>"
	elseif show == "word" then r = "reigned " 
		if cap == "y" then r = "Reigned "
		end
	elseif show == "colon" then r = "reign: " 
		if cap == "y" then r = "Reign: "
		end
	elseif show == "lword" then r = "[[Reign|reigned]] "
		if cap == "y" then r = "[[Reign|Reigned]] "
		end
	elseif show == "lcolon" then r = "[[Reign|reign:]] "
		if cap == "y" then r = "[[Reign|Reign:]] "
		end
	elseif show == "blank" then r = ""
	end
	if label ~= "" then r = label.." "
	end
	if string.match(startdate, " ") or string.match(enddate, " ") and era == "" then dash = " - " else dash = "-"
	end
	if string.match(secondstart, " ") or string.match(secondend, " ") and era == "" then dash2 = " - " else dash2 = "-"
	end
	if secondstart == "" and secondend == "" then dash2 =""
	end
	if secondstart ~= "" then enddate = enddate..", "
	end
	if single ~= "" then dash=""
	end
	local msg =r.." "..predate..startdate..dash..enddate..middate..secondstart..dash2..secondend..postdate.."<br>"
	if wrap ~= "" then msg = r..predate..startdate..dash..enddate..middate.."<br>"..secondstart..dash2..secondend..postdate.."<br>"
	end
	return msg
end

return p