Title: Module:Lua banner - freem URL Source: https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner Markdown Content: From freem Revision as of 02:45, 5 April 2024 by [en>Uzume](https://freemwiki.com/wiki/User:Uzume "en:User:Uzume") _Documentation for this module may be created at [Module:Lua banner/doc](https://freemwiki.com/index.php?title=Module:Lua\_banner/doc&action=edit&redlink=1 "Module:Lua banner/doc (page does not exist)")_ [](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-1)-- This module implements the {{[lua](https://freemwiki.com/wiki/Template:Lua "Template:Lua")}} template.[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-2)local yesno = require(['Module:Yesno'](https://freemwiki.com/wiki/Module:Yesno))[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-3)local mList = require(['Module:List'](https://freemwiki.com/wiki/Module:List))[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-4)local mTableTools = require(['Module:TableTools'](https://freemwiki.com/wiki/Module:TableTools))[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-5)local mMessageBox = require(['Module:Message box'](https://freemwiki.com/wiki/Module:Message_box))[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-6)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-7)local p = {}[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-8)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-9)function p.main(frame)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-10)local origArgs = frame:getParent().args[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-11)local args = {}[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-12)for k, v in pairs(origArgs) do[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-13)v = v:match('^%s*(.-)%s*$')[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-14)if v ~= '' then[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-15)args[k] = v[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-16)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-17)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-18)return p._main(args)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-19)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-20)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-21)function p._main(args)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-22)local modules = mTableTools.compressSparseArray(args)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-23)local box = p.renderBox(modules)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-24)local trackingCategories = p.renderTrackingCategories(args, modules)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-25)return box .. trackingCategories[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-26)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-27)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-28)function p.renderBox(modules)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-29)local boxArgs = {}[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-30)if #modules < 1 then[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-31)boxArgs.text = 'Error: no modules specified'[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-32)else[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-33)local moduleLinks = {}[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-34)for i, module in ipairs(modules) do[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-35)moduleLinks[i] = string.format('[[:%s]]', module)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-36)local maybeSandbox = mw.title.new(module .. '/sandbox')[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-37)if maybeSandbox and maybeSandbox.exists then[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-38)moduleLinks[i] = moduleLinks[i] .. string.format(' ([[:%s|sandbox]])', maybeSandbox.fullText)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-39)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-40)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-41)local moduleList = mList.makeList('bulleted', moduleLinks)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-42)local title = mw.title.getCurrentTitle()[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-43)if title.subpageText == "doc" then[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-44)title = title.basePageTitle[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-45)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-46)if title.contentModel == "Scribunto" then[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-47)boxArgs.text = 'This module depends on the following other modules:' .. moduleList[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-48)else[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-49)boxArgs.text = 'This template uses [[Wikipedia:Lua|Lua]]:\n' .. moduleList[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-50)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-51)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-52)boxArgs.type = 'notice'[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-53)boxArgs.small = true[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-54)boxArgs.image = '[[File:Lua-Logo.svg|30px|alt=|link=]]'[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-55)return mMessageBox.main('mbox', boxArgs)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-56)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-57)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-58)function p.renderTrackingCategories(args, modules, titleObj)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-59)if yesno(args.nocat) then[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-60)return ''[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-61)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-62)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-63)local cats = {}[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-64)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-65)-- Error category[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-66)if #modules < 1 then[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-67)cats[#cats + 1] = 'Lua templates with errors'[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-68)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-69)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-70)-- Lua templates category[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-71)titleObj = titleObj or mw.title.getCurrentTitle()[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-72)local subpageBlacklist = {[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-73)doc = true,[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-74)sandbox = true,[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-75)sandbox2 = true,[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-76)testcases = true[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-77)}[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-78)if not subpageBlacklist[titleObj.subpageText] then[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-79)local protCatName[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-80)if titleObj.namespace == 10 then[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-81)local category = args.category[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-82)if not category then[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-83)local categories = {[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-84)['Module:String'] = 'Templates based on the String Lua module',[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-85)['Module:Math'] = 'Templates based on the Math Lua module',[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-86)['Module:BaseConvert'] = 'Templates based on the BaseConvert Lua module',[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-87)['Module:Citation/CS1'] = 'Templates based on the Citation/CS1 Lua module'[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-88)}[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-89)category = modules[1] and categories[modules[1]][](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-90)category = category or 'Lua-based templates'[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-91)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-92)cats[#cats + 1] = category[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-93)protCatName = "Templates using under-protected Lua modules"[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-94)elseif titleObj.namespace == 828 then[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-95)protCatName = "Modules depending on under-protected modules"[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-96)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-97)if not args.noprotcat and protCatName then[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-98)local protLevels = {[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-99)autoconfirmed = 1,[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-100)extendedconfirmed = 2,[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-101)templateeditor = 3,[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-102)sysop = 4[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-103)}[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-104)local currentProt[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-105)if titleObj.id ~= 0 then[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-106)-- id is 0 (page does not exist) if am previewing before creating a template.[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-107)currentProt = titleObj.protectionLevels["edit"][1][](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-108)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-109)if currentProt == nil then currentProt = 0 else currentProt = protLevels[currentProt] end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-110)for i, module in ipairs(modules) do[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-111)if module ~= "WP:libraryUtil" then[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-112)local moduleTitle = mw.title.new(module)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-113)local moduleProt = moduleTitle and moduleTitle.protectionLevels["edit"][1][](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-114)if moduleProt == nil then moduleProt = 0 else moduleProt = protLevels[moduleProt] end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-115)if moduleProt < currentProt then[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-116)cats[#cats + 1] = protCatName[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-117)break[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-118)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-119)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-120)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-121)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-122)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-123)for i, cat in ipairs(cats) do[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-124)cats[i] = string.format('[[Category:%s]]', cat)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-125)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-126)return table.concat(cats)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-127)end[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-128)[](https://freemwiki.com/index.php?oldid=579895&title=Module%3ALua_banner#L-129)return p