[go: up one dir, main page]

跳转到内容

模組:Old vfd multi

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

local ovm={}
local getArgs
local timeParserFunction

local head=[[
{| class="plainlinks tmbox tmbox-notice"
|-
| class="mbox-image" | ]]..'[[File:Clipboard.svg|50px|link=]]\n'..[[
| class="mbox-text"  | ]]
local foot='|}'
local resultFunctionMap={
	['cc']=function(args,index) return [['''撤回請求''']] end,
	['kept']=function(args,index) return [['''保留''']] end,
	['nc']=function(args,index) return [['''無共識''',本页面暫時'''保留''']] end,
	['move']=function(args,index) 
		local target=''
		if index==1 then
			target=args['3']
		end
		if target=='' or target==nil then
			target=args['target'..index]
		end
		if target=='' or target==nil then
			target='其他位置'
		else
			target='[['..target..']]'
		end
		return [['''移動'''到]]..target
	end,
	['r']=function(args,index) 
		local target=''
		if index==1 then
			target=args['3']
		end
		if target=='' or target==nil then
			target=args['target'..index]
		end
		if target~='' and target~=nil then
			target='至[['..target..']]'
		else
			target=''
		end
		return [['''-{A|zh-cn:重定向; zh-tw:重新導向;}-''']]..target
	end,
	['sk']=function(args,index) return [['''快速保留''']] end,
	['ir']=function(args,index)
		local type=( args['type'] or args ['Type'] ) or '請求'
		return type..[['''無效''']]
	end,
	['rr']=function(args,index) return [['''請求理由已消失''',页面'''保留''']] end,
	['merge']=function(args,index) 
		local target=''
		if index==1 then
			target=args['3']
		end
		if target=='' or target==nil then
			target=args['target'..index]
		end
		if target=='' or target==nil then
			target='其他位置'
		else
			target='[['..target..']]'
		end
		return [['''併入''']]..target
	end,
	['deleted']=function(args,index) return [['''刪除''']] end,
	['sd']=function(args,index) return [['''快速刪除''']] end,
	['tk']=function(args,index) return [['''暫時保留''']] end,
	['cv']=function(args,index) return [['''轉送]]..'[[Wikipedia:頁面存廢討論/疑似侵權|疑似侵權討論]]'..[[''']] end,
	['relist']=function(args,index) return [['''重新提交討論''']] end,
	['_default_']=function(args,index) 
		local result=((index ==1 and args['2']) or args['result'..index]) or [['''保留''']]
		return result
	end
}
local resultMap={
	['cc']=resultFunctionMap['cc'],
	--
	['kept']=resultFunctionMap['kept'],
	['k']=resultFunctionMap['kept'],
	['保留']=resultFunctionMap['kept'],
	--
	['nc']=resultFunctionMap['nc'],
	['無共識']=resultFunctionMap['nc'],
	['无共识']=resultFunctionMap['nc'],
	--
	['m']=resultFunctionMap['move'],
	['moved']=resultFunctionMap['move'],
	['move']=resultFunctionMap['move'],
	['移動']=resultFunctionMap['move'],
	['移动']=resultFunctionMap['move'],
	--
	['r']=resultFunctionMap['r'],
	['重定向']=resultFunctionMap['r'],
	['重新導向']=resultFunctionMap['r'],
	--
	['sk']=resultFunctionMap['sk'],
	['快速保留']=resultFunctionMap['sk'],
	['速留']=resultFunctionMap['sk'],
	--
	['ir']=resultFunctionMap['ir'],
	['無效']=resultFunctionMap['ir'],
	['无效']=resultFunctionMap['ir'],
	--
	['rr']=resultFunctionMap['rr'],
	--
	['merge']=resultFunctionMap['merge'],
	['merged']=resultFunctionMap['merge'],
	['併入']=resultFunctionMap['merge'],
	['合併']=resultFunctionMap['merge'],
	['并入']=resultFunctionMap['merge'],
	['合并']=resultFunctionMap['merge'],
	--
	['deleted']=resultFunctionMap['deleted'],
	['d']=resultFunctionMap['deleted'],
	['刪除']=resultFunctionMap['deleted'],
	['删除']=resultFunctionMap['deleted'],
	--
	['sd']=resultFunctionMap['sd'],
	['speedy delete']=resultFunctionMap['sd'],
	['快速刪除']=resultFunctionMap['sd'],
	['快速删除']=resultFunctionMap['sd'],
	--
	['tk']=resultFunctionMap['tk'],
	['暫時保留']=resultFunctionMap['tk'],
	['暂时保留']=resultFunctionMap['tk'],
	--
	['cv']=resultFunctionMap['cv'],
	['copyvio']=resultFunctionMap['cv'],
	['侵權']=resultFunctionMap['cv'],
	['侵权']=resultFunctionMap['cv'],
	--
	['relist']=resultFunctionMap['relist'],
	--
	['_default_']=resultFunctionMap['_default_']
}

--检查
function isDate(inputStr)
	local pass=true
	local model = {'(%d%d%d%d)年(%d%d?)月(%d%d?)日','(%d%d%d%d)/(%d%d?)/(%d%d?)','(%d%d%d%d)(%d%d?)(%d%d?)'}
	local year,month,day=nil,nil,nil
	for _,_model in ipairs( model ) do
		year,month,day=nil,nil,nil
    	for y,m,d in mw.ustring.gmatch('2022年11月12日','(%d%d%d%d)年(%d%d)月(%d%d)日') do
		  year,month,day=y,m,d
		  break
    	end
		if year~=nil and month~=nil and day~=nil then
			year,month,day=tonumber(year),tonumber(month),tonumber(day)
			break
		else
			pass=false
		end
	end
	
	if pass then
		if year <=2001 then
			return false
		else
			if (1<=month and month<=12) and day >=1 then
				local m1={[1]=true,[3]=true,[5]=true,[7]=true,[8]=true,[10]=true,[12]=true}
				local m2={[4]=true,[6]=true,[9]=true,[11]=true}
				local leapyear=((year %4 ==0) and (year %100 ~=0 )) or (year%400==0)
				if (m1[month] and day<=31) or 
				   (m2[month] and day<=30) or 
				   (month==2 and ((leapyear and day<=29) or (day<=28 and not leapyear)) )
				then
					return 	year,month,day
				else 
					return false
				end
			else
				return false
			end
		end	
	else
		return false
	end
end

function generateDateLink(index,args,timestampVal,pageVal,isOnlyOne)
	--mw.log(index,args,timestampVal,pageVal,isOnlyOne)
	local pageType=args['_namespacenum_']==7 and '檔案' or '頁面'
	local t_date,isDate=nil,false
	local dateStr=''
	-- 测试1
	t_date=ovm.timeParserFunction('Ymd',timestampVal)
	if t_date==false then
		--测试2
		t_date=ovm.timeParserFunction('Y年n月j日',timestampVal)
		if t_date==false then
			dateStr=timestampVal or ''
		else
			dateStr=timestampVal
			isDate=true
		end
	else
		dateStr=timestampVal
		isDate=true
	end
	
	local afdlink=''
	--存废记录链接
	if isDate==false then
		afdlink=[[''']]..'[[Wikipedia:删除投票和请求/'..dateStr..'#'..pageVal..'|讨论结果]]'..[[''']]
	else
		t_date=ovm.timeParserFunction('Ymd',timestampVal)
		if t_date~=false and t_date < '20080812' then
			t_date=ovm.timeParserFunction('Y年n月j日',timestampVal)
			t_date = (t_date~=false and t_date) or ''
			afdlink=[[''']]..'[[Wikipedia:删除投票和请求/'..t_date..'#'..pageVal..'|讨论结果]]'..[[''']]
		else
			t_date=ovm.timeParserFunction('Y/m/d',timestampVal)
			t_date = (t_date~=false and t_date) or ''
			afdlink=[[''']]..'[[Wikipedia:'..pageType..'存廢討論/記錄/'..t_date..'#'..pageVal..'|讨论结果]]'..[[''']]
		end
	end
	--
	local resultVal = (index ==1 and args['2']) or args['result'..index] or ''
	local resultFunction = resultMap['_default_']
	if (resultVal~=nil and resultVal~='') and resultMap[string.lower(resultVal)]~=nil then 
		--mw.log("select:",string.lower(resultVal))	
		resultFunction = resultMap[string.lower(resultVal)]
	end	
	local result = resultFunction(args,index)
	--mw.log(resultVal,result)
	--
	local head=''
	if isOnlyOne then
		t_date=ovm.timeParserFunction('Y年n月j日',timestampVal)
		head='本'..pageType..'曾於'..((t_date~=false and t_date) or timestampVal)..'被送交[[Wikipedia:删除方针#存废讨论|存廢討論]],'
	else
		t_date=ovm.timeParserFunction('Y年n月j日',timestampVal)
		head='* '..((t_date~=false and t_date) or timestampVal)..','
	end
	--
	return head..afdlink..'為'..result..'。'
end

function ovm._main(args)
	local items={}
	local isMulti = (args['multi']~=nil and args['multi']~='')
	if isMulti then
		--多模式
		table.insert(items,
			[[<div align="center">'''本頁面曾被多次送交]]..'[[Wikipedia:删除方针#存废讨论|存廢討論]]'
			..[[。'''<br/>若要再次提交存廢討論,請先參考下列過往討論記錄:</div>]])
	end
	
	--
	local index=1
	while true do
		local dateStr= (index ==1 and args['1']) or args['date'..index]
		if (dateStr=='' or dateStr == nil) then
			break
		else
			local pageStr = (( index == 1 and args['page'] ) or args['page'..index]) or args['_subpagename_']
			local str=generateDateLink(index,args,dateStr,pageStr,(not isMulti))
			table.insert(items,str)
			index = index + 1
		end
		
		if not isMulti then --单模式的话,跳出
			break
		end
	end
	
	--
	table.insert(items,1,head)
	table.insert(items,foot)
	return table.concat(items,'\n')
end

function ovm.main(frame)
	if not getArgs then
		getArgs = require('Module:Arguments').getArgs
	end
	local args = getArgs(frame, {parentFirst=true})
	local curPage_obj=mw.title.getCurrentTitle()
	args["_subpagename_"]  = curPage_obj.subjectPageTitle.prefixedText
	args["_namespacenum_"] = curPage_obj.namespace
	timeParserFunction=function(formatStr,timestamp) 
		--local func=frame.callParserFunction
		--return frame:callParserFunction( '#time', formatStr, timestamp)
		local lang=mw.getContentLanguage()
		local ok,result=pcall(lang.formatDate,lang,formatStr,timestamp,true)
		--mw.log(timestamp,ok,result)
		if ok then
			return result
		else
			return false
		end
	end
	ovm.timeParserFunction=timeParserFunction
	return ovm._main(args)
end

return ovm