Module:Cite California statute

From the AARoads Wiki: Read about the road before you go
Jump to navigation Jump to search
local p = {}
local getArgs = require('Module:Arguments').getArgs
local format = mw.ustring.format
local frame = mw.getCurrentFrame()

local function titles(args)
	local year = args.year or args[1]
	local chapter = args.ch or args.chapter or args[2]
	local titleParam = args.title or ""
	local title
	
	local titleTable = {
	default = "<span class='error'>Invalid chapter</span>",
	["11"] = "An act to provide for a system of public streets and highways...",
	["13"] = "An act to amend Section 374 of, and to add Sections 512 and 543 to, the Streets and Highways Code, relating to state highways",
	["20"] = "An act to add Sections 100 and 411.5 to the Streets and Highways Code, relating to highways, and declaring the urgency thereof, to take effect immediately",
	["23"] = "An act to add Section 559 to the Streets and Highways Code, relating to state highways, declaring the urgency thereof, to take effect immediately",
	["24"] = "An act to add Section 560 to the Streets and Highways Code, relating to state highways, declaring the urgency thereof, to take effect immediately",
	["29"] = "An act to establish a Streets and Highways Code, thereby consolidating and revising the law relating to public ways and all appurtenances thereto, and to repeal certain acts and parts of acts specified herein",
	["32"] = "An act declaring the wagon road extending from the western end of the Lake Tahoe state wagon road to the eastern limits of the city of Placerville to be a state highway",
	["46"] = "Senate Constitutional Amendment No. 27—Resolution to propose to the people of the State of California an amendment to the constitution of said state, by adding to article sixteen thereof a new section to be numbered two, providing for the...",
	["48"] = "An act to amend section 368 of the Streets and Highways Code, relating to State highway route 68",
	["63"] = "An act to add Section 557 to the Streets and Highways Code, relating to state highways",
	["74"] = "Assembly Concurrent Resolution No. 21—Relative to the Ted Williams Freeway",
	["82"] = "An act establishing certain additional state highways and classifying them as secondary highways",
	["84"] = "Senate Concurrent Resolution No. 23—Relative to the designation of State Highway 17 as the 'Nimitz Freeway'",
	["94"] = "Senate Concurrent Resolution No. 17—Relative to delaying relinquishment of a portion of Interstate 80 leading to the State Capitol",
	["99"] = "An act to amend Section 354 of, and to amend and repeal Section 444 of, the Streets and Highways Code, relating to highways, and declaring the urgency thereof, to take effect immediately",
	["106"] = "An act to add and repeal Sections...of the Government Code, to amend Sections...of, the Streets and Highways Code...",
	["117"] = "An act to provide for...a state highway connecting the present county road systems of any one or all of the counties of Trinity, Tehama and Shasta with the road system of Humboldt county...",
	["122"] = "Assembly Concurrent Resolution No. 37—Relative to the naming of the James Lick Memorial Freeway",
	["123"] = "An act to amend Section 303 of the Streets and Highway Code, relating to state highways",
	["128"] = "An act to authorize the state of California to secure the title to and right of way for that certain wagon-road...commencing a short distance easterly from the village of Smith's Flat...and running thence to Lake Tahoe...",
	["142"] = "An act to amend Sections 345, 466 and 612 of the Streets and Highways Code, relating to descriptions of certain State highways",
	["144"] = "Relating to the Seaside Freeway",
	["172"] = "An act to amend Section 460 of, and to amend, repeal, and add Section 319 of, the Streets and Highways Code, relating to highways.",
	["179"] = "An act to add Sections 280, 281, 282, and 283 to the Streets and Highways Code, relating to highways",
	["181"] = "An act authorizing and directing the California highway commission to lay out and acquire a right of way or rights of way for a highway or highways from the county line of the city and county of San Francisco, in, to and through San Mateo county...",
	["219"] = "An act to amend section 374 of the Streets and Highways Code, relating to State Highway Route 74",
	["221"] = "An act to amend Sections 253.1, 263.3, 263.8, 357, and 510 of, and to repeal Section 330 of, the Streets and Highways Code, relating to highways",
	["274"] = "An act...relating to State highways",
	["283"] = "An act to establish the Yolo and Lake highway; to define its course; to provide for its location and survey; and to make an appropriation therefor",
	["292"] = "An act to amend...the Streets and Highways Code, relating to state highways",
	["294"] = "An act to amend Sections 253.1, 253.4, 253.5, 253.8, 263.3, 263.4, 263.8, 315, 360, 371, 374, 378, 379, 381, 391, 574 and 610 of, to add Sections 463 and 608 to, and to repeal Sections 403 and 486 of...",
	["309"] = "An act...to construct and maintain...a state highway, extending from the town of Oxnard to a point...at or near the town of El Rio, Ventura county",
	["338"] = "An act to add section 653 to the Streets and Highways Code, relating to State highways",
	["369"] = "An act authorizing and directing the California highway commission to acquire necessary rights of way, and to construct and maintain a highway, which is hereby declared to be a state highway, extending from Barstow...to a point...on the boundary line between the state of California and the state of Nevada...which said highway is commonly known and referred to as the Arrowhead trail",
	["385"] = "An act to add Section 253 and Article 3 (commencing with Section 300) to Chapter 2 of Division 1 of, and to repeal Section 253 and Article 3 (commencing with Section 300) of Chapter 2 of Division 1 of, the...",
	["386"] = "An act... to take effect immediately.",
	["398"] = "An act to provide for the survey and construction of a state highway from Saratoga Gap, on the line between the counties of Santa Clara and Santa Cruz, to, into and within California Redwood Park in Santa Cruz county, and making an appropriation therefor",
	["404"] = "An act authorizing the acquisition, construction, improvement, maintenance and control of the uncompleted portions of the system of state highways prescribed and contemplated by an act entitled 'An act authorizing the construction, acquisition, maintenance and control of a system of...",
	["409"] = "An act...relating to state highways",
	["421"] = "An act to repeal... to add Section 575 to, and to repeal Section 301.5 of, the Streets and Highways Code... relating to transportation",
	["426"] = "An act to add section 612 to, and to repeal section 486 of, the Streets and Highways Code, relating to secondary State highways ",
	["429"] = "An act to add section 641 to, and to amend section 493 of, the Streets and Highways Code, relating to State highways",
	["451"] = "An act to amend... Sections 143, 182.6, 182.7, 253.7, 392, 470, 485, 538, 890.4, and 2384 of the Streets and Highways Code... relating to transportation.",
	["471"] = "An act to provide for the establishment of a highway, to be known as the Bay Shore highway, in the counties of San Francisco, San Mateo and Santa Clara",
	["525"] = "An act to amend Sections 8879.1, 14070.4, 14076.4, 14524.2, and 65082 of, and to repeal Sections 8879.17 and 14524.15 of, the Government Code, to amend Sections 21602, 21702, 21704, 21707, and 102015 of, and to repeal Section 21604 of, and...",
	["526"] = "An act to amend...the Streets and Highways Code, relating to state highways",
	["537"] = "An act to amend Sections 315, 371, and 379 of, to add Sections 315.1, 379.1, 494, 494.1, 494.2, 607.1 and 607.2 of, and to repeal Section 331 of, the Streets and Highways Code, relating to state highways, and declaring the...",
	["594"] = "An act to amend Sections 374 and 411 of the Streets and Highways Code, relating to highways.",
	["718"] = "An act to amend Sections 379 and 411 of the Streets and Highways Code, relating to highways.",
	["724"] = "An act to amend Sections 14076.2 and 103113 of, and to repeal Section 14451 of, the Government Code, to amend Section 20300 of, and to amend the heading of Article 16 (commencing with Section 20300) of Chapter 1 of Part 3...",
	["740"] = "An act to amend Section 301 of the Streets and Highways Code, relating to state highways",
	["742"] = "An act to amend Sections 263.3, 263.8, and 415 of, and to add Section 486 to, the Streets and Highways Code, relating to state highways",
	["748"] = "An act to add Section 569 to the Streets and Highways Code, relating to state highways",
	["767"] = "An act to amend sections 2, 3 and 5 and to add two sections to be numbered 6 and 7 to an act entitled 'An act to provide for the acquisition of rights of way for and the construction, maintenance...",
	["775"] = "An act...relating to highways",
	["837"] = "An act declaring the county road extending from San Simeon to Cambria to be a state highway and providing for the maintenance thereof",
	["841"] = "An act to amend sections 251, 308, 340, 344, 351, 352, 361, 368, 369, 374, 377, 404 and 425 of, to add four two sections to be numbered 503, 504, 505 and 506 to, and to repeal sections 603, 611...",
	["877"] = "An act to amend Sections 21644.5, 21670.4, 21681, 99155.1, 99238.5, and 99401.5 of the Public Utilities Code, to amend Section 8352.3 of the Revenue and Taxation Code, to amend Sections 73, 163, 164.11, 164.16, 164.17, 164.18, 253.1, 253.3, 302, 319...",
	["914"] = "An act to add sections 307.1 and 347.1 to the Streets and Highways Code, relating to state highways",
	["964"] = "An act...relating to the State highway routes and adding a new route",
	["1062"] = "An act to amend Sections 306, 320, 332, 351, 362, 365, 369, 374, 382, 388, 397, 407, 408, 409, 410, 415, 422, 435, 440, 446, 453, 456, 460, 467, 470, 476, 487, 492, 493, 494, 506, 521, 528, and 529...",
	["1078"] = "An act...relating to state bridges and highways...",
	["1139"] = "An act to amend Sections 375 and 582 of the Streets and Highways Code, relating to state highways, and declaring the urgency thereof, to take effect immediately",
	["1146"] = "An act to amend Sections 253, 305, 308, 315, 316, 323, 326, 343, 354, 366, 368, 376, 399, 414, 415, 416, 468, 512, 513, 526, 572, 582, and 587, to amend and renumber Section 559, and to repeal Section 725.5...",
	["1154"] = "An act to amend Section 564 of the Code of Civil Procedure, to amend Section 19993.7 of, and to add Section 65088.5 to, the Government Code, and to amend Sections 11474, 44013.5, and 44521 of, and to repeal Sections 39047.4...",
	["1187"] = "An act to amend Sections 253.2, 253.6, 263.2, 302, 324, 335, 336, 414, 423, 428, 448, 452, 521, 522, 535, 536, 544, 554, and 618 of, and to add Section 307 to, the Streets and Highways Code, relating to highways",
	["1216"] = "An act to amend Sections 263.3, 263.8, and 415 of, and to add Section 486 to, the Streets and Highways Code, relating to state highways",
	["1220"] = "An act to amend Section 2982.2 of, and to add Section 3068.2 to, the Civil Code, to amend Sections 40084.5, 40088, and 40089 of the Education Code, to amend Section 29601 of, to amend and renumber Section 14035.6 of, to...",
	["1233"] = "An act to amend Sections 311, 352, 368, 369, 465, 472, and 496 of, the Streets and Highways Code, relating to state highway routes",
	["1258"] = "An act to amend Sections 435 and 546 of, to add Section 301.1 to, and to repeal Section 476 of, the Streets and Highways Code, relating to state highways, and declaring the urgency thereof, to take effect immediately",
	["1261"] = "An act to add Section 544 to the Streets and Highways Code, relating to state highway routes",
	["1350"] = "An act to add Section 575 to the Streets and Highways Code, relating to state highways",
	["1354"] = "An act to amend Sections 143.2, 186, 253.1, 253.2, 253.4, 253.5, 253.6, 263.1, 263.5, 263.7, 311, 312, 333, 360, 374, 375, 378, 381, 384, 388, 411, 417, 422, 440, 441, 460, 506, 559, 563, 582, and 620 of, to add...",
	["1355"] = "An act to amend Section 427 of the Streets and Highways Code, relating to highway Route 127",
	["1364"] = "An act to add Sections 188.4 and 531 to the Streets and Highways Code, relating to transportation",
	["1371"] = "An act...relating to state highways",
	["1372"] = "An act to amend Sections 253, 307, 317, 322, 334, 342, 347, 349, 361, 363, 372, 373, 374, 379, 384, 390, 407, 408, 443, 455, 470, 486, 514, 517, 548, and 550 of, to add Sections 556, 557, 558, 560...",
	["1408"] = "An act to amend Section 315 of the Streets and Highways Code, relating to the State Highway System",
	["1467"] = "An act...relating to state highway routes",
	["1473"] = "An act to amend Sections 253.1, 253.4, 253.7, 263.1, 333, 362, 365, 387, 404, 445, 462, 530, 547, 555, and 608 of, to add Sections 465, 543, 570, 571, 581, 583, 584, and 585 to, and to repeal Section 568...",
	["1483"] = "An act to amend Section 375 of, and to add Section 582 to, the Streets and Highways code, relating to state highways",
	["1562"] = "An act...relating to state highway routes",
	["1588"] = "An act to amend Section 356 of the Streets and Highways Code, relating to state highways",
	["1737"] = "An act authorizing the acquisition by the Department of Public Works of the ferry system across Carquinez Straits between Benicia and Martinez...",
	["1768"] = "An act...relating to state highway routes",
	["1788"] = "An act...relating to the state scenic highway system",
	["1853"] = "An act to add Section 516 to the Streets and Highways Code, relating to state highways",
	["1875"] = "An act...relating to state highway routes",
	["1911"] = "An act...relating to state highway routes",
	["2068"] = "An act to add Section 574 to the Streets and Highways Code, relating to state highways",
	["2155"] = "An act to amend Section 305 of, and to add Sections 553 and 593 to, the Streets and Highways Code, and to amend Section 326... relating to state highway routes"
}

	if titleParam ~= "" then
		title = titleParam
	elseif chapter == "928" and year == "1968" then
		title = "An act... relating to state highways"
	elseif chapter == "928" and year == "1986" then
		title = "An act to amend Sections 318, 341, 343, 360, 366, 370, 374, 388, 389, 403, 425, 468, 548, 624, 2104, and 2107 of, to add Section 632 to, and to repeal Sections 322.1, 355.1, 417, and 622.2 of, the Streets..."
	else
		title = titleTable[chapter]
	end

	return title
