Module:Solar eclipse
Appearance
From Wikipedia, the free encyclopedia
This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
Page semi-protected Editing of this module by new or unregistered users is currently disabled.
See the protection policy and protection log for more details. If you cannot edit this module and you wish to make a change, you can submit an edit request , discuss changes on the talk page, request unprotection, log in, or create an account.
See the protection policy and protection log for more details. If you cannot edit this module and you wish to make a change, you can submit an edit request , discuss changes on the talk page, request unprotection, log in, or create an account.
This module depends on the following other modules:
This module exists to be invoked by Template:Infobox solar eclipse.
Usage
{{#invoke:Solar eclipse|box}}
The above documentation is transcluded from Module:Solar eclipse/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
localp={} localargs={} localdata_module_prefix="Module:Solar eclipse/db/" localinfobox_image=nil-- lazy load localfunctionInfoboxImage(image) if(imageandimage~='')then ifinfobox_image==nilthen infobox_image=require('Module:InfoboxImage').InfoboxImage end returninfobox_image{args={ image=image, size='320px', sizedefault='frameless', upright=1 }} end returnnil end localfunctionifnotempty(s,a,b) return(sands~='')andaorb end localfunctionifexist(page) ifnotpagethenreturnfalseend ifmw.title.new(page).existsthenreturntrueend returnfalse end localfunctionparsedate(y,m,d) locallang=mw.language.getContentLanguage() d=string.format("%02d",tonumber(d)) m=string.format("%02d",tonumber(m)) localdate_str=y..'-'..m..'-'..d localsuccess,result=pcall(lang.formatDate,lang,'F j, Y',date_str) returnsuccessandresultordate_str end localfunctionparsecoord(frame,s) locallat,NS,lon,EW=s:match('^%s*(%d+%.?%d*)%s*([NS])%s*(%d+%.?%d*)%s*([EW])%s*$') iflatandNSandlonandEWthen returnframe:expandTemplate{ title='coord', args={lat,NS,lon,EW,'type:landmark'} } end returns end localfunctionparsekm(frame,s) if(sands:match('^%s*[%d][%d.]*%s*$'))then returnframe:expandTemplate{title='convert',args={s,'km','mi',abbr='on'}} else if(sands~='')then returns..' km' else returnnil end end end localfunctionparsetime(s) if(sands~='')then localmin=s:match('^%s*(%d+)m%s*%d+s%s*$') localsec=s:match('^%s*%d+m%s*(%d+)s%s*$') if(minandsec)then returntostring(tonumber(min)*60+tonumber(sec))..' s'.. ' ('..min..' min '..sec..' s)' end end returns end localfunctioncataloglink(c,y,m,d) y,m,d=tonumber(y),tonumber(m),tonumber(d) iftonumber(c)andyandmanddthen d=(d<10)and('0'..d)ord m=(m<10)and('0'..m)orm return'[https://eclipse.gsfc.nasa.gov/SEsearch/SEdata.php?Ecl=+'..y..m..d..' '..c..']' else returnc end end localfunctioncreateLink(label,suffix) ifnotlabelorlabel==''then return'' end localprefix="Solar eclipse of " -- check if label starts with the prefix ifmw.ustring.find(label,"^"..prefix)then -- extract the date part from the label localdateLabel=mw.ustring.sub(label,#prefix+1) localpage=label-- this is the full page title to link to ififexist(page)then returnstring.format('[[%s|%s]]',page,dateLabel) else -- if page doesn't exist, display the date returndateLabel end else -- if the label is a a link, keep it ifmw.ustring.match(label,"^%[%[.*%]%]$")then returnlabel else -- for labels without the prefix, display as plain text returnlabel end end end localfunctionloadsolardb(frame,s) localyearstr=s:match('^%s*(%d%d%d%d)[A-Z][a-z][a-z]%d%d%s*$')or'' localfunctionsetarg(k,v) if(vandv~='')then v=mw.ustring.gsub(v,'^%s*%-(%d)','−%1') args[k]=v end end if(yearstr~='')then localdbsubpage=math.floor((tonumber(yearstr)-1)/50)*5 localdbpage=data_module_prefix..tostring(dbsubpage) if(ifexist(dbpage))then localdata=mw.loadData(dbpage) localdargs=data[s]orerror('Error: unknown date '..s..' in Infobox solar eclipse',0) setarg('date',parsedate(dargs['y'],dargs['m']ordargs['m3']ordargs['m2'],dargs['d']ordargs['d2'])) setarg('image',(dargs['Ph']anddargs['Ph']~='')and'[[File:'..dargs['Ph']..'|320px]]'ornil) setarg('caption',dargs['PhCap']) setarg('map',(dargs['Map']anddargs['Map']~='')and'[[File:'..dargs['Map']..'|320px]]'ornil) setarg('map_caption','Map') setarg('type_ref','') setarg('cat',cataloglink(dargs['Cat'],dargs['y'],dargs['m']ordargs['m3']ordargs['m2'],dargs['d']ordargs['d2'])) setarg('nature',dargs['Ty']) setarg('gamma',dargs['Gam']) setarg('magnitude',dargs['Mag']) setarg('saros',dargs['Saros']and'[[Solar Saros '..dargs['Saros']..'|'..dargs['Saros']..']]') setarg('saros_sequence',dargs['Mem']) setarg('saros_total',dargs['Max']) setarg('max_eclipse_ref','') setarg('duration',parsetime(dargs['Dur'])) setarg('location','') setarg('coords',parsecoord(frame,dargs['Loc'])) setarg('max_width',parsekm(frame,dargs['Wid'])) setarg('times_ref','') setarg('start_partial',dargs['TiPB']) setarg('start_total',dargs['TiTB']) setarg('start_central','') setarg('greatest_eclipse',dargs['TiG']) setarg('end_central','') setarg('end_total',dargs['TiTE']) setarg('end_partial',dargs['TiPE']) setarg('previous','') setarg('next','') end end end localfunctioninfobox(frame) localtitlestr=ifnotempty(args['date'], "Solar eclipse of "..(args['date']or''), "For instructions on use, see [[Template:Infobox Solar eclipse]]") localbgcolor=args['background']orargs['bgcolour']or'' localmapstr=ifnotempty(args['map'], "<div style='padding-bottom:0.5em;'>".. (InfoboxImage(args['map'])or'')..ifnotempty(args['map_caption'], "<div style='line-height:1.2em; padding-top:0.1em;'>".. (args['map_caption']or'').."</div>",'')..'</div>') localprevLink=createLink(args['previous'],'solar eclipse') localnextLink=createLink(args['next'],'solar eclipse') localbelowstr='' ifprevLink~=''andnextLink~=''then belowstr=string.format('<div style="width:100%%"><div class="noprint" style="float:left">← %s</div><div class="noprint" style="float:right">%s →</div></div>', prevLink,nextLink) elseifprevLink~=''then belowstr=string.format('<div style="width:100%%"><div class="noprint" style="text-align:left">← %s</div></div>',prevLink) elseifnextLink~=''then belowstr=string.format('<div style="width:100%%"><div class="noprint" style="text-align:right">%s →</div></div>',nextLink) end localeclipse_types={ total={label="'''Total eclipse'''",color="#690005"}, partial={label="'''Partial eclipse'''",color="#854739"}, annular={label="'''Annular eclipse'''",color="#4C4CB1"}, hybrid={label="'''Hybrid eclipse'''",color="#006600"} } localnature=args['nature']andargs['nature']:lower()or'' localeclipse_config=eclipse_types[nature]or{label="Eclipse",color="#727272"} localtype_header=string.format( '<span style="background-color: %s; color: white; display: block;">%s</span>', eclipse_config.color, eclipse_config.label ) returnframe:expandTemplate{title='infobox',args={ ["bodyclass"]="vevent", ["bodystyle"]="width:25em; text-align:left; font-size:88%;", ["title"]=titlestr, ["subheader"]=type_header, ["below"]=belowstr, ["belowstyle"]="text-align:center; padding-top:0.5em", ------------------ Images and maps ------------------ ["image"]=InfoboxImage(args['image']), ["imagestyle"]="padding-bottom:0.5em;", ["caption"]=args['caption']or'', ["headerstyle"]="background:#eee; color:inherit; font-size:105%;", ["data1"]=mapstr, ------------- Type of eclipse and saros ------------- ["label4"]="[[Gamma (eclipse)|Gamma]]", ["data4"]=args['gamma']or'', ["label5"]="[[Magnitude of eclipse|Magnitude]]", ["data5"]=args['magnitude']or'', ------------------ Maximum eclipse ------------------ ["header7"]="Maximum eclipse"..(args['max_eclipse_ref']or''), ["label8"]="Duration", ["data8"]=args['duration']or'', ["label9"]="Location", ["data9"]=args['location']or'', ["class9"]="location", ["label10"]="Coordinates", ["data10"]=args['coords']or'', ["label11"]="Max. width of band", ["data11"]=args['max_width']or'', ----------------------- Times ----------------------- ["header12"]="Times ([[UTC]])"..(args['times_ref']or''), ["label13"]="(P1) Partial begin", ["data13"]=args['start_partial']or'', ["label14"]="(U1) Total begin", ["data14"]=args['start_total']or'', ["label15"]="(U2) Central begin", ["data15"]=args['start_central']or'', ["label16"]="Greatest eclipse", ["data16"]=args['greatest_eclipse']or'', ["label17"]="(U3) Central end", ["data17"]=args['end_central']or'', ["label18"]="(U4) Total end", ["data18"]=args['end_total']or'', ["label19"]="(P4) Partial end", ["data19"]=args['end_partial']or'', ------------------------ Event references ------------------------- ["header20"]="References", ["label21"]="[[Saros (astronomy)|Saros]]", ["data21"]=(args['saros']or'') .." ("..(args['saros_sequence']or'').." of "..(args['saros_total']or'')..")", ["label22"]="Catalog # (SE5000)", ["data22"]=args['cat']or'', }} end functionp.box(frame) args=require('Module:Arguments').getArgs(frame,{ wrappers='Template:Infobox solar eclipse' }) if(args['2']andargs['2']~='')then loadsolardb(frame,args['2']) elseif(args['1']andargs['1']~='')then loadsolardb(frame,args['1']) end returninfobox(frame) end returnp