Sabtu, 26 September 2026
21:15 WIB
TERKINI
Bandar Lampung Semangat Anak Sawah: Harumkan Nama Lampung di Kancah Nasional Tanpa Dukungan Pemda Lampung Selatan Gunung Anak Krakatau Kembali Erupsi, Status Siaga Tetap Dipertahankan Bandar Lampung BPS Lampung Tuntaskan Sensus Ekonomi 2026, Hasilnya Siap Rilis Awal 2027 Bandar Lampung Inovasi Double Teaching: Guru Ahli Berbagi Ilmu Lintas Sekolah di Lampung Bandar Lampung Coki, Buaya Peliharaan Warga Panjang yang Bikin Haru Jelang Evakuasi KKP Lampung Tekuni Hobi Sejak Kuliah, Dani Tetap Bertahan Jual Ikan Hias di Tengah Tantangan Cuaca Prakiraan Cuaca Lampung 26 September 2026: Cerah Berawan dan Potensi Hujan Humaniora Perlindungan Anak Digital: MPR Desak Komitmen Global Terwujud Nyata di Tanah Air Regional Bupati Gowa Sitti Husniah Talenrang Tersangka Pemerasan Perizinan Bangunan dan TPPU Bandar Lampung Puluhan Siswa di Lampung Tengah Diduga Keracunan Makanan Program MBG Bandar Lampung Semangat Anak Sawah: Harumkan Nama Lampung di Kancah Nasional Tanpa Dukungan Pemda Lampung Selatan Gunung Anak Krakatau Kembali Erupsi, Status Siaga Tetap Dipertahankan Bandar Lampung BPS Lampung Tuntaskan Sensus Ekonomi 2026, Hasilnya Siap Rilis Awal 2027 Bandar Lampung Inovasi Double Teaching: Guru Ahli Berbagi Ilmu Lintas Sekolah di Lampung Bandar Lampung Coki, Buaya Peliharaan Warga Panjang yang Bikin Haru Jelang Evakuasi KKP Lampung Tekuni Hobi Sejak Kuliah, Dani Tetap Bertahan Jual Ikan Hias di Tengah Tantangan Cuaca Prakiraan Cuaca Lampung 26 September 2026: Cerah Berawan dan Potensi Hujan Humaniora Perlindungan Anak Digital: MPR Desak Komitmen Global Terwujud Nyata di Tanah Air Regional Bupati Gowa Sitti Husniah Talenrang Tersangka Pemerasan Perizinan Bangunan dan TPPU Bandar Lampung Puluhan Siswa di Lampung Tengah Diduga Keracunan Makanan Program MBG

Modul:Userbox

Wikimedia module

