https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ASandbox%2FFavonide Module:Sandbox/Favonide - Revision history 2025-06-01T04:45:14Z Revision history for this page on the wiki MediaWiki 1.45.0-wmf.3 https://en.wikipedia.org/w/index.php?title=Module:Sandbox/Favonide&diff=1282774576&oldid=prev Favonide: + 2025-03-28T14:50:27Z <p>+</p> <a href="//en.wikipedia.org/w/index.php?title=Module:Sandbox/Favonide&amp;diff=1282774576&amp;oldid=1282773996">Show changes</a> Favonide https://en.wikipedia.org/w/index.php?title=Module:Sandbox/Favonide&diff=1282773996&oldid=prev Favonide: ←Created page with 'require('strict') local math_mod = require("Module:Math") local coordinates = {}; local isSandbox = mw.getCurrentFrame():getTitle():find('sandbox', 1, true); local current_page = mw.title.getCurrentTitle() local page_name = mw.uri.encode( current_page.prefixedText, 'WIKI' ); local coord_link = 'https://geohack.toolforge.org/geohack.php?pagename=' .. page_name .. '&params=' local function displaytitle(coords) return mw.getCurrentFrame():extensionTag{ n...' 2025-03-28T14:45:07Z <p><a href="/wiki/Wikipedia:AES" class="mw-redirect" title="Wikipedia:AES">←</a>Created page with &#039;require(&#039;strict&#039;) local math_mod = require(&quot;Module:Math&quot;) local coordinates = {}; local isSandbox = mw.getCurrentFrame():getTitle():find(&#039;sandbox&#039;, 1, true); local current_page = mw.title.getCurrentTitle() local page_name = mw.uri.encode( current_page.prefixedText, &#039;WIKI&#039; ); local coord_link = &#039;https://geohack.toolforge.org/geohack.php?pagename=&#039; .. page_name .. &#039;&amp;params=&#039; local function displaytitle(coords) return mw.getCurrentFrame():extensionTag{ n...&#039;</p> <p><b>New page</b></p><div>require(&#039;strict&#039;)<br /> <br /> local math_mod = require(&quot;Module:Math&quot;)<br /> local coordinates = {};<br /> local isSandbox = mw.getCurrentFrame():getTitle():find(&#039;sandbox&#039;, 1, true);<br /> <br /> local current_page = mw.title.getCurrentTitle()<br /> local page_name = mw.uri.encode( current_page.prefixedText, &#039;WIKI&#039; );<br /> local coord_link = &#039;https://geohack.toolforge.org/geohack.php?pagename=&#039; .. page_name .. &#039;&amp;params=&#039;<br /> <br /> local function displaytitle(coords)<br /> return mw.getCurrentFrame():extensionTag{<br /> name = &#039;indicator&#039;,<br /> args = { name = &#039;coordinates&#039; },<br /> content = &#039;&lt;span id=&quot;coordinates&quot;&gt;[[Geographic coordinate system|Coordinates]]: &#039; .. coords .. &#039;&lt;/span&gt;&#039;<br /> }<br /> end<br /> <br /> local function dmsTest(first, second)<br /> if type(first) ~= &#039;string&#039; or type(second) ~= &#039;string&#039; then<br /> return nil<br /> end<br /> local s = (first .. second):upper()<br /> return s:find(&#039;^[NS][EW]$&#039;) or s:find(&#039;^[EW][NS]$&#039;)<br /> end<br /> <br /> <br /> local function makeInvokeFunc(funcName)<br /> return function (frame)<br /> local args = require(&#039;Module:Arguments&#039;).getArgs(frame, {<br /> wrappers = &#039;Template:Coord&#039;<br /> })<br /> return coordinates[funcName](args, frame)<br /> end<br /> end<br /> <br /> local function optionalArg(arg, supplement)<br /> return arg and arg .. supplement or &#039;&#039;<br /> end<br /> <br /> local function errorPrinter(errors)<br /> local result = &quot;&quot;<br /> for i,v in ipairs(errors) do<br /> result = result .. &#039;&lt;strong class=&quot;error&quot;&gt;Coordinates: &#039; .. v[2] .. &#039;&lt;/strong&gt;&lt;br /&gt;&#039;<br /> end<br /> return result<br /> end<br /> <br /> local function displayDefault(default, mode)<br /> if default == &quot;&quot; then<br /> default = &quot;dec&quot;<br /> end<br /> <br /> if default == mode then<br /> return &quot;geo-default&quot;<br /> else<br /> return &quot;geo-nondefault&quot;<br /> end<br /> end<br /> <br /> local function specPrinter(args, coordinateSpec)<br /> local uriComponents = coordinateSpec[&quot;param&quot;]<br /> if uriComponents == &quot;&quot; then<br /> return &quot;ERROR param was empty&quot;<br /> end<br /> if args[&quot;name&quot;] then<br /> uriComponents = uriComponents .. &quot;&amp;title=&quot; .. mw.uri.encode(coordinateSpec[&quot;name&quot;])<br /> end<br /> <br /> local geodmshtml = &#039;&lt;span class=&quot;geo-dms&quot; title=&quot;Maps, aerial photos, and other data for this location&quot;&gt;&#039;<br /> .. &#039;&lt;span class=&quot;latitude&quot;&gt;&#039; .. coordinateSpec[&quot;dms-lat&quot;] .. &#039;&lt;/span&gt; &#039;<br /> .. &#039;&lt;span class=&quot;longitude&quot;&gt;&#039; ..coordinateSpec[&quot;dms-long&quot;] .. &#039;&lt;/span&gt;&#039;<br /> .. &#039;&lt;/span&gt;&#039;<br /> <br /> local lat = tonumber( coordinateSpec[&quot;dec-lat&quot;] ) or 0<br /> local geodeclat<br /> if lat &lt; 0 then<br /> -- FIXME this breaks the pre-existing precision<br /> geodeclat = tostring(coordinateSpec[&quot;dec-lat&quot;]):sub(2) .. &quot;°S&quot;<br /> else<br /> geodeclat = (coordinateSpec[&quot;dec-lat&quot;] or 0) .. &quot;°N&quot;<br /> end<br /> <br /> local long = tonumber( coordinateSpec[&quot;dec-long&quot;] ) or 0<br /> local geodeclong<br /> if long &lt; 0 then<br /> -- FIXME does not handle unicode minus<br /> geodeclong = tostring(coordinateSpec[&quot;dec-long&quot;]):sub(2) .. &quot;°W&quot;<br /> else<br /> geodeclong = (coordinateSpec[&quot;dec-long&quot;] or 0) .. &quot;°E&quot;<br /> end<br /> <br /> local geodechtml = &#039;&lt;span class=&quot;geo-dec&quot; title=&quot;Maps, aerial photos, and other data for this location&quot;&gt;&#039;<br /> .. geodeclat .. &#039; &#039;<br /> .. geodeclong<br /> .. &#039;&lt;/span&gt;&#039;<br /> <br /> local geonumhtml = &#039;&lt;span class=&quot;geo&quot;&gt;&#039;<br /> .. coordinateSpec[&quot;dec-lat&quot;] .. &#039;; &#039;<br /> .. coordinateSpec[&quot;dec-long&quot;]<br /> .. &#039;&lt;/span&gt;&#039;<br /> <br /> local inner = &#039;&lt;span class=&quot;&#039; .. displayDefault(coordinateSpec[&quot;default&quot;], &quot;dms&quot; ) .. &#039;&quot;&gt;&#039; .. geodmshtml .. &#039;&lt;/span&gt;&#039;<br /> .. &#039;&lt;span class=&quot;geo-multi-punct&quot;&gt;&amp;#xfeff; / &amp;#xfeff;&lt;/span&gt;&#039;<br /> .. &#039;&lt;span class=&quot;&#039; .. displayDefault(coordinateSpec[&quot;default&quot;], &quot;dec&quot; ) .. &#039;&quot;&gt;&#039;;<br /> <br /> if not args[&quot;name&quot;] then<br /> inner = inner .. geodechtml<br /> .. &#039;&lt;span style=&quot;display:none&quot;&gt;&amp;#xfeff; / &#039; .. geonumhtml .. &#039;&lt;/span&gt;&lt;/span&gt;&#039;<br /> else<br /> inner = inner .. &#039;&lt;span class=&quot;vcard&quot;&gt;&#039; .. geodechtml<br /> .. &#039;&lt;span style=&quot;display:none&quot;&gt;&amp;#xfeff; / &#039; .. geonumhtml .. &#039;&lt;/span&gt;&#039;<br /> .. &#039;&lt;span style=&quot;display:none&quot;&gt;&amp;#xfeff; (&lt;span class=&quot;fn org&quot;&gt;&#039;<br /> .. args[&quot;name&quot;] .. &#039;&lt;/span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&#039;<br /> end<br /> <br /> local stylesheetLink = &#039;Module:Coordinates&#039; .. ( isSandbox and &#039;/sandbox&#039; or &#039;&#039; ) .. &#039;/styles.css&#039;<br /> return mw.getCurrentFrame():extensionTag{<br /> name = &#039;templatestyles&#039;, args = { src = stylesheetLink }<br /> } .. &#039;&lt;span class=&quot;plainlinks nourlexpansion&quot;&gt;[&#039; .. coord_link .. uriComponents ..<br /> &#039; &#039; .. inner .. &#039;]&lt;/span&gt;&#039; .. &#039;[[Category:Pages using gadget WikiMiniAtlas]]&#039;<br /> end<br /> <br /> local function convert_dec2dms_d(coordinate)<br /> local d = math_mod._round( coordinate, 0 ) .. &quot;°&quot;<br /> return d .. &quot;&quot;<br /> end<br /> <br /> local function convert_dec2dms_dm(coordinate)<br /> coordinate = math_mod._round( coordinate * 60, 0 );<br /> local m = coordinate % 60;<br /> coordinate = math.floor( (coordinate - m) / 60 );<br /> local d = coordinate % 360 ..&quot;°&quot;<br /> <br /> return d .. string.format( &quot;%02d′&quot;, m )<br /> end<br /> <br /> local function convert_dec2dms_dms(coordinate)<br /> coordinate = math_mod._round( coordinate * 60 * 60, 0 );<br /> local s = coordinate % 60<br /> coordinate = math.floor( (coordinate - s) / 60 );<br /> local m = coordinate % 60<br /> coordinate = math.floor( (coordinate - m) / 60 );<br /> local d = coordinate % 360 ..&quot;°&quot;<br /> <br /> return d .. string.format( &quot;%02d′&quot;, m ) .. string.format( &quot;%02d″&quot;, s )<br /> end<br /> <br /> local function convert_dec2dms(coordinate, firstPostfix, secondPostfix, precision)<br /> local coord = tonumber(coordinate)<br /> local postfix<br /> if coord &gt;= 0 then<br /> postfix = firstPostfix<br /> else<br /> postfix = secondPostfix<br /> end<br /> <br /> precision = precision:lower();<br /> if precision == &quot;dms&quot; then<br /> return convert_dec2dms_dms( math.abs( coord ) ) .. postfix;<br /> elseif precision == &quot;dm&quot; then<br /> return convert_dec2dms_dm( math.abs( coord ) ) .. postfix;<br /> elseif precision == &quot;d&quot; then<br /> return convert_dec2dms_d( math.abs( coord ) ) .. postfix;<br /> end<br /> end<br /> <br /> local function convert_dms2dec(direction, degrees_str, minutes_str, seconds_str)<br /> local degrees = tonumber(degrees_str)<br /> local minutes = tonumber(minutes_str) or 0<br /> local seconds = tonumber(seconds_str) or 0<br /> <br /> local factor = 1<br /> if direction == &quot;S&quot; or direction == &quot;W&quot; then<br /> factor = -1<br /> end<br /> <br /> local precision = 0<br /> if seconds_str then<br /> precision = 5 + math.max( math_mod._precision(seconds_str), 0 );<br /> elseif minutes_str and minutes_str ~= &#039;&#039; then<br /> precision = 3 + math.max( math_mod._precision(minutes_str), 0 );<br /> else<br /> precision = math.max( math_mod._precision(degrees_str), 0 );<br /> end<br /> <br /> local decimal = factor * (degrees+(minutes+seconds/60)/60)<br /> return string.format( &quot;%.&quot; .. precision .. &quot;f&quot;, decimal ) -- not tonumber since this whole thing is string based.<br /> end<br /> <br /> local function validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, source, strong )<br /> local errors = {};<br /> lat_d = tonumber( lat_d ) or 0;<br /> lat_m = tonumber( lat_m ) or 0;<br /> lat_s = tonumber( lat_s ) or 0;<br /> long_d = tonumber( long_d ) or 0;<br /> long_m = tonumber( long_m ) or 0;<br /> long_s = tonumber( long_s ) or 0;<br /> <br /> if strong then<br /> if lat_d &lt; 0 then<br /> table.insert(errors, {source, &quot;latitude degrees &lt; 0 with hemisphere flag&quot;})<br /> end<br /> if long_d &lt; 0 then<br /> table.insert(errors, {source, &quot;longitude degrees &lt; 0 with hemisphere flag&quot;})<br /> end<br /> end<br /> <br /> if lat_d &gt; 90 then<br /> table.insert(errors, {source, &quot;latitude degrees &gt; 90&quot;})<br /> end<br /> if lat_d &lt; -90 then<br /> table.insert(errors, {source, &quot;latitude degrees &lt; -90&quot;})<br /> end<br /> if lat_m &gt;= 60 then<br /> table.insert(errors, {source, &quot;latitude minutes &gt;= 60&quot;})<br /> end<br /> if lat_m &lt; 0 then<br /> table.insert(errors, {source, &quot;latitude minutes &lt; 0&quot;})<br /> end<br /> if lat_s &gt;= 60 then<br /> table.insert(errors, {source, &quot;latitude seconds &gt;= 60&quot;})<br /> end<br /> if lat_s &lt; 0 then<br /> table.insert(errors, {source, &quot;latitude seconds &lt; 0&quot;})<br /> end<br /> if long_d &gt;= 360 then<br /> table.insert(errors, {source, &quot;longitude degrees &gt;= 360&quot;})<br /> end<br /> if long_d &lt;= -360 then<br /> table.insert(errors, {source, &quot;longitude degrees &lt;= -360&quot;})<br /> end<br /> if long_m &gt;= 60 then<br /> table.insert(errors, {source, &quot;longitude minutes &gt;= 60&quot;})<br /> end<br /> if long_m &lt; 0 then<br /> table.insert(errors, {source, &quot;longitude minutes &lt; 0&quot;})<br /> end<br /> if long_s &gt;= 60 then<br /> table.insert(errors, {source, &quot;longitude seconds &gt;= 60&quot;})<br /> end<br /> if long_s &lt; 0 then<br /> table.insert(errors, {source, &quot;longitude seconds &lt; 0&quot;})<br /> end<br /> <br /> return errors;<br /> end<br /> <br /> local function parseDec( lat, long, format )<br /> local coordinateSpec = {}<br /> local errors = {}<br /> <br /> if not long then<br /> return nil, {{&quot;parseDec&quot;, &quot;Missing longitude&quot;}}<br /> elseif not tonumber(long) then<br /> return nil, {{&quot;parseDec&quot;, &quot;Longitude could not be parsed as a number: &quot; .. long}}<br /> end<br /> <br /> errors = validate( lat, nil, nil, long, nil, nil, &#039;parseDec&#039;, false );<br /> coordinateSpec[&quot;dec-lat&quot;] = lat;<br /> coordinateSpec[&quot;dec-long&quot;] = long;<br /> <br /> local mode = coordinates.determineMode( lat, long );<br /> coordinateSpec[&quot;dms-lat&quot;] = convert_dec2dms( lat, &quot;N&quot;, &quot;S&quot;, mode)<br /> coordinateSpec[&quot;dms-long&quot;] = convert_dec2dms( long, &quot;E&quot;, &quot;W&quot;, mode)<br /> <br /> if format then<br /> coordinateSpec.default = format<br /> else<br /> coordinateSpec.default = &quot;dec&quot;<br /> end<br /> <br /> return coordinateSpec, errors<br /> end<br /> <br /> local function parseDMS( lat_d, lat_m, lat_s, lat_f, long_d, long_m, long_s, long_f, format )<br /> local coordinateSpec, errors, backward = {}, {}<br /> <br /> lat_f = lat_f:upper();<br /> long_f = long_f:upper();<br /> <br /> if lat_f == &#039;E&#039; or lat_f == &#039;W&#039; then<br /> lat_d, long_d, lat_m, long_m, lat_s, long_s, lat_f, long_f, backward = long_d, lat_d, long_m, lat_m, long_s, lat_s, long_f, lat_f, true;<br /> end<br /> <br /> errors = validate( lat_d, lat_m, lat_s, long_d, long_m, long_s, &#039;parseDMS&#039;, true );<br /> if not long_d then<br /> return nil, {{&quot;parseDMS&quot;, &quot;Missing longitude&quot; }}<br /> elseif not tonumber(long_d) then<br /> return nil, {{&quot;parseDMS&quot;, &quot;Longitude could not be parsed as a number:&quot; .. long_d }}<br /> end<br /> <br /> if not lat_m and not lat_s and not long_m and not long_s and #errors == 0 then<br /> if math_mod._precision( lat_d ) &gt; 0 or math_mod._precision( long_d ) &gt; 0 then<br /> if lat_f:upper() == &#039;S&#039; then<br /> lat_d = &#039;-&#039; .. lat_d;<br /> end<br /> if long_f:upper() == &#039;W&#039; then<br /> long_d = &#039;-&#039; .. long_d;<br /> end<br /> <br /> return parseDec( lat_d, long_d, format );<br /> end<br /> end<br /> <br /> coordinateSpec[&quot;dms-lat&quot;] = lat_d..&quot;°&quot;..optionalArg(lat_m,&quot;′&quot;) .. optionalArg(lat_s,&quot;″&quot;) .. lat_f<br /> coordinateSpec[&quot;dms-long&quot;] = long_d..&quot;°&quot;..optionalArg(long_m,&quot;′&quot;) .. optionalArg(long_s,&quot;″&quot;) .. long_f<br /> coordinateSpec[&quot;dec-lat&quot;] = convert_dms2dec(lat_f, lat_d, lat_m, lat_s) -- {{coord/dms2dec|{{{4}}}|{{{1}}}|0{{{2}}}|0{{{3}}}}}<br /> coordinateSpec[&quot;dec-long&quot;] = convert_dms2dec(long_f, long_d, long_m, long_s) -- {{coord/dms2dec|{{{8}}}|{{{5}}}|0{{{6}}}|0{{{7}}}}}<br /> <br /> if format then<br /> coordinateSpec.default = format<br /> else<br /> coordinateSpec.default = &quot;dms&quot;<br /> end<br /> <br /> return coordinateSpec, errors, backward<br /> end<br /> <br /> local function formatTest(args)<br /> local result, errors<br /> local backward, primary = false, false<br /> <br /> local function getParam(args, lim)<br /> local ret = {}<br /> for i = 1, lim do<br /> ret[i] = args[i] or &#039;&#039;<br /> end<br /> return table.concat(ret, &#039;_&#039;)<br /> end<br /> <br /> if not args[1] then<br /> return errorPrinter( {{&quot;formatTest&quot;, &quot;Missing latitude&quot;}} )<br /> elseif not tonumber(args[1]) then<br /> return errorPrinter( {{&quot;formatTest&quot;, &quot;Unable to parse latitude as a number:&quot; .. args[1]}} )<br /> elseif not args[4] and not args[5] and not args[6] then<br /> result, errors = parseDec(args[1], args[2], args.format)<br /> if not result then<br /> return errorPrinter(errors);<br /> end<br /> result.param = table.concat({<br /> math.abs(tonumber(args[1])),<br /> ((tonumber(args[1]) or 0) &lt; 0) and &#039;S&#039; or &#039;N&#039;,<br /> math.abs(tonumber(args[2])),<br /> ((tonumber(args[2]) or 0) &lt; 0) and &#039;W&#039; or &#039;E&#039;,<br /> args[3] or &#039;&#039;}, &#039;_&#039;)<br /> elseif dmsTest(args[4], args[8]) then<br /> result, errors, backward = parseDMS(args[1], args[2], args[3], args[4],<br /> args[5], args[6], args[7], args[8], args.format)<br /> if args[10] then<br /> table.insert(errors, {&#039;formatTest&#039;, &#039;Extra unexpected parameters&#039;})<br /> end<br /> if not result then<br /> return errorPrinter(errors)<br /> end<br /> result.param = getParam(args, 9)<br /> elseif dmsTest(args[3], args[6]) then<br /> result, errors, backward = parseDMS(args[1], args[2], nil, args[3],<br /> args[4], args[5], nil, args[6], args[&#039;format&#039;])<br /> if args[8] then<br /> table.insert(errors, {&#039;formatTest&#039;, &#039;Extra unexpected parameters&#039;})<br /> end<br /> if not result then<br /> return errorPrinter(errors)<br /> end<br /> result.param = getParam(args, 7)<br /> elseif dmsTest(args[2], args[4]) then<br /> result, errors, backward = parseDMS(args[1], nil, nil, args[2],<br /> args[3], nil, nil, args[4], args.format)<br /> if args[6] then<br /> table.insert(errors, {&#039;formatTest&#039;, &#039;Extra unexpected parameters&#039;})<br /> end<br /> if not result then<br /> return errorPrinter(errors)<br /> end<br /> result.param = getParam(args, 5)<br /> else<br /> return errorPrinter({{&quot;formatTest&quot;, &quot;Unknown argument format&quot;}}) .. &#039;[[Category:Pages with malformed coordinate tags]]&#039;<br /> end<br /> result.name = args.name<br /> <br /> local extra_param = {&#039;dim&#039;, &#039;globe&#039;, &#039;scale&#039;, &#039;region&#039;, &#039;source&#039;, &#039;type&#039;}<br /> for _, v in ipairs(extra_param) do<br /> if args[v] then<br /> table.insert(errors, {&#039;formatTest&#039;, &#039;Parameter: &quot;&#039; .. v .. &#039;=&quot; should be &quot;&#039; .. v .. &#039;:&quot;&#039; })<br /> end<br /> end<br /> <br /> local ret = specPrinter(args, result)<br /> if #errors &gt; 0 then<br /> ret = ret .. &#039; &#039; .. errorPrinter(errors) .. &#039;[[Category:Pages with malformed coordinate tags]]&#039;<br /> end<br /> return ret, backward<br /> end<br /> <br /> local function makeWikidataCategories(qid)<br /> local ret<br /> local qid = qid or mw.wikibase.getEntityIdForCurrentPage()<br /> if mw.wikibase and current_page.namespace == 0 then<br /> if qid and mw.wikibase.entityExists(qid) and mw.wikibase.getBestStatements(qid, &quot;P625&quot;) and mw.wikibase.getBestStatements(qid, &quot;P625&quot;)[1] then<br /> local snaktype = mw.wikibase.getBestStatements(qid, &quot;P625&quot;)[1].mainsnak.snaktype<br /> if snaktype == &#039;value&#039; then<br /> ret = &#039;Coordinates on Wikidata&#039;<br /> elseif snaktype == &#039;somevalue&#039; then<br /> ret = &#039;Coordinates on Wikidata set to unknown value&#039;<br /> elseif snaktype == &#039;novalue&#039; then<br /> ret = &#039;Coordinates on Wikidata set to no value&#039;<br /> end<br /> else<br /> ret = &#039;Coordinates not on Wikidata&#039;<br /> end<br /> end<br /> if ret then<br /> return string.format(&#039;[[Category:%s]]&#039;, ret)<br /> else<br /> return &#039;&#039;<br /> end<br /> end<br /> <br /> function coordinates.link(frame)<br /> return coord_link;<br /> end<br /> <br /> coordinates.dec2dms = makeInvokeFunc(&#039;_dec2dms&#039;)<br /> function coordinates._dec2dms(args)<br /> local coordinate = args[1]<br /> local firstPostfix = args[2] or &#039;&#039;<br /> local secondPostfix = args[3] or &#039;&#039;<br /> local precision = args[4] or &#039;&#039;<br /> <br /> return convert_dec2dms(coordinate, firstPostfix, secondPostfix, precision)<br /> end<br /> <br /> function coordinates.determineMode( value1, value2 )<br /> local precision = math.max( math_mod._precision( value1 ), math_mod._precision( value2 ) );<br /> if precision &lt;= 0 then<br /> return &#039;d&#039;<br /> elseif precision &lt;= 2 then<br /> return &#039;dm&#039;;<br /> else<br /> return &#039;dms&#039;;<br /> end<br /> end<br /> <br /> coordinates.dms2dec = makeInvokeFunc(&#039;_dms2dec&#039;)<br /> function coordinates._dms2dec(args)<br /> local direction = args[1]<br /> local degrees = args[2]<br /> local minutes = args[3]<br /> local seconds = args[4]<br /> <br /> return convert_dms2dec(direction, degrees, minutes, seconds)<br /> end<br /> <br /> coordinates.coord = makeInvokeFunc(&#039;_coord&#039;)<br /> function coordinates._coord(args)<br /> if not tonumber(args[1]) and not args[2] then<br /> args[3] = args[1]; args[1] = nil<br /> local entity = mw.wikibase.getEntityObject(args.qid)<br /> if entity<br /> and entity.claims<br /> and entity.claims.P625<br /> and entity.claims.P625[1].mainsnak.snaktype == &#039;value&#039;<br /> then<br /> local precision = entity.claims.P625[1].mainsnak.datavalue.value.precision<br /> args[1] = entity.claims.P625[1].mainsnak.datavalue.value.latitude<br /> args[2] = entity.claims.P625[1].mainsnak.datavalue.value.longitude<br /> if precision then<br /> precision = -math_mod._round(math.log(precision)/math.log(10),0)<br /> args[1] = math_mod._round(args[1],precision)<br /> args[2] = math_mod._round(args[2],precision)<br /> end<br /> end<br /> end<br /> <br /> local contents, backward = formatTest(args)<br /> local Notes = args.notes or &#039;&#039;<br /> local Display = args.display and args.display:lower() or &#039;inline&#039;<br /> <br /> local function isInline(s)<br /> return s:find(&#039;inline&#039;) ~= nil or s == &#039;i&#039; or s == &#039;it&#039; or s == &#039;ti&#039;<br /> end<br /> local function isInTitle(s)<br /> return s:find(&#039;title&#039;) ~= nil or s == &#039;t&#039; or s == &#039;it&#039; or s == &#039;ti&#039;<br /> end<br /> <br /> local function coord_wrapper(in_args)<br /> return mw.getCurrentFrame():callParserFunction(&#039;#coordinates&#039;, in_args) or &#039;&#039;<br /> end<br /> <br /> local text = &#039;&#039;<br /> if isInline(Display) then<br /> text = text .. &#039;&lt;span class=&quot;geo-inline&quot;&gt;&#039; .. contents .. Notes .. &#039;&lt;/span&gt;&#039;<br /> end<br /> if isInTitle(Display) then<br /> if not isInline(Display) then<br /> text = text .. &#039;&lt;span class=&quot;geo-inline-hidden noexcerpt&quot;&gt;&#039; .. contents .. Notes .. &#039;&lt;/span&gt;&#039;<br /> end<br /> text = text .. displaytitle(contents .. Notes) .. makeWikidataCategories(args.qid)<br /> end<br /> if not args.nosave then<br /> local page_title, count = mw.title.getCurrentTitle(), 1<br /> if backward then<br /> local tmp = {}<br /> while not string.find((args[count-1] or &#039;&#039;), &#039;[EW]&#039;) do tmp[count] = (args[count] or &#039;&#039;); count = count+1 end<br /> tmp.count = count; count = 2*(count-1)<br /> while count &gt;= tmp.count do table.insert(tmp, 1, (args[count] or &#039;&#039;)); count = count-1 end<br /> for i, v in ipairs(tmp) do args[i] = v end<br /> else<br /> while count &lt;= 9 do args[count] = (args[count] or &#039;&#039;); count = count+1 end<br /> end<br /> if isInTitle(Display) and not page_title.isTalkPage and page_title.subpageText ~= &#039;doc&#039; and page_title.subpageText ~= &#039;testcases&#039; then args[10] = &#039;primary&#039; end<br /> args.notes, args.format, args.display = nil<br /> text = text .. coord_wrapper(args)<br /> end<br /> return text<br /> end<br /> <br /> function coordinates._coord2text(coord,type)<br /> if coord == &#039;&#039; or type == &#039;&#039; or not type then return nil end<br /> type = mw.text.trim(type)<br /> if type == &#039;lat&#039; or type == &#039;long&#039; then<br /> local result, negative = mw.text.split((mw.ustring.match(coord,&#039;[%.%d]+°[NS] [%.%d]+°[EW]&#039;) or &#039;&#039;), &#039; &#039;)<br /> if type == &#039;lat&#039; then<br /> result, negative = result[1], &#039;S&#039;<br /> else<br /> result, negative = result[2], &#039;W&#039;<br /> end<br /> result = mw.text.split(result, &#039;°&#039;)<br /> if result[2] == negative then result[1] = &#039;-&#039;..result[1] end<br /> return result[1]<br /> else<br /> return mw.ustring.match(coord, &#039;params=.-_&#039; .. type .. &#039;:(.-)[ _]&#039;)<br /> end<br /> end<br /> <br /> function coordinates.coord2text(frame)<br /> return coordinates._coord2text(frame.args[1],frame.args[2])<br /> end<br /> <br /> function coordinates.coordinsert(frame)<br /> for i, v in ipairs(frame.args) do<br /> if i ~= 1 then<br /> if not mw.ustring.find(frame.args[1], (mw.ustring.match(frame.args[i], &#039;^(.-:)&#039;) or &#039;&#039;)) then<br /> frame.args[1] = mw.ustring.gsub(frame.args[1], &#039;(params=.-)_? &#039;, &#039;%1_&#039;..frame.args[i]..&#039; &#039;)<br /> end<br /> end<br /> end<br /> if frame.args.name then<br /> if not mw.ustring.find(frame.args[1], &#039;&lt;span class=&quot;vcard&quot;&gt;&#039;) then<br /> local namestr = frame.args.name<br /> frame.args[1] = mw.ustring.gsub(<br /> frame.args[1],<br /> &#039;(&lt;span class=&quot;geo%-default&quot;&gt;)(&lt;span[^&lt;&gt;]*&gt;[^&lt;&gt;]*&lt;/span&gt;&lt;span[^&lt;&gt;]*&gt;[^&lt;&gt;]*&lt;span[^&lt;&gt;]*&gt;[^&lt;&gt;]*&lt;/span&gt;&lt;/span&gt;)(&lt;/span&gt;)&#039;,<br /> &#039;%1&lt;span class=&quot;vcard&quot;&gt;%2&lt;span style=&quot;display:none&quot;&gt;&amp;#xfeff; (&lt;span class=&quot;fn org&quot;&gt;&#039; .. namestr .. &#039;&lt;/span&gt;)&lt;/span&gt;&lt;/span&gt;%3&#039;<br /> )<br /> frame.args[1] = mw.ustring.gsub(<br /> frame.args[1],<br /> &#039;(&amp;params=[^&amp;&quot;&lt;&gt;%[%] ]*) &#039;,<br /> &#039;%1&amp;title=&#039; .. mw.uri.encode(namestr) .. &#039; &#039;<br /> )<br /> end<br /> end<br /> <br /> frame.args[1] = mw.ustring.gsub(<br /> frame.args[1],<br /> &#039;(&lt;span class=&quot;geo%-inline[^&quot;]*&quot;&gt;(.+)&lt;/span&gt;)\127[^\127]*UNIQ%-%-indicator%-%x+%-%-?QINU[^\127]*\127&#039;,<br /> function (inline, coord) return inline .. displaytitle(coord) end<br /> )<br /> <br /> return frame.args[1]<br /> end<br /> <br /> return coordinates</div> Favonide