模組:Soft redirect

维基百科,自由的百科全书
文档图示 模块文档[创建]
local p = {}
local yesno = require('Module:Yesno')
local function errmsg (msg)
	return require('Module:Error').error{[1] = '[[Module:Soft_redirect]]錯誤:' .. msg}
end

p.namespaceCategory = {
	 [2] = '用户页软重定向',-- User
	 [3] = '用户页软重定向'--User talk
}

local function makecat (cat)
	return '[[Category:' .. cat .. ']]\n'
end

function main (args, frame)
	if not args[1] then
		return errmsg('沒有任何軟-{zh-hans:重定向;zh-hant:重新導向;}-目標')
	end
	local wt = {'-{H|zh-hans:用户页软重定向;zh-hant:用戶頁軟重新導向;zh-tw:使用者頁面軟重新導向;}--{H|zh-hans:重定向;zh-hant:重新導向;}-'}
	-- 照片
	table.insert( wt, '[[' .. (args['file'] or args['image'] or 'File:Softredirarrow.svg') .. '|64px|alt=' .. ( args['text'] or '軟重定向') .. '|link=]]' )
	-- 輸入頁面
	local pages = ''
	while true do
        page = args[i]
        if (page) then
        	if page == '' then else
        		if pages == ''  then
        			pages = '[[:' .. page:gsub('^:', '') .. ']]'
        		else
        			pages = pages .. ' or [[:' .. page:gsub('^:', '') .. ']]'
        		end
			end
			i = i +1
		else
			break
        end
    end
	table.insert( wt, '<span class="redirectText" id="softredirect">' .. table.concat(pages) .. '</span><br />' )
	-- 提示文字
	table.insert( wt, '<span style="font-size:small; padding-left:52px;" dir="ltr">本頁面為' .. (args['type'] or '') .. '[[Wikipedia:软重定向|软重定向]]</span>' )
	-- 分類
	local cat = { makecat('所有软重定向页面') }
	local ns = mw.title.getCurrentTitle().namespace
	if p.namespaceCategory[ns] then
		table.insert( cat, makecat(p.namespaceCategory[ns]) )
	end
	if args['category'] then
		table.insert( cat, makecat(args['category']) )
	end
	if args['cat'] then
		table.insert( cat, makecat(args['cat']) )
	end
	table.insert( wt, table.concat( cat ) )
	return frame:preprocess( table.concat( wt ) )
end

function p.main(frame)
	local args = {}
	if yesno(args['parent']) then
		args = frame:getParent().args
	else
		args = frame.args
	end
    return main(args, frame)
end

return p