မာတိကာသို့ ခုန်သွားရန်

မော်ဂျူး:unsubst

အဝ်ႏ ဝိစ်သိဉ်နရီ ကို

Documentation for this module may be created at မော်ဂျူး:unsubst/doc

local export = {}

local function serialise_frame(title, args)
	local result = { "{{", title }
	
	for i, value in ipairs(args) do
		if value:find("=") then
			value = i .. "=" .. value
		end
		table.insert(result, "|" .. value)
	end
	
	for key, value in pairs(args) do
		if type(key) == "string" then
			table.insert(result, "|" .. key .. "=" .. value)
		end
	end
	
	table.insert(result, "}}")
	return table.concat(result)
end

function export.unsubst_module(entry_point)
	local frame = mw.getCurrentFrame()
	return serialise_frame(
		((parent:getTitle() == mw.title.getCurrentTitle().fullText) and 'safesubst:' or '') ..
		'#invoke:' .. frame:getTitle():gsub('^Module:', '') .. '|' .. entry_point, frame.args	
	)
end

function export.unsubst_template(entry_point)
	local frame = mw.getCurrentFrame()
	local parent = frame:getParent()
	if parent:getTitle() == mw.title.getCurrentTitle().fullText then
		return serialise_frame('safesubst:#invoke:' .. frame:getTitle():gsub('^Module:', '') .. '|' .. entry_point, frame.args)
	end
	return serialise_frame(parent:getTitle():gsub('^Template:', ''), parent.args)
end

-- invokables

function export.me(frame)
	local parent = frame:getParent()

	if mw.isSubsting() then
		return export.unsubst_template('me')
	end

	-- "manual substitution"?
	if not frame.args.nocheck then
		if (frame ~= parent) and not parent:getTitle():find("^Template:") then
			return '<strong class="error">It appears that you have copied template code from a template page. ' ..
				'You should transclude the template instead, by putting its name in curly brackets, like so: ' ..
				'<code>{{template-name}}</code>.</strong>' -- XXX: maintenance category?
		end
	end

	return frame.args['']
end

return export