跳转到内容

模組:RedirectCheck

本页使用了标题或全文手工转换
维基百科,自由的百科全书
文档图示 模块文档[查看] [编辑] [历史] [清除缓存]

这个模组的main函数检查一层重定向,如请求页面是一个重定向则返回重定向目标,否则返回页面本身。

local keywords = {
	"重定向",
	"redirect",
	"重新導向"
}
local enlang = mw.language.new("en")

local p = {}

function p.main(frame)
	local pagename = frame
	if type(frame) ~= "string" then
		pagename = frame.args[1]
	end
	local titleobject = mw.title.new(pagename)
	if not titleobject.exists then
		mw.log("Given page does not exist!")
		return pagename
	end
	local pagecontent = enlang:lc(mw.text.trim(titleobject:getContent(),"%n"))
	mw.log("Processed PageContent: " .. pagecontent)
	for _,y in pairs(keywords) do
		local matchresult = pagecontent:match("#" .. y .. " %[%[(%S+)]]")
		if matchresult then return matchresult end
		mw.log("Match " .. y .. " failed")
	end
	return pagename
end

return p