VOOZH about

URL: https://minecraft.wiki/w/Module:Edit_table

⇱ Module:Edit table – Minecraft Wiki


Module:Edit table

From Minecraft Wiki
Jump to navigation Jump to search
Documentation[view] [edit] [history] [purge]Jump to code ↴

This module implements {{Edit table}}, see template's document for usages.

[view] [edit] [history] [purge]The above documentation is transcluded from Module:Edit table/doc.
localp={}
locali18n={
countsrc='{{Special:Editcount/%s/%s}}',
datadesc='Edit table',
errormsg='<span class="error" style="font-weight: bold;">[[Template:Edit table]]: %s</span>',
error_nogrp='At least one user and their namespace(s) is/are required.',
error_nons='At least one namespace is required.',
error_nouser='Must provide username.',
rownsname=mw.getCurrentFrame():callParserFunction('int:editcount namespace'),
rowcount=mw.getCurrentFrame():callParserFunction('int:editcount edits'),
type_multiuser='multiuser',
type_special='special',
usercontrib='Contributions of [[User:%s|%s]]:',
userlink='[[User:%s|%s]]',
}
localfunctionfetchElements(tbl,index,collapsed)
ifnottblortype(tbl)~='table'then
returnnil
end
index=indexor0
iftype(index)~='number'then
returnnil
end
localresult_pre={}
localkeys_anon={}
localkeys_name={}
ifindex==0then
result_pre=tbl
else
fork,vinpairs(tbl)do
iftype(k)=='number'then
ifk>indexthen
result_pre[k-index]=v
table.insert(keys_anon,k-index)
end
else
result_pre[k]=v
table.insert(keys_name,k)
end
end
end
ifnotcollapsedthen
if#keys_anon==0and#keys_name==0then
returnnil
else
returnresult_pre
end
end
localresult={}
table.sort(keys_anon)
for_,vinpairs(keys_anon)do
table.insert(result,result_pre[v])
end
for_,vinpairs(keys_name)do
result[v]=result_pre[v]
end
if#keys_anon==0and#keys_name==0then
returnnil
else
returnresult
end
end
localfunctiongetNSName(namespace)
ifnotnamespacethen
returnnil
end
ifnamespace:lower()=='main'then
returnmw.site.namespaces[0].displayName
else
returnmw.site.namespaces[namespace].name
end
end
localfunctiongetSingle(username,namespaces,sortable,showname,requireNS)
ifnotusernamethen
returni18n.errormsg:format(i18n.error_nouser)
end
ifnotnamespacesandrequireNSthen
returni18n.errormsg:format(i18n.error_nons)
end
ifnotnamespacesthen
namespaces={'main','talk','user','user talk','file','module','bucket','template','category','project','help','mediawiki','mcl','mcd','mcd2','mce','mcsm','forum','tutorial','movie'}
end
localresult=mw.html.create('table'):addClass('wikitable'):attr('data-description',i18n.datadesc)
if#namespaces>1andsortablethen
result:addClass('sortable')
end
ifshownamethen
result:tag('div'):css{['line-height']=1,['font-weight']='bold'}:wikitext(i18n.usercontrib:format(username,username)):done()
end
localtableHeader=mw.html.create('tr')
tableHeader:tag('th'):wikitext(i18n.rownsname):done()
tableHeader:tag('th'):wikitext(i18n.rowcount):done()
result:node(tableHeader)
fork,vinpairs(namespaces)do
iftype(k)=='number'then
localtableRow=mw.html.create('tr'):css{['text-align']='center'}
tableRow:tag('td'):addClass('tdtable'):wikitext(getNSName(v)):done()
tableRow:tag('td'):addClass('tdtable'):wikitext(mw.getCurrentFrame():preprocess(i18n.countsrc:format(username,v))):done()
result:node(tableRow)
end
end
returntostring(result)
end
localfunctiongetMultiple(groups)
ifnotgroupsthen
returni18n.errormsg:format(i18n.error_nogrp)
end
localresult=mw.html.create('table'):addClass('wikitable')
localtableHeader=mw.html.create('tr')
tableHeader:tag('th'):wikitext(i18n.rownsname):done()
tableHeader:tag('th'):wikitext(i18n.rowcount):done()
result:node(tableHeader)
fork,groupinpairs(groups)do
iftype(k)=='number'then
localsplits={}
forvinmw.text.gsplit(mw.text.trim(group),',',true)do
table.insert(splits,mw.text.trim(v))
end
localusername=splits[1]
localcolor=nil
-- Check if the username contains a color
ifusername:find("<")andusername:find(">")then
color=username:match("<(.-)>")
username=username:gsub("<.->","")
end
ifnotusernamethen
returni18n.errormsg:format(i18n.error_nouser)
end
localnamespaces=fetchElements(splits,1,false)
ifnotnamespacesthen
returni18n.errormsg:format(i18n.error_nons)
end
localtableRowUser=mw.html.create('tr')
tableRowUser:tag('th'):attr('colspan',2):wikitext(i18n.userlink:format(username,username))
ifcolorthen
tableRowUser:css{['background-color']=color}
end
tableRowUser:done()
result:node(tableRowUser)
for_,namespaceinpairs(namespaces)do
localtableRowEdit=mw.html.create('tr'):css{['text-align']='center'}
ifcolorthen
tableRowEdit:css{['background-color']=color}
end
tableRowEdit:tag('td'):wikitext(getNSName(namespace)):done()
tableRowEdit:tag('td'):wikitext(mw.getCurrentFrame():preprocess(i18n.countsrc:format(username,namespace))):done()
result:node(tableRowEdit)
end
end
end
returntostring(result)
end
functionp.main(f)
localargs=f
iff==mw.getCurrentFrame()then
args=require('Module:ProcessArgs').merge(true)
end
ifargs[1]then
ifargs[1]:lower()==i18n.type_specialthen
returngetSingle(args[2],fetchElements(args,2,true),notargs.nosort,args.showname,true)
elseifargs[1]:lower()==i18n.type_multiuserthen
returngetMultiple(fetchElements(args,1,true))
else
returngetSingle(args[1],nil,notargs.nosort,args.showname,false)
end
else
returnnil
end
end
returnp
Retrieved from "https://minecraft.wiki/w/Module:Edit_table?oldid=3600632"

Navigation menu