Module:Legislationuk

MyWikiBiz, Author Your Legacy — Friday July 19, 2024
Jump to navigationJump to search

Template:Module rating

Usage

{{#invoke:Legislationuk|function_name}}

Template:Sandbox other


require ( "Module:Legislationuk/Mw.html extension" )
require ( "Module:Legislationuk/data/session" )
require ("Module:Roman")
local p = {}

function p.main ( frame )
	local data = mw.loadData( "Module:Legislationuk/data/session" )
	local i = { }
	if frame == mw.getCurrentFrame() then
		local fa = { }
		for t = 1, 22 do
			i[ t ] = frame:getParent().args[ t ]
			if frame.args[ t ] then
				fa[ t ] = frame.args[ t ]
				i[ t ] = fa[ t ]
			end
		end
	else
		for _, t in ipairs( frame ) do
			i[ _ ] = frame[ _ ]
		end
	end
	i[ 6 ] = os.time {day = tonumber ( string.sub ( i[ 6 ], 1, 2 ) ), month = tonumber ( string.sub ( i[ 6 ], 4, 5 ) ), year = tonumber ( string.sub ( i[ 6 ], 7 ) ) }
	local o = "<tr><td colspan=3 style=background:#"
	if i[ 10 ] == "y" then o = o .. "f2cece;border-color:#bfa3a3" else o = o .. "ececec" end
	o = o .. "><div style=display:flex;align-items:center;width:42em;max-width:51vw class=box><div style=flex-grow:9>\'\'\'[[" .. i[ 1 ] .. "]]\'\'\'" .. i[ 2 ]
	if i[ 10 ] == "y" then o = o .. " (repealed)" end
	o = o .. "</div><div style=float:right;min-width:"
	if i[ 8 ] == "y" and i[ 9 ] ~= "n" then	o = o .. "4.5" else o = o .. "2.25" end
	o = o .. "em;max-width:"
	if i[ 8 ] == "y" and i[ 9 ] ~= "n" then	o = o .. "4.5" else o = o .. "2.25" end
	o = o .. "em>"
	if i[ 8 ] == "y" then
		local lt = { [ "public" ] = "ukpga", [ "local" ] = "ukla", [ "asp" ] = "asp", [ "asc" ] = "asc", [ "anaw" ] = "anaw", [ "nawm" ] = "mwa", [ "ania" ] = "nia", [ "church" ] = "ukcm" }
		local url = "https://www.legislation.gov.uk/" .. lt[ i[ 3 ] ] .. "/" .. os.date ( "%Y", i[ 6 ] ) .. "/" .. i[ 4 ] .. "/contents"
		o = o .. "[[File:Legislation.gov.uk External.svg|29x14px|link=" .. url .. "]]"
	end
	if i[ 8 ] == "y" and i[ 9 ] ~= "n" then o = o .. "<wbr>" end
	if i[ 9 ] ~= "n" then
		local lt = { [ "public" ] = "PU", [ "local" ] = "PB", [ "personal" ] = "PB", [ "private" ] = "PB" }
		if i[ 6 ] < os.time {day=1, month=1, year=1963} then
			for _, t in ipairs ( data ) do
				if i[ 6 ] >= tonumber ( t.sDate.date ) and inputDate <= tonumber ( t.eDate.date ) then
					s = t.archive
				end
			end
		else
			s = ""
		end
		local lt2 = { [ "public" ] = i[ 4 ], [ "local" ] = p.roman { i[ 4 ] }, [ "personal" ] = i[ 4 ], [ "private" ] = i[ 4 ], [ "asp" ] = i[ 4 ], [ "asc" ] = i[ 4 ], [ "anaw" ] = i[ 4 ], [ "nawm" ] = i[ 4 ], [ "ania" ] = i[ 4 ], [ "church" ] = i[ 4 ] }
		local url = "https://archives.parliament.uk/collections/getrecord/GB61_HL_PO_" .. lt[ i[ 3 ] ] .. "_1_" .. os.date ( "%Y", i[ 6 ] ) .. "_" .. s .. "c" .. lt2[ i[ 3 ] ]
		o = o .. "[[File:Parliamentary Archives External.svg|27x19px|link=" .. url .. "]]"
	end
	o = o .. "</div></div><td "
	if i[ 10 ] == "y" then o = o .. "style=background:#fff5f5;border-color:#bfa3a3 " end
	o = o .. "data-sort-value="
	for _, t in ipairs ( data ) do
		if tonumber ( i[ 6 ] ) >= tonumber ( t.sDate.date ) and tonumber ( i[ 6 ] ) <= tonumber ( t.eDate.date ) then
			o = o .. t.session.parliament * 1000000 + t.session.number * 10000 + i[ 4 ]
		end
	end
	o = o .. "><div style=width:10em;max-width:18vw>"
	if i[ 6 ] < os.time {day=1, month=1, year=1963} then
		for _, t in ipairs ( data ) do
			if tonumber ( i[ 6 ] ) >= tonumber ( t.sDate.date ) and tonumber ( i[ 6 ] ) <= tonumber ( t.eDate.date ) then
				o = o .. t.citation
			end
		end
	else
		o = o .. os.date ( "%Y", i[ 6 ] )
	end
	local lt = { [ "public" ] = "c. " .. i[ 4 ], [ "local" ] = "c. " .. p.roman { i[ 4 ] }, [ "personal" ] = "c. " .. "\'\'" .. i[ 4 ] .. "\'\'", [ "private" ] = "c. " .. "\'\'" .. i[ 4 ] .. "\'\'", [ "asp" ] = "asp " .. i[ 4 ], [ "asc" ] = "asc " .. i[ 4 ], [ "anaw" ] = "anaw " .. i[ 4 ], [ "nawm" ] = "nawm " .. i[ 4 ], [ "ania" ] = "c. " .. i[ 4 ] .. " (N.I.)", [ "church" ] = "No. " .. i[ 4 ] }
	o = o .. " " .. lt[ i[ 3 ] ] .. i[ 5 ] .. "</div><td"
	if i[ 10 ] == "y" then o = o .. " style=background:#fff5f5;border-color:#bfa3a3" end
	o = o .. "><div style=width:9em;max-width:18vw>" .. os.date("*t", i[ 6 ]).day .. " " .. os.date("%B %Y", i[ 6 ] ) .. i[ 7 ] .. "</div><tr class=expand-child><td colspan=5"
	if i[ 10 ] == "y" then o = o .. " style=background:#fff5f5;border-color:#bfa3a3" end
	o = o .. "><div style=max-width:fit-content;max-height:9em;overflow:auto>"
	if i[ 11 ] ~= "" then o = o .. "\'\'" .. i[ 11 ] .. "\'\'" .. i[ 12 ] else o = o .. "&nbsp;" end
	o = o .. "</div>"
	local c = 17
	while i[ c ] do
		o = o .. p.po{i[ c - 4 ], i[ c - 3 ], i[ c - 2 ], i[ c - 1 ], i[ c ], i[ 6 ] }
		c = c + 5
	end
	o = o .. "<tr class=expand-child><td colspan=5 style=\"border-style:none none none none;background:#fff\"><div style=min-height:.25em></div>"
	return o
end

function p.roman ( frame )
	local inputRoman
	inputRoman = tonumber ( frame[ 1 ] )
	local functionRoman = require ("Module:Roman")
	if inputRoman < 400 then
		inputRoman = tostring ( inputRoman )
		return string.lower ( functionRoman.main { inputRoman } )
	elseif inputRoman == 400 then
		return "cccc"
	elseif inputRoman < 500 then
		inputRoman = inputRoman - 400
		inputRoman = tostring ( inputRoman )
		return "cccc" .. string.lower ( functionRoman.main { inputRoman } )
	else
		return ""
	end
end

function p.po( frame )
	local i = { }
	if frame == mw.getCurrentFrame() then
		local fa = { }
		for t = 1, 6 do
			i[ t ] = frame:getParent().args[ t ]
			if frame.args[ t ] then
				fa[ t ] = frame.args[ t ]
				i[ t ] = fa[ t ]
			end
		end
	else
		for t = 1, 6 do
			i[ t ] = frame[ t ]
		end
	end
	if i[ 1 ] ~= "" then
		local output = "<tr class=expand-child><td style=\"background:#fff;width:1em;border-style:none solid none none\">&nbsp;<td style=background:#f5fdff;max-width:61em colspan=4><div>\'\'\'[[" .. i[ 1 ] .. "]]\'\'\'" .. i[ 2 ]
		if i[ 5 ] == "y" then
			-- output = output .. frame:extensionTag ( "ref", "Although passed in " .. os.date("%Y", i[ 6 ]) .. ", the short title is specified as the " .. i[ 1 ] .. ".", { name = mw.hash.hashValue( "crc32b", i[ 1 ] ), group = "lower-alpha" } )
		end
		if i[ 3 ] ~= "" then
			return output .. "<div style=max-height:7em;overflow:auto>\'\'" .. i[ 3 ] .. "\'\'" .. i[ 4 ]
		else
			return output
		end
	else
		return ""
	end
end

return p