文档图示 模块文档[查看] [编辑] [历史] [清除缓存]

本模板用于作者页面

用法 编辑

一般用法:

{{作者
|name        = <!-- 姓名 -->
|firstletter = <!-- 拼音首字母 -->
|birthyear   = <!-- 出生年份 -->
|deathyear   = <!-- 去世年份 -->
|notes       = <!-- 描述 -->
}}

其他可选参数:

  • |times= 朝代(生卒年未知时填写,“X朝”即可)
  • |image= 图像
  • |image_caption= 图像说明
  • |country= 国籍(非中国时填写)
  • |portal= 相关导览
  • |related_author= 相关作者

name未填写时将显示为页面名称。firstletterbirthyeardeathyearimage以及各姊妹项目链接可自动从维基数据获取。

{{Author}}重定向於此。

该模板曾经使用wikitext创建,后来因代码过于复杂,于2018年12月21日改为Lua语言模块,原来的模板存档,见Template:作者/存档

模板数据 编辑

这是用于新版可视化编辑器及其他工具的模板数据文档。

作者模板数据

本模板用于[[Help:作者页面|作者页面]]。

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

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

参数描述类型状态
姓名name Name

若未添加,会将页面名作为作者姓名。

字符串推荐
拼音首字母firstletter FirstLetterLastName

若未添加,从维基数据的姓氏英文标签的首字母获取此项。

字符串推荐
出生年份birthyear

若未添加,从维基数据获取此项。

数字推荐
去世年份deathyear

若未添加,从维基数据获取此项。模块会假设最近100年内出生的人物仍然在世,也可以用deathyear=-明确声明在世人物。

数字推荐
朝代times

无描述

字符串可选
简要说明notes MiscBio

无描述

未知可选
图像image

作者的照片或画像。若未填写此项,默认从维基数据获得图像。

未知可选
图像说明image_caption

无描述

字符串可选
国籍country

无描述

未知可选
性别sex

无描述

未知可选
相关导览portal

无描述

未知可选
相关作者related_author

无描述

未知可选
维基百科页面名wikipedia

若未添加,从维基数据获取此项。

字符串可选
维基大典页面名zh-classical-wikipedia

若未添加,从维基数据获取此项。

字符串弃用
维基语录页面名wikiquote

若未添加,从维基数据获取此项。

字符串弃用
维基共享资源分类名commons commonscat

若未添加,从维基数据获取此项。

字符串弃用
wikinewswikinews

无描述

未知可选
wiktionarywiktionary

无描述

未知可选
wikibookswikibooks

无描述

未知可选
wikiversitywikiversity

无描述

未知可选
wikispecieswikispecies

无描述

未知可选
wikivoyagewikivoyage

无描述

未知可选
wikilivreswikilivres

无描述

未知可选
metameta

无描述

未知可选

local p = {};
local timesTable = {
	['秦'] = '秦朝',
	['汉'] = '漢朝',
	['漢'] = '漢朝',
	['晋'] = '晉朝',
	['晉'] = '晉朝',
	['隋'] = '隋朝',
	['唐'] = '唐朝',
	['宋'] = '宋朝',
	['金'] = '金朝',
	['元'] = '元朝',
	['明'] = '明朝',
	['清'] = '清朝',
	['淸'] = '清朝',
	['阮'] = '阮朝'
}
local ChinaCountry = {['cn']=1,['china']=1,['China']=1,['中国']=1,['中國']=1}

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

local function getStatementYear(entityid, propertyid)
	local statement = mw.wikibase.getBestStatements(entityid, propertyid)
	if statement[1] ~= nil then
		if statement[1]['mainsnak']['snaktype'] == 'value' then
			if statement[1]['mainsnak']['datavalue']['value']['precision']>=9 then
				return tonumber(mw.ustring.match(statement[1]['mainsnak']['datavalue']['value']['time'], "^[+-]?%d+"))
			else
				return nil
			end
		else
			return nil
		end
	else
		return nil
	end
end

local function getStatementString(entityid, propertyid)
	local statement = mw.wikibase.getBestStatements(entityid, propertyid)
	if statement[1] ~= nil then
		if statement[1]['mainsnak']['snaktype'] == 'value' then
			return mw.wikibase.getLabel(statement[1]['mainsnak']['datavalue']['value']["id"])
		else
			return nil
		end
	else
		return nil
	end
end

local function getFirstLetter(entityid, propertyid)
	local statement = mw.wikibase.getBestStatements(entityid, propertyid)
	if statement[1] ~= nil then
		if statement[1]['mainsnak']['snaktype'] == 'value' then
			local enlabel = mw.wikibase.getLabelByLang(statement[1]['mainsnak']['datavalue']['value']["id"], 'en')
			if enlabel ~= nil then
				return string.sub(enlabel,0,1)
			else
				return nil
			end
		else
			return nil
		end
	else
		return nil
	end
end

local function yearToString(year)
	if year == nil then
		return '?'
	elseif year > 0 then
		return tostring(year) .. '年'
	elseif year < 0 then
		return '前' .. tostring(-year) .. '年'
	else
		return '?'
	end
end

