Kontent qismiga oʻtish

Modul:WikidataCoords: Versiyalar orasidagi farq

Vikipediya, ochiq ensiklopediya
Kontent oʻchirildi Kontent qoʻshildi
k upd.
Tahrir izohi yoʻq
Teg: Qaytarildi
Qator 24: Qator 24:


function p.execTplWithCoords( frame )
function p.execTplWithCoords( frame )
local moduleWikidata = require( 'Modul:Wikidata' );
local moduleWikidata = require( 'Module:Wikidata2' );


local pFrame = frame:getParent();
local pFrame = frame:getParent();
Qator 35: Qator 35:
local coord = args['coord'] or nil;
local coord = args['coord'] or nil;
if coord == '' then coord = nil end
if coord == '' then coord = nil end

local outType = args[2]
if outType then
outType = mw.text.trim( outType );
end

args[1] = args['01'];
args['01'] = nil;
args[2] = args['02'];
args['02'] = nil;


if not args.lat_deg or args.lat_deg == '' and not coord then
if not args.lat_deg or args.lat_deg == '' and not coord then
Qator 68: Qator 78:
args[name] = mw.text.trim( args[name], '°\'" ' );
args[name] = mw.text.trim( args[name], '°\'" ' );
end
end

if (args.lat_deg == '' and args.lon_deg == '') and not coord then
if (args.lat_deg == '' and args.lon_deg == '') and not coord then
return '';
return '';
end
end
if outType and not coord then
if outType == '12345678' or outType == '23456789' or outType == '345678910' then
local n = 0;
if outType == '23456789' then
n = 1;
elseif outType == '345678910' then
n = 2;
end


if args[2] then
local outType = mw.text.trim( args[2] );
if outType == '12345678' then
for i, name in ipairs( argsMap ) do
for i, name in ipairs( argsMap ) do
args[i] = args[name];
args[i + n] = args[name];
args[name] = nil;
args[name] = nil;
end
end
end
if outType == 'coord' then
args['coord'] = args.lat_deg .. '/' .. args.lat_min .. '/' .. args.lat_sec .. '/' .. args.lat_dir .. '/' .. args.lon_deg .. '/' .. args.lon_min .. '/' .. args.lon_sec .. '/' .. args.lon_dir
end
end
end
end

2024-yil 18-sentyabr, 12:42 dagi koʻrinishi

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

local p = {};

local defaultArgs = {
	['lat_deg'] = '',
	['lat_min'] = '0',
	['lat_sec'] = '0',
	['lat_dir'] = 'N',
	['lon_deg'] = '',
	['lon_min'] = '0',
	['lon_sec'] = '0',
	['lon_dir'] = 'E'
};

local argsMap = {
	'lat_deg',
	'lat_min',
	'lat_sec',
	'lat_dir',
	'lon_deg',
	'lon_min',
	'lon_sec',
	'lon_dir'
};

function p.execTplWithCoords( frame )
	local moduleWikidata = require( 'Module:Wikidata2' );

	local pFrame = frame:getParent();
	local args = mw.clone( pFrame.args );
	setmetatable( args, nil );

	local template = mw.text.trim( args[1] );
	args[1] = nil;
	
	local coord = args['coord'] or nil;
	if coord == ''  then coord = nil end

	local outType = args[2]
	if outType then
		outType = mw.text.trim( outType );
	end

	args[1] = args['01'];
	args['01'] = nil;
	args[2] = args['02'];
	args['02'] = nil;

	if not args.lat_deg or args.lat_deg == '' and not coord then
		frame.args = {
			['property'] = 'p625',
			['plain'] = true
		};
		local coords = moduleWikidata.formatProperty( frame );
		coords = string.gsub( coords, ''', '\'' );
		coords = string.gsub( coords, '"', '"' );

		coords = mw.text.split( coords, ', ', true );
		local lat = coords[1];
		local lon = coords[2];
		if lat and lat ~= '' then
			args.lat_deg = string.match( lat, '%d+°' );
			args.lat_min = string.match( lat, '%d+\'' );
			args.lat_sec = string.match( lat, '[0-9%.]+"' );
			args.lat_dir = string.match( lat, '[NS]' );
		end
		if lon and lon ~= '' then
			args.lon_deg = string.match( lon, '%d+°' );
			args.lon_min = string.match( lon, '%d+\'' );
			args.lon_sec = string.match( lon, '[0-9%.]+"' );
			args.lon_dir = string.match( lon, '[EW]' );
		end
	end

	for name, value in pairs( defaultArgs ) do
	    if not args[name] or args[name] == '' then
	    	args[name] = value;
	    end
    	args[name] = mw.text.trim( args[name], \'" ' );
	end

	if (args.lat_deg == '' and args.lon_deg == '') and not coord then
		return '';
	end
	
	if outType and not coord then
		if outType == '12345678' or outType == '23456789' or outType == '345678910' then
			local n = 0;
			if outType == '23456789' then
				n = 1;
			elseif outType == '345678910' then
				n = 2;
			end

			for i, name in ipairs( argsMap ) do
				args[i + n] = args[name];
				args[name] = nil;
			end
		end
		if outType == 'coord' then
			args['coord'] = args.lat_deg .. '/' .. args.lat_min .. '/' .. args.lat_sec .. '/' .. args.lat_dir .. '/' ..	args.lon_deg .. '/' ..	args.lon_min .. '/' .. args.lon_sec .. '/' .. args.lon_dir
		end
	end

	return frame:expandTemplate{ title = template, args = args };
end

return p;