Module:Coordinates: திருத்தங்களுக்கு இடையிலான வேறுபாடு

உள்ளடக்கம் நீக்கப்பட்டது உள்ளடக்கம் சேர்க்கப்பட்டது
changed back to getEntityObject after finding my mistake. very sorry for breaking it!
Fulfill edit request, remove superfluous function call
வரிசை 2:
This module is intended to replace the functionality of {{Coord}} and related
templates. It provides several methods, including
 
{{#Invoke:Coordinates | coord }} : General function formatting and displaying
coordinate values.
 
{{#Invoke:Coordinates | dec2dms }} : Simple function for converting decimal
degree values to DMS format.
 
{{#Invoke:Coordinates | dms2dec }} : Simple function for converting DMS format
to decimal degree format.
 
{{#Invoke:Coordinates | link }} : Export the link used to reach the tools
 
]]
 
local math_mod = require( "Module:Math" );
local globalFrame = nil
local coordinates = {};
 
local current_page = mw.title.getCurrentTitle()
local page_name = mw.uri.encode( current_page.prefixedText, 'WIKI' );
local coord_link = '//tools.wmflabs.org/geohack/geohack.php?pagename=' .. page_name .. '&params='
 
--[[ Helper function, replacement for {{coord/display/title}} ]]
local function displaytitle (s, notes)
local l = "[[புவியியல்Geographic ஆள்கூற்றுcoordinate முறைsystem|ஆள்கூறுகள்Coordinates]]: " .. s
local co = '<span id="coordinates">' .. l .. notes .. '</span>';
return '<span style="font-size: small;">' .. co .. '</span>';
end
 
--[[ Helper function, Replacement for {{coord/display/inline}} ]]
local function displayinline (s, notes)
return s .. notes
end
 
--[[ Helper function, used in detecting DMS formatting ]]
local function dmsTest (first, second)
local concatenated = first:upper() .. second:upper();
if concatenated == "NE" or concatenated == "NW" or concatenated == "SE" or concatenated == "SW" or
concatenated == "EN" or concatenated == "WN" or concatenated == "ES" or concatenated == "WS" then
வரிசை 46:
return false;
end
 
--[[ Helper function, handle optional args. ]]
local function optionalArg(arg, suplement)
வரிசை 54:
return ""
end
 
--[[
Formats any error messages generated for display
வரிசை 61:
local result = ""
for i,v in ipairs(errors) do
local errorHTML = '<strong class="error">ஆள்கூறுகள்Coordinates: ' .. v[2] .. '</strong>'
result = result .. errorHTML .. "<br />"
end
return result
end
 
--[[
Determine the required CSS class to display coordinates
 
Usually geo-nondefault is hidden by CSS, unless a user has overridden this for himself
default is the mode as specificied by the user when calling the {{coord}} template
வரிசை 78:
default = "dec"
end
if default == mode then
return "geo-default"
வரிசை 85:
end
end
 
--[[
specPrinter
 
Output formatter. Takes the structure generated by either parseDec
or parseDMS and formats it for inclusion on Wikipedia.
வரிசை 101:
uriComponents = uriComponents .. "&title=" .. mw.uri.encode(coordinateSpec["name"])
end
local geodmshtml = '<span class="geo-dms" title="Maps, aerial photos, and other data for this location">'
.. '<span class="latitude">' .. coordinateSpec["dms-lat"] .. '</span> '
.. '<span class="longitude">' ..coordinateSpec["dms-long"] .. '</span>'
.. '</span>'
 
local lat = tonumber( coordinateSpec["dec-lat"] ) or 0
local geodeclat
வரிசை 115:
geodeclat = (coordinateSpec["dec-lat"] or 0) .. "°N"
end
 
local long = tonumber( coordinateSpec["dec-long"] ) or 0
local geodeclong
வரிசை 124:
geodeclong = (coordinateSpec["dec-long"] or 0) .. "°E"
end
local geodechtml = '<span class="geo-dec" title="Maps, aerial photos, and other data for this location">'
.. geodeclat .. ' '
.. geodeclong
.. '</span>'
 
local geonumhtml = '<span class="geo">'
.. coordinateSpec["dec-lat"] .. '; '
.. coordinateSpec["dec-long"]
.. '</span>'
 
local inner = '<span class="' .. displayDefault(coordinateSpec["default"], "dms" ) .. '">' .. geodmshtml .. '</span>'
.. '<span class="geo-multi-punct">&#xfeff; / &#xfeff;</span>'
.. '<span class="' .. displayDefault(coordinateSpec["default"], "dec" ) .. '">';
 
if args["name"] == "" or args["name"] == nil then
inner = inner .. geodechtml
வரிசை 148:
.. args["name"] .. '</span>)</span></span></span>'
end
 
return '<span class="plainlinks nourlexpansion">' ..
'[' .. coord_link .. uriComponents .. ' ' .. inner .. ']' .. '</span>'
end
 
--[[ Helper function, convert decimal to degrees ]]
local function convert_dec2dms_d(coordinate)
வரிசை 158:
return d .. ""
end
 
--[[ Helper function, convert decimal to degrees and minutes ]]
local function convert_dec2dms_dm(coordinate)
வரிசை 165:
coordinate = math.floor( (coordinate - m) / 60 );
local d = coordinate % 360 .."°"
return d .. string.format( "%02d′", m )
end
 
--[[ Helper function, convert decimal to degrees, minutes, and seconds ]]
local function convert_dec2dms_dms(coordinate)
வரிசை 177:
coordinate = math.floor( (coordinate - m) / 60 );
local d = coordinate % 360 .."°"
 
return d .. string.format( "%02d′", m ) .. string.format( "%02d″", s )
end
 
--[[
Helper function, convert decimal latitude or longitude to
வரிசை 193:
postfix = secondPostfix
end
 
precision = precision:lower();
if precision == "dms" then
வரிசை 203:
end
end
 
--[[
Convert DMS format into a N or E decimal coordinate
வரிசை 211:
local minutes = tonumber(minutes_str) or 0
local seconds = tonumber(seconds_str) or 0
local factor = 1
direction = direction:gsub('^ *(.-) *$', '%1');
வரிசை 217:
factor = -1
end
local precision = 0
if seconds_str ~= nil and seconds_str ~= '' then
வரிசை 226:
precision = math.max( math_mod._precision(degrees_str), 0 );
end
local decimal = factor * (degrees+(minutes+seconds/60)/60)
return string.format( "%." .. precision .. "f", decimal ) -- not tonumber since this whole thing is string based.
end
 
--[[
Checks input values to for out of range errors.
வரிசை 242:
long_m = tonumber( long_m ) or 0;
long_s = tonumber( long_s ) or 0;
 
if strong then
if lat_d < 0 then
வரிசை 253:
#coordinates is inconsistent about whether this is an error. If globe: is
specified, it won't error on this condition, but otherwise it will.
For not simply disable this check.
if long_d > 180 then
table.insert(errors, {source, "longitude degrees > 180 with hemisphere flag"})
வரிசை 261:
]]
end
if lat_d > 90 then
table.insert(errors, {source, "latitude degrees > 90"})
வரிசை 298:
table.insert(errors, {source, "longitude seconds < 0"})
end
return errors;
end
 
--[[
parseDec
 
Transforms decimal format latitude and longitude into the a
structure to be used in displaying coordinates
வரிசை 311:
local coordinateSpec = {}
local errors = {}
if long == "" or long == nil then
return nil, {{"parseDec", "Missing longitude"}}
வரிசை 317:
return nil, {{"parseDec", "Longitude could not be parsed as a number: " .. long}}
end
errors = validate( lat, nil, nil, long, nil, nil, 'parseDec', false );
coordinateSpec["dec-lat"] = lat;
coordinateSpec["dec-long"] = long;
 
local mode = coordinates.determineMode( lat, long );
coordinateSpec["dms-lat"] = convert_dec2dms( lat, "N", "S", mode) -- {{coord/dec2dms|{{{1}}}|N|S|{{coord/prec dec|{{{1}}}|{{{2}}}}}}}
coordinateSpec["dms-long"] = convert_dec2dms( long, "E", "W", mode) -- {{coord/dec2dms|{{{2}}}|E|W|{{coord/prec dec|{{{1}}}|{{{2}}}}}}}
if format ~= "" then
coordinateSpec.default = format
வரிசை 331:
coordinateSpec.default = "dec"
end
 
return coordinateSpec, errors
end
 
--[[
parseDMS
 
Transforms degrees, minutes, seconds format latitude and longitude
into the a structure to be used in displaying coordinates
வரிசை 344:
local coordinateSpec = {}
local errors = {}
lat_f = lat_f:upper();
long_f = long_f:upper();
-- Check if specified backward
if lat_f == 'E' or lat_f == 'W' then
வரிசை 364:
long_f = t_f;
end
errors = validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, 'parseDMS', true );
if long_d == nil or long_d == "" then
வரிசை 371:
return nil, {{"parseDMS", "Longitude could not be parsed as a number:" .. long_d }}
end
if lat_m == nil and lat_s == nil and long_m == nil and long_s == nil and #errors == 0 then
if math_mod._precision( lat_d ) > 0 or math_mod._precision( long_d ) > 0 then
வரிசை 380:
long_d = '-' .. long_d;
end
return parseDec( lat_d, long_d, format );
end
end
coordinateSpec["dms-lat"] = lat_d.."°"..optionalArg(lat_m,"′") .. optionalArg(lat_s,"″") .. lat_f
coordinateSpec["dms-long"] = long_d.."°"..optionalArg(long_m,"′") .. optionalArg(long_s,"″") .. long_f
coordinateSpec["dec-lat"] = convert_dms2dec(lat_f, lat_d, lat_m, lat_s) -- {{coord/dms2dec|{{{4}}}|{{{1}}}|0{{{2}}}|0{{{3}}}}}
coordinateSpec["dec-long"] = convert_dms2dec(long_f, long_d, long_m, long_s) -- {{coord/dms2dec|{{{8}}}|{{{5}}}|0{{{6}}}|0{{{7}}}}}
 
if format ~= "" then
coordinateSpec.default = format
வரிசை 395:
coordinateSpec.default = "dms"
end
 
return coordinateSpec, errors
end
 
--[[
Check the input arguments for coord to determine the kind of data being provided
வரிசை 406:
local result, errors;
local primary = false;
if args[1] == "" then
-- no lat logic
வரிசை 460:
end
result.name = args["name"]
local extra_param = {'dim', 'globe', 'scale', 'region', 'source', 'type'}
for _, v in ipairs( extra_param ) do
வரிசை 467:
end
end
if #errors == 0 then
return specPrinter( args, result )
வரிசை 474:
end
end
 
--[[
link
 
Simple function to export the coordinates link for other uses.
 
Usage:
{{ Invoke:Coordinates | link }}
]]
function coordinates.link(frame)
return coord_link;
end
 
--[[
dec2dms
 
Wrapper to allow templates to call dec2dms directly.
 
Usage:
{{ Invoke:Coordinates | dec2dms | decimal_coordinate | positive_suffix |
negative_suffix | precision }}
decimal_coordinate is converted to DMS format. If positive, the positive_suffix
is appended (typical N or E), if negative, the negative suffix is appended. The
வரிசை 508:
local secondPostfix = frame.args[3]
local precision = frame.args[4]
 
return convert_dec2dms(coordinate, firstPostfix, secondPostfix, precision)
end
 
--[[
Helper function to determine whether to use D, DM, or DMS
வரிசை 526:
end
end
 
--[[
dms2dec
 
Wrapper to allow templates to call dms2dec directly.
 
Usage:
{{ Invoke:Coordinates | dms2dec | direction_flag | degrees |
minutes | seconds }}
Converts DMS values specified as degrees, minutes, seconds too decimal format.
direction_flag is one of N, S, E, W, and determines whether the output is
வரிசை 546:
local minutes = frame.args[3]
local seconds = frame.args[4]
 
return convert_dms2dec(direction, degrees, minutes, seconds)
end
 
--[[
coord
 
Main entry point for Lua function to replace {{coord}}
 
Usage:
{{ Invoke:Coordinates | coord }}
வரிசை 560:
{{ Invoke:Coordinates | coord | lat | lat_flag | long | long_flag }}
...
Refer to {{coord}} documentation page for many additional parameters and
configuration options.
Note: This function provides the visual display elements of {{coord}}. In
order to load coordinates into the database, the {{#coordinates:}} parser
வரிசை 580:
end
elseif pFrame.args[1] == nil and mw.wikibase.getEntityObject() ~= nil then
local entity = mw.wikibase.entity.create( mw.wikibase.getEntityObject() )
if entity and entity.claims and entity.claims.P625 and
entity.claims.P625[1].mainsnak.snaktype == "value" then
வரிசை 588:
end
end
for i=1,10 do
if args[i] == nil then
வரிசை 597:
end
args['format'] = args['format'] or '';
local contents = formatTest(args)
local Notes = args.notes or ""
வரிசை 604:
Display = 'inline';
end
local text = ''
if string.find( Display, 'inline' ) ~= nil
வரிசை 624:
if mw.wikibase and current_page.namespace == 0 then
local wikidata_cat
local entity = mw.wikibase.getEntityObject()
if entity and entity.claims and entity.claims.P625 then
local snaktype = entity.claims.P625[1].mainsnak.snaktype
if snaktype == 'value' then
wikidata_cat = '[[பகுப்புCategory:Coordinates on Wikidata]]' -- coordinates exist both here and on Wikidata, and can be compared
elseif snaktype == 'somevalue' then
wikidata_cat = '[[பகுப்புCategory:Coordinates on Wikidata set to unknown value]]'
elseif snaktype == 'novalue' then
wikidata_cat = '[[பகுப்புCategory:Coordinates on Wikidata set to no value]]'
end
else
wikidata_cat = '[[பகுப்புCategory:Coordinates not on Wikidata]]' -- we have to either import the coordinates to Wikidata or remove them here
end
if wikidata_cat then
வரிசை 642:
end
end
 
return text
end
 
return coordinates
"https://ta.wikipedia.org/wiki/Module:Coordinates" இலிருந்து மீள்விக்கப்பட்டது