跳转到内容

模組:LinkTools

被永久保护的模块
维基百科,自由的百科全书

这是本页的一个历史版本,由Xiplus-abot留言 | 贡献2022年7月15日 (五) 20:51 (已保护“Module:LinkTools”:​高風險模板:728引用<!-- 機器人3 -->([编辑=仅允许自动确认用户](无限期)[移动=仅允许自动确认用户](无限期)))编辑。这可能和当前版本存在着巨大的差异。

local p={}
--{{#invoke:LinkTools|navRedirect}}
function p.navRedirect(frame)
    local args, working_frame
    if frame == mw.getCurrentFrame() then
        -- We're being called via #invoke. The args are passed through to the module
        -- from the template page, so use the args that were passed into the template.
        args = frame.args
        working_frame = frame
    else
        -- We're being called from another module or from the debug console, so assume
        -- the args are passed in directly.
        args = frame
        working_frame = mw.getCurrentFrame()
        if type(args) ~= type({}) then args = {frame} end
    end
    local title = mw.text.trim(args[1] or args['1'] or '')
    local display = mw.text.trim(args[2] or args['2'] or '')
    local title_obj = mw.title.new(title)
    local title_target = title_obj
    local section = ''
    local title_sp = mw.text.trim(mw.ustring.sub(title, (({mw.ustring.find(title, '#')})[1]or 0)+1, -1) or '')
    if title_obj then
	    if  title_obj.isRedirect then
	    	title_target = title_obj.redirectTarget
	    end
	    if mw.text.trim(display) == '' then display = ((mw.text.trim(title_sp) == '') and title or title_sp) end
	    section = mw.text.trim(title_target.fragment or '')
	    local cur_title = mw.title.getCurrentTitle()
	    if (cur_title.namespace == title_target.namespace) and (cur_title.text == title_target.text)then
	    	local section_text = ''
	    	local section_name = mw.text.trim(title_target.fragment or '')
	    	if section_name ~= '' then
	    		section_text = "([[#" .. section_name .. "|章節]])"
	    	end
	    	return "'''"..display.."'''"..section_text
	    end
	    return "[["..title.."|"..display.."]]"
	else return ''
	end
end
return p