跳转到内容

模組:DYKCount

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

这是本页的一个历史版本,由A2569875留言 | 贡献2020年3月4日 (三) 05:02编辑。这可能和当前版本存在着巨大的差异。

local p={}
local lib_var={};

function p.find_dyk_edit(frame) 
	local pattern = "{{%s*DYKEntry%s*|.-timestamp%s*="
	if lib_var._arg_process == nil then lib_var = require('Module:Var') end
	local args, working_frame = lib_var._arg_process(frame)
    local title = args[1] or args['1']
    local offset = tonumber(args[2] or args['2'] or '0') or 0
    title = mw.title.new( args[1], '')
    if title then
    	local wikitext = title:getContent()
    	wikitext = mw.text.decode(wikitext)
    	local _,count = mw.ustring.gsub(wikitext, pattern, '')
    	local h_id = count + 1 + offset
    	return title:fullUrl( {action='edit',section=h_id}, 'relative' )
    end
    return ''
end

function p.find_dyk_edit2(frame) 
	local pattern = "\127'\"`UNIQ%-%-h%-(%d+)%-%-QINU`\"'\127"
	if lib_var._arg_process == nil then lib_var = require('Module:Var') end
	local args, working_frame = lib_var._arg_process(frame)
    local title = args[1] or args['1']
    local offset = tonumber(args[2] or args['2'] or '0') or 0
    title = mw.title.new( args[1], '')
    if title then
    	local wikitext = title:getContent()
    	wikitext = mw.text.decode(wikitext)
    	wikitext = mw.ustring.gsub(wikitext, '[%[%{%}%]]', '')
    	local avoid_r = working_frame:newChild{ title = title.fullText, args = {} }
    	local checker = avoid_r:preprocess( "== ~ ==\n\n" .. wikitext )
    	local max_id, min_id = 0, -1
    	mw.ustring.gsub(checker, pattern, function(h_id)
    		local h_idx = tonumber(h_id)
    		if h_idx then
    			if h_idx > max_id then max_id = h_idx end
    			if min_id < 0 or h_idx < max_id then min_id = h_idx end
    		end
    		
    	end)
		return title:fullUrl( {action='edit',section=(max_id + offset - min_id)}, 'relative' )
    end
    return ''
end

function p.getDYKCount(frame)
	if lib_var._arg_process == nil then lib_var = require('Module:Var') end
	local args, working_frame = lib_var._arg_process(frame)
    local input_n = mw.text.trim(args[1] or args['1'] or '')
	local src = working_frame:preprocess{ text = "{{msgnw:" .. input_n .. "}}" }
	local st,ed = mw.ustring.find(src, "&#123;&#123;%s-[Pp]roduceEncouragement%s-&#124;%s-count%s-&#61;%s-%d+%s-&#125;&#125;" );
	if st then
		local dyk_template = mw.ustring.sub(src, st,ed)
		st,ed = mw.ustring.find(dyk_template, "count%s-&#61;%s-%d+" )
		dyk_template = mw.text.decode(mw.ustring.sub(dyk_template, st,ed))
		st,ed = mw.ustring.find(dyk_template, "%d+" )
		local dyk_count = mw.ustring.sub(dyk_template, st,ed)
		return dyk_count;
	else
		return 0;
	end
end
return p;