end

local function url(args)
	local year = args.year or args[1]

	if year == "1850" or "1851" or "1852" or "1853" or "1854" or "1855" or "1856" or "1857" or "1858" or "1859" or "1860" or "1861" or "1862" or "1863" or "1863" or "1865" or "1867" or "1869" or "1871" or "1873" or "1875" or "1877" or "1880" or "1881" or "1883" or "1885" or "1889" or "1891" or "1893" or "1895" or "1897" or "1899" or "1900" or "1903" or "1905" or "1906" or "1907" or "1910" or "1913" or "1915" or "1917" or "1919" or "1921" or "1923" or "1925" or "1927" or "1929" or "1931" or "1933" or "1935" or "1937" or "1938" or "1939" or "1941" or "1943" or "1945" or "1947" or "1948" or "1949" or "1950" or "1951" or "1953" or "1955" or "1957" or "1959" or "1961" or "1963" or "1965" or "1966" or "1967" or "1968" or "1969" or "1970" or "1971" or "1972" or "1973" or "1974" or "1975" or "1976" or "1977" or "1978" or "1979" or "1980" or "1981" or "1982" or "1983" or "1984" or "1985" or "1986" or "1987" or "1988" or "1989" or "1990" or "1991" or "1992" or "1993" or "1994" or "1995" or "1996" or "1997" or "1998" or "1999" or "2000" or "2001" or "2002" or "2003" or "2004" or "2005" then
		url = string.format("https://clerk.assembly.ca.gov/historical-information/archive-list/statutes-and-amendments-codes-%s?field_archive_type_value=Statutes", year)
	elseif year == "2006" or "2007" or "2008" then
		url = string.format("https://clerk.assembly.ca.gov/historical-information/archive-list/statutes-and-digests-measures-%s?field_archive_type_value=Statutes", year)
	elseif year == "2009" or "2010" then
		url = string.format("https://clerk.assembly.ca.gov/historical-information/archive-list/california-state-assembly-journals-2009-10-session?field_archive_type_value=Journals", year)
	elseif year == "2011" or "2012" then
		url = string.format("https://clerk.assembly.ca.gov/historical-information/archive-list/california-state-assembly-journals-2011-12-session?field_archive_type_value=Journals", year)
	else
		url = "https://clerk.assembly.ca.gov/archive-list"
	end
	
	return url
