Module:Gdtablerow/listed buildings

--This module is invoked from Template:English Heritage listed building row/Leeds University local getArgs = require('Module:Arguments').getArgs local gd = require('Module:Gd') local p = {} local qid= {} local label_t local label_text local location_p local location_text local completed_year local completed_text local source_circumstance local earliest_date local latest_date local range_start_date local has_creator local has_architect local architect_text local image_text local commons_cat_text local return_text

function p.main(frame)

local row_header_text='|-style=\"text-align: center;\"\n!scope=\"row\" | ' --sets up row style sets 1st cell as header row local args = getArgs(frame) --assign passed parameters qid= (args.qid or args[1] or '') local o_name= (args.name or args[2] or '') --local name local o_location= (args.location or args[3] or '') --local location local entry_notes= (args.notes or args[4] or '') -- freetext notes local image_title=(args.image or args[5] or '') -- local image --label if o_name=='' then label_t=gd._label ( {qid} ) --use gd label else label_t=o_name --overwrite name with local value end local site_link = mw.wikibase.sitelink(qid) --check if there is a sitelink if site_link then --if there is make the link = the sitelink but piped with the label/overwrite name label_text=..label_t.. else label_text=label_t end local gd_link='('..gd._label({'raw','edit@end',qid})..')' --whatever the label add a Gratisdata link underneath and enclose in brackets --location if gd._property ( {qid,'P64'} ) ~='' then location_p='P64' --use P64 if present else location_p='P177' --fallback if P64 isn't present end if o_location~='' then location_text=o_location --overwrite with local value else location_text=gd._property ( {qid,location_p} )-- use gd location end --image if image_title~='' then image_text=image_title --overwrite GD value if filename is passed. No error checking i.e. is filename valid as yet. else image_text=gd._property ( {'raw',qid,'image'} ) --otherwise use GD image end if image_text~='' then --add markup only if an image file is named image_text = '' --add wiki markup end --non-overwriteable parameters --completion year completed_year=gd._property ( {qid,'P11'} ) --determine in P11 (inception) is present if completed_year~='' then completed_year='P11' --if it is make the value equal inception else completed_year='P174' --else make it equal start year end completed_text=gd._property ( {qid, completed_year} ) --set return value to whichever --check for qualifiers source_circumstance=gd._qualifier( {qid, completed_year, 'P160'} ) --check for circa etc qualifier to completion date earliest_date=gd._qualifier( {qid, completed_year, 'P173'} ) --check for the earliest and latest date qualifiers latest_date=gd._qualifier( {qid, completed_year, 'P172'} ) if source_circumstance~='' then completed_text='data-sort-value=\"'..completed_text..'\"|'..source_circumstance..' '..completed_text --if there is a qualifier use it 			as a prefix to the date but keep the date as the sort-value end if earliest_date~= and latest_date~= then --only proceed if both are present completed_text='data-sort-value=\"'..completed_text..'\"|'..earliest_date..'–'..latest_date --if there is a range use it 			as the date but keep the completed date as the sort-value end --architect or creator has_creator=gd._property ( {qid, 'P114'} ) --get P114 if it exists has_architect= gd._property ( {qid, 'P290'} ) --get P290 if it exists if has_architect~= and has_creator== then --if no creator then architect_text=gd._properties ( {'linked', qid, 'P290'} ) --use P290 architect. Note properties to catch multiple uses elseif has_architect== and has_creator~= then architect_text=gd._property ( {'linked', qid,'P114'} ) --use P114 creator elseif has_architect== and has_creator== then --if no creator then architect_text='' --use an empty string if neither are present end --heritage designation and date local heritage_text=gd._property ( {qid, 'P324'} ) --heritage designation local heritage_date_text=gd._qualifier ( {qid,'P324','P174'} ) --and date of listing local heritage_type=gd._property ( {'raw',qid,'P324'} ) --decides cell shading based on listing grade if heritage_type=='Q731' then --Grade I           cell_shading='style=\"background: #FFC0CB;\"|' elseif heritage_type=='Q730' then --Grade II* cell_shading='style=\"background: #87CEEB;\"| ' elseif heritage_type=='Q729' then --Grade II               cell_shading='style=\"background: #ACE1AF;\"| ' else cell_shading='' end if entry_notes~='' then entry_notes = 'style=\"text-align: left;\" |'..entry_notes end local gbmapping_text=frame:expandTemplate{title='gbmappingsmall',args={gd._property ( {qid,'P323'} ) }} --gb map local coord_text=gd._property ( {'linked',qid,'coord'} ) --and co-ords local list_number_text=frame:expandTemplate{title='National Heritage List for England', args={num=gd._property ( {qid,'P322'} ),short='yes'}} --NHLE number local commons_cat_name=gd._property ( {qid,'P164'} ) if commons_cat_name=='' then --commons category commons_cat_text='' --ignore non-existent or unlinked in GD categories else commons_cat_text=..commons_cat_name.. end --return cell values to page return_text=row_header_text..label_text..' '..gd_link..'\n|' --includes code to create new line and make first cell row header ..location_text..'\n|' ..completed_text..'\n|' ..architect_text..'\n|' ..cell_shading..heritage_text..' ('..heritage_date_text..')\n|' ..entry_notes..'\n|' ..gbmapping_text..' '..coord_text..'\n|' ..image_text..'\n|' ..list_number_text..'\n|' ..commons_cat_text return return_text

end return p