Module:Lockbox
Appearance
![]() | This module can only be edited by administrators because it is transcluded onto one or more cascade-protected pages. |
This module transcludes templates whose names have been given as parameters in order to trigger cascade protection.
Usage
{{#invoke:lockbox|lock|silent=1 | X1 | X2 | X3 | ... }}
See also
local export = {}
-- XXX: OUTRAGEOUS ABUSE OF SCRIBUNTO API
-- generates a transclusion without incrementing the "expensive function" count
local generate_transclusion
do
local mock_title = mw.title.new(mw.title.getCurrentTitle().id)
local getContent = mock_title.getContent
function generate_transclusion(title)
rawset(mock_title, 'fullText', title)
getContent(mock_title)
end
-- I can do the same thing without rawset.
end
function export.lock(frame)
local output = {}
-- check if the current page is cascade-protected
-- XXX: unfortunately there is no other way; title.protectionLevels does not report cascading protection status
mw.title.getCurrentTitle():getContent() -- self-transclude; see [[mw:Extension:Scribunto/Lua reference manual#Title objects]]
if frame:preprocess "{{CASCADINGSOURCES}}" == "" then
table.insert(output, '<strong class="warning">Warning: this page (' .. mw.title.getCurrentTitle().fullText .. ') is not cascade-protected.</strong>\n')
end
local match = string.match
for _, item in ipairs(frame.args) do
item = mw.text.trim(item)
local ns, rest = match(item, "^(.-):(.*)")
if not ns or not mw.site.namespaces[ns] then
generate_transclusion('Template:' .. item)
table.insert(output, '* [[Template:' .. item .. ']]\n')
elseif (ns == "File") or (ns == "Image") then
generate_transclusion(item)
table.insert(output, '* [[:' .. item .. ']]\n')
elseif ns == "Category" then
generate_transclusion(item)
table.insert(output, '* [[:' .. item .. ']]\n')
elseif rest ~= '' then
generate_transclusion(item)
table.insert(output, '* [[' .. item .. ']]\n')
end
end
if frame.args.silent then
return ""
else
return table.concat(output)
end
end
return export