<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AWDloc</id>
	<title>Module:WDloc - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AWDloc"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:WDloc&amp;action=history"/>
	<updated>2026-05-27T17:55:28Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:WDloc&amp;diff=147593&amp;oldid=prev</id>
		<title>imported&gt;Uzume: the same argument can be made for &quot;table&quot; functions like &quot;insert&quot; which always treat tables as an ordered sequences</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:WDloc&amp;diff=147593&amp;oldid=prev"/>
		<updated>2020-06-27T00:45:32Z</updated>

		<summary type="html">&lt;p&gt;the same argument can be made for &amp;quot;table&amp;quot; functions like &amp;quot;insert&amp;quot; which always treat tables as an ordered sequences&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--&lt;br /&gt;
-- Lua functions for returning locations&lt;br /&gt;
-- may be used in infoboxes, so implements whitelist, blacklist, etc.&lt;br /&gt;
--&lt;br /&gt;
&lt;br /&gt;
p = {}&lt;br /&gt;
&lt;br /&gt;
----------------------------------------&lt;br /&gt;
-- location returns the various different locations available in Wikidata&lt;br /&gt;
--&lt;br /&gt;
-- located on terrain feature (P706)&lt;br /&gt;
-- location (P276)&lt;br /&gt;
-- located in the administrative territorial entity (P131)&lt;br /&gt;
-- country (P17)&lt;br /&gt;
-- continent (P30)&lt;br /&gt;
--&lt;br /&gt;
p.location = function(frame)&lt;br /&gt;
	local loc = frame.args.location or &amp;quot;&amp;quot;&lt;br /&gt;
	if loc and (#loc == 0) then loc = nil end&lt;br /&gt;
&lt;br /&gt;
	-- can take a named parameter |qid which is the Wikidata ID for the article.&lt;br /&gt;
	local qid = frame.args.qid or &amp;quot;&amp;quot;&lt;br /&gt;
	if #qid == 0 then qid = mw.wikibase.getEntityIdForCurrentPage() or &amp;quot;&amp;quot; end&lt;br /&gt;
&lt;br /&gt;
	-- The blacklist is passed in named parameter |suppressfields&lt;br /&gt;
	local blacklist = frame.args.suppressfields&lt;br /&gt;
&lt;br /&gt;
	-- The whitelist is passed in named parameter |fetchwikidata&lt;br /&gt;
	local whitelist = frame.args.fetchwikidata&lt;br /&gt;
&lt;br /&gt;
	-- The name of the field that this function is called from is passed in named parameter |name&lt;br /&gt;
	local fieldname = frame.args.name&lt;br /&gt;
	if blacklist then&lt;br /&gt;
		-- The name is compulsory when blacklist is used, so return nil if it is not supplied&lt;br /&gt;
		if not fieldname or (#fieldname == 0) then return nil end&lt;br /&gt;
		-- If this field is on the blacklist, then return nil&lt;br /&gt;
		if blacklist:find(fieldname) then return nil end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- If we got this far then we&amp;#039;re not on the blacklist&lt;br /&gt;
	-- The blacklist overrides any locally supplied parameter as well&lt;br /&gt;
	-- If a non-blank input parameter was supplied return it&lt;br /&gt;
	if loc then return loc end&lt;br /&gt;
&lt;br /&gt;
	-- Otherwise see if this field is on the whitelist:&lt;br /&gt;
	if not (whitelist and (whitelist == &amp;#039;ALL&amp;#039; or whitelist:find(fieldname))) then&lt;br /&gt;
		-- not on the whitelist so just return nil&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- if qid is invalid or Wikidata item is nonexistent, return nothing&lt;br /&gt;
	if not (mw.wikibase.isValidEntityId(qid) and mw.wikibase.entityExists(qid)) then return nil end&lt;br /&gt;
&lt;br /&gt;
	local sep = &amp;quot;, &amp;quot; -- internationalise / parameterise later&lt;br /&gt;
&lt;br /&gt;
	-- There may be multiple values for each of these five types of location&lt;br /&gt;
	local geofeature, location, adminunit, country, continent&lt;br /&gt;
	-- so set up tables for Qid, label, and article&lt;br /&gt;
	-- for each of geofeature, location, adminunit, country, and continent&lt;br /&gt;
	local geofeatureQid, locationQid, adminunitQid, countryQid, continentQid = {}, {}, {}, {}, {}&lt;br /&gt;
	local geofeatureLbl, locationLbl, adminunitLbl, countryLbl, continentLbl = {}, {}, {}, {}, {}&lt;br /&gt;
	local geofeatureArt, locationArt, adminunitArt, countryArt, continentArt = {}, {}, {}, {}, {}&lt;br /&gt;
&lt;br /&gt;
	-- located on terrain feature (P706)&lt;br /&gt;
	local bestP706 = mw.wikibase.getBestStatements(qid, &amp;quot;P706&amp;quot;)&lt;br /&gt;
	if bestP706[1] then&lt;br /&gt;
		for k, v in ipairs(bestP706) do&lt;br /&gt;
			if v.mainsnak.datatype == &amp;quot;wikibase-item&amp;quot; and v.mainsnak.snaktype == &amp;quot;value&amp;quot; then&lt;br /&gt;
				local wid = v.mainsnak.datavalue.value[&amp;quot;id&amp;quot;]&lt;br /&gt;
				local lbl = mw.wikibase.getLabel(wid)&lt;br /&gt;
				local art = mw.wikibase.getSitelink(wid)&lt;br /&gt;
				table.insert(geofeatureQid, wid)&lt;br /&gt;
				if lbl then table.insert(geofeatureLbl, mw.text.nowiki(lbl)) end&lt;br /&gt;
				if art then&lt;br /&gt;
					if lbl then&lt;br /&gt;
						table.insert(geofeatureArt, &amp;quot;[[&amp;quot; .. art .. &amp;quot;|&amp;quot; .. lbl .. &amp;quot;]]&amp;quot;)&lt;br /&gt;
					else&lt;br /&gt;
						table.insert(geofeatureArt, &amp;quot;[[&amp;quot; .. art .. &amp;quot;|&amp;quot; .. art .. &amp;quot;]]&amp;quot;)&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if geofeatureArt[1] then&lt;br /&gt;
			geofeature = table.concat(geofeatureArt, sep)&lt;br /&gt;
		else&lt;br /&gt;
			if geofeatureLbl[1] then&lt;br /&gt;
				geofeature = table.concat(geofeatureLbl, sep)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- location (P276)&lt;br /&gt;
	local bestP276 = mw.wikibase.getBestStatements(qid, &amp;quot;P276&amp;quot;)&lt;br /&gt;
	if bestP276[1] then&lt;br /&gt;
		for k, v in ipairs(bestP276) do&lt;br /&gt;
			if v.mainsnak.datatype == &amp;quot;wikibase-item&amp;quot; and v.mainsnak.snaktype == &amp;quot;value&amp;quot; then&lt;br /&gt;
				local wid = v.mainsnak.datavalue.value[&amp;quot;id&amp;quot;]&lt;br /&gt;
				local lbl = mw.wikibase.getLabel(wid)&lt;br /&gt;
				local art = mw.wikibase.getSitelink(wid)&lt;br /&gt;
				table.insert(locationQid, wid)&lt;br /&gt;
				if lbl then table.insert(locationLbl, mw.text.nowiki(lbl)) end&lt;br /&gt;
				if art then&lt;br /&gt;
					if lbl then&lt;br /&gt;
						table.insert(locationArt, &amp;quot;[[&amp;quot; .. art .. &amp;quot;|&amp;quot; .. lbl .. &amp;quot;]]&amp;quot;)&lt;br /&gt;
					else&lt;br /&gt;
						table.insert(locationArt, &amp;quot;[[&amp;quot; .. art .. &amp;quot;|&amp;quot; .. art .. &amp;quot;]]&amp;quot;)&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if locationArt[1] then&lt;br /&gt;
			location = table.concat(locationArt, sep)&lt;br /&gt;
		else&lt;br /&gt;
			if locationLbl[1] then&lt;br /&gt;
				location = table.concat(locationLbl, sep)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- located in the administrative territorial entity (P131)&lt;br /&gt;
	local bestP131 = mw.wikibase.getBestStatements(qid, &amp;quot;P131&amp;quot;)&lt;br /&gt;
	if bestP131[1] then&lt;br /&gt;
		for k, v in ipairs(bestP131) do&lt;br /&gt;
			if v.mainsnak.datatype == &amp;quot;wikibase-item&amp;quot; and v.mainsnak.snaktype == &amp;quot;value&amp;quot; then&lt;br /&gt;
				local wid = v.mainsnak.datavalue.value[&amp;quot;id&amp;quot;]&lt;br /&gt;
				local lbl = mw.wikibase.getLabel(wid)&lt;br /&gt;
				local art = mw.wikibase.getSitelink(wid)&lt;br /&gt;
				table.insert(adminunitQid, wid)&lt;br /&gt;
				if lbl then table.insert(adminunitLbl, mw.text.nowiki(lbl)) end&lt;br /&gt;
				if art then&lt;br /&gt;
					if lbl then&lt;br /&gt;
						table.insert(adminunitArt, &amp;quot;[[&amp;quot; .. art .. &amp;quot;|&amp;quot; .. lbl .. &amp;quot;]]&amp;quot;)&lt;br /&gt;
					else&lt;br /&gt;
						table.insert(adminunitArt, &amp;quot;[[&amp;quot; .. art .. &amp;quot;|&amp;quot; .. art .. &amp;quot;]]&amp;quot;)&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if adminunitArt[1] then&lt;br /&gt;
			adminunit = table.concat(adminunitArt, sep)&lt;br /&gt;
		else&lt;br /&gt;
			if adminunitLbl[1] then&lt;br /&gt;
				adminunit = table.concat(adminunitLbl, sep)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- country (P17)&lt;br /&gt;
	local bestP17 = mw.wikibase.getBestStatements(qid, &amp;quot;P17&amp;quot;)&lt;br /&gt;
	if bestP17[1] then&lt;br /&gt;
		for k, v in ipairs(bestP17) do&lt;br /&gt;
			if v.mainsnak.datatype == &amp;quot;wikibase-item&amp;quot; and v.mainsnak.snaktype == &amp;quot;value&amp;quot; then&lt;br /&gt;
				local wid = v.mainsnak.datavalue.value[&amp;quot;id&amp;quot;]&lt;br /&gt;
				local lbl = mw.wikibase.getLabel(wid)&lt;br /&gt;
				local art = mw.wikibase.getSitelink(wid)&lt;br /&gt;
				table.insert(countryQid, wid)&lt;br /&gt;
				if lbl then table.insert(countryLbl, mw.text.nowiki(lbl)) end&lt;br /&gt;
				if art then table.insert(countryArt, art) end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if countryArt[1] then&lt;br /&gt;
			country = table.concat(countryArt, sep)&lt;br /&gt;
		else&lt;br /&gt;
			if countryLbl[1] then&lt;br /&gt;
				country = table.concat(countryLbl, sep)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		-- apparently it should be &amp;quot;US&amp;quot;, unless there is no other location information in which case it&amp;#039;s &amp;quot;United States&amp;quot;&lt;br /&gt;
		if country == &amp;quot;United States&amp;quot; then country = &amp;quot;US&amp;quot; end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- continent (P30)&lt;br /&gt;
	local bestP30 = mw.wikibase.getBestStatements(qid, &amp;quot;P30&amp;quot;)&lt;br /&gt;
	if bestP30[1] then&lt;br /&gt;
		for k, v in ipairs(bestP30) do&lt;br /&gt;
			if v.mainsnak.datatype == &amp;quot;wikibase-item&amp;quot; and v.mainsnak.snaktype == &amp;quot;value&amp;quot; then&lt;br /&gt;
				local wid = v.mainsnak.datavalue.value[&amp;quot;id&amp;quot;]&lt;br /&gt;
				local lbl = mw.wikibase.getLabel(wid)&lt;br /&gt;
				local art = mw.wikibase.getSitelink(wid)&lt;br /&gt;
				table.insert(continentQid, wid)&lt;br /&gt;
				if lbl then table.insert(continentLbl, mw.text.nowiki(lbl)) end&lt;br /&gt;
				if art then table.insert(continentArt, art) end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if continentArt[1] then&lt;br /&gt;
			continent = table.concat(continentArt, sep)&lt;br /&gt;
		else&lt;br /&gt;
			if continentLbl[1] then&lt;br /&gt;
				continent = table.concat(continentLbl, sep)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- for now, let&amp;#039;s construct a table of what we&amp;#039;ve found&lt;br /&gt;
	local tbl = &amp;#039;&amp;lt;table class=&amp;quot;wikitable&amp;quot;&amp;gt;&amp;#039;&lt;br /&gt;
	tbl = tbl .. &amp;#039;&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Type&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Article&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Label&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;QID&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;&amp;#039;&lt;br /&gt;
	tbl = tbl .. &amp;#039;&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Geo-feature&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;&amp;#039; .. (table.concat(geofeatureArt, sep) or &amp;quot;&amp;quot;) .. &amp;#039;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;#039; .. (table.concat(geofeatureLbl, sep) or &amp;quot;&amp;quot;) .. &amp;#039;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;#039; .. (table.concat(geofeatureQid, sep) or &amp;quot;&amp;quot;) .. &amp;#039;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;#039;&lt;br /&gt;
	tbl = tbl .. &amp;#039;&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Location&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;&amp;#039; .. (table.concat(locationArt, sep) or &amp;quot;&amp;quot;) .. &amp;#039;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;#039; .. (table.concat(locationLbl, sep) or &amp;quot;&amp;quot;) .. &amp;#039;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;#039; .. (table.concat(locationQid, sep) or &amp;quot;&amp;quot;) .. &amp;#039;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;#039;&lt;br /&gt;
	tbl = tbl .. &amp;#039;&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Admin unit&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;&amp;#039; .. (table.concat(adminunitArt, sep) or &amp;quot;&amp;quot;) .. &amp;#039;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;#039; .. (table.concat(adminunitLbl, sep) or &amp;quot;&amp;quot;) .. &amp;#039;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;#039; .. (table.concat(adminunitQid, sep) or &amp;quot;&amp;quot;) .. &amp;#039;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;#039;&lt;br /&gt;
	tbl = tbl .. &amp;#039;&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Country&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;&amp;#039; .. (table.concat(countryArt, sep) or &amp;quot;&amp;quot;) .. &amp;#039;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;#039; .. (table.concat(countryLbl, sep) or &amp;quot;&amp;quot;) .. &amp;#039;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;#039; .. (table.concat(countryQid, sep) or &amp;quot;&amp;quot;) .. &amp;#039;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;#039;&lt;br /&gt;
	tbl = tbl .. &amp;#039;&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Continent&amp;lt;/th&amp;gt;&amp;lt;td&amp;gt;&amp;#039; .. (table.concat(continentArt, sep) or &amp;quot;&amp;quot;) .. &amp;#039;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;#039; .. (table.concat(continentLbl, sep) or &amp;quot;&amp;quot;) .. &amp;#039;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&amp;#039; .. (table.concat(continentQid, sep) or &amp;quot;&amp;quot;) .. &amp;#039;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;#039;&lt;br /&gt;
	tbl = tbl .. &amp;#039;&amp;lt;/table&amp;gt;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
	-- best candidate for location&lt;br /&gt;
	local wdloc = &amp;quot;&amp;quot;&lt;br /&gt;
	local wdloctbl = {}&lt;br /&gt;
	-- geo-feature and location are mutually exclusive, so we order doesn&amp;#039;t matter&lt;br /&gt;
	--  then add the others: adminunit, country&lt;br /&gt;
	-- if none of them, fall back to continent alone&lt;br /&gt;
	if geofeature then table.insert(wdloctbl, geofeature) end&lt;br /&gt;
	if location then table.insert(wdloctbl, location) end&lt;br /&gt;
	if adminunit then table.insert(wdloctbl, adminunit) end&lt;br /&gt;
	if country then table.insert(wdloctbl, country) end&lt;br /&gt;
	if wdloctbl[1] then&lt;br /&gt;
		wdloc = table.concat(wdloctbl, &amp;quot;, &amp;quot;)&lt;br /&gt;
	else&lt;br /&gt;
		if continent then wdloc = continent end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- deal with US vs United States as sole value&lt;br /&gt;
	if wdloc == &amp;quot;US&amp;quot; then wdloc = &amp;quot;United States&amp;quot; end&lt;br /&gt;
&lt;br /&gt;
	return tbl .. &amp;quot;&amp;lt;p&amp;gt;Location = &amp;quot; .. wdloc .. &amp;quot;&amp;lt;/p&amp;gt;&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Uzume</name></author>
	</entry>
</feed>