Module:Legislationuk

local p = {}

function p.main( frame ) local args if frame:getParent.args[ 1 ] then args = frame:getParent.args else args = frame.args end local input = "" local divider = "|" local o = " " .. frame:expandTemplate{ title = "notelist" } return o end

function p.act( args ) local data = mw.loadData( "Module:Legislationuk/data" ) local legShortTitle = args[ 1 ] or "" local link = args[ "link" ] or "" local legNote1 = args[ "note1" ] or "" local cyShortTitle = args[ "cyshort" ] or "" local legType = args[ 2 ] or "" local legNumber = args[ 3 ] or "" local legNote2 = args[ "note2" ] or "" local legDate = args[ 4 ] or "" local legNote3 = args[ "note3" ] or "" local maintained = args[ "maintained" ] or "" local archived = args[ "archived" ] or "" local repealed = args[ "repealed" ] or "" local legLongTitle = args[ 5 ] or "" local legNote4 = args[ "note4" ] or "" local cyLongTitle = args[ "cylong" ] or "" local url = args[ "url" ] or "" legDate = os.time {day = tonumber( mw.ustring.sub( legDate, 1, 2 ) ), month = tonumber( mw.ustring.sub( legDate, 4, 5 ) ), year = tonumber( mw.ustring.sub( legDate, 7 ) ) } local o = "  \'\'\'" end	o = o .. legShortTitle .. "\'\'\'" .. legNote1 if repealed == "y" then o = o .. " (repealed)" end if cyShortTitle ~= "" then o = o .. " " .. cyShortTitle .. " " end o = o .. " " if maintained == "y" then local lt = { [ "public" ] = "ukpga", [ "local" ] = "ukla", [ "asp" ] = "asp", [ "asc" ] = "asc", [ "anaw" ] = "anaw", [ "nawm" ] = "mwa", [ "ania" ] = "nia", [ "mnia" ] = "mnia", [ "church" ] = "ukcm", [ "private" ] = "ukppa", [ "personal" ] = "ukppa" } local url = "https://www.legislation.gov.uk/" .. lt[ legType ] .. "/" .. os.date( "%Y", legDate ) .. "/" .. legNumber .. "/contents" o = o .. ""	end local s	if maintained == "y" and archived ~= "n" then o = o .. " " end if archived ~= "n" then if legType == "nawm" or legType == "anaw" or legType == "asc" then o = o .. ""		else local lt = { [ "public" ] = "PU", [ "local" ] = "PB", [ "personal" ] = "PB", [ "private" ] = "PB" } if legDate < os.time {day=1, month=1, year=1963} then for _, t in ipairs( data ) do					if legDate >= t.sDate.date and legDate <= t.eDate.date then s = t.archive end end end local lt2 = { [ "public" ] = legNumber, [ "local" ] = p.roman { legNumber }, [ "personal" ] = legNumber, [ "private" ] = legNumber, [ "asp" ] = legNumber, [ "asc" ] = legNumber, [ "anaw" ] = legNumber, [ "nawm" ] = legNumber, [ "ania" ] = legNumber, [ "mnia" ] = legNumber, [ "church" ] = legNumber } url = "https://archives.parliament.uk/collections/getrecord/GB61_HL_PO_" .. lt[ legType ] .. "_1_" .. os.date( "%Y", legDate ) .. "_" .. (s or "") .. "c" .. lt2[ legType ] o = o .. ""		end end o = o .. " = os.time{ day = 1, month = 1, year = 1963 } then o = o .. os.time{ day = 1, month = 1, year = tonumber (os.date( "%Y", legDate ) ) } + legNumber else for _, t in ipairs( data ) do			if tonumber( legDate ) >= tonumber( t.sDate.date ) and tonumber( legDate ) <= tonumber( t.eDate.date ) then o = o .. tonumber( t.sDate.date ) + legNumber end end end o = o .. "> "	if legDate < os.time {day=1, month=1, year=1963} then for _, t in ipairs( data ) do			if tonumber( legDate ) >= tonumber( t.sDate.date ) and tonumber( legDate ) <= tonumber( t.eDate.date ) then o = o .. t.citation end end else o = o .. os.date( "%Y", legDate ) end local lt = { [ "public" ] = "c. " .. legNumber, [ "local" ] = "c. " .. p.roman { legNumber }, [ "personal" ] = "c. \'\'" .. legNumber .. "\'\'", [ "private" ] = "c. \'\'" .. legNumber .. "\'\'", [ "asp" ] = "asp " .. legNumber, [ "asc" ] = "asc " .. legNumber .. " \'\'" .. os.date( "%Y", legDate ) .. " dsc " .. legNumber .. "\'\'", [ "anaw" ] = "anaw " .. legNumber .. " \'\'" .. os.date( "%Y", legDate ) .. " dccc " .. legNumber .. "\'\'", [ "nawm" ] = "nawm " .. legNumber .. " \'\'" .. os.date( "%Y", legDate ) .. " mccc " .. legNumber .. "\'\'", [ "ania" ] = "c. " .. legNumber .. " (N.I.)", [ "mnia" ] = "c. " .. legNumber .. " (N.I.)", [ "church" ] = "No. " .. legNumber } o = o .. " " .. lt[ legType ] .. legNote2 .. "  " .. os.date("*t", legDate).day .. " " .. os.date("%B %Y", legDate ) .. legNote3 .. " " if legLongTitle ~= "" then o = o .. legLongTitle .. legNote4 else o = o .. " " end o = o .. " "	if cyLongTitle ~= "" then o = o .. "" .. cyLongTitle .. " "	end local c = 1 local n = 0 local po = args[ "po1" ] while po do local poIsShortTitle = args[ "po" .. c .. "short" ] local poNote1 = args[ "po" .. c .. "note1" ] or "" local poYearOffset = args[ "po" .. c .. "year" ] or "" local poIsLongTitle = args[ "po" .. c .. "long" ] local poLongTitle if poIsLongTitle == "n" then poLongTitle = "" n = n + 1 else poLongTitle = args[ c + 5 - n ] end local poNote2 = args[ "po" .. c .. "note2" ] or "" o = o .. p.po{po, poIsShortTitle, poNote1, poLongTitle, poNote2, poYearOffset, legDate } c = c + 1 po = args[ "po" .. c ] end o = o .. " " return o end

