Jump to content

Module:Lockbox/sandbox: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
use the parent frame title instead of the current title
don't transclude the current page - there should already be a transclusion from the lockbox from using #invoke there
Line 19: Line 19:
-- check if the transcluding page is cascade-protected
-- check if the transcluding page is cascade-protected
-- XXX: unfortunately there is no other way; title.protectionLevels does not report cascading protection status
-- 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]]
do
do
local parent_title = frame:getParent():getTitle()
local parent_title = frame:getParent():getTitle()

Revision as of 00:49, 17 March 2017

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 transcluding page is cascade-protected
	-- XXX: unfortunately there is no other way; title.protectionLevels does not report cascading protection status
	do
		local parent_title = frame:getParent():getTitle()
		if frame:preprocess("{{CASCADINGSOURCES:" .. parent_title .. "}}") == "" then
			output[#output + 1] = '<strong class="warning">Warning: the page "' .. parent_title .. '" is not cascade-protected.</strong>\n'
		end
	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)
			output[#output + 1] = '* [[Template:' .. item .. ']]'
		elseif (ns == "File") or (ns == "Image") then
			generate_transclusion(item)
			output[#output + 1] = '* [[:' .. item .. ']]'
		elseif ns == "Category" then
			generate_transclusion(item)
			output[#output + 1] = '* [[:' .. item .. ']]'
		elseif rest ~= '' then
			generate_transclusion(item)
			output[#output + 1] = '* [[' .. item .. ']]'
		end
	end

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

return export