پرش به محتوا

پودمان:Redirect-distinguish

از ویکی‌پدیا، دانشنامهٔ آزاد
توضیحات پودمان[ایجاد] [پاکسازی]
local mHatnote = require('Module:Hatnote')
local mHatlist = require('Module:Hatnote list')
local mArguments --initialize lazily
local mTableTools = require('Module:TableTools')
local p = {}

function p.redirectDistinguish (frame)
	mArguments = require('Module:Arguments')
	local args = mArguments.getArgs(frame)
	return p._redirectDistinguish(args)
end

function p._redirectDistinguish(args)
	if not args[1] then
		return mHatnote.makeWikitextError(
			'تغییرمسیری مشخص نشده‌است',
			'الگو:تغییرمسیر-تمایز',
			args.category or args['رده']
		)
	end
	local redirectTitle = mw.title.new(args[1])
	local currentTitle = currentTitle or mw.title.getCurrentTitle()
	if
		mw.ustring.match(args[1], '(REDIRECT|تغییر_?مسیر)%d+') or
		args[1] == 'TERM' or
		currentTitle.namespace ~= 0
	then
		--do nothing
	elseif not redirectTitle or not redirectTitle.exists then
		args[1] = args[1] .. '[[رده:تغییرمسیرهای گم‌شده]]'
	elseif not redirectTitle.isRedirect then
		if mw.ustring.find(redirectTitle:getContent(), '#(invoke|درخواست):RfD') then
			args[1] = args[1] ..
				'[[رده:مقاله‌های دارای سرنویس تغییرمسیر تحت تأثیر نبح]]'
		else
			args[1] = args[1] ..
				'[[رده:مقاله‌های دارای سرنویس تغییرمسیر نیازمند بازبینی]]'
		end
	end
	if not args[2] then
		return mHatnote.makeWikitextError(
			'صفحه‌ای که نیازمند تمیز دادن باشد مشخص نشده‌است',
			'الگو:تغییرمسیر-تمایز',
			args.category or args['رده']
		)
	end
	args = mTableTools.compressSparseArray(args)
	--Assignment by removal here makes for convenient concatenation later
	local redirect = table.remove(args, 1)
	local text = mw.ustring.format(
		'«%s» به اینجا تغییر مسیر دارد. با %s اشتباه نشود.',
		redirect,
		mHatlist.orList(args, true)
	)
	return mHatnote._hatnote(text)
end

return p