Jump to content

Module:Lua banner

Permanently protected module
From Wikipedia, the free encyclopedia

-- This module implements the {{lua}} template.
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