Kontent qismiga oʻtish

Modul:GeoInfobox

Vikipediya, ochiq ensiklopediya

Bu modul uchun Modul:GeoInfobox/doc nomli hujjat sahifasini yaratishingiz mumkin

local geo = {};

function geo.renderId( frame )
	local idArray = {
		['p884'] = '[[Davlat suv reestri|DSR]]',
		['p1566'] = '[[GeoNames]]',
		['p1886'] = '[[Global Volcanism Program|GVP]]',
		['p4708'] = '{{comment|VOGRIPA|Volcano Global Risk Identification and Analysis Project}}'
	}
	local text = ''
	
	for i, j in pairs( idArray ) do
		local tmp = frame:expandTemplate{ title = 'Wikidata', args = {i} }
		if tmp and tmp ~= '' then
			text = text .. '<li>' .. frame:preprocess(j) .. ':&nbsp;' .. tmp .. '</li>'
		end
	end
	
	if text ~= '' then
		return '<tr><td class="hlist" colspan="2"><hr><ul>' .. text .. '</ul></td></tr>'
	end
	
	end
	
function geo.renderLine( frame )
	local args = frame:getParent().args;
	frame.args = frame:getParent().args;
	local cat = ''
	local prefix = {
		['~'] = 'около',
		['>'] = 'более',
		['<'] = 'менее'
	}
	local before = ''
	local ref = ''

	local text = args[1] or '';
	local label = args[2] or ''; -- одиночная метка
	local label2 = args[3] or ''; -- множественная метка
	local wikify = args[4] or '';
	local after = args[5] or '';
	
	if text == '-' then 
		return ''; 
	end
	
    if text ~= '' then
    	if label2 ~= '' then
    		if mw.ustring.match( text, "[^/]+/[^/]+") then
    			label = label2
    		end
    		if wikify == '1' then 
				frame.args['o'] = '[[%]]'
				frame.args['nodis'] = '1'
			end
	    	local split = require('Module:String/split').split
	    	frame.args[1] = text
	    	text = split(frame)
	    else
    	    if after ~= ''  then
    	    	if mw.ustring.match( text, '\127' ) and not mw.ustring.match( text, 'templatestyles' ) then
	    			text, ref = mw.ustring.match( text, '[^\127]+' ), mw.ustring.match( text, '\127.+' )
	    		end	
	    		if not mw.ustring.match( text, '[-—×]' ) then 
			    	local tmp_text = mw.ustring.gsub( text, '[≈−, ]', {['≈'] = '~', ['−'] = '-', [','] = '.', [' '] = ''} )
			    	if  mw.ustring.match( text, '^[≈~<>]%s*%d' ) and prefix[tmp_text:sub(1, 1)] then
			    		before = prefix[tmp_text:sub(1, 1)] .. '&nbsp;'
			    		text = mw.ustring.gsub(text, '^[≈~<>]%s*', '')
			    	elseif mw.ustring.match( text, '^[бдмо][еко][лно]?[ел]?[ео]?' ) then -- до|около|более|менее
			    		before = mw.ustring.match( text, '^[бдмо][еко][лно]?[ел]?[ео]?' ) .. '&nbsp;'
			    		text = mw.ustring.gsub(text, '^[бдмо][еко][лно]?[ел]?[ео]?%s*', '')
			    	end
			    	tmp_text = mw.ustring.gsub(tmp_text, '^[≈~<>бдмо][еко]?[лно]?[ел]?[ео]?%s*', '')
	    	    	if tonumber(tmp_text) then
	    	    	   	local lang = mw.language.getContentLanguage()
	    	    	   	text = lang:formatNum( tonumber( tmp_text ) )
	    	    	elseif mw.title.getCurrentTitle():inNamespace(0) then
	    	    		cat = '[[Категория:Карточка на Геокаре: исправить: числовые параметры]]'
	    	    	end
	    	    end
	    	end
	    	if wikify == '1' then
	    		text = '[[' .. text .. '|' .. mw.ustring.gsub(text, '%s?%(.*%)$', '' ) .. ']]'
			end
			text = before .. text .. ref .. '&nbsp;' .. after 
		end
	else
		if args[ 'd' ] and args[ 'd' ] ~= '' then
			text = frame:expandTemplate{ title = 'Wikidata', args = {
				args[ 'd' ],
				text,
				separator = args['r'] or ''
			} };
		
		end
	end	 
	
	if text ~= '' then 
		return '<tr><th>' .. label .. '</th><td>' .. text .. '</td></tr>' .. cat;
	end
    
	return '';
end

function geo.findImage( frame )
	local page = mw.title.getCurrentTitle()
	local txt, args = page:getContent(), frame.args
	if args and args[1] and args[1] ~= '' then
		if txt:match(':' .. args[1]) and mw.title.getCurrentTitle():inNamespace(0) then return '[[Turkum:Geokar kartochkalari:tasvirni tuzatish]]' end
	end
end

return geo