跳转到内容

模組:Science redirect

本页使用了标题或全文手工转换
维基百科,自由的百科全书
文档图示 模块文档[查看] [编辑] [历史] [清除缓存]

本模块为{{R from scientific name}}{{R to monotypic taxon}}{{R from monotypic taxon}}模板的后端。

模板的参数和分类在Module:Science redirect/conf中设置。

使用[编辑]

{{#invoke:Science redirect|R|template name excluding 'R'}}

例如,对于{{R from scientific name}},可以使用{{#invoke:Science redirect|R|from scientific name}}来生成:

  • 學名重定向:这是由生物分类的學名,指向该分类的俗名的重定向。它引導出學名標題至遵循命名常規的合適名稱,能夠協助編者寫作。除非為了更新重定向頁,一般不應該用管道链接取代重定向链接。

添加或修改支持模板[编辑]

模板的参数和分类在Module:Science redirect/conf中设置。

调试模板时,可添加参数|debug=true,例如{{#invoke:Science redirect|R|from scientific name|debug=true}}会生成:

{{Redirect template
| info = 它引導出學名標題至遵循命名常規的合適名稱,能夠協助編者寫作。除非為了更新重定向頁,一般不應該用管道链接取代重定向链接。
| name = 學名重定向
| from = 生物分类的學名
| id = R_from_scientific_name
| all category = 學名重定向
| printworthy = yes
| to = 该分类的俗名
}}

分类索引[编辑]

Science redirects ( 0 )[编辑]

Category:重定向 ( 55 )

Category:昆虫重定向 ( 0 )

Category:爬行动物重定向 ( 0 )

Category:节肢动物重定向 ( 1 )

Category:两栖动物重定向 ( 0 )

Category:哺乳动物重定向 ( 0 )

Category:植物重定向 ( 0 )

Category:鸟类重定向 ( 0 )

Category:病毒重定向 ( 0 )

Category:微生物重定向 ( 0 )

Category:甲壳动物重定向 ( 0 )

Category:蜘蛛重定向 ( 0 )

Category:动物重定向 ( 0 )

Category:藻类重定向 ( 0 )

Category:真菌重定向 ( 0 )

Category:软体动物重定向 ( 0 )

Category:鱼类重定向 ( 0 )


无效参数[编辑]

local conf = require( "Module:Science redirect/conf" )

local p = {}

function p.R(frame)
	local template = mw.ustring.gsub(frame.args[1], ' ', '_')
	if conf.templates[template] then
		return p._main(frame, 'R_' .. template, conf.templates[template].name, conf.templates[template].from, conf.templates[template].to, conf.templates[template].category, conf.templates[template].info)
	elseif template then
		return '<span class="error">'..template..'模板不可用。</span>\n'
	else
		return '<span class="error">未指明任何模板。</span>\n'
	end
end

function p.list(frame)
	local outstr = ""
	local ocats={}

	for _, v in pairs(conf.cats) do ocats[v] = true end
	
	for k, _ in pairs(ocats) do
	    outstr = outstr .. "\n=== " .. frame:expandTemplate{ title = 'cl', args = { (k .. "重定向"), count = "yes" } } .. " ===\n"
	    for kk, vv in pairs (conf.templates) do
	        outstr = outstr .. "*" .. frame:expandTemplate{ title = 'cl', args = { (mw.ustring.gsub(vv.category, '$1', k) .. "重定向"), count = "yes" } } .. "\n"
	    end
	end
	
	return outstr
end

function p._main(frame, id, name, from, to, category, info)
	--initialize variables
	local args = frame:getParent().args
	local chineseNoun = ''
	local outStr = ''
	
	--Check for known parameter 1
	local cat = mw.ustring.match(mw.ustring.lower(args[1] or 'none'), '^(.-)s?$')
	if conf.cats[cat] then chineseNoun = conf.cats[cat] else
		chineseNoun = ''
		outStr = '[[Category:使用学名重定向未知参数1]]'
	end
	
	--support alternative indications for printworthy
	if args[2] == 'unprintworthy' or args['unprintworthy'] == 'true' then args['printworthy'] = 'no' end
	
	--build template arguments
	local outArgs = {
		id = id,
		name = mw.ustring.gsub(name..'重定向', '$1', chineseNoun),
		from = mw.ustring.gsub(from, '$1', chineseNoun),
		to = mw.ustring.gsub(to, '$1', chineseNoun),
		['all category'] = mw.ustring.gsub(category..'重定向', '$1', chineseNoun),
		printworthy = (args['printworthy'] or 'yes'),
		info = info,
	}
	
	--build output string
	if frame.args['debug'] == 'true' then
		local debugStr = '{{Redirect template<br />\n'
		for k,v in pairs( outArgs ) do
			debugStr = debugStr..'| '..k..' = '..v..'<br />\n'
		end
		outStr = debugStr..'}}'..frame:extensionTag{ name = 'nowiki', content = outStr}
	else
		outStr = frame:expandTemplate{ title = 'Redirect template', args = outArgs }..outStr
	end
	
	return outStr
end

return p