Module:Lua banner: Difference between revisions
Appearance
pc>Rob Kam m 1 revision imported |
m 1 revision imported Tags: Mobile edit Mobile web edit |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
-- This module implements the {{lua}} template. | -- This module implements the {{lua}} template. | ||
local yesno = require('Module:Yesno') | local yesno = require('Module:Yesno') | ||
local mList = require('Module:List') | local mList = require('Module:List') | ||
Line 35: | Line 36: | ||
moduleLinks[i] = string.format('[[:%s]]', module) | moduleLinks[i] = string.format('[[:%s]]', module) | ||
local maybeSandbox = mw.title.new(module .. '/sandbox') | local maybeSandbox = mw.title.new(module .. '/sandbox') | ||
if maybeSandbox.exists then | if maybeSandbox and maybeSandbox.exists then | ||
moduleLinks[i] = moduleLinks[i] .. string.format(' ([[:%s|sandbox]])', maybeSandbox.fullText) | moduleLinks[i] = moduleLinks[i] .. string.format(' ([[:%s|sandbox]])', maybeSandbox.fullText) | ||
end | end | ||
Line 52: | Line 53: | ||
boxArgs.type = 'notice' | boxArgs.type = 'notice' | ||
boxArgs.small = true | boxArgs.small = true | ||
boxArgs.image = '[[File:Lua- | boxArgs.image = '[[File:Lua-Logo.svg|30px|alt=|link=]]' | ||
return mMessageBox.main('mbox', boxArgs) | return mMessageBox.main('mbox', boxArgs) | ||
end | end | ||
Line 76: | Line 77: | ||
testcases = true | testcases = true | ||
} | } | ||
if not subpageBlacklist[titleObj.subpageText] then | if not subpageBlacklist[titleObj.subpageText] then | ||
local protCatName | local protCatName | ||
Line 82: | Line 84: | ||
if not category then | if not category then | ||
local categories = { | local categories = { | ||
['Module:String'] = 'Lua | ['Module:String'] = 'Templates based on the String Lua module', | ||
['Module:Math'] = 'Templates based on the Math Lua module', | ['Module:Math'] = 'Templates based on the Math Lua module', | ||
['Module:BaseConvert'] = 'Templates based on the BaseConvert Lua module', | ['Module:BaseConvert'] = 'Templates based on the BaseConvert Lua module', | ||
['Module:Citation'] = 'Lua | ['Module:Citation/CS1'] = 'Templates based on the Citation/CS1 Lua module' | ||
} | } | ||
category = modules[1] and categories[modules[1]] | category = modules[1] and categories[modules[1]] | ||
category = category or 'Lua-based templates' | category = category or 'Lua-based templates' | ||
Line 96: | Line 97: | ||
protCatName = "Modules depending on under-protected modules" | protCatName = "Modules depending on under-protected modules" | ||
end | end | ||
if not args.noprotcat and protCatName then | if not args.noprotcat and protCatName then | ||
local protLevels = { | local protLevels = { | ||
Line 105: | Line 107: | ||
local currentProt | local currentProt | ||
if titleObj.id ~= 0 then | if titleObj.id ~= 0 then | ||
-- | -- check protection level only if page exists | ||
if titleObj.protectionLevels and titleObj.protectionLevels["edit"] then | |||
currentProt = titleObj.protectionLevels["edit"][1] | |||
end | |||
end | end | ||
if currentProt == nil then currentProt = 0 else currentProt = protLevels[currentProt] end | if currentProt == nil then currentProt = 0 else currentProt = protLevels[currentProt] end | ||
for i, module in ipairs(modules) do | for i, module in ipairs(modules) do | ||
if module ~= "WP:libraryUtil" then | if module ~= "WP:libraryUtil" then | ||
local | local moduleTitle = mw.title.new(module) | ||
local moduleProt | |||
if moduleTitle and moduleTitle.protectionLevels and moduleTitle.protectionLevels["edit"] then | |||
moduleProt = moduleTitle.protectionLevels["edit"][1] | |||
end | |||
if moduleProt == nil then moduleProt = 0 else moduleProt = protLevels[moduleProt] end | if moduleProt == nil then moduleProt = 0 else moduleProt = protLevels[moduleProt] end | ||
if moduleProt < currentProt then | if moduleProt < currentProt then | ||
Line 121: | Line 130: | ||
end | end | ||
end | end | ||
for i, cat in ipairs(cats) do | for i, cat in ipairs(cats) do | ||
cats[i] = string.format('[[Category:%s]]', cat) | cats[i] = string.format('[[Category:%s]]', cat) |