Jump to content

Module:Lockbox

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Kephir (talk | contribs) at 09:43, 2 August 2014 (trim). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local export = {}

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>')
	end
	
	-- transclude everything, and discard the output
	for _, item in ipairs(frame.args) do
		item = mw.text.trim(item)
		
		-- getContent() on a title object might be cleaner, but getContent() and title objects
		-- are considered "expensive". even though they are probably cheaper than actual transclusion
		frame:expandTemplate { title = item }

		if not item:match(":") then
			item = "Template:" .. item
		elseif item:match("^File:") or item:match("^Image:") then
			-- XXX: leaving this separate just in case it needs special handling
			item = ":" .. item
		elseif item:match("^Category:") then
			item = ":" .. item
		end
		table.insert(output, ('* [[%s]]'):format(item))
	end

	if frame.args.silent then
		return ""
	else
		return table.concat(output, "\n")
	end
end

return export