Difference between revisions of "Module:Sandbox/Yurik/OSM NoWD"

From Northumberland Climbing
Jump to navigation Jump to search
module>Baris6161TURK
m (Add span tag.)
 
m (1 revision imported)
 
(No difference)

Latest revision as of 05:51, 31 July 2020

Documentation for this module may be created at Module:Sandbox/Yurik/OSM NoWD/doc

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 = '<span class="plainlinks">[http://wikidata.org/wiki/' .. wikidata .. ' ' .. wikidata .. ']</span>'
        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| ' ..
			'| <span class="plainlinks">[http://www.openstreetmap.org/' .. idtype .. '/' .. osmid .. ' ' .. id .. ']&nbsp;([http://www.openstreetmap.org/edit?' .. idtype .. '=' .. osmid .. ' edit])</span>\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' ..
			'| <span class="plainlinks">[http://www.openstreetmap.org/relation/' .. relid .. ' ' .. relid .. ']&nbsp;([http://www.openstreetmap.org/edit?relation=' .. relid .. ' edit])</span>\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 = "&nbsp;&nbsp;&nbsp;'''<span class='plainlinks'>[https://wikidata.org/wiki/" .. wikidata .. " " .. wikidata .. "]</span>'''"
        elseif wikipedia then
        	wikidata = "''[[:" .. wikipedia .. "]]''"
        else
        	wikidata = ''
    	end
        local line = '|-\n| ' ..
			'| ' .. wikidata .. '\n' ..
			'| <span class="plainlinks">[http://www.openstreetmap.org/relation/' .. relid .. ' ' .. relid .. ']&nbsp;([http://www.openstreetmap.org/edit?relation=' .. relid .. ' edit])</span>\n' ..
			'| ' .. (admin_level or '') .. '\n' ..
			'| ' .. namestr .. '\n'
		table.insert(results, line)
    end

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

return p