Module:Element
--[[ Please remember to use the talk page before changing this template! When the first Lua version was written this was used on more than 5000 pages, now it is probably some 3000 more. A change will cause a re-rendering of all pages. Keep that in mind! ]]--
local p = {} local translations = mw.loadData('Module:Element/translation')
-- start for Template:Area function p.area(frame) -- extracting arguments local areaId = frame.args[1] local areaName = frame.args[2] local toolbarSetting = frame.args["tools"] local langcodeInput = frame.args["lang"]
-- checking for correct parameters assert(tonumber(areaId), "Given way id parameter is not a number") if areaName == "" then areaName = nil elseif areaName ~= nil then areaName = mw.text.trim(areaName) end areaId = mw.text.trim(areaId) if langcodeInput ~= nil then langcodeInput = string.lower(langcodeInput) end
return elementText("area", areaId, areaName, toolbarSetting, langcodeInput) end
-- start for Template:Node function p.node(frame) -- extracting arguments local nodeId = frame.args[1] local nodeName = frame.args[2] local toolbarSetting = frame.args["tools"] local langcodeInput = frame.args["lang"]
-- checking for correct parameters assert(tonumber(nodeId), "Given node id parameter is not a number") if nodeName == "" then nodeName = nil elseif nodeName ~= nil then nodeName = mw.text.trim(nodeName) end nodeId = mw.text.trim(nodeId) if langcodeInput ~= nil then langcodeInput = string.lower(langcodeInput) end
return elementText("node", nodeId, nodeName, toolbarSetting, langcodeInput) end
-- start for Template:Relation function p.relation(frame) -- extracting arguments local relationId = frame.args[1] local relationName = frame.args[2] local toolbarSetting = frame.args["tools"] local langcodeInput = frame.args["lang"]
-- checking for correct parameters assert(tonumber(relationId), "Given relation id parameter is not a number") if relationName == "" then relationName = nil elseif relationName ~= nil then relationName = mw.text.trim(relationName) end relationId = mw.text.trim(relationId) if langcodeInput ~= nil then langcodeInput = string.lower(langcodeInput) end
return elementText("relation", relationId, relationName, toolbarSetting, langcodeInput) end
-- start for Template:Way function p.way(frame) -- extracting arguments local wayId = frame.args[1] local wayName = frame.args[2] local toolbarSetting = frame.args["tools"] local langcodeInput = frame.args["lang"]
-- checking for correct parameters assert(tonumber(wayId), "Given way id parameter is not a number") if wayName == "" then wayName = nil elseif wayName ~= nil then wayName = mw.text.trim(wayName) end wayId = mw.text.trim(wayId) if langcodeInput ~= nil then langcodeInput = string.lower(langcodeInput) end
return elementText("way", wayId, wayName, toolbarSetting, langcodeInput) end
-- Main function compiling the wiki text function elementText(elementType, elementId, elementName, toolbarSetting, langcodeInput) local output = {} local elementDescription = elementType if elementType == "area" then elementType = "way" end -- non-existing area type
output[1] = ''
if elementName == nil then output[2] = elementId else output[2] = elementName end
output[3] = ''
if(toolbarSetting == "mini") then output[4] = '[//osm.org/' .. elementType ..'/' .. elementId if elementName == nil then output[5] = '' .. elementId else output[5] = '' .. elementName end output[6] = ']'
elseif (toolbarSetting == "short") then output[4] = '[//osm.org/' .. elementType .. '/' .. elementId if elementName == nil then output[5] = '' .. elementId else output[5] = '' .. elementName end output[6] = '] (' .. '[//osm.org/edit?editor=id&' .. elementType .. '=' .. elementId .. 'i] ' output[7] = '[http://localhost:8111/import?url=https://api.osm.org/api/0.6/' .. elementType .. '/' .. elementId .. '/full J] ' output[8] = '[//osm.org/edit?editor=potlatch2&zoom=11&' .. elementType .. '=' .. elementId .. ' P2]' output[9] = ')'
else output[4] = '' .. elementDescription .. ' ' output[7] = '[//osm.org/' .. elementType .. '/' .. elementId .. ' ' .. elementId else output[8] = ' ' .. elementId .. '">' .. elementName end output[9] = ']'
if toolbarSetting == "all" then local pageLanguage = langcode(langcodeInput) local translationComplete = true local transHistory = translations.translateHistory[pageLanguage] if not transHistory then translationComplete = false transHistory = translations.translateHistory['en'] end
output[10] = ' ([//osm.org/edit?editor=id&' .. elementType .. '=' .. elementId .. ' iD] ' output[11] = '[http://localhost:8111/import?url=https://api.osm.org/api/0.6/' .. elementType .. '/' .. elementId .. '/full JOSM] ' output[12] = '[//osm.org/edit?editor=potlatch2&zoom=11&' .. elementType .. '=' .. elementId .. ' Potlatch2] ' output[13] = '[http://osm.virtuelle-loipe.de/history/?type=' .. elementType .. '&ref=' .. elementId .. ' ' .. transHistory .. ']' if elementType == 'relation' then -- relation analysis local transAnalyse = translations.translateAnalyse[pageLanguage] if not transAnalyse then translationComplete = false transAnalyse = translations.translateAnalyse['en'] end output[14] = ' [http://ra.osmsurround.org/analyze.jsp?relationId=' .. elementId .. ' ' .. transAnalyse ..']' end table.insert(output, ')') if not translationComplete then local fullEnglishName = languageName(pageLanguage) if string.len(fullEnglishName) ~= 0 then table.insert(output, '[[Category:Pages unavailable in ' .. fullEnglishName .. ']] Help translate this to ' .. fullEnglishName .. '') end end
elseif toolbarSetting == "josm" then output[10] = ' ([http://localhost:8111/import?url=' .. 'https://api.openstreetmap.org/api/0.6/' .. elementType output[11] = '/' .. elementId .. '/full JOSM])' end end
table.insert(output, "") -- ends class plainlinks return tostring(table.concat(output)) end
-- this uses the external module 'OsmPageTitleParser': function langcode(langcodeInput) --[[ Priorities: 1 user input 2 dedicated language namespace 3 language title prefix 4 'en' as default ]]--
if langcodeInput then return string.lower(langcodeInput) end
local langModule = require('Module:OsmPageTitleParser') return tostring((langModule.parseTitle(mw.title.getCurrentTitle()).language):getCode()) end
function languageName(code) local constantsModule = mw.loadData('Module:OSM Constants') -- should be already loaded (needed by OsmPageTitleParser as well) local customLangName = constantsModule.customLangCodes[code]
if customLangName ~= nil then return customLangName else return mw.language.fetchLanguageName(code, 'en') end end
return p