Модуль:GeoInfobox

З Вікіпедыі, свабоднай энцыклапедыі

Дакументацыю да гэтага модуля можна стварыць у Модуль:GeoInfobox/Дакументацыя

local p = {};

function p.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 strip = require('Module:String/strip').strip
	    	frame.args[1] = text
	    	text = strip(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 p.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 '[[Катэгорыя:Картка на Геакары: выправіць выяву]]' end
	end
end

return p;