Jump to content

Module:ⵜⴰⴼⵍⵓⵖⵎⵉⵙⵜ ⴰⴷⵔⴰⵔ

ⵙⴳ ⵡⵉⴽⵉⴱⵉⴷⵢⴰ
local p = {}
local wikibase = mw.wikibase

local function trimWhitespace(s)
	if type(s) ~= 'string' then return nil end
	s = s:match('^%s*(.-)%s*$')
	if s == '' then return nil end
	return s
end

local function getArgs(frame)
	local args = {}
	local parent = frame:getParent()
	if parent and parent.args then
		for k, v in pairs(parent.args) do
			args[k] = trimWhitespace(v)
		end
	end
	for k, v in pairs(frame.args) do
		args[k] = trimWhitespace(v)
	end
	return args
end

local function getSmartLink(entityId)
	if not entityId then return nil end
	
	local sitelink = mw.wikibase.getSitelink(entityId)
	
	if sitelink then
		return '[[' .. sitelink .. ']]'
	end
	
	local label = mw.wikibase.getLabelByLang(entityId, 'zgh')
	
	if not label then
		label = mw.wikibase.getLabel(entityId)
	end
	
	if not label then
		local entity = mw.wikibase.getEntity(entityId)
		if entity and entity.labels and entity.labels.en then
			label = entity.labels.en.value
		end
	end
	
	label = label or entityId

	local title = mw.title.new(label)
	if title and title.exists then
		return '[[' .. label .. ']]'
	else
		return '[[:d:' .. entityId .. '|' .. label .. ']]'
	end
end

local function getEntity(entityId)
	if not mw.wikibase then return nil end
	if entityId == '' then entityId = nil end
	entityId = entityId or mw.wikibase.getEntityIdForCurrentPage()
	if not entityId or entityId == '' then return nil end

	local success, entity = pcall(function() return mw.wikibase.getEntity(entityId) end)
	if success and entity then
		entity.getBestStatements = function(self, propertyId)
			if not self.claims or not self.claims[propertyId] then return {} end
			local statements = {}
			for _, claim in pairs(self.claims[propertyId]) do
				if claim.mainsnak.snaktype == 'value' then
					table.insert(statements, claim)
				end
			end
			return statements
		end
		return entity
	end
	return nil
end

local function getCoordinates(entity)
	local statements = entity:getBestStatements('P625')
	if #statements > 0 then
		local val = statements[1].mainsnak.datavalue.value
		return val.latitude, val.longitude
	end
	return nil, nil
end

local function formatBigNumber(amount)
	if not amount then return '' end
	local lang = mw.getContentLanguage()
	local res = lang:formatNum(amount)
	res = res:gsub('%s+', ',')
	return res:gsub(' ', ',')
end

local function getQuantityValue(entity, propertyId)
	local claims = entity:getBestStatements(propertyId)
	if #claims == 0 then return nil end

	local bestClaim = claims[1] 

	if bestClaim then
		local val = bestClaim.mainsnak.datavalue.value
		local amount = nil
		local unit = ''
		
		if type(val) == 'table' and val.amount then
			amount = tonumber(val.amount)
		elseif type(val) == 'number' then
			amount = val
		end

		if amount then
			return formatBigNumber(amount)
		end
	end
	return nil
end

local function makeEditIcon(entityId, propertyId)
	if not entityId or not propertyId then return '' end
	return ' [[ⴰⴼⴰⵢⵍⵓ:Edit-icon.svg|15px|link=https://www.wikidata.org/wiki/' .. entityId .. '#' .. propertyId .. '|ⵙⵏⴼⵍ ⴳ ⵡⵉⴽⵉⴷⴰⵜⴰ]]'
end

local function getCountryWithFlag(countryId)
	local label = getSmartLink(countryId)
	local flag = nil
	
	local entity = getEntity(countryId)
	if entity then
		local flags = entity:getBestStatements('P41')
		if #flags > 0 and flags[1].mainsnak.datavalue then
			flag = flags[1].mainsnak.datavalue.value
		end
	end
	
	if flag then
		return '[[ⴰⴼⴰⵢⵍⵓ:' .. flag .. '|20px|border|link=]] ' .. label
	else
		return label
	end
