Jump to content

Module:WikidataCoord

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Trappist the monk (talk | contribs) at 10:22, 8 May 2016 (create;). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs

local p = {}

function p.main (frame)
	local args = getArgs(frame);
	local lat_long = {};														-- table of lat/long coords extracted from wikidata return 
	
	if nil == args[1] then														-- in case wikidata returns nothing (what does it return for errors?)
		return '<span style="font-size:100%" class="error">{{WikidataCoord}} – missing coordinate data'
	elseif mw.ustring.match (args[1], '%d+°%d+&#39;[%d%.]+&#34;[NS],%s*%d+°%d+&#39;%d+&#34;[EW]') then				-- if the returned data looks like this
		lat_long[1], lat_long[2], lat_long[3], lat_long[4], lat_long[5], lat_long[6], lat_long[7], lat_long[8] =	-- parse it into the table
			mw.ustring.match (args[1], '(%d+)°(%d+)&#39;([%d%.]+)&#34;([NS]),%s*(%d+)°(%d+)&#39;(%d+)&#34;([EW])')
	else
		return '<span style="font-size:100%" class="error">{{WikidataCoord}} – malformed coordinate data';			-- wikidata returned something else
	end

	return frame:expandTemplate{title = 'coord', args = lat_long}				-- invoke template {{coord}} with wikidata lat/long
end

return p;