Module:Legislationuk/test

local p = {}

function p.main( frame ) if frame:getParent.args[ 1 ] then args = frame:getParent.args else args = frame.args end local qid, snakShort, snakLong, snakDate, snakSession, snakCitation, snaklegGovUK local o = "" local leg = {} for _,v in pairs( args ) do		qid = args[ _ ] --short title snakShort = mw.wikibase.getBestStatements( qid, 'P1813' ) leg.Short = {} for __,vv in ipairs( snakShort ) do			if snakShort[ __ ].mainsnak.datavalue.value.language == "en" then leg.Short.en = snakShort[ __ ].mainsnak.datavalue.value.text elseif snakShort[ __ ].mainsnak.datavalue.value.language == "cy" then leg.Short.cy = snakShort[ __ ].mainsnak.datavalue.value.text end end --long title snakLong = mw.wikibase.getBestStatements( qid, 'P1448' ) leg.Long = {} for __,vv in ipairs( snakLong ) do			if snakLong[ __ ].mainsnak.datavalue.value.language == "en" then leg.Long.en = snakLong[ __ ].mainsnak.datavalue.value.text elseif snakLong[ __ ].mainsnak.datavalue.value.language == "cy" then leg.Long.cy = snakLong[ __ ].mainsnak.datavalue.value.text end end --date snakDate = mw.ustring.sub( mw.wikibase.getBestStatements( qid, 'P7589' )[1].mainsnak.datavalue.value.time, 2, 11 ) leg.Date = os.time { day = tonumber( mw.ustring.sub( snakDate, 9, 10 ) ), month = tonumber( mw.ustring.sub( snakDate, 6, 7 ) ), year = tonumber( mw.ustring.sub( snakDate, 1, 4 ) ) } --session snakSession = mw.wikibase.getBestStatements( qid, 'P2937' ) for __,vv in ipairs( snakSession ) do			leg.Session = snakSession[ __ ].mainsnak.datavalue.value.id		end --citation snakCitation = mw.wikibase.getBestStatements( qid, 'P1031' ) leg.Citation = {} for __,vv in ipairs( snakCitation ) do --for each citation statement if snakCitation[ __ ].qualifiers then --if there are qualifiers if snakCitation[ __ ].qualifiers.P1001 and snakCitation[ __ ].qualifiers.P407 then --if it has jurisdiction and language local c = 0 for ___,vvvv in ipairs( snakCitation[ __ ].qualifiers.P1001 ) do --for each jurisdiction if snakCitation[ __ ].qualifiers.P1001[ ___ ].datavalue.value.id == "Q145" then c = c + 4 end --if jurisdiction is UK					end for ___,vvvv in ipairs( snakCitation[ __ ].qualifiers.P407 ) do --for each language if snakCitation[ __ ].qualifiers.P1001[ ___ ].datavalue.value.id == "Q1860" then c = c + 2 --if language is English elseif snakCitation[ __ ].qualifiers.P1001[ ___ ].datavalue.value.id == "Q9309" then c = c + 1 --if langauge is Welsh end end if c == 6 then leg.Citation.en = snakCitation[ __ ].mainsnak.datavalue.value --if jurisdiction is UK and language English elseif c == 5 then leg.Citation.cy = snakCitation[ __ ].mainsnak.datavalue.value --if jurisdiction is UK and language Welsh end c = 0 elseif snakCitation[ __ ].qualifiers.P1001 then --if it has jurisdiction but not language for ___,vvvv in ipairs( snakCitation[ __ ].qualifiers.P1001 ) do --for each jurisdiction if snakCitation[ __ ].qualifiers.P1001[ ___ ].datavalue.value.id == "Q145" then leg.Citation.en = snakCitation[ __ ].mainsnak.datavalue.value end end elseif snakCitation[ __ ].qualifiers.P407 then --if it has language but not jurisdiction for ___,vvvv in ipairs( snakCitation[ __ ].qualifiers.P407 ) do --for each language if snakCitation[ __ ].qualifiers.P407[ ___ ].datavalue.value.id == "Q1860" then --if language is English leg.Citation.en = snakCitation[ __ ].mainsnak.datavalue.value elseif snakCitation[ __ ].qualifiers.P407[ ___ ].datavalue.value.id == "Q9309" then --if langauge is Welsh leg.Citation.cy = snakCitation[ __ ].mainsnak.datavalue.value end end else leg.Citation.en = snakCitation[ __ ].mainsnak.datavalue.value --if no relevant qualifiers end else leg.Citation.en = snakCitation[ __ ].mainsnak.datavalue.value --if no qualifiers end end --legislation.gov.uk ID		snaklegGovUK = mw.wikibase.getBestStatements( qid, 'P3343' ) for __,vv in ipairs( snaklegGovUK ) do leg.GovUK = "https://www.legislation.gov.uk/id/" .. snaklegGovUK[ __ ].mainsnak.datavalue.value end o = o .. " " .. leg.Short.en	end return o end

return p