Module:Listing

local linkPhone = require('Module:LinkPhone') local isLatin  = require('Module:IsLatin')

local conf = { -- parameter name, function for getting Wikidata info, function for fallback {'counter', nil, function(parentArgs) return parentArgs['counter'] or parentArgs['type'] or 'listing' end}, {'type', nil, function(parentArgs) return parentArgs['type'] or 'listing' end}, {'name', function(frame, item) return item:getLabel end}, {'wikipedia', function(frame, item) return item:getLabel end}, {'alt', function(frame, item) return item:formatPropertyValues('P1705').value end}, {'url', function(frame, item) return item:formatPropertyValues('P856').value end}, {'email', function(frame, item) return item:formatPropertyValues('P968').value end}, {'address', function(frame, item) return item:formatPropertyValues('P969').value end}, {'lat', function(frame, item) if #item:getBestStatements( 'P625' ) == 0 then return nil end local statement = item:getBestStatements( 'P625' )[1] if statement.mainsnak.datavalue.value.globe ~= 'http://www.wikidata.org/entity/Q2' then return nil end return statement.mainsnak.datavalue.value.latitude end}, {'long', function(frame, item) if #item:getBestStatements( 'P625' ) == 0 then return nil end local statement = item:getBestStatements( 'P625' )[1] if statement.mainsnak.datavalue.value.globe ~= 'http://www.wikidata.org/entity/Q2' then return nil end return statement.mainsnak.datavalue.value.longitude end}, {'directions', function(frame, item) local statements = item:getBestStatements( 'P2795' ) if #statements == 0 then return nil end local res = {} for _, statement in pairs(statements) do			if statement.mainsnak.datavalue.value.language == 'en' then table.insert(res, statement.mainsnak.datavalue.value.text) end end return table.concat(res, ', ') end}, {'phone', function(frame, item) return item:formatPropertyValues('P1329').value end}, {'tollfree'}, {'fax', function(frame, item) return item:formatPropertyValues('P2900').value end}, {'image', function(frame, item) if #item:getBestStatements( 'P18' ) == 0 then return nil end return item:getBestStatements( 'P18' )[1].mainsnak.datavalue.value end}, {'hours'}, {'price'}, {'checkin'}, {'checkout'}, {'lastedit'}, {'content', nil, function(parentArgs) return parentArgs[1] or nil end} }

local p = {}

function p.listing( frame) local parentArgs = frame:getParent.args local item = nil if parentArgs['wikidata'] and string.match(parentArgs['wikidata'], '^Q%d+$') ~= nil then item = mw.wikibase.getEntity( parentArgs['wikidata'] ) end local useWikidata = (item ~= nil and item.claims ~= nil)

local params = {} for _,c in pairs(conf) do 		if parentArgs[c[1]] ~= nil and parentArgs[c[1]] ~= '' then params[c[1]] = parentArgs[c[1]] -- take value from template else if useWikidata and c[2] ~= nil then params[c[1]] = c[2](frame, item) -- take value from Wikidata end end if params[c[1]] == nil and c[3] ~= nil then params[c[1]] = c[3]( parentArgs ) -- take value from fallback function end if params[c[1]] == '' then params[c[1]] = nil end end local elements = {} table.insert(elements, frame:expandTemplate{ title = 'marker', args = {counter = params['counter'], type = params['type'], name = params['name'], lat = params['lat'], long = params['long'], image = params['image'], url = params['url'], islisting = 'yes'} }) if params['alt'] ~= nil then if isLatin.IsLatin({args = {params['alt']}}) == 'yes' then table.insert(elements, '&#32;(\'\' '.. params['alt'] ..' \'\')') else table.insert(elements, '&#32;( '.. params['alt'] ..' )') end end if params['address'] ~= nil then if params['name'] ~= nil or params['url'] ~= nil then table.insert(elements, ',&#160;') end table.insert(elements, ' '.. params['address'] ..'  ') end if params['directions'] ~= nil then table.insert(elements, '&#32;(\'\' '..params['directions']..' \'\')') end local elements2 = {} if params['phone'] ~= nil then table.insert(elements2, ' ☎ '.. linkPhone.LinkPhone({args = {params['phone']}}) ..' ') end if params['tollfree'] ~= nil then table.insert(elements2, 'toll-free: '.. linkPhone.LinkPhone({args = {params['tollfree'], tollfree=true}}) .. ' ') end if params['fax'] ~= nil then table.insert(elements2, ' fax : '.. linkPhone.LinkPhone({args = {params['fax'], fax=true}}) .. '  ') end if params['mail'] ~= nil then table.insert(elements2, 'e-mail: [mailto:'..params['email']..' '..params['email']..'] ') end if #elements2 > 0 then table.insert(elements, ',&#160;' .. table.concat(elements2, ',&#160;' )) end if params['hours'] ~= nil then table.insert(elements, '&#32; '.. params['hours']..' .') end if params['checkin'] ~= nil then table.insert(elements, '&#32; Check-in: ' .. params['checkin'] .. ' ') if params['checkout'] ~= nil then table.insert(elements, ', check-out: '.. params['checkout'] ..' ') end table.insert(elements, ' ') else if params['checkout'] ~= nil then table.insert(elements, '&#32; Check-out: '.. params['checkout'].. ' .') end end if params['content'] ~= nil then table.insert(elements, ' '..params['content']..' ') end if params['price'] ~= nil then table.insert(elements, '&#32; '.. params['price']..' .') end -- TODO: Metadata, hidden unicode, email tracking table.insert(elements, ' ') if params['lastedit'] ~= nil then table.insert(elements, ' (' ) end	table.insert(elements, ' ')	if params['lastedit'] ~= nil then		table.insert(elements, ' updated '.. mw.getContentLanguage:formatDate(' M Y', params['lastedit']) .. ' ')	else		table.insert(elements, ' ');	end	if useWikidata then		table.insert(elements, ' &#32; ')		end	if params['wikipedia'] ~= nil then	   table.insert(elements, ' &#32;&#32; ')	end	table.insert(elements, ' ');	if params['lastedit'] ~= nil then table.insert(elements, ')' ) end table.insert(elements, ' ') -- from Module:HiddenUnicode for k,txt in pairs(params) do -- Note the quote ("") below is not empty and actually contains a hidden unicode character. if mw.ustring.match(txt,"‎") ~= nil then table.insert(elements, '') break end end -- from Module:EmailTracking if params['email'] ~= nil and mw.title.getCurrentTitle.namespace == 0 and mw.ustring.match(params['email'],'@.*@') ~= nil then table.insert(elements, ' MULTIPLE-EMAIL ') end return ' ' .. table.concat(elements) .. ' ' end

return p