跳转到内容

模組:LinkTools

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

这是本页的一个历史版本,由A2569875留言 | 贡献2021年10月16日 (六) 09:34 建立内容为“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…”的新页面)编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)
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 display == '' then display = ((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