Module:Header

維基文庫,自由的圖書館
文档图示 模块文档[查看] [编辑] [历史] [清除缓存]

该模板曾经使用维基文本创建,后来因代码过于复杂,于2022年10月18日 (二) 改为Lua语言模块,原来的模板存档,见Template:Header/存档

使用方法[编辑]

抄錄以下格式,輸入內容,放在條目頂端。

  • 其中作者為個人時,用“author=”輸入作者姓名,但不冠“作者:”,例如“author=班固”就自動連到作者:班固。有需要時,可用“override_author=”,將不自動加上作者的連結。如是法律文獻,則用“lawmaker=”。有特殊需要省略作者欄時,用“noauthor=”,例如“noauthor=中華民國行政院”或“noauthor=中華人民共和國國務院”。在author、noauthor、override_author、lawmaker四項中任選其中適當的一項。
  • 若有前後相關文章,前者在previous而後者在next輸入頁面名稱,模板自動產生向前和向後的箭頭,請勿手動添加箭頭。
  • 翻譯文章請標示譯者。

範本[编辑]

{{Header
| title    = [[三民主義]]
| alias    = 四民主义
| section  = 第一卷
| times    = 漢朝
| year  = 1911
| author   = 孫中山
| author2  = 杜甫
| author3  = 李白
| override_author = 孫中山(override)
| noauthor = 孫中山(no)
| collector = 蘇軾
| lawmaker = 國民政府
| translator=孟浩然
| previous = [[前一篇]]
| next     = [[後一篇]]
| theme    = 政治
| theme2   = 哲學
| theme3   = 社會
| loc      = 古代中國
| type     = 唐詩
| type2    = 五言絕句
| from     = 全唐詩
| from2    = 古文觀止
| notes    = 孫中山 著,孟浩然 譯
| edition = yes
}}
輸出結果:

前一篇 三民主義
又名:四民主义
第一卷
作者:孫中山 杜甫 李白 漢朝

輯者:蘇軾
孫中山(no)
孫中山(override)
制定机关:國民政府
1911年于古代中國
譯者:孟浩然
後一篇
本作品收錄於《全唐詩》和《古文觀止

孫中山 著,孟浩然 譯

詳細說明[编辑]

title[编辑]

文獻名稱,不自動加鏈接。填該文獻的總名稱,而不是子名稱(例如卷22)。

若屬於文集,需為單個文章建立單獨的頁面而不是子頁面。title填寫單個文章的標題,把父名稱填寫在from中。

alias[编辑]

文献的别名,显示为“又名:”

section[编辑]

填寫章節,如“第一卷”或“水部”。

若此参数不为空,则不会给页面添加以下任何分类。

时间信息[编辑]

日期[编辑]

  • 公历

例如:

|year = 1949 |month = 10 |day = 1
在title下换行显示为:1949年10月1日
并自动加分类:1949年1949年10月1949年10月1日
  • date:自定日期信息,請改用date

时期[编辑]

  • times

該作品的朝代。一般作品時代與作者時代相同,如果作者處於兩朝更替之時,請寫作者撰寫該作品的朝代。建議盡量填入朝代己有的分類:

夏朝 商朝 周朝 西周 東周 春秋 戰國 秦朝 漢朝 西漢 新莽 東漢 三國 晉朝 十六國 南北朝 魏 梁 陳 齊 周 隋朝 唐朝 五代十國 宋朝 遼 西夏 金 元朝 明朝 清朝

模板會自動加上朝代的分類。

  • notimes:如果想自定时代信息,請改用notimes

作者[编辑]

  • author:作者名,自動加上「作者:」及分類。如果有多個作者,可在author後面加2~5。
  • author_link:作者名的链接。
  • override_author:同上,但不自動加分類。
  • noauthor:不自動加分類。
  • translator:譯者。
  • notranslator:譯者,不自動加分類。

法规/公文[编辑]

  • lawmaker:法律規章制定機關。
  • 发布者:法律規章发布机关。
  • 发布于:法律規章发布文件,如主席令、通知。
  • 公布於
  • 发文字号
  • 公布字號
  • 案号
  • 生效日期
  • 失效日期