Dokumentasi modulbuatsegarkan
Anda dapat membuat halaman dokumentasi untuk buat pada modul Scribunto ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
-- This module implements {{userbox}}.
localcategoryHandler=require('Module:Category handler').main
localp={}
--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------
localfunctioncheckNum(val,default)
-- Checks whether a value is a number greater than or equal to zero. If so,
-- returns it as a number. If not, returns a default value.
val=tonumber(val)
ifvalandval>=0then
returnval
else
returndefault
end
end
localfunctionaddSuffix(num,suffix)
-- Turns a number into a string and adds a suffix.
ifnumthen
returntostring(num)..suffix
else
returnnil
end
end
localfunctioncheckNumAndAddSuffix(num,default,suffix)
-- Checks a value with checkNum and adds a suffix.
num=checkNum(num,default)
returnaddSuffix(num,suffix)
end
localfunctionmakeCat(cat,sort)
-- Makes a category link.
ifsortthen
returnmw.ustring.format('[[Category:%s|%s]]',cat,sort)
else
returnmw.ustring.format('[[Category:%s]]',cat)
end
end
--------------------------------------------------------------------------------
-- Argument processing
--------------------------------------------------------------------------------
localfunctionmakeInvokeFunc(funcName)
returnfunction(frame)
localorigArgs=require('Module:Arguments').getArgs(frame)
localargs={}
fork,vinpairs(origArgs)do
args[k]=v
end
returnp.main(funcName,args)
end
end
p.userbox=makeInvokeFunc('_userbox')
p['userbox-2']=makeInvokeFunc('_userbox-2')
p['userbox-r']=makeInvokeFunc('_userbox-r')
--------------------------------------------------------------------------------
-- Main functions
--------------------------------------------------------------------------------
functionp.main(funcName,args)
localuserboxData=p[funcName](args)
localuserbox=p.render(userboxData)
localcats=p.categories(args)
returnuserbox..(catsor'')
end
functionp._userbox(args)
-- Does argument processing for {{userbox}}.
localdata={}
-- Get div tag values.
data.float=args.floator'left'
localborderWidthNum=checkNum(args['border-width']orargs['border-s'],1)-- Used to calculate width.
data.borderWidth=addSuffix(borderWidthNum,'px')
data.borderColor=args['border-color']orargs['border-c']orargs[1]orargs['id-c']or'#999'
data.width=addSuffix(240-2*borderWidthNum,'px')-- Also used in the table tag.
data.bodyClass=args.bodyclass
-- Get table tag values.
data.backgroundColor=args['info-background']orargs[2]orargs['info-c']or'#eee'
-- Get info values.
data.info=args.infoorargs[4]or"<code>{{{info}}}</code>"
data.infoTextAlign=args['info-a']or'left'
data.infoFontSize=checkNumAndAddSuffix(args['info-size']orargs['info-s'],8,'pt')
data.infoHeight=checkNumAndAddSuffix(args['logo-height']orargs['id-h'],45,'px')
data.infoPadding=args['info-padding']orargs['info-p']or'0 4px 0 4px'
data.infoLineHeight=args['info-line-height']orargs['info-lh']or'1.25em'
data.infoColor=args['info-color']orargs['info-fc']or'black'
data.infoOtherParams=args['info-other-param']orargs['info-op']
data.infoClass=args['info-class']
-- Get id values.
localid=args.logoorargs[3]orargs.id
data.id=id
data.showId=idandtrueorfalse
data.idWidth=checkNumAndAddSuffix(args['logo-width']orargs['id-w'],45,'px')
data.idHeight=checkNumAndAddSuffix(args['logo-height']orargs['id-h'],45,'px')
data.idBackgroundColor=args['logo-background']orargs[1]orargs['id-c']or'#ddd'
data.idTextAlign=args['id-a']or'center'
data.idFontSize=checkNum(args['logo-size']orargs[5]orargs['id-s'],14)
data.idColor=args['logo-color']orargs['id-fc']ordata.infoColor
data.idPadding=args['logo-padding']orargs['id-p']or'0 1px 0 0'
data.idLineHeight=args['logo-line-height']orargs['id-lh']or'1.25em'
data.idOtherParams=args['logo-other-param']orargs['id-op']
data.idClass=args['id-class']
returndata
end
p['_userbox-2']=function(args)
-- Does argument processing for {{userbox-2}}.
localdata={}
-- Get div tag values.
data.float=args.floator'left'
localborderWidthNum=checkNum(args['border-s']orargs[9],1)-- Used to calculate width.
data.borderWidth=addSuffix(borderWidthNum,'px')
data.borderColor=args['border-c']orargs[6]orargs['id1-c']orargs[1]or'#999999'
data.width=addSuffix(240-2*borderWidthNum,'px')-- Also used in the table tag.
data.bodyClass=args.bodyclass
-- Get table tag values.
data.backgroundColor=args['info-c']orargs[2]or'#eeeeee'
-- Get info values.
data.info=args.infoorargs[4]or"<code>{{{info}}}</code>"
data.infoTextAlign=args['info-a']or'left'
data.infoFontSize=checkNumAndAddSuffix(args['info-s'],8,'pt')
data.infoColor=args['info-fc']orargs[8]or'black'
data.infoPadding=args['info-p']or'0 4px 0 4px'
data.infoLineHeight=args['info-lh']or'1.25em'
data.infoOtherParams=args['info-op']
-- Get id values.
data.showId=true
data.id=args.logoorargs[3]orargs.id1or'id1'
data.idWidth=checkNumAndAddSuffix(args['id1-w'],45,'px')
data.idHeight=checkNumAndAddSuffix(args['id-h'],45,'px')
data.idBackgroundColor=args['id1-c']orargs[1]or'#dddddd'
data.idTextAlign='center'
data.idFontSize=checkNum(args['id1-s'],14)
data.idLineHeight=args['id1-lh']or'1.25em'
data.idColor=args['id1-fc']ordata.infoColor
data.idPadding=args['id1-p']or'0 1px 0 0'
data.idOtherParams=args['id1-op']
-- Get id2 values.
data.showId2=true
data.id2=args.logoorargs[5]orargs.id2or'id2'
data.id2Width=checkNumAndAddSuffix(args['id2-w'],45,'px')
data.id2Height=data.idHeight
data.id2BackgroundColor=args['id2-c']orargs[7]orargs[1]or'#dddddd'
data.id2TextAlign='center'
data.id2FontSize=checkNum(args['id2-s'],14)
data.id2LineHeight=args['id2-lh']or'1.25em'
data.id2Color=args['id2-fc']ordata.infoColor
data.id2Padding=args['id2-p']or'0 0 0 1px'
data.id2OtherParams=args['id2-op']
returndata
end
p['_userbox-r']=function(args)
-- Does argument processing for {{userbox-r}}.
localdata={}
-- Get div tag values.
data.float=args.floator'left'
localborderWidthNum=checkNum(args['border-width']orargs['border-s'],1)-- Used to calculate width.
data.borderWidth=addSuffix(borderWidthNum,'px')
data.borderColor=args['border-color']orargs['border-c']orargs[1]orargs['id-c']or'#999'
data.width=addSuffix(240-2*borderWidthNum,'px')-- Also used in the table tag.
data.bodyClass=args.bodyclass
-- Get table tag values.
data.backgroundColor=args['info-background']orargs[2]orargs['info-c']or'#eee'
-- Get id values.
data.showId=false-- We only show id2 in userbox-r.
-- Get info values.
data.info=args.infoorargs[4]or"<code>{{{info}}}</code>"
data.infoTextAlign=args['info-align']orargs['info-a']or'left'
data.infoFontSize=checkNumAndAddSuffix(args['info-size']orargs['info-s'],8,'pt')
data.infoPadding=args['info-padding']orargs['info-p']or'0 4px 0 4px'
data.infoLineHeight=args['info-line-height']orargs['info-lh']or'1.25em'
data.infoColor=args['info-color']orargs['info-fc']or'black'
data.infoOtherParams=args['info-other-param']orargs['info-op']
-- Get id2 values.
data.showId2=true
data.id2=args.logoorargs[3]orargs.idor'id'
data.id2Width=checkNumAndAddSuffix(args['logo-width']orargs['id-w'],45,'px')
data.id2Height=checkNumAndAddSuffix(args['logo-height']orargs['id-h'],45,'px')
data.id2BackgroundColor=args['logo-background']orargs[1]orargs['id-c']or'#ddd'
data.id2TextAlign=args['id-a']or'center'
data.id2FontSize=checkNum(args['logo-size']orargs[5]orargs['id-s'],14)
data.id2Color=args['logo-color']orargs['id-fc']ordata.infoColor
data.id2Padding=args['logo-padding']orargs['id-p']or'0 0 0 1px'
data.id2LineHeight=args['logo-line-height']orargs['id-lh']or'1.25em'
data.id2OtherParams=args['logo-other-param']orargs['id-op']
returndata
end
functionp.render(data)
-- Renders the userbox html using the content of the data table. 
-- Render the div tag html.
localroot=mw.html.create('div')
root
:css('float',data.float)
:css('border',(data.borderWidthor'')..' solid '..(data.borderColoror''))
:css('margin','1px')
:css('width',data.width)
:addClass('wikipediauserbox')
:addClass(data.bodyClass)
-- Render the table tag html.
localtableroot=root:tag('table')
tableroot
:attr('role','presentation')
:css('border-collapse','collapse')
:css('width',data.width)
:css('margin-bottom','0')
:css('margin-top','0')
:css('background',data.backgroundColor)
:css('color','inherit')
-- Render the id html.
localtablerow=tableroot:tag('tr')
ifdata.showIdthen
tablerow:tag('td')
:css('border','0')
:css('width',data.idWidth)
:css('height',data.idHeight)
:css('background',data.idBackgroundColor)
:css('text-align',data.idTextAlign)
:css('font-size',data.idFontSize..'pt')
:css('font-weight','bold')
:css('color',data.idColor)
:css('padding',data.idPadding)
:css('line-height',data.idLineHeight)
:css('vertical-align','middle')
:cssText(data.idOtherParams)
:addClass(data.idClass)
:wikitext(data.id)
end
-- Render the info html.
tablerow:tag('td')
:css('border','0')
:css('text-align',data.infoTextAlign)
:css('font-size',data.infoFontSize)
:css('padding',data.infoPadding)
:css('height',data.infoHeight)
:css('line-height',data.infoLineHeight)
:css('color',data.infoColor)
:css('vertical-align','middle')
:cssText(data.infoOtherParams)
:addClass(data.infoClass)
:wikitext(data.info)
-- Render the second id html.
ifdata.showId2then
tablerow:tag('td')
:css('border','0')
:css('width',data.id2Width)
:css('height',data.id2Height)
:css('background',data.id2BackgroundColor)
:css('text-align',data.id2TextAlign)
:css('font-size',data.id2FontSize..'pt')
:css('font-weight','bold')
:css('color',data.id2Color)
:css('padding',data.id2Padding)
:css('line-height',data.id2LineHeight)
:css('vertical-align','middle')
:cssText(data.id2OtherParams)
:wikitext(data.id2)
end
localtitle=mw.title.getCurrentTitle()
if(title.namespace==2)andnottitle.text:match("/")then
returntostring(root)-- regular user page
elseiftitle.namespace==14then
returntostring(root)-- category
elseiftitle.isTalkPagethen
returntostring(root)-- talk page
end
locallegible=true
localcontrast=require('Module:Color contrast')._ratio
localfunctionhas_text(wikitext)
wikitext=wikitext:gsub("]]","|]]")
wikitext=wikitext:gsub("%[%[%s*[Mm][Ee][Dd][Ii][Aa]%s*:[^|]-(|.-)]]","")
wikitext=wikitext:gsub("%[%[%s*[Ii][Mm][Aa][Gg][Ee]%s*:[^|]-(|.-)]]","")
wikitext=wikitext:gsub("%[%[%s*[Ff][Ii][Ll][Ee]%s*:[^|]-(|.-)]]","")
returnmw.text.trim(wikitext)~=""
end
ifcontrast{data.infoColor,data.backgroundColor,error=0}<4.5then
legible=false
end
-- For bold text >= 14pt, requirement is only 3.
localidContrastThreshold=4.5
localid2ContrastThreshold=4.5
if(data.idFontSizeor0)>=14then
idContrastThreshold=3
end
if(data.id2FontSizeor0)>=14then
id2ContrastThreshold=3
end
ifdata.showIdandcontrast{data.idColor,data.idBackgroundColor,error=0}<idContrastThresholdthen
ifhas_text(data.idor"")then
legible=false
end
end
ifdata.showId2andcontrast{data.id2Color,data.id2BackgroundColor,error=0}<id2ContrastThresholdthen
ifhas_text(data.id2or"")then
legible=false
end
end
ifnotlegiblethen
root:wikitext('[[Category:Userboxes with insufficient color contrast]]')
end
returntostring(root)
end
functionp.categories(args,page)
-- Gets categories from [[Module:Category handler]].
-- The page parameter makes the function act as though the module was being called from that page.
-- It is included for testing purposes.
localcats={}
cats[#cats+1]=args.usercategory
cats[#cats+1]=args.usercategory2
cats[#cats+1]=args.usercategory3
cats[#cats+1]=args.usercategory4
cats[#cats+1]=args.usercategory5
-- Get the title object
localtitle
ifpagethen
title=mw.title.new(page)
else
title=mw.title.getCurrentTitle()
end
-- Build category handler arguments.
localchargs={}
chargs.page=page
chargs.nocat=args.nocat
chargs.main='[[Category:Pages with templates in the wrong namespace]]'
ifargs.notcatsubpagesthen
chargs.subpage='no'
end
-- User namespace.
localuser=''
fori,catinipairs(cats)do
user=user..makeCat(cat)
end
chargs.user=user
-- Template namespace.
localbasepage=title.baseText
localtemplate=''
fori,catinipairs(cats)do
template=template..makeCat(cat,' '..basepage)
end
chargs.template=template
returncategoryHandler(chargs)
end
returnp
Konten disalin dari Wikipedia Bahasa Indonesia (lisensi CC BY-SA) Lihat versi asli di Wikipedia

Rekomendasi Pilihan