模組解[] [] [] []

用途一 編輯

呢個模組會自動載入最近嘅刪文討論。

用法 編輯

用法:{{#invoke:AfD log|transcludeRecentLog|''搵最多日數''|''載入最多日數''}}

示例:{{#invoke:AfD log|transcludeRecentLog|365|20}} 由今日起計,搵過去365日(即係一年,除非閏年)嘅刪文討論。但係如果過去365日有超過20日有討論,咁就只載入最近有討論嗰20日。

搵最多日數嘅預設值係90(大約三個月)、載入最多日數嘅預設值係30。例如 {{#invoke:AfD log|transcludeRecentLog||5}} 會搵最近5版討論,但係最多只追溯90日。

用途二 編輯

擺喺{{AfdCalendar}}入面,自動搵最近嘅討論紀錄。

用法 編輯

用法:{{#invoke:AfD log|tabulateRecentLog}}

睇埋 編輯

local m = {}

local function transclude(frame, pageName, args)
	return frame:expandTemplate{title = pageName, args = args}
end

--copied from [[mw:Module:Archive list]], see attribution there
local function checkPageExists( title )
    if not title then
        error('No title passed to checkPageExists', 2)
    end
    local noError, titleObject = pcall(mw.title.new, title)
    if not noError then
        -- If we are over the expensive function limit then assume
        -- that the page doesn't exist.
        return false
    else
        if titleObject then
            return titleObject.exists
        else
            return false -- Return false if given a bad title.
        end
    end
end

function m.transcludeRecentLog(frame)
	
	local dayLimit = 90 --default value: 90 days, about 3 months
	local pageLimit = 30 --default value: 30 pages
	
	local args = frame.args
	
	--copied from [[en:Module:RfD close]], see attribution there
	local function argIsSet(key)
		if args[key] and args[key]:find('%S') then
			return true
		else
			return false
		end
	end
	
	if argIsSet(1) then
		dayLimit = tonumber(args[1])
	end
	
	if argIsSet(2) then
		pageLimit = tonumber(args[2])
	end
	
	local textPrint = {}
	local aa = 1
	
	for dd = 1, dayLimit, 1 do
		local pageTitleString = os.date('Wikipedia:刪文討論/記錄/%Y/%m/%d', os.time() - 86400 * (dd - 1))
		if checkPageExists(pageTitleString) then
			textPrint[aa] = transclude(frame, pageTitleString)
			aa = aa + 1
		end
		
		if aa >= pageLimit then
			break
		end
	end

	return table.concat(textPrint, '\n') 
end

function m.tabulateRecentLog(frame)
	local dayLimit = 500 --default value: 366 days, about 1 year
	local pageLimit = 20 --the template has 20 boxes
	
	local args = frame.args
	
	--copied from [[en:Module:RfD close]], see attribution there
	local function argIsSet(key)
		if args[key] and args[key]:find('%S') then
			return true
		else
			return false
		end
	end
	
	local timestamp = os.time() --grab time now in case runtime passes midnight and weird things happen
	local pageTitleStringArray = {}
	local logDayOffsetArray = {}
	local aa = 1
	
	local textPrint = {}
	local tt = 1 --for use with textPrint
	
	for dd = 1, dayLimit, 1 do
		local checkTimestamp = timestamp - 86400 * dd
		local pageTitleString = os.date('Wikipedia:刪文討論/記錄/%Y/%m/%d', checkTimestamp) --start from yesterday and go backwards
		if checkPageExists(pageTitleString) then
			pageTitleStringArray[aa] = pageTitleString
			logDayOffsetArray[aa] = dd
			aa = aa + 1
		end
		
		if aa > pageLimit then
			aa = aa - 1 --so that aa ends on the last index with a defined value
			break
		end
	end

	for bb = 20, 1, -1 do
		if aa >= bb then
			textPrint[tt] = '||' .. transclude(frame, 'AfdCalendar/day', {tostring(-logDayOffsetArray[bb])} ) --use existing template to generate link because it formats well
		else
			textPrint[tt] = '|| – '
		end
		tt = tt + 1
		
		if bb == 14 or bb == 7 then
			textPrint[tt] = '\n|-\n' --new row of table after 7 links
		elseif bb == 1 then
			textPrint[tt] = '' --don't print a newline to the very last item because we expect a newline right after invoking this module function
		else
			textPrint[tt] = '\n'
		end
		tt = tt + 1
	end
	
	return table.concat(textPrint) 
end


return m