end

local function session(args)
	local year = args.year or args[1]
	local ex = args.ex or ""

	local session = frame:expandTemplate ({title='California State legislature session', args = {year}})  .. " Session of the Legislature"
	local extra = frame:expandTemplate ({title='Ordinal', args = {ex, "d"}}) .. " Extraordinary Session"
	
	if ex ~= "" then
		return session .. ", " .. extra
	else
		return session
	end
end

local function resolution(args)
	local res = args.res or ""
	local hr = args.HR or ""
	
	if res ~= "" then
		return "Resolution"
	elseif hr ~= "" then
		return "House Resolution"
	else
		return ""
	end
end

local function chapter(args)
	local chapter = args.ch or args.chapter or args[2]
	local section = args.section or ""
	local direct = args["direct-url"] or ""
	local pages = args.pages or args.pp or nil
	local page = args.page or args.p or args[3] or nil

	if section ~= "" then
		return chapter .. ", §" .. section
	elseif direct ~= "" then
		return chapter .. ", " .. direct
	elseif section ~= "" and direct ~= "" then
		return chapter .. ", §" .. section .. ", " .. direct
	else
		if page ~= nil then
			return "Ch. " .. chapter .. ", p. " .. page
		elseif pages ~= nil then
			return "Ch. " .. chapter .. ", pp. " .. pages
		else
			return "Ch. " .. chapter
		end
	end
end

function p.statute(frame)
	local args = getArgs(frame, {removeBlanks = true})
	local year = args.year or args[1]
	local chap = args.ch or args.chapter or args[2]
	
	if year == nil or chap == nil then
		return "<span class='error'>Parameters ''year'' and ''chapter'' are mandatory</span>"
	elseif year <= "1849" then
		return "<span class='error'>Invalid year</span>"
	else
		return frame:expandTemplate ({title='Cite book',
			args = {
				series = "''Statutes of California''",
				title = titles(args),
				author = "California State Assembly",
				url = url(args),
				type = resolution(args),
				publisher = "State of California",
				department = session(args),
				at = chapter(args),
				quote = args.quote or ""
			}
		})
	end
end

return p