function p.main(frame)
	local text = ''
	local entityid = nil
	if mw.wikibase ~= nil then
		entityid = mw.wikibase.getEntityIdForCurrentPage()
	end
	
	local name = frame.args['name']
	if name==nil or name=='' then 
		name=frame.args['Name']
	end
	if name==nil or name=='' then
		name = mw.title.getCurrentTitle().text
	end
	local firstletter = frame.args['firstletter']
	if firstletter==nil or firstletter=='' then
		firstletter=frame.args['FirstLetterLastName']
	end
	local surname = frame.args['surname']
	if entityid ~= nil then
		surname = getStatementString(entityid, 'P734')
		if firstletter == nil or firstletter=='' then
			firstletter = getFirstLetter(entityid, 'P734')
		end
	end
	-- if firstletter==nil or firstletter=='' then
	-- 	text = text .. frame:expandTemplate{title='Template error', args={'未指定作者名称拼音首字母'}}
	-- end
	local times = frame.args['times']
	local birthyear = frame.args['birthyear']
	if (birthyear == nil or birthyear == '') and entityid ~= nil then
		birthyear = getStatementYear(entityid, 'P569')
	end
	local deathyear = frame.args['deathyear']
	if (deathyear == nil or deathyear == '') and entityid ~= nil then
		deathyear = getStatementYear(entityid, 'P570')
	end
	local dates = frame.args['Dates']
	local country = frame.args['country']
	if country==nil or country=='' then
		country = 'China'
	end
	local sex = frame.args['sex']
	local notes = frame.args['notes']
	if notes==nil or notes=='' then
		notes = frame.args['MiscBio']
		if notes==nil or notes=='' then
			note, lang = mw.wikibase.getDescriptionWithLang(entityid)
			if mw.ustring.sub(lang or '',1,2)=='zh' then
				notes = note .. "{{Plain sister}}"
			else
				notes = "{{Plain sister}}"
			end
		end
	end

	local image = frame.args['image']
	if (image == nil or image == '') then
		image = frame.args['Image']
	end
	if (image == nil or image == '') and (entityid ~= nil) then
		local imageStatement = mw.wikibase.getBestStatements(entityid, 'P18')
		if imageStatement[1] ~= nil then
			image = imageStatement[1]['mainsnak']['datavalue']['value']
		end
	end
	local image_caption = frame.args['image_caption']
	if image_caption == nil or image_caption == '' then
		image_caption = name
	end
	
	if firstletter ~= nil then
		text = text .. '<div align="right" style="font-size:12px">[[Portal:作者/' .. firstletter .. '|作者-' .. firstletter .. ']]</div>'
	end
	text = text .. '<div style="width:100%; margin-bottom:1px; border:1px solid #D6C5C5; background:#FAF8F8;text-align:center" >';
	text = text .. '<div style="font-weight:bold">' .. frame:preprocess(name) .. '</div>'
	if (birthyear ~= nil and birthyear ~= '') or (deathyear ~= nil and deathyear ~= '') then
		if birthyear ~= nil then
			birthyear = tonumber(birthyear)
		end
		if deathyear ~= nil and deathyear ~= '-' then
			deathyear = tonumber(deathyear)
		end
		text = text .. yearToString(birthyear)
		text = text .. ' — '
		if deathyear ~= '-' and (deathyear ~= nil or birthyear == nil or birthyear<os.date("*t").year-100) then
			text = text .. yearToString(deathyear)
		end
	elseif dates ~= nil and dates ~= '' then
		text = text .. frame:preprocess(dates)
	end
	if times ~= nil and times ~= '' then
		text = text .. ' ' .. frame:preprocess(times)
	end
	text = text .. '</div>'
	text = text .. '<div style="width:100%; margin-bottom:1px; font-size:small; border-bottom:1px solid #D6C5C5; background:#FEFFF0;" >'
	if notes ~= nil then
		text = text .. frame:preprocess(notes)
	end
    text = text .. frame:expandTemplate{title='works about author',args={}}
	text = text .. '</div>'
	if image ~= nil and image ~= '' then
		text = text .. '[[File:' .. frame:preprocess(image) .. '|thumb|200px'
		if image_caption ~= nil then
			text = text .. '|' .. frame:expandTemplate{title='center',args={frame:preprocess(image_caption)}}
		end
		text = text .. ']]'
	end
	
	if name ~= nil and firstletter ~= nil then
		text = addCategoryIf(text, name ~= nil and firstletter ~= nil, frame:preprocess(name) .. '|*')
	end
	if country ~= nil and country ~= '' then
		text = addCategoryIf(text, ChinaCountry[country] == nil, frame:preprocess(country) .. '作者')
	end
	if firstletter ~= nil and firstletter ~= '' then
		text = addCategoryIf(text, firstletter ~= nil and name ~= nil, '作者-' .. firstletter .. '|' .. frame:preprocess(name))
	end
	if sex ~= nil and sex ~= '' then
		text = addCategoryIf(text, true, frame:preprocess(sex) .. '作者')
	end
	if birthyear ~= nil and birthyear ~='' then
		text = addCategoryIf(text, birthyear >= 0, tostring(birthyear) .. '年出生')
		text = addCategoryIf(text, birthyear < 0, '前' .. tostring(-birthyear) .. '年出生')
	end
	if deathyear ~= nil and deathyear ~='' and deathyear ~='-' then
		text = addCategoryIf(text, deathyear >= 0, tostring(deathyear) .. '年逝世')
		text = addCategoryIf(text, deathyear < 0, '前' .. tostring(-deathyear) .. '年逝世')
	end
	if times ~= nil and times ~= '' then
		times = frame:preprocess(times)
		if timesTable[times] ~= nil then
			text = addCategoryIf(text, true, timesTable[times] .. '作者')
		else
			text = addCategoryIf(text, true, frame:preprocess(times) .. '作者')
		end
	end
	if surname ~= nil and surname ~= '' then
		text = addCategoryIf(text, true, surname .. '姓作者')
	end
	return text
end

return p;