Module:Lua banner/sandbox
Appearance
From Wikipedia, the free encyclopedia
This is the module sandbox page for Module:Lua banner (diff).
See also the companion subpage for test cases.
See also the companion subpage for test cases.
Warning This Lua module is used on approximately 11,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them.
This module depends on the following other modules:
This module implements the {{lua }} template.
Usage from wikitext
[edit ]This module cannot be used directly from wikitext. It can only be used through the {{lua }} template. Please see the template page for documentation.
Usage from Lua modules
[edit ]To use this module from other Lua modules, first load the module.
localmLuaBanner=require('Module:Lua banner')
You can then generate a side box using the _main function.
mLuaBanner._main(args)
The args variable should be a table containing the arguments to pass to the module. To see the different arguments that can be specified and how they affect the module output, please refer to the {{lua }} template documentation.
Tracking category
[edit ]The above documentation is transcluded from Module:Lua banner/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit) pages.
Add categories to the /doc subpage. Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit) pages.
Add categories to the /doc subpage. Subpages of this module.
localyesno=require('Module:Yesno') localmList=require('Module:List') localmTableTools=require('Module:TableTools') localmMessageBox=require('Module:Message box') localp={} functionp.main(frame) localorigArgs=frame:getParent().args localargs={} fork,vinpairs(origArgs)do v=v:match('^%s*(.-)%s*$') ifv~=''then args[k]=v end end returnp._main(args) end functionp._main(args) localmodules=mTableTools.compressSparseArray(args) localbox=p.renderBox(modules) localtrackingCategories=p.renderTrackingCategories(args,modules) returnbox..trackingCategories end functionp.renderBox(modules) localboxArgs={} if#modules<1then boxArgs.text='<strong class="error">Error: no modules specified</strong>' else localmoduleLinks={} fori,moduleinipairs(modules)do moduleLinks[i]=string.format('[[:%s]]',module) localmaybeSandbox=mw.title.new(module..'/sandbox') ifmaybeSandboxandmaybeSandbox.existsthen moduleLinks[i]=moduleLinks[i]..string.format(' ([[:%s|sandbox]])',maybeSandbox.fullText) end end localmoduleList=mList.makeList('bulleted',moduleLinks) localtitle=mw.title.getCurrentTitle() iftitle.subpageText=="doc"then title=title.basePageTitle end iftitle.contentModel=="Scribunto"then boxArgs.text='This module depends on the following other modules:'..moduleList else boxArgs.text='This template uses [[Wikipedia:Lua|Lua]]:\n'..moduleList end end boxArgs.type='notice' boxArgs.small=true boxArgs.image='[[File:Lua-Logo.svg|30px|alt=|link=]]' returnmMessageBox.main('mbox',boxArgs) end functionp.renderTrackingCategories(args,modules,titleObj) ifyesno(args.nocat)then return'' end localcats={} -- Error category if#modules<1then cats[#cats+1]='Lua templates with errors' end -- Lua templates category titleObj=titleObjormw.title.getCurrentTitle() localsubpageBlacklist={ doc=true, sandbox=true, sandbox2=true, testcases=true } ifnotsubpageBlacklist[titleObj.subpageText]then localprotCatName iftitleObj.namespace==10then localcategory=args.category ifnotcategorythen localcategories={ ['Module:String']='Templates based on the String Lua module', ['Module:Math']='Templates based on the Math Lua module', ['Module:BaseConvert']='Templates based on the BaseConvert Lua module', ['Module:Citation/CS1']='Templates based on the Citation/CS1 Lua module' } category=modules[1]andcategories[modules[1]] category=categoryor'Lua-based templates' end cats[#cats+1]=category protCatName="Templates using under-protected Lua modules" elseiftitleObj.namespace==828then protCatName="Modules depending on under-protected modules" end ifnotargs.noprotcatandprotCatNamethen localprotLevels={ autoconfirmed=1, extendedconfirmed=2, templateeditor=3, sysop=4 } localcurrentProt iftitleObj.id~=0then -- id is 0 (page does not exist) if am previewing before creating a template. currentProt=titleObj.protectionLevels["edit"][1] end ifcurrentProt==nilthencurrentProt=0elsecurrentProt=protLevels[currentProt]end fori,moduleinipairs(modules)do ifmodule~="WP:libraryUtil"then localmoduleTitle=mw.title.new(module) localmoduleProt=moduleTitleandmoduleTitle.protectionLevels["edit"][1] ifmoduleProt==nilthenmoduleProt=0elsemoduleProt=protLevels[moduleProt]end ifmoduleProt<currentProtthen cats[#cats+1]=protCatName break end end end end end fori,catinipairs(cats)do cats[i]=string.format('[[Category:%s]]',cat) end returntable.concat(cats) end returnp