function p.po( args ) local frame = mw.getCurrentFrame local o = " \'\'\'" .. args[ 1 ] .. "\'\'\'" .. args[ 3 ] if args[ 6 ] == "y" then o = o .. frame:extensionTag( "ref", "Although passed in " .. os.date("%Y", args[ 7 ]) .. ", the short title is specified as the " .. args[ 1 ] .. ".", { name = mw.hash.hashValue( "crc32b", args[ 1 ] ), group = "lower-alpha" } ) end if args[ 4 ] ~= "" then return o .. " " .. args[ 4 ] .. args[ 5 ] else return o		end else o = o .. " style=max-height:8.25em;overflow:auto>" .. args[ 1 ] .. args[ 3 ] return o	end end

function p.ordinal( args ) local ordinal, digit = {"st", "nd", "rd"}, mw.ustring.sub( args, -1 ) if tonumber( digit ) > 0 and tonumber( digit ) <= 3 and mw.ustring.sub( args, -2 ) ~= 11 and mw.ustring.sub( args, -2 ) ~= 12 and mw.ustring.sub( args, -2 ) ~= 13 then return args .. ordinal[ tonumber( digit ) ] else return args .. "th" end end

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

function p.header( frame ) local data = mw.loadData( "Module:Legislationuk/data" ) local pargs = frame:getParent.args local args = frame.args local inputType = pargs[ 1 ] or args[ 1 ] or "" local inputState = pargs[ "state" ] or args[ "state" ] or "" local inputNumber = tonumber( pargs[ 2 ] ) or tonumber( args[ 2 ] ) or "" local inputSession = pargs[ "session" ] or args[ "session" ] or "" local actsPublic = tonumber( pargs[ 3 ] ) or tonumber( args[ 3 ] ) or 0 local actsLocal = tonumber( pargs[ 4 ] ) or tonumber( args[ 4 ] ) or 0 local actsPrivate = tonumber( pargs[ 5 ] ) or tonumber( args[ 5 ] ) or 0 local currentSession = "" local o = "" if inputState == "scotland" or inputState == "wales" or inputState == "northern ireland" then inputType = "year" inputNumber = tonumber( pargs[ 1 ] ) or tonumber( args[ 1 ] ) or 0 actsPublic = tonumber( pargs[ 2 ] ) or tonumber( args[ 2 ] ) or 0 actsLocal = tonumber( pargs[ 3 ] ) or tonumber( args[ 3 ] ) or 0 end local acts = actsPublic + actsLocal + actsPrivate if inputState == "scotland" then o = o .. frame:preprocess( "" ) elseif inputState == "wales" then o = o .. frame:preprocess( "" ) elseif inputState == "northern ireland" then if inputNumber >= 2000 then o = o .. frame:preprocess( "" ) end else if inputType == "year" then o = o .. frame:preprocess( "" ) else if inputSession == "only" then o = o .. frame:preprocess( "" ) else o = o .. frame:preprocess( "" ) end end end o = o .. " " .. frame:expandTemplate{ title = "Use British English", args = { date = "July 2021" } } .. " " .. frame:expandTemplate{ title = "Use dmy dates", args = { date = "July 2021" } } .. " " .. frame:expandTemplate{ title = "Short description", args = { "None" } } .. " "	if inputState == "UK" or inputState == "" then o = o .. frame:expandTemplate{ title = "British legislation lists", args = { "uk" } } else o = o .. frame:expandTemplate{ title = "British legislation lists", args = { "devolved" } } end o = o .. "\n\n" .. "This is a list of acts of the Scottish Parliament " elseif inputState == "wales" then if inputNumber >= 2021 then o = o .. "Act of Senedd Cymru|acts of Senedd Cymru]] " elseif inputNumber == 2020 then o = o .. "Act of the National Assembly for Wales|acts of the National Assembly for Wales]] and acts of Senedd Cymru " elseif inputNumber <= 2020 and inputNumber >= 2012 then o = o .. "Act of the National Assembly for Wales|acts of the National Assembly for Wales]] " else o = o .. "Measure of the National Assembly for Wales|measures of the National Assembly for Wales]] " end elseif inputState == "northern ireland" then if inputNumber >= 2000 then o = o .. "Act of the Northern Ireland Assembly|acts of the Northern Ireland Assembly]] " end else o = o .. "Act of Parliament (UK)|acts]] of the " if inputType == "parliament" and inputSession == "only" then o = o .. p.ordinal( inputNumber ) .. " " elseif inputType == "parliament" then o = o .. p.ordinal( inputSession ) .. " session of the " .. p.ordinal( inputNumber ) .. " " end o = o .. "Parliament of the United Kingdom" end if inputType == "year" then o = o .. " passed in " .. inputNumber .. "."	else o = o .. ", which " for _, t in ipairs( data ) do			if t.session then if tonumber( inputNumber ) == tonumber( t.session.parliament ) and ( tonumber( inputSession ) == tonumber( t.session.number ) or ( inputSession == "only" and tonumber( t.session.number ) == 1 ) ) then if t.eDate == "current" then if inputSession == "only" then o = o .. "has so far consisted of a single session that " end o = o .. "began on " .. os.date( "*t", t.sDate.date ).day .. " " .. os.date("%B %Y", t.sDate.date ) if t.sDate.citation.work ~= "LG" then o = o .. frame:extensionTag( "ref", p.citation( t.sDate.citation ) .. "." ) else o = o .. frame:extensionTag( "ref", p.citation( t.sDate.citation ) ) end o = o .. " and has not yet concluded." currentSession = "y" else if inputSession == "only" then o = o .. "consisted of a single session that " end o = o .. "ran from " .. os.date( "*t", t.sDate.date ).day .. " " .. os.date("%B %Y", t.sDate.date ) if t.sDate.citation.work ~= "LG" then o = o .. frame:extensionTag( "ref", p.citation( t.sDate.citation ) .. "." ) else o = o .. frame:extensionTag( "ref", p.citation( t.sDate.citation ) ) end o = o .. " until " .. os.date( "*t", t.eDate.date ).day .. " " .. os.date("%B %Y", t.eDate.date ) .. "."						if t.eDate.citation.work ~= "LG" then o = o .. frame:extensionTag( "ref", p.citation( t.eDate.citation ) .. "." ) else o = o .. frame:extensionTag( "ref", p.citation( t.eDate.citation ) ) end end end end end end if inputState == "scotland" then o = o .. " Acts of the Scottish Parliament are enacted by the Scottish Parliament, which has legislative authority over devolved matters in relation to Scotland under the authority of the Scotland Act 1998." .. frame:extensionTag( "ref", "." ) elseif inputState == "wales" then if inputNumber >= 2020 then o = o .. " Acts of Senedd Cymru are enacted by Senedd Cymru (the Welsh Parliament; or simply the Senedd), which has" elseif inputNumber >= 2012 then o = o .. " Acts of the National Assembly for Wales are acts of Senedd Cymru enacted by Senedd Cymru (the Welsh Parliament; or simply the Senedd) under its former name of the National Assembly for Wales." .. frame:extensionTag( "ref", "." ) .. " It has" else o = o .. " Measures of the National Assembly for Wales were enacted by Senedd Cymru (the Welsh Parliament; or simply the Senedd) under its former name of the National Assembly for Wales," .. frame:extensionTag( "ref", "." ) .. " as part of its" end o = o .. " legislative authority over devolved matters in relation to Wales under the authority of the Government of Wales Act 2006." if inputNumber >= 2012 then o = o .. frame:extensionTag( "ref", "." ) if inputNumber == 2020 then o = o .. " Before 6 May 2020, the Senedd was known as the National Assembly for Wales," .. frame:extensionTag( "ref", "." ) .. " and acts passed before that date are accordingly known as acts of the National Assembly for Wales." end else o = o .. frame:extensionTag( "ref", "." ) .. " It has no longer been possible for the Senedd to pass measures since 5 May 2011, when it was conferred with the power to pass acts of Senedd Cymru (then known as acts of the National Assembly for Wales) following a referendum" if inputNumber == 2011 then o = o .. "," else o = o .. "." end o = o .. frame:extensionTag( "ref", "; ." ) if inputNumber == 2011 then o = o .. " although a minor exemption was granted to any proposed measures which had been passed by the National Assembly but not yet given royal assent at that date." .. frame:extensionTag( "ref", "." ) end end elseif inputState == "northern ireland" then if inputNumber >= 2000 then o = o .. " Acts of the Northern Ireland Assembly are enacted by the Northern Ireland Assembly, which has legislative authority over devolved matters in relation to Northern Ireland under the authority of the Northern Ireland Act 1998." .. frame:extensionTag( "ref", "." ) end end if inputType == "year" then inputNumber = tonumber( inputNumber ) end o = o .. "\n\n" if inputState == "wales" then o = o .. "All legislation passed by the Senedd is bilingual, with the English and Welsh texts being equally authoritative." if inputNumber <= 2020 then o = o .. frame:extensionTag( "ref", "." ) end if inputNumber >= 2020 then o = o .. frame:extensionTag( "ref", "." ) end o = o .. "\n" end if inputState == "wales" and inputNumber <= 2011 then o = o .. "Measures " else o = o .. "Acts " end if inputState == "scotland" or inputState == "wales" or ( inputState == "northern ireland" and inputNumber >= 2000 ) then o = o .. "are cited by calendar year, in the same fashion as acts of Parliament of the United Kingdom." else if ( inputType == "year" and inputNumber >= 1963 ) or ( inputType == "parliament" and tonumber( inputNumber ) >= 43 ) or ( inputType == "parliament" and tonumber( inputNumber ) == 42 and tonumber( inputSession ) >= 4 ) then o = o .. "passed since 1963 are cited by calendar year," .. frame:extensionTag( "ref", "." ) if inputType == "parliament" and tonumber( inputNumber ) == 42 and tonumber( inputSession ) == 4 then o = o .. " while the convention used for earlier acts is to cite" else o = o .. " as opposed to the convention used for earlier acts of citing" end o = o .. " the regnal year(s) in which the relevant " if inputType == "year" then o = o .. "parliamentary session" else o = o .. "parliamentary session" end o = o .. " was held." .. frame:extensionTag( "ref", "; cf. and the ." ) else o = o .. "passed before 1963 are cited by the regnal year(s) in which the relevant " if inputType == "year" then o = o .. "parliamentary session" else o = o .. "parliamentary session" end o = o .. " was held," .. frame:extensionTag( "ref", "; cf. and the ." ) .. " as opposed to the convention used for later acts of citing the calendar year." .. frame:extensionTag( "ref", "." ) end end o = o .. " Each " if inputState == "wales" and inputNumber <= 2011 then o = o .. "measure" else o = o .. "act" end o = o .. " passed in a respective " if ( inputType == "year" and inputNumber >= 1963 ) or ( inputType == "parliament" and tonumber( inputNumber ) >= 43 ) or ( inputType == "parliament" and tonumber( inputNumber ) == 42 and tonumber( inputSession ) == 5 ) then o = o .. "year" elseif inputType == "parliament" and tonumber( inputNumber ) == 42 and tonumber( inputSession ) == 4 then o = o .. "session or year" else o = o .. "session" end o = o .. " is " if inputState == "scotland" then o = o .. "numbered consecutively with Arabic numerals, following the prefix \"asp\"." .. frame:extensionTag( "ref", "; formerly the ." ) elseif inputState == "wales" then o = o .. "numbered consecutively with Arabic numerals, following the prefix \""		if inputNumber >= 2021 then o = o .. "asc\"" elseif inputNumber == 2020 then o = o .. "anaw\" or \"asc\" respectively" elseif inputNumber <= 2020 and inputNumber >= 2012 then o = o .. "anaw\"" else o = o .. "nawm\"" end		o = o .. " (or, in Welsh, \""		if inputNumber >= 2021 then o = o .. "dsc" elseif inputNumber == 2020 then o = o .. "dccc\" or \"dsc" elseif inputNumber <= 2020 and inputNumber >= 2012 then o = o .. "dccc" else			o = o .. "mccc" end		o = o .. "\")."		o = o .. frame:extensionTag( "ref", "; ; ." )	elseif inputState == "northern ireland" then		o = o .. "given a chapter number (abbreviated \"c.\") denoted by Arabic numerals," .. frame:extensionTag( "ref", "; ." ) .. " and citations are usually followed by the suffix \"(N.I.)\" so as to prevent confusion with acts of Parliament of the United Kingdom."	else		o = o .. "given a chapter number (abbreviated \"c.\"), denoted by Arabic numerals in the case of public general acts, lowercase Roman numerals in the case of local acts, or italicised Arabic numerals in the case of personal acts. These run as separate series." .. frame:extensionTag( "ref", "." )	end	o = o .. "\n\n"	if inputState == "wales" and inputNumber == 2020 then		o = o .. actsPublic .. " acts of the National Assembly for Wales and " .. actsLocal .. " acts of Senedd Cymru "	else		o = o .. actsPublic + actsLocal + actsPrivate		if inputState == "wales" and inputNumber <= 2011 then			o = o .. " measure"		else			o = o .. " act"		end		if acts > 1 then o = o .. "s" end		if inputState == "scotland" then			o = o .. " of the Scottish Parliament "		elseif inputState == "wales" then			if inputNumber >= 2021 then				o = o .. " of Senedd Cymru "			else				o = o .. " of the National Assembly for Wales "			end		elseif inputState == "northern ireland" then			o = o .. " of the Northern Ireland Assembly "		else			o = o .. " of Parliament "		end	end	if inputNumber == tonumber (os.date( "%Y", os.time ) ) or currentSession == "y" then if acts == 1 then o = o .. "has" else o = o .. "have" end o = o .. " so far been" else if acts == 1 then o = o .. "was" else o = o .. "were" end end o = o .. " passed " if inputType == "year" then o = o .. "in " .. inputNumber else o = o .. "by the " .. p.ordinal( inputNumber ) .. " Parliament in its " if inputSession == "only" then o = o .. "only" else o = o .. p.ordinal( inputSession ) end o = o .. " session" end local actsPublicString = "" local actsLocalString = "" local actsPrivateString = "" if inputState == "scotland" or inputState == "wales" or ( inputState == "northern ireland" and inputNumber >= 2000 ) then o = o .. "."	else if actsPublic > 1 then actsPublicString = actsPublic .. " public general acts" else actsPublicString = actsPublic .. " public general act" end if actsLocal > 1 then actsLocalString = actsLocal .. " local acts" else actsLocalString = actsLocal .. " local act" end if actsPrivate > 1 then actsPrivateString = actsPrivate .. " personal acts" else actsPrivateString = actsPrivate .. " personal act" end if actsPublic > 0 and actsLocal > 0 and actsPrivate > 0 then o = o .. ": " .. actsPublicString .. ", " .. actsLocalString .. " and " .. actsPrivateString .. "."		elseif actsPublic > 0 and actsLocal > 0 and actsPrivate == 0 then o = o .. ": " .. actsPublicString .. " and " .. actsLocalString .. "."		elseif actsPublic > 0 and actsLocal == 0 and actsPrivate > 0 then o = o .. ": " .. actsPublicString .. " and " .. actsPrivateString .. "."		elseif actsPublic == 0 and actsLocal > 0 and actsPrivate > 0 then o = o .. ": " .. actsLocalString .. " and " .. actsPrivateString .. "."		elseif actsPublic > 0 and actsLocal == 0 and actsPrivate == 0 then if actsPublic == 1 then o = o .. ": a public general act." else if actsPublic == 2 then o = o .. "; both " else o = o .. "; all " end if inputNumber == tonumber(os.date( "%Y", os.time ) ) or currentSession == "y" then o = o .. "are" else o = o .. "were" end o = o .. " public general acts." end elseif actsPublic == 0 and actsLocal > 0 and actsPrivate == 0 then if actsLocal == 1 then o = o .. ": a local act." else if actsLocal == 2 then o = o .. "; both " else o = o .. "; all " end if inputNumber == tonumber(os.date( "%Y", os.time ) ) or currentSession == "y" then o = o .. "are" else o = o .. "were" end o = o .. " local acts." end elseif actsPublic == 0 and actsLocal == 0 and actsPrivate > 0 then if actsPrivate == 1 then o = o .. ": a personal act." else if actsPrivate == 2 then o = o .. "; both " else o = o .. "; all " end if inputNumber == tonumber (os.date( "%Y", os.time ) ) or currentSession == "y" then o = o .. "are" else o = o .. "were" end o = o .. " personal acts." end end end o = o .. "\n\n indicates that a"	if inputState == "wales" and inputNumber < 2012 then o = o .. " measure" else o = o .. "n act" end o = o .." is available to view at legislation.gov.uk, and " if inputState == "wales" then o = o .. ""	else o = o .. ""	end o = o .. " indicates the location of the original " if inputState == "wales" and inputNumber < 2012 then o = o .. "measure" else o = o .. "act" end o = o .. " in the " if inputState == "wales" then o = o .. "National Library of Wales." else o = o .. "Parliamentary Archives." end return o end

