Module:Sandbox/Yurik/OSM NoWD

local p = {}

function p.list( frame ) local dataPage = frame.args[1] local results = {} local count = 0

table.insert(results, '!ID||Wikidata||Wikipedia\n') for key, row in pairs(mw.ext.data.get(dataPage).data) do       local id, wikidata, wikipedia = unpack(row) if wikipedia and wikipedia ~= '' then wikipedia =  .. wikipedia ..  end if wikidata and wikidata ~= '' then wikidata = ' [http://wikidata.org/wiki/' .. wikidata .. ' ' .. wikidata .. '] '       end local idtype = id:sub(1,1) local osmid = id:sub(2) if idtype == 'r' then idtype = 'relation' elseif idtype == 'w' then idtype = 'way' else idtype = 'node' end local line = '|-\n| ' .. '| [http://www.openstreetmap.org/' .. idtype .. '/' .. osmid .. ' ' .. id .. '] (.. idtype .. '=' .. osmid .. ' edit) \n' .. '| ' .. (wikidata or '') .. '\n' .. '| ' .. (wikipedia or '') .. '\n' table.insert(results, line) count = count + 1 end

return '{| class="wikitable sortable"\n' .. table.concat(results, '\n') .. '|}\n\n' .. count .. ' rows. Original data is at commons:Data:' .. dataPage .. '' end

function p.show( frame ) local dataPage = 'Sandbox/Yurik/OSM objects with missing Wikidata ID.tab' local results = {}

table.insert(results, '!Name||LVL||ID||Wikipedia||Boundary||Type||Designation\n') for key, row in pairs(mw.ext.data.get(dataPage).data) do       local relid, admin_level, latitude, longitude, name, wikipedia, boundary, type_, designation = unpack(row) if wikipedia then wikipedia =  .. wikipedia ..  end local line = '|-\n| ' .. '| ' .. (name or '') .. '\n' .. '| ' .. (admin_level or '') .. '\n' .. '| [http://www.openstreetmap.org/relation/' .. relid .. ' ' .. relid .. '] (.. relid .. ' edit) \n' .. '| ' .. (wikipedia or '') .. '\n' .. '| ' .. (boundary or '') .. '\n' .. '| ' .. (type_ or '') .. '\n' .. '| ' .. (designation or '') .. '\n' table.insert(results, line) end

return '{| class="wikitable sortable"\n' .. table.concat(results, '\n') .. '|}' end

function p.dup( frame ) local dataPage = 'Sandbox/Yurik/OSM objects with duplicate Wikidata ID.tab' local results = {} local lastId = nil

table.insert(results, '! Wikidata ID, title || OSM relation || LVL || Name in OSM\n') for key, row in pairs(mw.ext.data.get(dataPage).data) do       local admin_level, relid, wikidata, name, wikipedia, boundary, type_, altname, designation = unpack(row) local isNewRow = lastId ~= wikidata lastId = wikidata local namestr = (name and (name .. '/') or '') .. (boundary and (boundary .. '_') or '') .. (type_ or '') .. (altname and ('/' .. altname) or '') .. (designation and ('/' .. designation) or '') if isNewRow then table.insert(results, '|-\n| colspan=4 style="background-color: black;" |\n') wikidata = "  ''' [https://wikidata.org/wiki/" .. wikidata .. " " .. wikidata .. "] '''"       elseif wikipedia then wikidata = "" .. wikipedia .. "" else wikidata = '' end local line = '|-\n| ' .. '| ' .. wikidata .. '\n' .. '| [http://www.openstreetmap.org/relation/' .. relid .. ' ' .. relid .. '] (.. relid .. ' edit) \n' .. '| ' .. (admin_level or '') .. '\n' .. '| ' .. namestr .. '\n' table.insert(results, line) end

return '{| class="wikitable"\n' .. table.concat(results, '\n') .. '|}' end

return p