Module:CuisineTaglink

From OpenStreetMap Wiki
Jump to navigation Jump to search
[Edit] [Purge] Documentation


This is a copy of Module:Taglink, with one change to allow tags without data items to fall back to a regular red link. Usage is otherwise the same as Taglink.

Discussion on Module talk:Taglink. This module should only be used by Key:cuisine and its templates. If you have a need for a similar change, please comment on the Taglink talk page.

The change is from:

if not dataitem then
	return '' .. "Data item not found. Check your spelling." .. ''
end

To:

if not dataitem then
	return page -- red link to English page title
end

See also

local p = {}

function p.docbylanguage(page, lang) 
	if not mw.wikibase then
		return '<span class="error">' .. "The OSM wiki is experiencing technical difficulties. Infoboxes will be restored soon." .. '</span>'
	end

	local dataitem = mw.wikibase.getEntityIdForTitle(page)
	if not dataitem then
		return page -- red link to English page title
	end

	local pages = mw.wikibase.getBestStatements(dataitem, 'P31') -- documentation wiki pages
	if #pages == 0 then
		return page -- red link to English page title
	end

	local fallbacks = mw.language.getFallbacksFor(lang)
	table.insert(fallbacks, 1, lang)

	-- find relevant page
	for _, language in ipairs(fallbacks) do
		for _, translation in ipairs(pages) do
			if translation.mainsnak.datavalue.value.language == language then
				return translation.mainsnak.datavalue.value.text
			end
		end
	end
	
	-- find any page
	return pages[1].mainsnak.datavalue.value.text
end

function p.keypage(frame) 
	return p.docbylanguage('Key:' .. frame.args['key'],
		frame.args['lang'])
end

function p.valuepage(frame) 
	return p.docbylanguage('Tag:' .. frame.args['key'] .. '=' .. frame.args['value'],
		frame.args['lang'])
end

return p