Modul:Vorlage:RGBl

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Die Dokumentation für dieses Modul kann unter Modul:Vorlage:RGBl/Doku erstellt werden

local function fault( alert )
	-- Format message with class="error"
	--     alert   -- string, with message
	-- Returns message with markup
	return string.format( "<span class=\"error\">%s [[Vorlage:RGBl|(Hilfe)]]</span>[[Kategorie:Wikipedia:Vorlagenfehler/Vorlage:RGBl]]", alert )
end -- fault()

local function generate(text, lbl, abbr, url)
	-- Generate link
	local lbl2
	if text == "{{{text}}}" or text == "" then
		text = string.format("<abbr title=\"%s\">%s</abbr>", abbr, lbl)
	elseif not string.match(text, "<abbr ") then
		text = string.format("<abbr title=\"%s\">%s</abbr>", abbr, text)
	end
	if url == '' then
		return text
	else
		return string.format("[%s %s]", url, text)
	end

end -- generate()

-- Export
local p = { }

offa = {
["1919"]=203, ["1920"]=235, ["1921"]=71, ["1922"]=99, ["1923"]=135,
["1924"]=23, ["1925"]=53, ["1926"]=51, ["1927"]=53, ["1928"]=53, ["1929"]=51,
["1930"]=71, ["1931"]=99, ["1932"]=75, ["1933"]=126, ["1934"]=115,
["1935"]=143, ["1936"]=91, ["1937"]=107, ["1938"]=179, ["1939"]=230,
["1940"]=47, ["1941"]=29, ["1942"]=103, ["1943"]=21, ["1944"]=15, ["1945"]=1
}

offb = {
["1922"]=29, ["1923"]=35, ["1924"]=27, ["1925"]=25, ["1926"]=27, ["1927"]=27,
["1928"]=27, ["1929"]=29, ["1930"]=29, ["1931"]=27, ["1932"]=19, ["1933"]=17,
["1934"]=31, ["1935"]=35, ["1936"]=27, ["1937"]=27, ["1938"]=15, ["1939"]=15,
["1940"]=19, ["1941"]=19, ["1942"]=13, ["1943"]=7, ["1944"]=1, ["1945"]=1
}



function p.linkRGBl(arglist)
	local name = arglist[1]
	local text = arglist.text

	-- Die nächsten Zeilen sind ausschließlich für direkten Modultest sinnvoll.
	if not name then name = "{{{1}}}" end
	if not text then text = "{{{text}}}" end
	--

	local name = arglist[1]
	local teil = ''
	local jahr = ''
	local seite = ''
	local lbl = ''
	local abbr = ''
	local iseite = ''
	local wartung = ''
	local austria = false

	-- Parse Eingabe
	tmp = string.match(name, "&nbsp;")
	if tmp then
		return fault("&amp;nbsp; nicht erlaubt")
	end
	tmp = string.match(name, "  ") or string.match(name, "/ ") or string.match(name, " [/,%.a-z]")
	if tmp then
		return fault("überschüssiges Leerzeichen")
	end
	tmp = string.match(name, "nI") or string.match(name, "%dI") or string.match(name, "I[SN]") or string.match(name, "[,%.]%d")
	if tmp then
		return fault("fehlendes Leerzeichen")
	end
	jahr, sichtbar, teil, seite, iseite, trash = string.match(name, "(%d+)(n*) (%a+) S. (%d+),* *(%d*)([^ \t\n,0-9]*)")
	if not jahr then
		teil = "I"
		jahr, sichtbar, seite, iseite, trash = string.match(name, "(%d+)(n*) S. (%d+),* *(%d*)([^ \t\n,0-9]*)")
	end
	if trash and string.len(trash) > 0 then
		return fault("überschüssige Zeichen am Ende")
	end
	if not seite then
		jahr, sichtbar, teil, nummer = string.match(name, "(%d+)(n*) (%a+) Nr. (%d+)")
	end
	if not teil then
		austria = true
		teil, nummer, jahr = string.match(name, "(I+) Nr. (%d+a*)/(%d+)")
		if not teil then
			nummer, jahr = string.match(name, "Nr. (%d+a*)/(%d+)")
			teil = ""
			if not jahr then
				return fault('"S." oder "Nr." fehlt')
			end
		end
	end
	
	-- Generiere Ausgaben
	-- Österreich
	if austria then
		lbl = string.format("RGBl. Nr. %s/%d", nummer, jahr)
		if (jahr + 0) >= 1870 then
			abbr = string.format("Reichsgesetzblatt für die im Reichsrathe vertretenen Königreiche und Länder, Nummer %s, Jahrgang %d", nummer, jahr)
		else
			abbr = string.format("Reichs-Gesetz-Blatt für das Kaiserthum Oesterreich, Nummer %s, Jahrgang %d", nummer, jahr)
		end
		url = string.format("https://www.ris.bka.gv.at/Ergebnis.wxe?Abfrage=BgblAlt&Bgblnummer=%s/%d&amp;SkipToDocumentPage=True&amp;BisKundmachungsdatum=09.11.1920", nummer, jahr)
		return generate(text, lbl, abbr, url) .. wartung
	end

	-- Deutsches Reich
	if teil == "I" then
		ateil = "dra"
	elseif teil == "II" then
		ateil = "drb"
	else
		return fault("Angabe zum Teil falsch")
	end
	if not iseite then
		iseite = ""
	end
	if not sichtbar then sichtbar = "" end
	if sichtbar == "n" then
		lbl = "RGBl."
	else
		lbl = string.format("RGBl. %d", jahr)
	end
	abbr = string.format("Reichsgesetzblatt Jahrgang %d", jahr)
	if jahr + 0 > 1921 then
		lbl = string.format("%s %s", lbl, teil)
		abbr = string.format("%s Teil %s", abbr, teil)
	elseif teil == "drb" then
		return fault("%s gab es keinen Teil %s", jahr, teil)
	end
	lbl = string.format("%s S. %d", lbl, seite)
	abbr = string.format("%s Seite %d, ausgegeben zu Berlin", abbr, seite)
	if string.len(iseite) > 0 then
		lbl = lbl .. ", " .. iseite
	end
	if (jahr + 0) >= 1919 and (jahr + 0) <= 1945 then
		if iseite == "" then tmp = seite else tmp = iseite end
		if ateil == "dra" then
			if (jahr + 0) == 1935 and tmp + 0 > 1286 then tmp = tmp + 4 end -- unnummerierter Einschub dra 1935
			if (jahr + 0) == 1939 and tmp + 0 > 128  then tmp = tmp + 2 end -- unnummerierter Einschub dra 1939
			if (jahr + 0) == 1940 and tmp + 0 > 1152  then tmp = tmp - 10 end -- doppelseitiger Einschub dra 1940
			aseite = offa[jahr] + tmp - 1
		else
			aseite = offb[jahr] + tmp - 1
		end
		url = string.format("https://alex.onb.ac.at/cgi-content/alex?aid=%s&datum=%s&page=%d", ateil, jahr, aseite)
	else
		if (jahr + 0) > 1945 then return fault("Kein Reichsgesetzblatt nach 1945."); end
		-- Andere Jahrgänge des Reichsgesetzblattes ohne URL möglich.
		url = ''
	end
	return generate(text, lbl, abbr, url) .. wartung
end


function p.getrgbl(frame)
	local lucky, r = pcall(p.linkRGBl, frame.args)
	if not lucky then
		r = fault("Parameterfehler in [[Vorlage:RGBl]]: " .. r)
	end
	return r
end



return p