Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Module:Medals table

Permanently protected module
From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
Thismodule is rated asready 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 onhelp pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed throughsandbox testing rather than repeated trial-and-error editing.
Page template-protectedThis module is currentlyprotected from editing.
See theprotection policy andprotection log for more details. Please discuss any changes on thetalk page; you maysubmit an edit request to ask anadministrator to make an edit if it isuncontroversial or supported byconsensus. You may alsorequest that this page be unprotected.
WarningThis Lua module is used onapproximately 16,000 pages and changes may be widely noticed. Test changes in the module's/sandbox or/testcases subpages, or in your ownmodule sandbox. Consider discussing changes on thetalk page before implementing them.

Usage

See:Template:Medals table

The abovedocumentation istranscluded fromModule:Medals table/doc.(edit |history)
Editors can experiment in this module'ssandbox(edit |diff) and testcases(create) pages.
Subpages of this module.

require('strict')localgetArgs=require('Module:Arguments').getArgslocalflagg=require('Module:Flagg').luaMainlocalp={}localfunctiondeflag(s)s=mw.ustring.gsub(sor'','%[%[[Ff][Ii][Ll][Ee]:[^%[%]]*%]%]','')s=mw.ustring.gsub(s,'%[%[[Ii][Mm][Aa][Gg][Ee]:[^%[%]]*%]%]','')s=mw.ustring.gsub(s,'<[^<>]*>','')s=mw.ustring.gsub(s,'%s*%([A-Z][A-Z][A-Z]%)%s*$','')whiles:match('^%s*&[Nn][Bb][Ss][Pp];%s*')dos=mw.ustring.gsub(s,'^%s*&[Nn][Bb][Ss][Pp];%s*','')ends=mw.ustring.gsub(s,'%s*&[Nn][Bb][Ss][Pp];%s*$','')s=mw.ustring.gsub(s,'%s%s+',' ')s=mw.ustring.gsub(s,'^%s*(.-?)%s*$','%1')returnsendlocalfunctionifexists(arg)return((argor'')~='')andargorfalseendfunctionp.createTable(frame,args)ifnotargsthenargs=getArgs(frame)endlocalteam=args['team']or'Nation'localroot=mw.html.create()localhost=args['host']or''localhost1=args['host1']or''localhost2=args['host2']or''localhostColor='#ccccff'localdefaultRowColor='inherit'localflagTemplate=ifexists(args['flag_template'])or'flagteam'localevent=args['event']locallegendpos=(args['legend_position']or't'):lower()localheader,footer='',''localtotalGold=0localtotalSilver=0localtotalBronze=0localremainingGold=0localremainingSilver=0localremainingBronze=0localremainingStart=0localremainingEnd=0locallimitReached=falselocalshowLimit=tonumber(args['show_limit'])locallang=mw.getContentLanguage()localfunctiongetFlag(code)if(flagTemplate=='flagteam'ormw.ustring.lower(flagTemplate)=='flagcountry')thenlocalalias=ifexists(event)or'23px'localfout=flagg(frame,{'usce',code,mw.ustring.match(alias,"[12]%d%d%d")oralias})if(flagTemplate=='flagteam')thenfout=fout..'&nbsp;<span style="font-size:90%;">('..code..')</span>'endreturnfoutendreturnframe:expandTemplate{title=flagTemplate,args={code,event}}end-- build the legendifhost2~=''andhost1~=''thenifargs['name_'..host1]thenhost1=args['name_'..host1]elseifhost1:match('^([A-Z][A-Z][A-Z])')thenhost1=getFlag(host1)endifargs['name_'..host2]thenhost2=args['name_'..host2]elseifhost2:match('^([A-Z][A-Z][A-Z])')thenhost2=getFlag(host2)endhost='Host nations ('..deflag(host1)..', '..deflag(host2)..')'host=frame:expandTemplate{title='color box',args={hostColor,'&nbsp;*&nbsp;','border=darkgray'}}..'&nbsp;'..hostelseifhost~=''thenifargs['name_'..host]thenhost=args['name_'..host]elseifhost:match('^([A-Z][A-Z][A-Z])')thenhost=getFlag(host)endhost='Host nation ('..deflag(host)..')'host=host..(args['host_note']or'')host=frame:expandTemplate{title='color box',args={hostColor,'&nbsp;*&nbsp;','border=darkgray'}}..'&nbsp;'..hostendlocalleading=''ifargs['leading']thenleading=frame:expandTemplate{title='legend',args={'#E9D66B',"'''Leading in that sport'''"}}endiflegendpos=='t'thenheader=header..host..leadingelsefooter=footer..host..leadingendlocalsticky=frame:extensionTag{name="templatestyles",args={src="template:sticky header/styles.css"}}root=root:tag('table'):addClass('wikitable'):addClass('sortable'):addClass('sticky-header-multi'):addClass('plainrowheaders'):addClass('jquery-tablesorter'):css('text-align','center')root:tag('caption'):wikitext(args['caption'])-- add the header rowlocalrow=root:tag('tr')ifnotargs['hide_rank']thenrow:tag('th'):attr('scope','col'):css('color','inherit'):wikitext('Rank')endrow:tag('th'):attr('scope','col'):wikitext(team):tag('th'):attr('scope','col'):addClass('headerSort'):css('width','4em'):css('background-color','gold'):css('color','#333'):wikitext('Gold'):tag('th'):attr('scope','col'):addClass('headerSort'):css('width','4em'):css('background-color','silver'):css('color','#333'):wikitext('Silver'):tag('th'):attr('scope','col'):addClass('headerSort'):css('width','4em'):css('background-color','#c96'):css('color','#333'):wikitext('Bronze'):tag('th'):attr('scope','col'):css('width','4em'):wikitext('Total')-- enumerate the rowslocalrowNums={}localIOCs={}fork,vinpairs(args)dok=''..klocalIOC=k:match('^gold_([A-Z][A-Z][A-Z])$')ork:match('^gold_(%d+)$')ork:match('^silver_([A-Z][A-Z][A-Z])$')ork:match('^silver_(%d+)$')ork:match('^bronze_([A-Z][A-Z][A-Z])$')ork:match('^bronze_(%d+)$')ifIOCandIOCs[IOC]==nilthenIOCs[IOC]=1localgold=(tonumber(args['gold_'..IOC])or0)localsilver=(tonumber(args['silver_'..IOC])or0)localbronze=(tonumber(args['bronze_'..IOC])or0)localnoskip=args['skip_'..IOC]and0or1localnation=args['name_'..IOC]orgetFlag(IOC)nation=deflag(nation)ifnation:match('%[%[[^%[%]%|]*%|([^%[%]]*)%]%]')thennation=nation:match('%[%[[^%[%]%|]*%|([^%[%]]*)%]%]')endifnation:match('%[%[([^%[%]%|]*)%]%]')thennation=nation:match('%[%[([^%[%]%|]*)%]%]')endtable.insert(rowNums,{gold,silver,bronze,noskip,nation,IOC})endendifargs['team']=='Games'thentable.sort(rowNums,function(a,b)returna[5]<b[5]end)elsetable.sort(rowNums,function(a,b)returna[1]>b[1]or(a[1]==b[1]anda[2]>b[2])or(a[1]==b[1]anda[2]==b[2]anda[3]>b[3])or(a[1]==b[1]anda[2]==b[2]anda[3]==b[3]anda[4]>b[4])or(a[1]==b[1]anda[2]==b[2]anda[3]==b[3]anda[4]==b[4]anda[5]<b[5])end)endlocallastGold,lastSilver,lastBronze=-1localrank=0locallastspan,lastrankcell=1,nilfori,anuminipairs(rowNums)dolocalIOC=anum[6]ifargs['skip_'..IOC]thenlastGold,lastSilver,lastBronze,lastspan=-1,-1,-1,1elserank=rank+1endlocalnation=args['name_'..IOC]orgetFlag(IOC)localgold=tonumber(args['gold_'..IOC])or0localsilver=tonumber(args['silver_'..IOC])or0localbronze=tonumber(args['bronze_'..IOC])or0localisHost=args['host_'..IOC]-- this is mainly for the parameter names example so you can override it.localtotal=tonumber(args['total_'..IOC])or(gold+silver+bronze)localcolor=isHostandhostColorordefaultRowColorifnotargs['grand_total']thentotalGold=totalGold+goldtotalSilver=totalSilver+silvertotalBronze=totalBronze+bronzeendifargs['host_'..IOC]thennation=nation..'*'endifargs['note_'..IOC]thennation=nation..args['note_'..IOC]endifshowLimitand(rank>showLimit)thenifremainingStart==0thenremainingStart=rankendlimitReached=trueremainingGold=remainingGold+goldremainingSilver=remainingSilver+silverremainingBronze=remainingBronze+bronzeelselocalrowifargs['leading_'..IOC]thenrow=root:tag('tr'):css('background-color','#E9D66B'):css('color','#202122')color='#E9D66B'elserow=root:tag('tr')end--Don't put the color on the row because of ranks spanning multiple rows.--:css('background-color', color):css('color', '#202122')ifnotargs['hide_rank']thenif(gold==lastGold)and(silver==lastSilver)and(bronze==lastBronze)thenlastspan=lastspan+1lastrankcell:attr('rowspan',lastspan)elselastspan=1ifargs['skip_'..IOC]thenlastrankcell=row:tag('td'):wikitext(frame:expandTemplate{title='sort',args={'999','–'}})elselastrankcell=row:tag('td'):wikitext(rank)lastGold=goldlastSilver=silverlastBronze=bronzeendendendrow:tag('th'):attr('scope','row'):css('background-color',color):css('color','inherit'):css('text-align','left'):wikitext(nation):tag('td'):wikitext(lang:formatNum(gold)):tag('td'):wikitext(lang:formatNum(silver)):tag('td'):wikitext(lang:formatNum(bronze)):tag('td'):wikitext(lang:formatNum(total))endremainingEnd=rankendiflimitReachedthenroot:tag('tr'):tag('td'):wikitext(remainingStart..'–'..remainingEnd):tag('td'):css('font-style','italic'):css('text-align','left'):wikitext(args['remaining_link']orargs['remaining_text']or'Remaining'):tag('td'):wikitext(lang:formatNum(remainingGold)):tag('td'):wikitext(lang:formatNum(remainingSilver)):tag('td'):wikitext(lang:formatNum(remainingBronze)):tag('td'):wikitext(lang:formatNum(remainingGold+remainingSilver+remainingBronze))endifnot(team:match('^[A-Z][A-Z][A-Z]$')orteam:match('>[A-Z][A-Z][A-Z]<'))thenteam=team:lower()endifteam:match('^games$')thenteam='game'endlocalcolspanifargs['hide_rank']thencolspan=1elsecolspan=2endifnotargs['hide_totals']thenroot:tag('tr'):addClass('sortbottom'):css('background','var(--background-color-neutral,#eaecf0)'):css('color','var(--color-base,#202122)'):css('font-weight','bold'):tag('th'):wikitext('Totals ('..remainingEnd..' entries)'):attr('scope','row'):attr('colspan',colspan):css('font-weight','bold'):tag('td'):wikitext(lang:formatNum(tonumber(args['total_gold'])ortotalGold)):tag('td'):wikitext(lang:formatNum(tonumber(args['total_silver'])ortotalSilver)):tag('td'):wikitext(lang:formatNum(tonumber(args['total_bronze'])ortotalBronze)):tag('td'):wikitext(lang:formatNum(tonumber(args['grand_total'])or(totalGold+totalSilver+totalBronze)))end-- Build the rest of the footerifargs['source']orargs['notes']theniffooter~=''thenfooter=footer..'<br>'endfooter=frame:expandTemplate{title='refbegin'}..footerifargs['source']thenfooter=footer..'Source: '..args['source']endifargs['notes']thenifargs['source']thenfooter=footer..'<br>'endfooter=footer..'Notes: '..args['notes']endfooter=footer..frame:expandTemplate{title='refend'}endreturnheader..sticky..tostring(root)..footerendreturnp
Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:Medals_table&oldid=1326021250"
Category:
Hidden category:

[8]ページ先頭

©2009-2025 Movatter.jp