function p.citation( frame ) local t = frame or "" local o = "" elseif t[ "work" ] == "JHL" then o = o .. "citation|author=House of Lords|title=Journals of the House of Lords|volume=" if t.part ~= "" then o = o .. "\'\'\'" .. t.vol .. " pt. " .. require("Module:Roman").main{ t.part } .. "\'\'\'" else o = o .. t.vol end o = o .. "|page" if mw.ustring.find( t.page, "–" ) then o = o .. "s" end o = o .. "="		if t.page == "before 1" then o = o .. "before p. 1|no-pp=yes" else o = o .. t.page end o = o .. "}}"	elseif t[ "work" ] == "Hansard" then o = o .. "citation|author=Parliament of the United Kingdom|title=Hansard|series=" .. t.series .. "|volume=" .. t.vol o = o .. "|page=col" if mw.ustring.find( t.col, "–" ) then o = o .. "s" end o = o .. ". " .. t.col .. "|no-pp=yes}}" elseif t[ "work" ] == "LG" then o = o .. "London Gazette|issue=" .. t.issue if t.supplement ~= "" then o = o .. "|supp=" .. t.supplement end o = o .. "|page" if mw.ustring.find( t.page, "–" ) then o = o .. "s" end o = o .. "=" .. t.page o = o .. "|date=" .. os.date( "*t", t.date ).day .. " " .. os.date("%B %Y", t.date ) .. "}}"	end return o end

return p