导航[编辑]

  • previous:前一篇,請自行加鏈接。
  • next:后一篇,請自行加鏈接。

属性/分类[编辑]

  • type:文章屬性,自動加分類。請填最小、最精確的分類(例如:如果是「五言絕句」,就不要填「絕句」或「五言詩」)。一般以四庫全書的最低級標題為準。可填type2~type5。

若為四庫全書的集部,或全唐詩類的,請為各子文章建立頁面,並在from填上「母文章」,而母文章的type請加上“集”。

  • theme:功能相同,可填2~5。參見主題選一填上。(請填最小、最精確的分類)
  • loc:功能相同。參見地域選一填上。(請填最小、最精確的分類)
  • from:出處,自動加鏈接和分類。若有兩個,可用from2。

注释[编辑]

  • notes

注释栏备用模板[编辑]

edition = yes 版本信息,连接至对应对话页。

跨计划链接[编辑]

通过操作对应的wikidata自动获取。 如果有特别需要,在项目同名参数中指定对应页面即可。比如

{{header|wikipedia=中华人民共和国宪法}}

相關模板[编辑]

文章说明

模板参数[编辑模板数据]

此模板首选参数换行的代码块格式。

参数描述类型状态
标题title

无描述

未知推荐
作者author

无描述

未知推荐
朝代times

无描述

未知推荐
year y

无描述

数字可选

无描述

数字可选
month m

无描述

数字可选
day d

无描述

数字可选
收录于from

无描述

未知可选
说明notes

无描述

内容可选
上一卷previous

至上一卷作品的链接

未知可选
下一卷next

至下一卷作品的链接

未知可选
发布者发布者

无描述

未知可选
发布文件发布文件

无描述

未知可选
譯者translator

无描述

单行文本可选
translator2translator2

无描述

未知可选
translator3translator3

无描述

未知可选
发文字号发文字号

无描述

单行文本可选
author4author4

无描述

未知可选
author5author5

无描述

未知可选
datedate

无描述

单行文本可选
times2times2

无描述

未知可选
别名alias

无描述

未知可选
章节section

无描述

未知可选
民2民2

无描述

数字可选
月2月2

无描述

数字可选
日2日2

无描述

数字可选
是否显示文本信息edition

如有填写yes

单行文本可选

local p = {}
local timesTable = {
	['夏'] = '夏朝',
	['夏代'] = '夏朝',
	['商'] = '商朝',
	['商代'] = '商朝',
	['周'] = '周朝',
	['周代'] = '周朝',
	['秦'] = '秦朝',
	['秦代'] = '秦朝',
	['漢'] = '漢朝',
	['汉'] = '漢朝',
	['漢代'] = '漢朝',
	['汉代'] = '漢朝',
	['晉'] = '晉朝',
	['晋'] = '晉朝',
	['晉代'] = '晉朝',
	['晋代'] = '晉朝',
	['南朝宋'] = '劉宋',
	['隋'] = '隋朝',
	['隋代'] = '隋朝',
	['唐'] = '唐朝',
	['唐代'] = '唐朝',
	['宋'] = '宋朝',
	['宋代'] = '宋朝',
	['遼'] = '遼朝',
	['遼代'] = '遼朝',
	['金'] = '金朝',
	['金代'] = '金朝',
	['元'] = '元朝',
	['元代'] = '元朝',
	['明'] = '明朝',
	['明代'] = '明朝',
	['清'] = '清朝',
	['淸'] = '清朝',
	['清代'] = '清朝',
	['民國'] = '中華民國',
	['民国'] = '中華民國',
	['阮'] = '阮朝',
	['阮代'] = '阮朝'
}

local function addCategoryIf(text, condition, category)
	local text2 = text
	if condition and category ~= nil and category ~= '' then
		text2 = text2 .. '[[Category:' .. category .. ']]'
	end
	return text2
end

local function isempty(arg)
	return arg == nil or arg == ''
end

local function ROC(year, base)
	if (year == '1' or year == '元') and base == 0 then
		return '元'
	elseif year == '元' and base == 1911 then
		return '1912'
	else
		return tostring(tonumber(year) + base) -- 0 or 1911
	end