end

local function makeRequest(entityId, property, options)
	options = options or {}
	local entity = getEntity(entityId)
	if not entity then return nil, false end
	
	if property == 'P856' then
		local claims = entity:getBestStatements('P856')
		if #claims > 0 and claims[1].mainsnak.datavalue then
			local url = claims[1].mainsnak.datavalue.value
			local display = url:gsub('^https?://', '')
			if display:sub(-1) == '/' then display = display:sub(1, -2) end
			return '[' .. url .. ' ' .. display .. ']', true
		end
		return nil, false
	end

	if property == 'P2044' or property == 'P2660' or property == 'P2046' or property == 'P2043' or property == 'P2049' or property == 'P2234' or property == 'P2386' or property == 'P4184' then
		local val = getQuantityValue(entity, property)
		if val then 
			return val, true 
		else
			return nil, false
		end
	end

	local statements = entity:getBestStatements(property)
	local filteredStatements = statements

	if #filteredStatements > 0 then
		local valuesWithLinks = {}
		
		for i, statement in ipairs(filteredStatements) do
			if options.limit and i > options.limit then break end
			
			local isHistorical = false
			if property == 'P17' and statement.qualifiers and statement.qualifiers['P582'] then
				isHistorical = true
			end

			if not isHistorical then
				local datavalue = statement.mainsnak.datavalue
				local valueToAdd = nil

				if datavalue.type == 'string' then
					valueToAdd = datavalue.value
				elseif datavalue.type == 'monolingualtext' then
					valueToAdd = datavalue.value.text
				elseif datavalue.type == 'wikibase-entityid' then
					local targetEntityId = datavalue.value.id
					if property == 'P17' then
						valueToAdd = getCountryWithFlag(targetEntityId)
					else
						valueToAdd = getSmartLink(targetEntityId)
					end
				elseif datavalue.type == 'quantity' then
					local amount = tonumber(datavalue.value.amount)
					valueToAdd = formatBigNumber(amount)
				elseif datavalue.type == 'time' then
					local timeValue = datavalue.value.time
					local yearStr = string.match(timeValue, "^[%+%-](%d+)")
					if yearStr then valueToAdd = yearStr end
				end

				if property == 'P793' and options.firstAscentMode then
					local qualifiers = statement.qualifiers
					local participants = nil
					
					if qualifiers and qualifiers['P710'] then
						local partsList = {}
						for _, q in ipairs(qualifiers['P710']) do
							if q.snaktype == 'value' and q.datavalue.type == 'wikibase-entityid' then
								table.insert(partsList, getSmartLink(q.datavalue.value.id))
							end
						end
						if #partsList > 0 then
							participants = table.concat(partsList, ' - ')
						end
					end
					
					if participants then
						valueToAdd = participants
					end

					if qualifiers and qualifiers['P585'] then
						local dateClaim = qualifiers['P585'][1]
						if dateClaim.snaktype == 'value' then
							local timeValue = dateClaim.datavalue.value.time
							local yearStr = string.match(timeValue, "^[%+%-](%d+)")
							if yearStr then
								valueToAdd = valueToAdd .. ' (' .. yearStr .. ')'
							end
						end
					end
				end

				if valueToAdd then
					table.insert(valuesWithLinks, valueToAdd)
				end
			end
		end
		
		if #valuesWithLinks > 0 then
			local resultString = ""
			if options.collapsible and #valuesWithLinks > 3 then
				local header = valuesWithLinks[1] .. ', ' .. valuesWithLinks[2] .. '...'
				local content = table.concat(valuesWithLinks, ', ')
				resultString = mw.html.create('div')
					:addClass('mw-collapsible mw-collapsed')
					:tag('div'):wikitext(header):done()
					:tag('div'):addClass('mw-collapsible-content'):wikitext(content):done()
					:allDone()
				return tostring(resultString), true
			else
				local sep = (property == 'P17' and #valuesWithLinks > 1) and '<br>' or ", "
				return table.concat(valuesWithLinks, sep), true, #valuesWithLinks
			end
		end
	end
	return nil, false
end

local function getValueOrWikidata(args, paramName, propertyId, options)
	local value = args[paramName]
	local fromWikidata = false
	local count = 0
	if value then value = trimWhitespace(value) end
	if not value then
		if propertyId and args.qid ~= '' then
			value, fromWikidata, count = makeRequest(args.qid, propertyId, options)
		end
	end
	return value, fromWikidata, count
end

function p.main(frame)
	local args = getArgs(frame)
	local entityId = args.qid 
	if entityId == '' then entityId = nil end
	entityId = entityId or mw.wikibase.getEntityIdForCurrentPage()

	local entity = getEntity(entityId)

	frame:extensionTag('templatestyles', '', {src = 'ⴰⵍⴱⵓⴹ:ⵜⴰⴼⵍⵓⵖⵎⵉⵙⵜ ⴰⴷⵔⴰⵔ/styles.css'})

	local infobox = mw.html.create('table')
	infobox:addClass('infobox geography vcard')
	infobox:css({
		['border'] = '1px solid #a2a9b1',
		['background-color'] = '#f8f9fa',
		['color'] = 'black',
		['margin'] = '0.5em 0 0.5em 1em',
		['float'] = 'right',
		['clear'] = 'right',
		['font-size'] = '90%',
		['width'] = '20em',
	})

	local headerValue = args['ⵉⵙⵎ'] or args['name']
	if not headerValue and entityId then
		headerValue = mw.wikibase.getLabelByLang(entityId, 'zgh') or mw.wikibase.getLabel(entityId)
		if not headerValue and entity and entity.labels and entity.labels.en then
			headerValue = entity.labels.en.value
		end
	end
	headerValue = headerValue or mw.title.getCurrentTitle().text

	local headerRow = infobox:tag('tr')
	local headerCell = headerRow:tag('th')
		:attr('colspan', 2)
		:css({
			['background-color'] = '#996633',
			['color'] = '#ffffff',
			['padding'] = '0.4em',                
			['text-align'] = 'center',
			['font-weight'] = 'bold',
			['font-size'] = '125%',
			['position'] = 'relative'
		})

	local headerContainer = mw.html.create('div')
		:css({
			['padding-right'] = '50px', 
			['padding-left'] = '50px',  
		})
		:wikitext(headerValue)
	
	headerCell:node(headerContainer)

	local iconContainer = mw.html.create('div')
		:css({
			['position'] = 'absolute',
			['top'] = '1px',
			['right'] = '1px',
		})
		:wikitext('[[ⴰⴼⴰⵢⵍⵓ:Picto_infobox_map.png|95px|alt=ⵜⴰⵢⴽⵓⵏⵜ|link=]]')
		
	headerCell:node(iconContainer)

	local image = args['ⵜⴰⵡⵍⴰⴼⵜ'] or args['image']
	local caption = args['ⴰⵣⵡⵍ ⵏ ⵜⴰⵡⵍⴰⴼⵜ'] or args['caption']

	if not image and entity then
		local imgs = entity:getBestStatements('P18')
		if #imgs > 0 and imgs[1].mainsnak.datavalue then
			image = imgs[1].mainsnak.datavalue.value
		end
	end

	if image then
		local imageRow = infobox:tag('tr')
		local imageCell = imageRow:tag('td')
			:attr('colspan', 2)
			:css({
				['text-align'] = 'center',
				['padding'] = '5px',
			})
		
		imageCell:wikitext('[[ⴰⴼⴰⵢⵍⵓ:' .. image .. '|260px|frameless]]')
		
		if caption then
			imageCell:tag('div')
				:css('font-size', '90%')
				:css('margin-top', '3px')
				:wikitext(caption)
		elseif entityId then
			imageCell:tag('div')
				:css('font-size', '80%')
				:css('text-align', 'right')
				:wikitext(makeEditIcon(entityId, 'P18'))
		end
	end

	local sectionHeaderStyle = {
		['background-color'] = '#963',
		['color'] = '#ffffff',
		['text-align'] = 'center',
		['font-weight'] = 'normal',
		['padding'] = '2px',
	}

	local sections = {
		{
			title = 'ⵓⵎⵍⴰⵏ ⵉⵎⴰⵜⴰⵢⵏ',
			properties = {
				{ 'ⴰⴳⴰⵎⵓⵔ', 'ⴰⴳⴰⵎⵓⵔ', 'P376' },
				{ 'ⵜⴰⵎⵓⵔⵜ', 'ⵜⴰⵎⵓⵔⵜ', 'P17' },
				{ 'ⴰⴷⵖⴰⵔ', 'ⴰⴷⵖⴰⵔ', 'P131' },
				{ 'ⵜⴰⴳⵣⵉⵔⵜ', 'ⵜⴰⴳⵣⵉⵔⵜ', nil },
				{ 'ⴰⵎⵙⵎⵓⵏ ⵏ ⵡⴰⵎⴰⵏ', 'ⴰⵎⵙⵎⵓⵏ ⵏ ⵡⴰⵎⴰⵏ', nil },
				{ 'ⵜⴰⵎⵏⴰⴹⵜ ⵉⵜⵜⵓⵃⴹⴰⵏ', 'ⵜⴰⵎⵏⴰⴹⵜ ⵉⵜⵜⵓⵃⴹⴰⵏ', nil },
				{ 'ⴰⴳⵣⵣⵓⵎ ⵙⴳ', 'ⴰⴳⵣⵣⵓⵎ ⵙⴳ', 'P361' },
				{ 'ⵜⴰⵎⵏⴰⴹⵜ ⵜⴰⵡⵏⴹⴰⵏⵜ', 'ⵜⴰⵎⵏⴰⴹⵜ ⵜⴰⵡⵏⴹⴰⵏⵜ', 'P1425' },
				{ 'ⵉⵍⵍⴰ ⴳ ⵜⵎⵏⴰⴹⵜ ⵏ ⵉⵔⴽⴰⵣⵏ', 'ⵉⵍⵍⴰ ⴳ ⵜⵎⵏⴰⴹⵜ ⵏ ⵉⵔⴽⴰⵣⵏ', 'P706' }
			}
		},
		{
			title = 'ⵜⴰⵔⴰⴽⴰⵍⵜ',
			properties = {
				{ 'ⵉⵙⵎⵍⴰⵏ', 'ⵉⵙⵎⵍⴰⵏ','P624' },
				{ 'ⴰⴼⴰ', 'ⴰⴼⴰ', 'P610' },
				{ 'ⵜⴰⵜⵜⵓⵢⵜ', 'ⵜⴰⵜⵜⵓⵢⵜ', 'P2044' },
				{ 'ⴰⴱⵓⵊⵊ ⴰⵟⵓⴱⴱⵓⴳⵕⴰⴼⵉ', 'ⴰⴱⵓⵊⵊ ⴰⵟⵓⴱⴱⵓⴳⵕⴰⴼⵉ', 'P2660' },
				{ 'ⴰⵡⵍⵉⵡⵍ ⴰⵟⵓⴱⴱⵓⴳⵕⴰⴼⵉ', 'ⴰⵡⵍⵉⵡⵍ ⴰⵟⵓⴱⴱⵓⴳⵕⴰⴼⵉ', 'P2659' },
				{ 'ⵜⴰⵇⵉⵛⵛⵉⵜ ⵜⴰⵢⵎⵎⴰⵜ', 'ⵜⴰⵇⵉⵛⵛⵉⵜ ⵜⴰⵢⵎⵎⴰⵜ', 'P3137' },
				{ 'ⵜⵉⵖⵣⵉ', 'ⵜⵉⵖⵣⵉ', 'P2043' },
				{ 'ⵜⵓⵔⵔⵓⵜ', 'ⵜⵓⵔⵔⵓⵜ', 'P2049' },
				{ 'ⴰⵡⵓⵎ', 'ⴰⵡⵓⵎ', 'P2386' },
				{ 'ⵜⴰⵊⵓⵎⵎⴰ', 'ⵜⴰⵊⵓⵎⵎⴰ', 'P2046' },
				{ 'ⴰⴽⵙⴰⵢ', 'ⴰⴽⵙⴰⵢ', 'P2234' },
				{ 'ⵜⴰⴽⵙⴰⵔⵜ', 'ⵜⴰⴽⵙⴰⵔⵜ', 'P4184' }
			}
		},
		{
			title = 'ⵜⵓⵙⵙⵏⴰⴽⴰⵍ',
			properties = {
				{ 'ⴰⵎⵏⵥⴰⵡ', 'ⴰⵎⵏⵥⴰⵡ', 'P30' },
				{ 'ⴰⵙⵖⴰⵍ ⴰⵊⵢⵓⵎⵓⴼⵓⵍⵓⵊⵉ', 'ⴰⵙⵖⴰⵍ ⴰⵊⵢⵓⵎⵓⴼⵓⵍⵓⵊⵉ', 'P4688' },
				{ 'ⵜⴰⵙⵉⵍⵉ', 'ⵜⴰⵙⵉⵍⵉ', 'P4552' },
				{ 'ⴰⵏⴰⵡ', 'ⴰⵏⴰⵡ', 'P31' },
				{ 'ⴰⵙⵏⵉⵎⴰⵍ ⵏ ⵓⵡⵜⴰⵢ', 'ⴰⵙⵏⵉⵎⴰⵍ ⵏ ⵓⵡⵜⴰⵢ', 'P7584' },
				{ 'ⵖⵓⵔⵙ ⴰⴳⵣⵣⵓⵎ ⵏⵉⵖ ⵉⴳⵣⵣⵓⵎⵏ', 'ⵖⵓⵔⵙ ⴰⴳⵣⵣⵓⵎ ⵏⵉⵖ ⵉⴳⵣⵣⵓⵎⵏ', 'P527' },
				{ 'ⵉⵙⵓⵍⵉⵍⵉⵏ', 'ⵉⵙⵓⵍⵉⵍⵉⵏ', 'P186' },
				{ 'ⴰⵡⵜⴰⵢ ⵏ ⵓⵥⵕⵓ', 'ⴰⵡⵜⴰⵢ ⵏ ⵓⵥⵕⵓ', 'P2348' },
				{ 'ⵜⴰⵎⵙⴰⵔⵜ ⵜⴰⵏⴼⵔⴰⵔⵜ', 'ⵜⴰⵎⵙⴰⵔⵜ ⵜⴰⵏⴼⵔⴰⵔⵜ', 'P793', { collapsible = true } },
				{ 'ⴰⵙⴰⴹⴰⴼ', 'ⴰⵙⴰⴹⴰⴼ', 'P3815' }
			}
		},
		{
			title = 'ⴰⵎⵣⵔⵓⵢ ⴷ ⵜⴷⵍⵙⴰ',
			properties = {
				{ 'ⵜⴰⵡⴰⴼⵉⵜ', 'ⵜⴰⵡⴰⴼⵉⵜ', 'P575' },
				{ 'ⵉⵙⵎ ⴰⴷⵖⵔⴰⵏ', 'ⵉⵙⵎ ⴰⴷⵖⵔⴰⵏ', 'P1705' },
				{ 'ⴰⵏⴰⵣⵓⴼ', 'ⴰⵏⴰⵣⵓⴼ', 'P61' },
				{ 'ⵉⵜⵜⵓⵙⵎⵎⴰ ⵙ', 'ⵉⵜⵜⵓⵙⵎⵎⴰ ⵙ', nil },
				{ 'ⵉⵙⵎⵎⴰ ⵜ', 'ⵉⵙⵎⵎⴰ ⵜ', 'P3938' },
				{ 'ⵜⴰⵙⵍⴼⵙⵜ', 'ⵜⴰⵙⵍⴼⵙⵜ', 'P1449' },
				{ 'ⴰⵙⴼⴼⵓⵥⵔ ⵙⴳ', 'ⴰⵙⴼⴼⵓⵥⵔ ⵙⴳ', 'P1049' },
				{ 'ⴰⵛⴼⴰⵍ ⴰⵎⵣⵡⴰⵔⵓ', 'ⴰⵛⴼⴰⵍ ⴰⵎⵣⵡⴰⵔⵓ', 'P793', { limit = 1, firstAscentMode = true } },
				{ 'ⴰⴱⵔⵉⴷ', 'ⴰⴱⵔⵉⴷ', 'P2795' },
				{ 'ⵉⵎⵉⵣⵉ', 'ⵉⵎⵉⵣⵉ', 'P3335' },
				{ 'ⵜⴰⵎⴽⵔⵔⴰ ⵏ ⵓⵛⴼⴰⵍ', 'ⵜⴰⵎⴽⵔⵔⴰ ⵏ ⵓⵛⴼⴰⵍ', 'nil' },
				{ 'ⴷⴰ ⵉⵜⵜⴰⴳⴳⵯⴰ ⵅⴼ', 'ⴷⴰ ⵉⵜⵜⴰⴳⴳⵯⴰ ⵅⴼ', 'P3173' },
				{ 'ⵉⵏⵣⵔⴰⴼ', 'ⵉⵏⵣⵔⴰⴼ', nil },
				{ 'ⴰⴷⴷⴰⴷ ⵏ ⵜⴰⵢⵙⵉ', 'ⴰⴷⴷⴰⴷ ⵏ ⵜⴰⵢⵙⵉ', nil },
				{ 'ⵢⵓⵏⵉⵙⴽⵓ', 'ⵢⵓⵏⵉⵙⴽⵓ', nil }
			}
		}
	}

	for _, section in ipairs(sections) do
		local sectionContent = mw.html.create('')
		local hasData = false

		for _, prop in ipairs(section.properties) do
			local label, param, pid, options = unpack(prop)
			local value, fromWikidata, count = getValueOrWikidata(args, param, pid, options)

			if value then
				hasData = true
				
				if pid == 'P17' and count and count > 1 then
					label = 'ⵜⵉⵎⵓⵔⴰ'
				end

				if param == 'ⵜⴰⵜⵜⵓⵢⵜ' or param == 'ⴰⴱⵓⵊⵊ' or param == 'ⴰⵡⵍⵉⵡⵍ ⴰⵟⵓⴱⴱⵓⴳⵕⴰⴼⵉ' then
					value = value .. ' ⵎⵉⵜⵔ'
				end

				if param == 'ⵜⴰⵊⵓⵎⵎⴰ' then
					value = value .. ' ⴽⵎ²'
				end

				if param == 'ⵜⴰⴽⵙⴰⵔⵜ' then
					value = value .. ' %'
				end

				if param == 'ⵜⵉⵖⵣⵉ' or param == 'ⵜⵓⵔⵔⵓⵜ' or param == 'ⴰⵡⵓⵎ' then
					value = value .. ' ⴽⵎ' 
				end
				
				local row = sectionContent:tag('tr')
				row:tag('th')
					:wikitext(label)
					:css({
						['text-align'] = 'left',
						['width'] = '40%',
						['padding-right'] = '10px',
						['font-weight'] = 'normal',
						['background-color'] = '#F3F3F3',
						['vertical-align'] = 'top'
					})
				
				local cell = row:tag('td'):css({['padding'] = '2px', ['width'] = '60%'})
				
				if fromWikidata and pid and entityId then
					cell:wikitext(value .. makeEditIcon(entityId, pid))
				else
					cell:wikitext(value)
				end
			end
		end

		if hasData then
			infobox:tag('tr'):tag('th')
				:attr('colspan', 2)
				:css(sectionHeaderStyle)
				:wikitext(section.title)
			infobox:node(sectionContent)
		end
	end

	if entityId then
		local lat, lon = getCoordinates(entity)
		if lat and lon then
			local mapFeatures = {}

			table.insert(mapFeatures, {
				type = "ExternalData",
				service = "geoshape",
				ids = entityId,
				properties = {
					["stroke-width"] = 2,
					stroke = "#FF0000",
					["fill-opacity"] = 0.2
				}
			})

			table.insert(mapFeatures, {
				type = "Feature",
				geometry = {
					type = "Point",
					coordinates = { lon, lat }
				},
				properties = {
					["marker-symbol"] = "mountain",
					["marker-color"] = "#996633",
					["marker-size"] = "medium"
				}
			})

			local mapFrame = frame:extensionTag{
				name = 'mapframe',
				content = mw.text.jsonEncode(mapFeatures),
				args = {
					width = "280",
					height = "250",
					zoom = "4",
					align = "center",
					frameless = "frameless"
				}
			}
			
			infobox:tag('tr'):tag('th')
				:attr('colspan', 2)
				:css(sectionHeaderStyle)
				:wikitext('ⴰⴷⵖⴰⵔ ⴰⵔⴰⴽⴰⵍ') 
			
			infobox:tag('tr'):tag('td')
				:attr('colspan', 2)
				:css('text-align', 'center')
				:wikitext(mapFrame)
		end
	end

	local separatorRow = infobox:tag('tr')
	local separatorCell = separatorRow:tag('td')
		:attr('colspan', 2)
		:css({
			['padding'] = '0',
			['border-top'] = '2px dashed #963',
		})
	separatorCell:tag('div'):css({['height'] = '1px', ['background-color'] = 'transparent'})

	local currentTitle = mw.title.getCurrentTitle()
	local editSourceUrl = currentTitle:fullUrl({action='edit', section='0'})
	local editVisualUrl = currentTitle:fullUrl({veaction='edit'})
	local templateDocUrl = mw.title.new('ⴰⵍⴱⵓⴹ:ⵜⴰⴼⵍⵓⵖⵎⵉⵙⵜ ⴰⴷⵔⴰⵔ'):fullUrl()

	local footerRow = infobox:tag('tr')
	local footerCell = footerRow:tag('td')
		:attr('colspan', 2)
		:css({
			['padding'] = '0.2em',
			['font-size'] = '85%',
			['text-align'] = 'left',
			['background-color'] = '#f8f9fa',
		})

	local footerContainer = mw.html.create('div')
		:css({
			['display'] = 'flex',
			['justify-content'] = 'space-between',
			['align-items'] = 'center',
		})

	local editLinksSpan = footerContainer:tag('span'):addClass('plainlinks')
	if entityId and entityId ~= '' then
		local wikidataUrl = 'https://www.wikidata.org/wiki/Special:EntityPage/' .. entityId
		editLinksSpan:wikitext('[' .. editSourceUrl .. ' <span style="color:#002bb8;">ⵙⵏⴼⵍ ⴰⵙⴰⴳⵎ</span>] - [' ..
			editVisualUrl .. ' <span style="color:#002bb8;">ⵙⵏⴼⵍ</span>] - [' ..
			wikidataUrl .. ' <span style="color:#002bb8;">ⵡⵉⴽⵉⴷⴰⵜⴰ</span>]')
	else
		editLinksSpan:wikitext('[' .. editSourceUrl .. ' <span style="color:#002bb8;">ⵙⵏⴼⵍ ⴰⵙⴰⴳⵎ</span>] - [' ..
			editVisualUrl .. ' <span style="color:#002bb8;">ⵙⵏⴼⵍ</span>]')
	end

	footerContainer:tag('span')
		:css({['float'] = 'right', ['margin-left'] = '5px'})
		:wikitext('[[ⴰⴼⴰⵢⵍⵓ:Info Simple.svg|15px|ⵥⵕ ⵓⴳⴳⴰⵔ ⵅⴼ ⵡⴰⵍⴱⵓⴹ ⴰⴷ |link=' .. templateDocUrl .. ']]')

	footerCell:node(footerContainer)

	return tostring(infobox)
end

return p