Module:Wdtablerow/listed buildings

This is an old revision of this page, as edited by Nthep (talk | contribs) at 20:16, 22 February 2021. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local getArgs = require('Module:Arguments').getArgs 
local wd = require('Module:Wd')
local p = {}
local qid={}
local location_text={}
local image_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
    	local label_text=wd._label  ( {'edit@end',qid} ) --use wd label
    	else
    		local label_text=o_name --overwrite  name with local value
    end
    --___location
	if wd._property ( {qid,'P276'} ) ~='' then
		local location_p='P276' --use P276 if present
		else
			local location_p='P131' --fallback if P276 isn't present
	end
    if o_location=='' then 
    	location_text=wd._property ( {qid,location_p} )-- use wd ___location
    	else
    		location_text=o_location --overwrite with local value
    end
    --image
    if  image_title~='' then 
    	image_text=image_title --overwrite WD value if filename is passed. No error checking i.e. is filename valid as yet.
    	else
    		image_text=wd._property ( {'raw',qid,'image'} ) --otherwise use WD image
    end
	image_text = '[[File:'..image_text..'|150x150px|center]]' --add wiki markup
	
   --non-overwriteable parameters
    local completed_text=wd._property ( {qid,'P580'} ) --year completed
    local architect_text=wd._property ( {qid,'P84'} ) --architect
    local heritage_text=wd._property ( {qid,'P1435'} ) --heritage designation
	local heritage_date_text=wd._qualifier ( {qid,'P1435','P580'} ) --and date of listing
	local heritage_type=wd._property ( {'raw',qid,'P1435'} ) --decides cell shading based on listing grade
	if heritage_type=='Q15700818' then --Grade I
			cell_shading='style=\"background: #FFC0CB;\"|' 
			elseif heritage_type=='Q15700831' then --Grade II*
				cell_shading='style=\"background: #87CEEB;\"| '
			elseif heritage_type=='Q15700834' then --Grade II
				cell_shading='style=\"background: #ACE1AF;\"| '
            else cell_shading=''
			end
    local gbmapping_text=frame:expandTemplate{title='gbmappingsmall',args={wd._property ( {qid,'P613'} ) }} --gb map 
    local coord_text=wd._property ( {'linked',qid,'coord'} ) --and co-ords
    local list_number_text=frame:expandTemplate{title='National Heritage List for England',
		args={num=wd._property ( {qid,'P1216'} ),short='yes'}} --NHLE number
    local commons_cat_name=wd._property ( {qid,'P373'} )
    if commons_cat_name=='' then --commons category
    		local commons_cat_text='' --ignore non-existent or unlinked in WD categories
    	else
        	commons_cat_text='[[:commons:category:'..commons_cat_name..'|'..commons_cat_name..']]'  
    end 
 
    --return cell values to page
    return_text=row_header_text..label_text..'\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..'<br>('..heritage_date_text..')\n|'
          ..entry_notes..'\n|'
          ..gbmapping_text..'<br>'..coord_text..'\n|'
          ..image_text..'\n|'
          ..list_number_text..'\n|'
          ..commons_cat_text
    return return_text

end
return p