বিষয়বস্তুতে চলুন

মডিউল:নির্দেশক

উইকিভ্রমণ থেকে
(মডিউল:Marker থেকে পুনর্নির্দেশিত)

এই মডিউলের জন্য মডিউল:নির্দেশক/নথি-এ নথিপত্র তৈরি করা হয়ে থাকতে পারে

--[[
	Source script:	https://it.wikivoyage.org/wiki/Modulo:Marker
	Maintainer:		Andyrom75

	Lazy loads:
	require('Module:WikidataIB').getSiteLink
]]
local coord2Dec = require('Module:Coordinates').toDec
local type2color = require('Module:ধরন থেকে রঙ').convertImpl

local function _isDefined(s)
	return s ~= '' and s
end

local paramAliases = {
	name     = {'name', 'নাম'},
	type     = {'type', 'ধরন'},
	wikidata = {'wikidata', 'উইকিউপাত্ত'},
	lat      = {'lat', 'অক্ষাংশ'},
	long     = {'long', 'দ্রাঘিমাংশ'},
	zoom     = {'zoom', 'জুম'},
	url      = {'url', 'ইউআরএল'},
	image    = {'image', 'চিত্র'},
	group    = {'group', 'গ্রুপ', 'দল'},
	counter  = {'counter', 'কাউন্টার'},
}

local function normalizeArgs(args)
	local norm = {}
	for eng, aliases in pairs(paramAliases) do
		for _, alias in ipairs(aliases) do
			if args[alias] and args[alias] ~= '' then
				norm[eng] = args[alias]
				break
			end
		end
	end
	for k, v in pairs(args) do
		if not norm[k] then norm[k] = v end
	end
	return norm
end

local function _makeMarkerSymbol( args, frame )
	local image4map = _isDefined(args.image) and ('[[File:' .. args.image .. '|300px]]') or ''
	local tagArgs = {
		zoom = tonumber( args.zoom ),
		latitude = tonumber( args.lat ),
		longitude = tonumber( args.long ),
		show = args.show,
		group = args.group,
		description = (_isDefined(args.description) or '') .. image4map
	}
	if _isDefined( args.text ) then
		tagArgs.text = args.text
		if not args.useIcon then
			tagArgs.class = 'no-icon'
		end
	end

	local geoJson = {
		type = 'Feature',
		geometry = {
			type = 'Point',
			coordinates = { tagArgs.longitude, tagArgs.latitude }
		},
		properties = {
			title = args.name,
			description = tagArgs.description,
			['marker-symbol'] = args.symbol,
			['marker-color'] = args.color,
			['marker-size'] = 'medium',
		}
	}

	return frame:extensionTag( 'maplink', mw.text.jsonEncode( geoJson ), tagArgs )
end

local function _Marker(frame)
	local args = normalizeArgs(frame.args)
	local imageErrMsg = ''
	local nome = args.name or ''
	local tag = ((args.islisting ~= 'yes') and mw.html.create( 'span' ):addClass( 'vcard' )) or mw.html.create()
	local anchor = ''

	if _isDefined( args.wikidata ) then
		if not _isDefined(args.lat) or not _isDefined(args.long) then
			local coords = mw.wikibase.getBestStatements( args.wikidata, 'P625')
			if coords[1] then
				args.lat = coords[1].mainsnak.datavalue.value.latitude
				args.long = coords[1].mainsnak.datavalue.value.longitude
			end
		end
		if not _isDefined(args.image) then
			local image = mw.wikibase.getBestStatements( args.wikidata, 'P18')
			args.image = image[1] and image[1].mainsnak.datavalue.value
		end
	end

	if args.lat ~= 'NA' and args.long ~= 'NA' then
		if _isDefined(args.lat) and _isDefined(args.long) then
			args.lat = coord2Dec(args.lat or 0, '', 6).dec
			args.long = coord2Dec(args.long or 0, '', 6).dec
			args.type = _isDefined(args.type) or 'listing'
			args.zoom = _isDefined(args.zoom) or '17'
			args.group = _isDefined(args.group) or args.type
			args.symbol = '-number-' .. ( args.counter or args.type or 'listing' )
			args.color = type2color( args.type )
			args.show = args.show or 'mask,around,buy,city,do,drink,eat,go,listing,other,see,sleep,vicinity,view'
	
			local mapTagOutput = _makeMarkerSymbol( args, frame )

			tag:tag( 'span' )
				:addClass( 'noprint listing-coordinates' )
				:css('display','none')
				:tag( 'span' )
					:addClass( 'geo' )
					:tag( 'abbr' )
						:addClass( 'latitude' )
						:wikitext( args.lat )
					:done()
					:tag( 'abbr' )
						:addClass( 'longitude' )
						:wikitext( args.long )
			:allDone()
			:tag( 'span' )
				:attr( 'title', 'এই উপদানটি মানচিত্রে দেখুন' )
				:wikitext( mapTagOutput )
		else
			local listingTypes = {see=true, eat=true, buy=true, drink=true, sleep=true, ['do']=true, go=true, city=true, vicinity=true}
			
			if mw.title.getCurrentTitle().namespace == 0 and args.type and listingTypes[args.type] then
				local type = args.type
				anchor = anchor .. "[[Category:" .. type .. " listing with no coordinates]]"
			end
		end
	end

	if nome ~= '' then
		local anchor2 = ''
		anchor2 = '<span id="' .. mw.uri.anchorEncode( nome ) .. '" class="fn org listing-name" style="font-weight:bold;">' .. nome .. '</span>'
		if _isDefined(args.url) then
			anchor2 = string.match(nome, '%[%[') and ('[[Category:Listing without plain text name]]' .. anchor2)
				or ('[' .. args.url .. ' ' .. anchor2 .. ']')
		end
		anchor = anchor .. anchor2
	end
	if mw.title.getCurrentTitle().namespace == 0 then
		anchor = anchor .. '[[Category:Has map markers]]'
	end

	if _isDefined( args.image ) then
		local image = 'Media:' .. args.image
		if mw.title.new( image ) and mw.title.new( image ).exists == true then
			args.description = '[[' .. image .. '|100x100px|' .. nome .. ']]'
		else
			imageErrMsg = mw.html.create( 'span' )
				:addClass('imageinfo debuginfo')
				:css('display','none')
				:wikitext( 'NOT EXISTING LISTING IMAGE' )
		end
	end

	if (args.islisting ~= 'yes') and _isDefined( args.wikidata ) then
		local getSiteLink = require('Module:WikidataIB').getSiteLink
		if _isDefined( getSiteLink{args={wiki='bnwikivoyage', qid=args.wikidata}} ) then
			anchor = anchor .. (string.match(nome, '%[%[') and '' or '[[Category:Marker with Wikivoyage article but no wikilink]]')
		else
			local wpLink = _isDefined( getSiteLink{args={wiki='bnwiki', qid=args.wikidata}} )
			anchor = anchor .. (wpLink and '<span class="listing-sister-icons">&#32;[[File:Antu wikipedia.svg|15px|class=listing-sister|link=w:' .. wpLink .. '|<span>' .. wpLink .. '</span> on Wikipedia]]</span>' or '')
		end
	end

	return tostring(tag:node(imageErrMsg):wikitext(' ' .. anchor))
end

local p = {}

function p.MarkerTemplate(frame)
	return _Marker(frame:getParent())
end

function p.MarkerInvoke(frame)
	return _Marker(frame)
end

function p.MarkerModule(frame)
	local Cframe = mw.getCurrentFrame()
	Cframe.args = frame.args
	return _Marker(Cframe)
end

return p