<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://themidnight.wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AWikidata_label</id>
	<title>Module:Wikidata label - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://themidnight.wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3AWikidata_label"/>
	<link rel="alternate" type="text/html" href="https://themidnight.wiki/index.php?title=Module:Wikidata_label&amp;action=history"/>
	<updated>2026-04-03T22:54:41Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://themidnight.wiki/index.php?title=Module:Wikidata_label&amp;diff=14111&amp;oldid=prev</id>
		<title>Timothy: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://themidnight.wiki/index.php?title=Module:Wikidata_label&amp;diff=14111&amp;oldid=prev"/>
		<updated>2024-04-19T17:40:59Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 13:40, 19 April 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Timothy</name></author>
	</entry>
	<entry>
		<id>https://themidnight.wiki/index.php?title=Module:Wikidata_label&amp;diff=14110&amp;oldid=prev</id>
		<title>wikimedia&gt;WOSlinker: use require(&#039;strict&#039;) instead of require(&#039;Module:No globals&#039;)</title>
		<link rel="alternate" type="text/html" href="https://themidnight.wiki/index.php?title=Module:Wikidata_label&amp;diff=14110&amp;oldid=prev"/>
		<updated>2022-10-30T13:19:50Z</updated>

		<summary type="html">&lt;p&gt;use require(&amp;#039;strict&amp;#039;) instead of require(&amp;#039;Module:No globals&amp;#039;)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[[&lt;br /&gt;
  __  __           _       _      __        ___ _    _     _       _          _       _          _&lt;br /&gt;
 |  \/  | ___   __| |_   _| | ___ \ \      / (_) | _(_) __| | __ _| |_ __ _  | | __ _| |__   ___| |&lt;br /&gt;
 | |\/| |/ _ \ / _` | | | | |/ _ (_) \ /\ / /| | |/ / |/ _` |/ _` | __/ _` | | |/ _` | &amp;#039;_ \ / _ \ |&lt;br /&gt;
 | |  | | (_) | (_| | |_| | |  __/_ \ V  V / | |   &amp;lt;| | (_| | (_| | || (_| | | | (_| | |_) |  __/ |&lt;br /&gt;
 |_|  |_|\___/ \__,_|\__,_|_|\___(_) \_/\_/  |_|_|\_\_|\__,_|\__,_|\__\__,_| |_|\__,_|_.__/ \___|_|&lt;br /&gt;
&lt;br /&gt;
This module is intended to be the engine behind &amp;quot;Template:Label&amp;quot;.&lt;br /&gt;
This module was copied from Commons please ask for changes there.&lt;br /&gt;
&lt;br /&gt;
Please do not modify this code without applying the changes first at &amp;quot;Module:Wikidata label/sandbox&amp;quot; and testing&lt;br /&gt;
at &amp;quot;Module:Wikidata label/testcases&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Authors and maintainers:&lt;br /&gt;
* User:Jarekt - original version&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
require(&amp;#039;strict&amp;#039;) -- used for debugging purposes as it detects cases of unintended global variables&lt;br /&gt;
&lt;br /&gt;
--=============================================&lt;br /&gt;
--=== Internal functions ======================&lt;br /&gt;
--=============================================&lt;br /&gt;
&lt;br /&gt;
---------------------------------------------------------------------------&lt;br /&gt;
-- Normalize input arguments by converting them all to lower case and&lt;br /&gt;
-- replacing space with &amp;quot;_&amp;quot; in the argument name. Also empty strings are&lt;br /&gt;
-- converted to nils. Arguments are collected from arguments passed to the&lt;br /&gt;
-- module and if missing from the template that calls the module&lt;br /&gt;
local function getArgs(frame)&lt;br /&gt;
	local function normalize_input_args(input_args, output_args)&lt;br /&gt;
		for name, value in pairs( input_args ) do&lt;br /&gt;
			value = mw.text.trim(value) -- trim whitespaces from the beggining and the end of the string&lt;br /&gt;
			if value ~= &amp;#039;&amp;#039; then -- nuke empty strings&lt;br /&gt;
				if type(name)==&amp;#039;string&amp;#039; then&lt;br /&gt;
					name = string.gsub( string.lower(name), &amp;#039; &amp;#039;, &amp;#039;_&amp;#039;)&lt;br /&gt;
				end&lt;br /&gt;
				output_args[name] = value&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		return output_args&lt;br /&gt;
	end&lt;br /&gt;
	local args = {}&lt;br /&gt;
	args = normalize_input_args(frame:getParent().args, args)&lt;br /&gt;
	args = normalize_input_args(frame.args, args)&lt;br /&gt;
	return args&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
---------------------------------------------------------------------------&lt;br /&gt;
-- Function allowing for consistent treatment of boolean-like wikitext input.&lt;br /&gt;
-- It works similarly to Module:Yesno but does not assume val is a string&lt;br /&gt;
local function yesno(val, default)&lt;br /&gt;
	if type(val) == &amp;#039;boolean&amp;#039; then&lt;br /&gt;
		return val&lt;br /&gt;
	elseif type(val) == &amp;#039;number&amp;#039; then&lt;br /&gt;
		if val == 1 then&lt;br /&gt;
			return true&lt;br /&gt;
		elseif val == 0 then&lt;br /&gt;
			return false&lt;br /&gt;
		end&lt;br /&gt;
	elseif type(val) == &amp;#039;string&amp;#039; then&lt;br /&gt;
		val = mw.ustring.lower(val)  -- put in lower case&lt;br /&gt;
		if val == &amp;#039;no&amp;#039;  or val == &amp;#039;n&amp;#039; or val == &amp;#039;false&amp;#039; or val == &amp;#039;0&amp;#039; then&lt;br /&gt;
			return false&lt;br /&gt;
		elseif val == &amp;#039;yes&amp;#039; or val == &amp;#039;y&amp;#039; or val == &amp;#039;true&amp;#039; or val == &amp;#039;1&amp;#039; then&lt;br /&gt;
			return true&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return default&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-------------------------------------------------------------------------&lt;br /&gt;
-- get message in a given language&lt;br /&gt;
-- INPUTS:&lt;br /&gt;
-- * msg  - name of a message. For it to work [[MediaWiki:msg]] page need to be set up&lt;br /&gt;
-- * lang - translate message to language &amp;quot;lang&amp;quot;&lt;br /&gt;
-- * default - string to return in case this module is moved to a project where this message is not set&lt;br /&gt;
-- OUTPUT:&lt;br /&gt;
--  * translated message&lt;br /&gt;
local function getMessage(msg, lang, default)&lt;br /&gt;
	msg = mw.message.new(msg):inLanguage(lang):plain()&lt;br /&gt;
	return (msg == nil and default) or msg&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
---------------------------------------------------------------------------&lt;br /&gt;
-- use different sitelink call depending if you already have an entity or not&lt;br /&gt;
-- INPUTS:&lt;br /&gt;
--  * item and entity - entity id and entity: if full entity already uploded than use that&lt;br /&gt;
--                      otherwise use entity id to look up sitelink&lt;br /&gt;
--  * lang - language of the project&lt;br /&gt;
-- OUTPUT:&lt;br /&gt;
--  * sitelink&lt;br /&gt;
local function getSitelink(item, entity, lang)&lt;br /&gt;
	if entity and entity.getSitelink then -- if we have entity then use it&lt;br /&gt;
		return entity:getSitelink(lang .. &amp;#039;wiki&amp;#039;)&lt;br /&gt;
	else -- if no entity then use different function&lt;br /&gt;
		return mw.wikibase.getSitelink(item, lang .. &amp;#039;wiki&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
---------------------------------------------------------------------------&lt;br /&gt;
-- use different sitelink call depending if you already have an entity or not&lt;br /&gt;
-- INPUTS:&lt;br /&gt;
--  * item and entity - entity id and entity: if full entity already uploded than use that&lt;br /&gt;
--                      otherwise use entity id to look up sitelink&lt;br /&gt;
--  * prop - property for which to return the best statment&lt;br /&gt;
-- OUTPUT:&lt;br /&gt;
--  * value of the best statment (only from the first one)&lt;br /&gt;
local function getBestStatementsValue(item, entity, prop)&lt;br /&gt;
	local statments&lt;br /&gt;
	if entity then&lt;br /&gt;
		statments = entity:getBestStatements(prop)&lt;br /&gt;
	else&lt;br /&gt;
		statments = mw.wikibase.getBestStatements(item, prop)&lt;br /&gt;
	end&lt;br /&gt;
	for _, statment in ipairs(statments) do&lt;br /&gt;
		if statment and statment.mainsnak.datavalue.value then&lt;br /&gt;
			return statment.mainsnak.datavalue.value&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
---------------------------------------------------------------------------&lt;br /&gt;
-- change capitalization of the label&lt;br /&gt;
-- INPUTS:&lt;br /&gt;
--  * label - label string&lt;br /&gt;
--  * capitalization - capitalization to be applied: allowed values are &amp;quot;tc&amp;quot;, &amp;quot;lc&amp;quot;,&lt;br /&gt;
--      &amp;quot;uc&amp;quot;, &amp;quot;lcfirst&amp;quot;, and &amp;quot;ucfirst&amp;quot;. Any other value will return original string&lt;br /&gt;
--  * lang - language of the label&lt;br /&gt;
-- OUTPUT:&lt;br /&gt;
--  * value of the best statment (only from the first one)&lt;br /&gt;
local function apply_capitalization(label, capitalization, lang)&lt;br /&gt;
	capitalization = string.lower(capitalization or &amp;#039;none&amp;#039;)&lt;br /&gt;
	if capitalization == &amp;#039;none&amp;#039; then&lt;br /&gt;
		return label&lt;br /&gt;
	elseif capitalization == &amp;#039;uc&amp;#039; then&lt;br /&gt;
		return mw.language.new(lang):uc(label)&lt;br /&gt;
	elseif capitalization == &amp;#039;lc&amp;#039; then&lt;br /&gt;
		return mw.language.new(lang):lc(label)&lt;br /&gt;
	elseif capitalization == &amp;#039;tc&amp;#039; then -- title case&lt;br /&gt;
		local new_label = {}&lt;br /&gt;
		for _, word in ipairs(mw.text.split(label, &amp;#039; &amp;#039;)) do&lt;br /&gt;
			table.insert(new_label, mw.language.new(lang):ucfirst(word))	&lt;br /&gt;
		end&lt;br /&gt;
		return table.concat(new_label, &amp;#039; &amp;#039;)&lt;br /&gt;
	elseif capitalization == &amp;#039;ucfirst&amp;#039; then&lt;br /&gt;
		return mw.language.new(lang):ucfirst(label)&lt;br /&gt;
	elseif capitalization == &amp;#039;lcfirst&amp;#039; then&lt;br /&gt;
		return mw.language.new(lang):lcfirst(label)&lt;br /&gt;
	end&lt;br /&gt;
	return label&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[-------------------------------------------------------------------------&lt;br /&gt;
get link based on user preference&lt;br /&gt;
INPUTS:&lt;br /&gt;
* link_type - can be :&lt;br /&gt;
   * &amp;quot;wikidata&amp;quot; - link to wikidata&lt;br /&gt;
   * &amp;quot;wikipedia&amp;quot; - link to wikipedia (language dependent)&lt;br /&gt;
   * &amp;quot;wikidata talk&amp;quot; - link to wikidata talk page&lt;br /&gt;
   * &amp;quot;commons&amp;quot; - link to commons (try sitelink then commons category then commons gallery)&lt;br /&gt;
   * &amp;quot;commonscat&amp;quot; - link to commons (try commons category then commons gallery)&lt;br /&gt;
   * &amp;quot;-&amp;quot; - means no link&lt;br /&gt;
* item   - entity ID (always provided)&lt;br /&gt;
* entity - whole entity. It can be nil if whole entity is not loaded&lt;br /&gt;
* langList - language fallback list for preferred language (required)&lt;br /&gt;
OUTPUT:&lt;br /&gt;
* link - link to the wikimedia page&lt;br /&gt;
]]&lt;br /&gt;
local function getLink(link_type, item, entity, langList)&lt;br /&gt;
	local link, eLink&lt;br /&gt;
	link_type = mw.ustring.lower(link_type or &amp;#039;&amp;#039;)&lt;br /&gt;
	local item_type = mw.ustring.sub(item, 1, 1) -- first letter prefix of item entity ID: &amp;#039;Q&amp;#039;, &amp;#039;P&amp;#039; or &amp;#039;M&amp;#039;&lt;br /&gt;
	if item_type == &amp;#039;M&amp;#039; then&lt;br /&gt;
		eLink=&amp;#039;c:Special:EntityPage/&amp;#039;..item&lt;br /&gt;
	elseif item_type == &amp;#039;Q&amp;#039; then&lt;br /&gt;
		eLink=&amp;#039;d:&amp;#039;..item -- wikibase entity page link&lt;br /&gt;
	elseif item_type == &amp;#039;P&amp;#039; then&lt;br /&gt;
		eLink=&amp;#039;d:Property:&amp;#039;..item -- wikibase entity page link&lt;br /&gt;
	else&lt;br /&gt;
		eLink=&amp;#039;d:Special:EntityPage/&amp;#039;..item&lt;br /&gt;
	end&lt;br /&gt;
	if link_type == &amp;#039;-&amp;#039; then -- allow different link formats&lt;br /&gt;
		link = &amp;#039;&amp;#039;            -- no link&lt;br /&gt;
	elseif link_type == &amp;#039;wikidata&amp;#039; or item_type == &amp;#039;M&amp;#039; then&lt;br /&gt;
		link = eLink        -- link to wikibase entity page&lt;br /&gt;
	elseif link_type == &amp;#039;wikidata talk&amp;#039; and item_type == &amp;#039;P&amp;#039; then&lt;br /&gt;
		link = &amp;#039;d:Property talk:&amp;#039;.. item        -- link to wikidata property talk page&lt;br /&gt;
	elseif link_type == &amp;#039;wikidata talk&amp;#039; then&lt;br /&gt;
		link = &amp;#039;d:Talk:&amp;#039;..item   -- link to wikidata talk page&lt;br /&gt;
	elseif link_type == &amp;#039;commons&amp;#039; or link_type == &amp;#039;commonscat&amp;#039; then&lt;br /&gt;
		--[[&lt;br /&gt;
		When link_type == &amp;#039;commons&amp;#039; we try the following links (in specified order):&lt;br /&gt;
		  1) commons sitelink&lt;br /&gt;
		  2) P373 &amp;quot;Commons Category&amp;quot; claims&lt;br /&gt;
		  3) P935 &amp;quot;Commons Gallery&amp;quot;  claims&lt;br /&gt;
		Since most items have a commons sitelink we never have to look for claims&lt;br /&gt;
		When link_type == &amp;#039;commonscat&amp;#039; we try to maximize chances of commons link being a category, so we&lt;br /&gt;
		      try the following links (in specified order):&lt;br /&gt;
		  1) commons sitelink, which is kept if it points to a category&lt;br /&gt;
		  2) P373 &amp;quot;Commons Category&amp;quot; claims&lt;br /&gt;
		  3) commons sitelink (which does not point to a category)&lt;br /&gt;
		  4) P935 &amp;quot;Commons Gallery&amp;quot;  claims&lt;br /&gt;
		Since most pages have a commons sitelink we never have to look for claims&lt;br /&gt;
		]]&lt;br /&gt;
		local sLink = getSitelink(item, entity, &amp;#039;commons&amp;#039;)  -- look for sitelink to commons&lt;br /&gt;
		if sLink then&lt;br /&gt;
			sLink = &amp;#039;c:&amp;#039;..sLink&lt;br /&gt;
			if (link_type == &amp;#039;commons&amp;#039;) or (link_type == &amp;#039;commonscat&amp;#039; and mw.ustring.find(sLink, &amp;#039;Category:&amp;#039;)) then&lt;br /&gt;
				link = sLink&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if not link then -- try linking to P373 &amp;quot;Commons Category&amp;quot;&lt;br /&gt;
			local cat = getBestStatementsValue(item, entity, &amp;#039;P373&amp;#039;)&lt;br /&gt;
			link = (cat ~= nil and &amp;#039;c:Category:&amp;#039; .. cat) or nil&lt;br /&gt;
		end&lt;br /&gt;
		link = link or sLink&lt;br /&gt;
		if not link then -- try linking to P935 &amp;quot;Commons Gallery&amp;quot;&lt;br /&gt;
			link = getBestStatementsValue(item, entity, &amp;#039;P935&amp;#039;)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if not link then -- apply default &amp;quot;Wikipedia&amp;quot; link type&lt;br /&gt;
		for _, language in ipairs(langList) do&lt;br /&gt;
			local sitelink = getSitelink(item, entity, language)&lt;br /&gt;
			if sitelink then&lt;br /&gt;
				link = &amp;#039;w:&amp;#039;.. language ..&amp;#039;:&amp;#039;.. sitelink&lt;br /&gt;
				break&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return link or eLink  -- no wiki sitelink, so link to wikidata&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--=============================================&lt;br /&gt;
--=== External functions ======================&lt;br /&gt;
--=============================================&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
--======================================================================&lt;br /&gt;
--=== API functions for use from other Scribunto modules ===============&lt;br /&gt;
--======================================================================&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
_getLabel&lt;br /&gt;
&lt;br /&gt;
This function returns a label translated to desired language, created based on wikidata&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
	1: item - wikidata&amp;#039;s item&amp;#039;s q-id or entity class&lt;br /&gt;
	2: lang - desired language of the label&lt;br /&gt;
	3: link_type - link style. Possible values (case-insensitive): &amp;quot;wikipedia&amp;quot;, &amp;quot;wikidata&amp;quot;, &amp;quot;Commons&amp;quot;, or &amp;quot;-&amp;quot; (no link)&lt;br /&gt;
	4: capitalization - can be &amp;quot;uc&amp;quot; (upper case), &amp;quot;lc&amp;quot; (lower case), &amp;quot;ucfirst&amp;quot; (upper case for the first letter),&lt;br /&gt;
			&amp;quot;lcfirst&amp;quot; (lower case for the first letter), or &amp;#039;none&amp;#039; (default)&lt;br /&gt;
&lt;br /&gt;
Error Handling:&lt;br /&gt;
	Bad q-id will result in displayed error&lt;br /&gt;
]]&lt;br /&gt;
function p._getLabel(item, lang, link_type, capitalization, show_id)&lt;br /&gt;
	local entity, s, link, label, language, desc&lt;br /&gt;
&lt;br /&gt;
	-- clean up the input parameters&lt;br /&gt;
	if type(item) ~= &amp;#039;string&amp;#039; then -- &amp;quot;item&amp;quot; is not a q-id&lt;br /&gt;
		entity = item            -- &amp;quot;item&amp;quot; must be the entity&lt;br /&gt;
		item   = entity.id       -- look-up q-id&lt;br /&gt;
	elseif tonumber(item) then   -- if it is just the number then add &amp;quot;Q&amp;quot; in front&lt;br /&gt;
		item = &amp;#039;Q&amp;#039;..item&lt;br /&gt;
	end&lt;br /&gt;
	item = mw.ustring.gsub(mw.ustring.upper(item), &amp;#039;PROPERTY:P&amp;#039;, &amp;#039;P&amp;#039;) -- make all the properties the same and capitalize&lt;br /&gt;
&lt;br /&gt;
	if not lang then&lt;br /&gt;
		label, lang = mw.wikibase.getLabelWithLang(item)&lt;br /&gt;
	end&lt;br /&gt;
	if not lang then -- if still no language&lt;br /&gt;
		lang  = mw.getCurrentFrame():callParserFunction(&amp;quot;int&amp;quot;,&amp;quot;lang&amp;quot;)  -- get user&amp;#039;s chosen language&lt;br /&gt;
		label = nil&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- build language fallback list&lt;br /&gt;
	lang = mw.ustring.lower(lang)&lt;br /&gt;
	local langList = mw.language.getFallbacksFor(lang)&lt;br /&gt;
	table.insert(langList, 1, lang)&lt;br /&gt;
&lt;br /&gt;
	-- get label (visible part of the link)&lt;br /&gt;
	if not label then&lt;br /&gt;
		for _, language in ipairs(langList) do  -- loop over language fallback list looking for label in the specific language&lt;br /&gt;
			if entity then&lt;br /&gt;
				label = entity:getLabel(language)&lt;br /&gt;
			else&lt;br /&gt;
				label = mw.wikibase.getLabelByLang(item, language)&lt;br /&gt;
			end&lt;br /&gt;
			if label then break end                    -- label found and we are done&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if label then  -- wikitext-escape the label if we have one&lt;br /&gt;
		label = mw.text.nowiki(label)&lt;br /&gt;
	end&lt;br /&gt;
	if not label then                              -- no labels found, so just show the q-id&lt;br /&gt;
		label = item&lt;br /&gt;
	elseif show_id then           -- add id&lt;br /&gt;
		show_id = yesno(show_id,false)&lt;br /&gt;
		if show_id then&lt;br /&gt;
			local wordsep = getMessage(&amp;#039;Word-separator&amp;#039;, lang, &amp;#039; &amp;#039;)&lt;br /&gt;
			local id = mw.message.new(&amp;#039;parentheses&amp;#039;, item):inLanguage(lang):plain()&lt;br /&gt;
			id = (id~=nil and id) or (&amp;#039;(&amp;#039;..item..&amp;#039;)&amp;#039;) -- in case this module is moved to a project where {{int:parenthesis}} is not set&lt;br /&gt;
			label = label .. wordsep .. &amp;quot;&amp;lt;small&amp;gt;&amp;quot; .. id .. &amp;quot;&amp;lt;/small&amp;gt;&amp;quot;&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	label = apply_capitalization(label, capitalization, lang)&lt;br /&gt;
	&lt;br /&gt;
	-- look for description&lt;br /&gt;
	if  entity and entity.descriptions and lang then &lt;br /&gt;
		for _, language in ipairs(langList) do&lt;br /&gt;
			if entity.descriptions[language] then&lt;br /&gt;
				desc = entity.descriptions[language].value &lt;br /&gt;
				break&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		desc = mw.wikibase.getDescription(item)&lt;br /&gt;
	end&lt;br /&gt;
	if desc and link_type ~= &amp;#039;-&amp;#039; then  -- wikitext-escape the description if we have one&lt;br /&gt;
		desc = mw.text.nowiki(desc) -- add description as hover text&lt;br /&gt;
		label = &amp;#039;&amp;lt;span title=&amp;quot;&amp;#039; .. desc .. &amp;#039;&amp;quot;&amp;gt;&amp;#039; .. label .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- return the results&lt;br /&gt;
	if link_type == &amp;#039;-&amp;#039; then&lt;br /&gt;
		return label -- return just the label&lt;br /&gt;
	else&lt;br /&gt;
		link = getLink(link_type, item, entity, langList)&lt;br /&gt;
		return &amp;#039;[[&amp;#039; .. link .. &amp;#039;|&amp;#039; .. label .. &amp;#039;]]&amp;#039; -- return link&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[-------------------------------------------------------------------------------&lt;br /&gt;
_sitelinks&lt;br /&gt;
&lt;br /&gt;
This function returns a table of sitelinks for a single project organized by language&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
	1: item - wikidata&amp;#039;s item&amp;#039;s q-id or entity class&lt;br /&gt;
	2: project - (case-insensitive) one of: &amp;quot;wikipedia&amp;quot;, &amp;quot;wikisource&amp;quot;, &amp;quot;wikiquote&amp;quot;, &amp;quot;wikibooks&amp;quot;, &amp;quot;wikinews&amp;quot;,&lt;br /&gt;
			&amp;quot;wikiversity&amp;quot;, &amp;quot;wikivoyage&amp;quot;, &amp;quot;wiktionary&amp;quot;, &amp;quot;commons&amp;quot;, &amp;quot;mediawiki&amp;quot;, &amp;quot;wikispecies&amp;quot;, &amp;quot;wikidata&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
	Table of sitelinks with language fields&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
	Table of sitelinks with language fields&lt;br /&gt;
See also&lt;br /&gt;
* [https://foundation.wikimedia.org/wiki/Special:SiteMatrix] for the full list of supported interwikis.&lt;br /&gt;
* [https://dumps.wikimedia.org/backup-index.html] for the full list of sitecodes (used in database dumps).&lt;br /&gt;
]]&lt;br /&gt;
function p._sitelinks(item, project)&lt;br /&gt;
	local entity, sitelink&lt;br /&gt;
	-- get entity&lt;br /&gt;
	if type(item) == &amp;#039;string&amp;#039; then -- &amp;quot;item&amp;quot; is a q-id&lt;br /&gt;
		entity = mw.wikibase.getEntity(item)&lt;br /&gt;
	else&lt;br /&gt;
		entity = item              -- &amp;quot;item&amp;quot; is the entity&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- convert from english project name  to proproject code&lt;br /&gt;
	local projLUT = {&lt;br /&gt;
		wikipedia   = &amp;#039;wiki&amp;#039;,           commons   = &amp;#039;commonswiki&amp;#039;,&lt;br /&gt;
		foundation  = &amp;#039;foundationwiki&amp;#039;, mediawiki = &amp;#039;mediawikiwiki&amp;#039;,&lt;br /&gt;
		wikispecies = &amp;#039;specieswiki&amp;#039;,    wikidata  = &amp;#039;wikidatawiki&amp;#039;,&lt;br /&gt;
		incubator   = &amp;#039;incubatorwiki&amp;#039;,	oldwikisource = &amp;#039;sourceswiki&amp;#039;,&lt;br /&gt;
	}&lt;br /&gt;
	local langLUT = {&lt;br /&gt;
		-- These are not language codes before the &amp;#039;wiki&amp;#039; or &amp;#039;wikiversity&amp;#039; suffix in a sitecode:&lt;br /&gt;
		foundation = &amp;#039;~&amp;#039;, commons = &amp;#039;~&amp;#039;,	-- they will be skipped&lt;br /&gt;
		incubator  = &amp;#039;~&amp;#039;, meta    = &amp;#039;~&amp;#039;,&lt;br /&gt;
		mediawiki  = &amp;#039;~&amp;#039;, sources = &amp;#039;~&amp;#039;,&lt;br /&gt;
		species    = &amp;#039;~&amp;#039;, beta    = &amp;#039;~&amp;#039;,&lt;br /&gt;
		-- Legacy language codes used in sitecodes, remapped to standard Wikimedia language codes:&lt;br /&gt;
		-- See https://meta.wikimedia.org/wiki/Special_language_codes for details&lt;br /&gt;
		als     = &amp;#039;gsw&amp;#039;, bat_smg      = &amp;#039;sgs&amp;#039;,&lt;br /&gt;
		fiu_vro = &amp;#039;vro&amp;#039;, be_x_old     = &amp;#039;be-tarask&amp;#039;,&lt;br /&gt;
		roa_rup = &amp;#039;rup&amp;#039;, zh_classical = &amp;#039;lzh&amp;#039;,&lt;br /&gt;
		zh_yue  = &amp;#039;yue&amp;#039;, zh_min_nan   = &amp;#039;nan&amp;#039;,&lt;br /&gt;
		zh_wuu  = &amp;#039;wuu&amp;#039;, no           = &amp;#039;nb&amp;#039;,&lt;br /&gt;
	}&lt;br /&gt;
	project = project:lower()&lt;br /&gt;
	project = projLUT[project] or project -- correct the project name&lt;br /&gt;
	local n = project:len()&lt;br /&gt;
	local linkTable = {}&lt;br /&gt;
	if entity and entity.sitelinks then  -- See if entity exists, and that it has sitelinks&lt;br /&gt;
		for _, sitelink in pairs(entity.sitelinks) do -- loop over all sitelinks&lt;br /&gt;
			local site = sitelink.site&lt;br /&gt;
			local m    = site:len() - n&lt;br /&gt;
			local proj = site:sub(m +1)  -- project part of the siteID&lt;br /&gt;
			if proj == project  then -- proj matches desired &amp;quot;project&amp;quot;&lt;br /&gt;
				local lang = site:sub(1, m)  -- language part of the siteID&lt;br /&gt;
				lang = langLUT[lang] or lang:gsub(&amp;#039;_&amp;#039;,&amp;#039;-&amp;#039;)&lt;br /&gt;
				if lang ~= &amp;#039;~&amp;#039; then -- proj matches desired &amp;quot;project&amp;quot;&lt;br /&gt;
					linkTable[lang] = sitelink.title&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return linkTable&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[----------------------------------------------------------------&lt;br /&gt;
_aliases&lt;br /&gt;
&lt;br /&gt;
This function returns a table of aliases for a single language&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
	1: item - wikidata&amp;#039;s item&amp;#039;s q-id or entity class&lt;br /&gt;
	2: lang - language code, like &amp;#039;en&amp;#039; or &amp;#039;de&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
	Table of aliases with language fields&lt;br /&gt;
]]&lt;br /&gt;
function p._aliases(item, lang)&lt;br /&gt;
	local entity&lt;br /&gt;
	if type(item) == &amp;#039;string&amp;#039; then -- &amp;quot;item&amp;quot; is a q-id&lt;br /&gt;
		entity = mw.wikibase.getEntity(item)&lt;br /&gt;
	else&lt;br /&gt;
		entity = item            -- &amp;quot;item&amp;quot; is the entity&lt;br /&gt;
	end&lt;br /&gt;
	local aliasTable = {}&lt;br /&gt;
	if entity and entity.aliases then						-- See if there is an entity and that is has aliases&lt;br /&gt;
		if entity.aliases[lang] then						-- See if it has English Aliases&lt;br /&gt;
			for _, alias in pairs(entity.aliases[lang]) do  -- Make a loop around the English aliases&lt;br /&gt;
				table.insert(aliasTable, alias.value)				-- Create a table of English aliases&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return aliasTable&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--======================================================================&lt;br /&gt;
--=== Invoke functions for use from wikitext, e.g., templates ==========&lt;br /&gt;
---=====================================================================&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
getLabel&lt;br /&gt;
&lt;br /&gt;
This function returns a label translated to desired language, created based on wikidata&lt;br /&gt;
&lt;br /&gt;
Usage:&lt;br /&gt;
{{#invoke:Wikidata label|getLabel|item=Q...|lang=..|link_style=..|capitalization=..}}&lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
	1: wikidata&amp;#039;s item&amp;#039;s q-id (required)&lt;br /&gt;
	2: language (optional; default {{int:lang}})&lt;br /&gt;
	3: link_style: &amp;quot;wikipedia&amp;quot; (default), &amp;quot;Wikidata&amp;quot;, &amp;quot;Commons&amp;quot;, or &amp;quot;-&amp;quot; (no link)&lt;br /&gt;
	4: capitalization - can be &amp;quot;uc&amp;quot;, &amp;quot;lc&amp;quot;, &amp;quot;tc&amp;quot;, &amp;quot;ucfirst&amp;quot;, &amp;quot;lcfirst&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Error Handling:&lt;br /&gt;
	Bad q-id will result in displayed error&lt;br /&gt;
]]&lt;br /&gt;
function p.getLabel(frame)&lt;br /&gt;
	local args = getArgs(frame)&lt;br /&gt;
	return p._getLabel(args.item, args.lang, args.link, args.capitalization, args.show_id)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[-------------------------------------------------------------------------------&lt;br /&gt;
sitelinks&lt;br /&gt;
&lt;br /&gt;
This function returns a comma separated list of sitelinks for a single project organized by language&lt;br /&gt;
Its main purpose is to help with testing of _sitelinks function.&lt;br /&gt;
&lt;br /&gt;
Usage:&lt;br /&gt;
{{#invoke:Wikidata label|sitelinks|item=Q...|project=..}}&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
	1: item - wikidata&amp;#039;s item&amp;#039;s q-id or entity class&lt;br /&gt;
	2: project - &amp;quot;wikipedia&amp;quot; (or &amp;quot;wiki&amp;quot;), &amp;quot;wikisource&amp;quot;, &amp;quot;wikiquote&amp;quot;, &amp;quot;wikibooks&amp;quot;,&lt;br /&gt;
	             &amp;quot;wikinews&amp;quot;, &amp;quot;wikiversity&amp;quot;, &amp;quot;wikivoyage&amp;quot;, &amp;quot;wiktionary&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
	comma separated list&lt;br /&gt;
]]&lt;br /&gt;
function p.sitelinks(frame)&lt;br /&gt;
	local args = getArgs(frame)&lt;br /&gt;
	local sitelinks = p._sitelinks(args.item, args.project)&lt;br /&gt;
	local sitelinkList = {}&lt;br /&gt;
	for lang, sitelink in pairs(sitelinks) do&lt;br /&gt;
		table.insert(sitelinkList, (lang==&amp;#039;&amp;#039; and sitelink) or (lang .. &amp;#039;:&amp;#039; .. sitelink))&lt;br /&gt;
	end&lt;br /&gt;
	return table.concat(sitelinkList, &amp;#039;, &amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[----------------------------------------------------------------------------&lt;br /&gt;
aliases&lt;br /&gt;
&lt;br /&gt;
This function returns a comma separated list of aliases for a single language&lt;br /&gt;
Its main purpose is to help with testing of _aliases function.&lt;br /&gt;
&lt;br /&gt;
Usage:&lt;br /&gt;
{{#invoke:Wikidata label|aliases|item=Q...|lang=..}}&lt;br /&gt;
&lt;br /&gt;
Inputs:&lt;br /&gt;
	1: item - wikidata&amp;#039;s item&amp;#039;s q-id or entity class&lt;br /&gt;
	2: lang - language code, like &amp;#039;en&amp;#039; or &amp;#039;de&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Output:&lt;br /&gt;
	Comma separated list of aliases&lt;br /&gt;
]]&lt;br /&gt;
function p.aliases(frame)&lt;br /&gt;
	local args = getArgs(frame)&lt;br /&gt;
	return table.concat(p._aliases(args.item, args.lang), &amp;#039;, &amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>wikimedia&gt;WOSlinker</name></author>
	</entry>
</feed>