Title: Module:Uses TemplateStyles - freem URL Source: https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles Markdown Content: From freem _Documentation for this module may be created at [Module:Uses TemplateStyles/doc](https://freemwiki.com/index.php?title=Module:Uses\_TemplateStyles/doc&action=edit&redlink=1 "Module:Uses TemplateStyles/doc (page does not exist)")_ [](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-1)local yesno = require(['Module:Yesno'](https://freemwiki.com/wiki/Module:Yesno))[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-2)local mList = require(['Module:List'](https://freemwiki.com/wiki/Module:List))[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-3)local mTableTools = require(['Module:TableTools'](https://freemwiki.com/wiki/Module:TableTools))[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-4)local mMessageBox = require(['Module:Message box'](https://freemwiki.com/wiki/Module:Message_box))[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-5)local TNT = require(['Module:TNT'](https://freemwiki.com/wiki/Module:TNT))[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-6)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-7)local p = {}[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-8)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-9)local function format(msg, ...)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-10)return TNT.format('I18n/Uses TemplateStyles', msg, ...)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-11)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-12)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-13)local function getConfig()[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-14)return mw.loadData(['Module:Uses TemplateStyles/config'](https://freemwiki.com/wiki/Module:Uses_TemplateStyles/config))[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-15)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-16)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-17)local function renderBox(tStyles)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-18)local boxArgs = {[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-19)type = 'notice',[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-20)small = true,[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-21)image = string.format('[[File:Farm-Fresh css add.svg|32px|alt=%s]]', format('logo-alt'))[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-22)}[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-23)if #tStyles < 1 then[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-24)boxArgs.text = string.format('%s', format('error-emptylist'))[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-25)else[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-26)local cfg = getConfig()[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-27)local tStylesLinks = {}[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-28)for i, ts in ipairs(tStyles) do[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-29)local link = string.format('[[:%s]]', ts)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-30)local sandboxLink = nil[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-31)local tsTitle = mw.title.new(ts)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-32)if tsTitle and cfg['sandbox_title'] then[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-33)local tsSandboxTitle = mw.title.new(string.format([](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-34)'%s:%s/%s/%s', tsTitle.nsText, tsTitle.baseText, cfg['sandbox_title'], tsTitle.subpageText))[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-35)if tsSandboxTitle and tsSandboxTitle.exists then[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-36)sandboxLink = format('sandboxlink', link, ':' .. tsSandboxTitle.prefixedText)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-37)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-38)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-39)tStylesLinks[i] = sandboxLink or link[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-40)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-41)local tStylesList = mList.makeList('bulleted', tStylesLinks)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-42)boxArgs.text = format([](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-43)mw.title.getCurrentTitle():inNamespaces(828,829) and 'header-module' or 'header-template') ..[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-44)'\n' .. tStylesList[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-45)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-46)return mMessageBox.main('mbox', boxArgs)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-47)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-48)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-49)local function renderTrackingCategories(args, tStyles, titleObj)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-50)if yesno(args.nocat) then[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-51)return ''[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-52)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-53)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-54)local cfg = getConfig()[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-55)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-56)local cats = {}[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-57)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-58)-- Error category[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-59)if #tStyles < 1 and cfg['error_category'] then[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-60)cats[#cats + 1] = cfg['error_category'][](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-61)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-62)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-63)-- TemplateStyles category[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-64)titleObj = titleObj or mw.title.getCurrentTitle()[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-65)if (titleObj.namespace == 10 or titleObj.namespace == 828)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-66)and not cfg['subpage_blacklist'][titleObj.subpageText][](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-67)then[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-68)local category = args.category or cfg['default_category'][](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-69)if category then[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-70)cats[#cats + 1] = category[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-71)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-72)if not yesno(args.noprotcat) and (cfg['protection_conflict_category'] or cfg['padlock_pattern']) then[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-73)local currentProt = titleObj.protectionLevels["edit"] and titleObj.protectionLevels["edit"][1] or nil[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-74)local addedLevelCat = false[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-75)local addedPadlockCat = false[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-76)for i, ts in ipairs(tStyles) do[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-77)local tsTitleObj = mw.title.new(ts)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-78)local tsProt = tsTitleObj.protectionLevels["edit"] and tsTitleObj.protectionLevels["edit"][1] or nil[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-79)if cfg['padlock_pattern'] and tsProt and not addedPadlockCat then[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-80)local content = tsTitleObj:getContent()[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-81)if not content:find(cfg['padlock_pattern']) then[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-82)cats[#cats + 1] = cfg['missing_padlock_category'][](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-83)addedPadlockCat = true[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-84)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-85)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-86)if cfg['protection_conflict_category'] and currentProt and tsProt ~= currentProt and not addedLevelCat then[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-87)currentProt = cfg['protection_hierarchy'][currentProt] or 0[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-88)tsProt = cfg['protection_hierarchy'][tsProt] or 0[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-89)if tsProt < currentProt then[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-90)addedLevelCat = true[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-91)cats[#cats + 1] = cfg['protection_conflict_category'][](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-92)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-93)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-94)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-95)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-96)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-97)for i, cat in ipairs(cats) do[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-98)cats[i] = string.format('[[Category:%s]]', cat)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-99)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-100)return table.concat(cats)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-101)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-102)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-103)function p._main(args)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-104)local cfg = getConfig()[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-105)if #args == 0 then[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-106)local prefixed = mw.title.getCurrentTitle().prefixedText[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-107)prefixed = prefixed:gsub("/doc","")[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-108)args[1] = prefixed .. "/" .. cfg["default_subpage_name"][](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-109)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-110)local tStyles = mTableTools.compressSparseArray(args)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-111)local box = renderBox(tStyles)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-112)local trackingCategories = renderTrackingCategories(args, tStyles)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-113)return box .. trackingCategories[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-114)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-115)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-116)function p.main(frame)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-117)local origArgs = frame:getParent().args[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-118)local args = {}[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-119)for k, v in pairs(origArgs) do[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-120)v = v:match('^%s*(.-)%s*$')[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-121)if v ~= '' then[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-122)args[k] = v[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-123)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-124)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-125)return p._main(args)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-126)end[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-127)[](https://freemwiki.com/index.php?oldid=579628&title=Module%3AUses_TemplateStyles#L-128)return p