Module:Taglink
Jump to navigation
Jump to search
This documentation is transcluded from Module:Taglink/doc. (Edit | history)
Note to editors: Please don't categorize this template by editing it directly. Instead, place the category in its documentation page, in its "includeonly" section.
Note to editors: Please don't categorize this template by editing it directly. Instead, place the category in its documentation page, in its "includeonly" section.
Returns the page name of a documentation page. If the page isn’t available in the preferred language but is available in another one, a page that exists is returned using Mediawiki’s language fallbacks if possible.
Usage
{{#invoke:taglink | keypage | key= | lang=}}
{{#invoke:taglink | valuepage | key= | value= | lang=}}
where:
key
is the tag key.value
is the tag value.lang
is the language code of the preferred language.
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 '<span class="error">' .. "Data item not found. Check your spelling." .. '</span>'
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