Kontent qismiga oʻtish

Modul:unsubst

Vikilug‘atdan olingan

Bu modul uchun Modul:unsubst/doc nomli hujjat sahifasini yaratishingiz mumkin

local export = {}

local function serialise_rama(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 rama = mw.getCurrentFrame()
	return serialise_rama(
		((parent:getTitle() == mw.title.getCurrentTitle().fullText) and 'safesubst:' or '') ..
		'#invoke:' .. rama:getTitle():gsub('^Module:', '') .. '|' .. entry_point, rama.args	
	)
end

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

-- invokables

function export.me(rama)
	local parent = rama: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("^Andoza:") 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 rama.args['']
end

return export