end

local function CategoryYMD(year, month, day)
	text = ''
	if not isempty(year) then
		text = '[[Category:' .. year .. '年]]'
		if not isempty(month) then
			text = text .. '[[Category:' .. year .. '年' .. month .. '月]]'
			if not isempty(day) then
				text = text .. '[[Category:' .. year .. '年' .. month .. '月' .. day .. '日]]'
			end
		end
	end
	return text
end

function p.main(frame)
	-- 参数
    local args = frame.args
    -- 处理 Template:Header
    if not isempty(args["included_via_template"]) then
    	if args["included_via_template"] == "1" then
    		args = frame:getParent().args
    	end
    end
	local title = args['title']
	if isempty(title) then
		title = mw.title.getCurrentTitle().text
	end
	local notes = args['notes']
	if notes == nil then
		notes = ''
	end
	local times = {
		args['times'],
		args['times2']
	}
	local from = {
		args['from'],
		args['from2'],
		args['from3']
	}
	local author = {
		args["author"],
		args["author2"],
		args["author3"],
		args["author4"],
		args["author5"],
		args["author6"],
		args["author7"],
		args["author8"],
		args["author9"],
		args["author10"],
		args["author11"],
		args["author12"],
		args["author13"],
		args["author14"],
		args["author15"],
		args["author16"],
		args["author17"],
		args["author18"],
		args["author19"],
		args["author20"]
	}
    local author_link = args["author_link"]
    local sign = args["署名"]
	local articleNo = args['发文字号']
	if isempty(articleNo) then
		articleNo = args['發文字號']
	end
	if isempty(articleNo) then
		articleNo = args['文号']
	end
	if isempty(articleNo) then
		articleNo = args['文號']
	end
	local caseNo = args['案号']
	if isempty(caseNo) then
		caseNo = args['案號']
	end
	local section = args['section']
	local alias = args['alias']
	local lawmaker = args["lawmaker"]
	local seealso = {
		args['seealso'],
		args['seealso2'],
		args['seealso3'],
		args['seealso4'],
		args['seealso5']
	}
	local collector = {
		args['collector'],
		args['collector2'],
		args['collector3'],
		args['collector4'],
		args['collector5'],
		args['collector6'],
		args['collector7'],
		args['collector8']
	}
	local ROCyear = {
		args['民'],
		args['民2'],
		args['民3']
	}
	local ROCmonth = {
		args['月'],
		args['月2'],
		args['月3']
	}
	local ROCday = {
		args['日'],
		args['日2'],
		args['日3']
	}
    local previous = args["previous"]
    local next = args["next"]
    local prv = args["prv"]
    local nxt = args["nxt"]
    
    if mw.wikibase ~= nil then
		entityid = mw.wikibase.getEntityIdForCurrentPage()
	else
		entityid = nil
	end
	-- 输出
	local text = '<div id="headerContainer">\n';
	text = text .. '{| style="width:100%; margin-top:0px;'
	text = text .. 'margin-bottom:3px;'; --此处原Header模版有判断语句,由于Plain sister模版的使用可能无需处理。
	text = text .. 'border:1px solid #93A6C0; background-color: #F9F9F9; text-align:center;"\n'
	text = text .. '|-\n'
	text = text .. '| style="width:0; text-align:left; font-size:small;"|'

    if not (isempty(previous) and isempty(prv)) then 
        text = text .. '  ←'
    end

    text = text .. '\n| style="width:25%; text-align:left; font-size:small;"|'

	if not isempty(previous) then
        text = text .. previous
    elseif not isempty(prv) then
        text = text ..  '[[' .. mw.title.rootPageTitle .. '/' .. prv .. '|' .. prv .. ']]'
    end
    text = text .. '\n|style="width:50%;" |<b>'
    text = text .. title
    text = text .. '</b>'
    
    if not isempty(articleNo) then
    	text = text .. '<br /><b>' .. frame:expandTemplate{title="i", args={articleNo}} .. '</b>'
    end
    if not isempty(caseNo) then
    	text = text .. '<br /><div style="text-align:right; font-weight:bold">' .. caseNo .. '</div>'
    end
    if not isempty(alias) then
    	text = text .. '<br />又名:<b>' .. alias .. '</b>'
    end
    if not isempty(section) then
    	text = text .. '<br />' .. section
    end
    if not isempty(author[1]) then
    	text = text .. '<br /><span style="color:#999999">作者:</span>'
    	if not isempty(author_link) then
    		text = text .. '[[作者:' .. author_link .. '|' .. author[1] .. ']]'
    	else
    		text = text .. '[[作者:' .. author[1] .. '|' .. author[1] .. ']]'
    	end
    end
    if not isempty(sign) then
    	text = text .. '<br /><span style="color:#999999">(署名:</span>'
    	text = text .. '[[作者:' .. sign .. '|' .. sign .. ']]'
    	text = text .. '<span style="color:#999999">)</span>'
    end
    for i = 2, 20 do
    	if not isempty(author[i]) then
    		text = text .. ' [[作者:' .. author[i] .. '|' .. author[i] .. ']]'
    	end
    end
    if not isempty(times[1]) then
    	text = text .. ' <span style="color:#999999">' .. times[1] .. '</span>'
    end
    if not isempty(collector[1]) then
    	if not isempty(author[1]) then
    		text = text .. '<br />'
    	end
    	text = text .. ' <br /><span style="color:#999999">輯者:</span>[[作者:' .. collector[1] .. '|' .. collector[1] .. ']]'
    	for i = 2, 8 do
    		if not isempty(collector[i]) then
				text = text .. ' [[作者:' .. collector[i] .. '|' .. collector[i] .. ']]'
            end
    	end
    end
	if not isempty(times[2]) then
		text = text .. ' <span style="color:#999999">' .. times[2] .. '</span>'
	end
	if not isempty(args['noauthor']) then
		text = text .. '<br/>' .. args["noauthor"]
	end
	if not isempty(args['override_author']) then
		text = text .. '<br/>' .. args["override_author"]
	end
	if not isempty(args['override_author2']) then
		text = text .. '<br/>' .. args["override_author2"]
	end
    if not isempty(args["notimes"]) then
    	text = text .. '<br/><span style="color:#999999">' .. args["notimes"] .. '</span>'
    end
    if not isempty(lawmaker) then
    	text = text .. '<br /><span style="color:#999999">制定机关:</span>' .. lawmaker
    end
    if not isempty(args["紀元"]) then
    	text = text .. '<br /><span style="color:#999999"><b>' .. args["紀元"]
    	local year = args['紀年']
    	if not isempty(year) then
    		if year == "一" then
    			text = text .. "元"
    		else
    			text = text .. year
    		end
    		text = text .. "年"
    		if not isempty(args["紀月"]) then
    			text = text .. args["紀月"] .. "月"
    			if not isempty(args["紀日"]) then
    				text = text .. args["紀日"] .. "日"
    			end
    		else
    			text = text .. '年間'
    		end
    	end
    	text = text .. "</b></span>"
    end
    -- 民
    for i = 1, 3 do
	    if not isempty(ROCyear[i]) then
	    	text = text .. '<br /><span style="color:#999999"><b>中華民國'
	    	if ROCyear[i] == '1' or ROCyear[i] == '元' then
	    		text = text .. '元年(1912年)'
	    	else
	    		text = text .. ROCyear[i] .. '年(' .. ROC(ROCyear[i], 1911) .. '年)'
	    	end
	    	if not isempty(ROCmonth[i]) then
	    		text = text .. ROCmonth[i] .. '月'
	    		if not isempty(ROCday[i]) then
	    			text = text .. ROCday[i] .. '日'
	    		end
	    	end
	    	text = text .. '</b></span>'
	    end
    end
    -- 年月日
    if not isempty(args["年"]) then
    	text = text .. '<br /><span style="color:#999999">'
    	text = text .. args['年'] .. '年'
    	if not isempty(args['月']) then
    		text = text .. args['月'] .. '月'
    		if not isempty(args['日']) then
    			text = text .. args['日'] .. '日'
    		end
    	end
    	text = text .. '</span>'
    end
    -- year,month,day
    if not isempty(args["year"]) then
    	text = text .. '<br /><span style="color:#999999">'
    	text = text .. args['year'] .. '年'
    	if not isempty(args['month']) then
    		text = text .. args['month'] .. '月'
    		if not isempty(args['day']) then
    			text = text .. args['day'] .. '日'
    		end
    	end
    	text = text .. '</span>'
    end
    -- y,m,d
    if not isempty(args["y"]) then
    	text = text .. '<br /><span style="color:#999999">'
    	text = text .. args['y'] .. '年'
    	if not isempty(args['m']) then
    		text = text .. args['m'] .. '月'
    		if not isempty(args['d']) then
    			text = text .. args['d'] .. '日'
    		end
    	end
    	text = text .. '</span>'
    end
    -- date
    if not isempty(args["date"]) then
    	text = text .. '<br /><span style="color:#999999">' .. args["date"] .. '</span>'
    end
    -- loc
    if not isempty(args["loc"]) then
    	text = text .. '<span style="color:#999999">于' .. args["loc"] .. '</span>'
    end
    if not isempty(args["at"]) then
    	text = text .. '<br /><span style="color:#999999"><small>(在[[:Category:' .. args["at"] .. '|' .. args["at"] .. ']]上)</small></span>'
    end
    if not isempty(args["发布者"]) then
    	text = text .. '<br /><span style="color:#999999">发布机关:</span>' .. args["发布者"]
    end
    if not isempty(args["发布于"]) then
    	text = text .. '<br /><span style="color:#999999">发布于</span>' .. args["发布于"]
    end
    if not isempty(args["公布於"]) then
    	text = text .. '<br /><span style="color:#999999">公布於</span>' .. args["公布於"]
    end
    if not isempty(args["公布字號"]) then
    	text = text .. '<br />' .. args["公布字號"]
    elseif not isempty(args["公布字号"]) then
    	text = text .. '<br />' .. args["公布字号"]
    end
    if not isempty(args["生效日期"]) then
    	text = text .. '<br /><span style="color:#999999">有效期:' .. args["生效日期"]
    	if isempty(args["失效日期"]) then
    		text = text .. '至今</span>'
    	else
    		text = text .. '—' .. args["失效日期"] .. '<small>(不含本日)</small></span>'
    	end
    end
    if not isempty(args["translator"]) then
    	text = text .. '<br /><span style="color:#999999">譯者:</span>'
    	text = text .. '[[作者:' .. args["translator"] .. '|' .. args["translator"] .. ']]'
    end
    if not isempty(args["notranslator"]) then
    	text = text .. '<br /><span style="color:#999999">譯者:</span>'
    	text = text .. args["notranslator"]
    end
    if not isempty(args["translator2"]) then
    	text = text .. ' [[作者:' .. args["translator2"] .. '|' .. args["translator2"] .. ']]'
    end
    if not isempty(args["translator3"]) then
    	text = text .. ' [[作者:' .. args["translator3"] .. '|' .. args["translator3"] .. ']]'
    end
    
    text = text .. '\n| style="width:25%; text-align:right; font-size:small;"|'

	if not isempty(next) then
        text = text .. next
    elseif not isempty(nxt) then
        text = text ..  '[[' .. mw.title.rootPageTitle .. '/' .. nxt .. '|' .. nxt .. ']]'
    end
    
	text = text .. '\n| class="noprint" style="width:0; text-align:right; font-size:small;"|'

    if not (isempty(next) and isempty(nxt)) then 
        text = text .. '  →'
    end
    
    text = text .. '\n|}'
    
    text = text .. '\n{| style="width:100%; background:#F8FCFF; font-size:small; border-bottom:1px solid #93A6C0"'
    text = text .. '\n|-'
    text = text .. '\n|'
    
    if not isempty(from[1]) then
    	text = text .. '\n{| style="font-size:0.9em; text-align:left; background:#F9F9F9; float:right;"'
    	text = text .. '\n| style="color: #999999;" |'
    	text = text .. frame:preprocess("-{zh:本作品收錄於;zh-hant:本作品收錄於;zh-hans:本作品收录于}-《'''[[" .. from[1] .. "]]'''》")
    	if not isempty(from[2]) then
    		text = text .. frame:preprocess("和《'''[[" .. from[2] .. "]]'''》")
	    	if not isempty(from[3]) then
	    		text = text .. frame:preprocess("以及《'''[[" .. from[3] .. "]]'''》")
	    	end
    	end
    	text = text .. '\n|}\n'
    end
    
    text = text .. notes
    -- 维基跨语言链接自动生成。
	-- if page is not connected to Wikidata, only show plain sister if at least one of its parameters is filled in
	-- if page is connected to Wikidata, always show plain sister
    if not (entityid == nil and isempty(args["disambiguation"]) and isempty(args["edition"]) and isempty(args["portal"]) and isempty(args["related_author"]) and isempty(args["wikipedia"]) and isempty(args["commons"]) and isempty(args["commonscat"]) and isempty(args["wikiquote"]) and isempty(args["wikinews"]) and isempty(args["wiktionary"]) and isempty(args["wikibooks"]) and isempty(args["wikilivres"]) and isempty(args["wikidata"]) and isempty(args["wikivoyage"]) and isempty(args["wikiversity"]) and isempty(args["wikispecies"]) and isempty(args["meta"])) then
    	text = text .. frame:expandTemplate{title='Plain sister',args={disambiguation = args["disambiguation"], edition = args["edition"], portal = args["portal"], related_author = args["related_author"], wikipedia = args["wikipedia"], commons = args["commons"], commonscat = args["commonscat"], wikiquote = args["wikiquote"], wikinews = args["wikinews"], wiktionary = args["wiktionary"], wikibooks = args["wikibooks"], wikilivres = args["wikilivres"], wikidata = args["wikidata"], wikivoyage = args["wikivoyage"], wikiversity = args["wikiversity"], wikispecies = args["wikispecies"], meta = args["meta"]}}
    end
    text = text .. frame:expandTemplate{title='main subject',args={}}
    text = text .. '\n|}'
	text = text .. '</div>'
	
	for i = 1, 2 do
		if not isempty(times[i]) then
			if timesTable[times[i]] ~= nil then
				text = addCategoryIf(text, 1, timesTable[times[i]])
			else
				local times_object = mw.title.new('Category:' .. times[i] .. '作品')
				if times_object.exists then
					text = addCategoryIf(text, 1, times[i] .. '作品')
			else
					text = addCategoryIf(text, 1, times[i])
				end
			end
		end
	end
	if not isempty(author_link) then
		text = addCategoryIf(text, 1, author_link)
	else
		text = addCategoryIf(text, 1, author[1])
	end
	for i = 2, 20 do
		text = addCategoryIf(text, 1, author[i])
    end
	text = addCategoryIf(text, 1, args["translator"])
	text = addCategoryIf(text, 1, args["theme"])
	for i = 2, 7 do
		text = addCategoryIf(text, 1, args["theme" .. tostring(i)])
	end
	text = addCategoryIf(text, 1, args["at"])
	text = addCategoryIf(text, 1, args["loc"])
	if not isempty(args["loc"]) then
		if not isempty(args["y"]) then
			text = addCategoryIf(text, 1, args["y"] .. '年' .. args["loc"])
		end
		if not isempty(args["year"]) then
			text = addCategoryIf(text, 1, args["year"] .. '年' .. args["loc"])
		end
		if not isempty(args["年"]) then
			text = addCategoryIf(text, 1, args["年"] .. '年' .. args["loc"])
		end
		if not isempty(args["紀元"]) and not isempty(args["紀年"]) then
			text = addCategoryIf(text, 1, args["紀元"] .. args["紀年"] .. '年' .. args["loc"])
		end
		for i = 1, 3 do
			if not isempty(ROCyear[i]) then
				text = addCategoryIf(text, 1, '中華民國' .. ROC(ROCyear[i], 0) .. '年' .. args["loc"])
			end
		end
	end
	if not isempty(args["type"]) then
		if not isempty(args["y"]) then
			text = addCategoryIf(text, 1, args["y"] .. '年' .. args["type"])
		end
		if not isempty(args["year"]) then
			text = addCategoryIf(text, 1, args["year"] .. '年' .. args["type"])
		end
		if not isempty(args["年"]) then
			text = addCategoryIf(text, 1, args["年"] .. '年' .. args["type"])
		end
		for i = 1, 3 do
			if not isempty(ROCyear[i]) then
				text = addCategoryIf(text, 1, '中華民國' .. ROC(ROCyear[i], 0) .. '年' .. args["type"])
			end
		end
		if not isempty(args["紀元"]) and not isempty(args["紀年"]) then
			text = addCategoryIf(text, 1, args["紀元"] .. args["紀年"] .. '年' .. args["type"])
		end
		if args["type"] == "五言" or args["type"] == "四言" or args["type"] == "七言" then
			text = text .. '[[Category:' .. args["type"] .. '詩]]'
		else
			text = text .. '[[Category:' .. args["type"] .. ']]'
		end
	end
	for i = 2, 10 do
		local typei = args["type" .. tostring(i)]
		if not isempty(typei) then
			if not isempty(args["y"]) then
				text = addCategoryIf(text, 1, args["y"] .. '年' .. typei)
			end
			if not isempty(args["year"]) then
				text = addCategoryIf(text, 1, args["year"] .. '年' .. typei)
			end
			if not isempty(args["年"]) then
				text = addCategoryIf(text, 1, args["年"] .. '年' .. typei)
			end
			if not isempty(ROCyear[1]) then
				text = addCategoryIf(text, 1, '中華民國' .. ROC(ROCyear[1], 0) .. '年' .. typei)
			end
			text = text .. '[[Category:' .. typei .. ']]'
		end
	end
	for i = 1, 3 do
		if not isempty(from[i]) then
			local from_page = mw.text.split(from[i], "|")[1]
			local from_page_object = mw.title.new('Category:' .. from_page)
			if from_page_object ~= nil then
				if from_page_object.exists then
					text = text .. '[[Category:' .. from[i] .. ']]'
				end
			end
		end
	end
	text = text .. CategoryYMD(args["y"], args["m"], args["d"])
	text = text .. CategoryYMD(args["year"], args["month"], args["day"])
	text = text .. CategoryYMD(args["年"], args["月"], args["日"])
	for i = 1, 3 do
		if not isempty(ROCyear[i]) then
			text = text .. '[[Category:中華民國' .. ROC(ROCyear[i], 0) .. '年]]'
			if not isempty(ROCmonth[i]) then
				text = text .. '[[Category:中華民國' .. ROC(ROCyear[i], 0) .. '年' .. ROCmonth[i] .. '月]]'
				if not isempty(ROCday[i]) then
					text = text .. '[[Category:' .. ROC(ROCyear[i], 1911) .. '年' .. ROCmonth[i] .. '月' .. ROCday[i] .. '日]]'
				end
			end
		end
	end
	if not isempty(args["紀元"]) then
		if not isempty(args["紀年"]) then
			text = text .. '[[Category:' .. args["紀元"] .. args["紀年"] .. '年]]'
			if not isempty(args["月"]) then
				text = text .. '[[Category:' .. args["紀元"] .. args["紀年"] .. '年' .. args["月"] .. '月]]'
				if not isempty(args["日"]) then
					text = text .. '[[Category:' .. args["紀元"] .. args["紀年"] .. '年' .. args["月"] .. '月' .. args["日"] .. '日]]'
				end
			end
		else
			text = text .. '[[Category:' .. args["紀元"] .. ']]'
		end
	end
	
	text = addCategoryIf(text, 1, args["main"])
	if not isempty(args["is_main_of"]) then
		text = text .. '[[Category:' .. args["is_main_of"] .. '| ]]'
	end
	-- 通过categories参数添加分类,分类按照 A/B/C 形式输入,自动划分
	if not isempty(args["categories"]) then
		for i in mw.text.gsplit(args["categories"], "/", true) do
			text = addCategoryIf(text, 1, i)
		end
	end
	
	return text;
end

return p