Module:Science redirect

විකිපීඩියා වෙතින්
Jump to navigation Jump to search

This module is designed to serve as a back end for {{R from alternative scientific name}}, {{R to scientific name}}, {{R from scientific name}}, {{R to monotypic taxon}} and {{R from monotypic taxon}}.

The template parameters and recognized categories are set in Module:Science redirect/conf.


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

For example, for {{R to scientific name}}, you would use {{#invoke:Science redirect|R|to scientific name}} to produce:

  • මෙය යළියොමු කිරීමකි.

Adding or modifying supported templates[සංස්කරණය]

The template parameters and recognized categories are set in Module:Science redirect/conf. Instructions on how to add data are in the comments of that file.

For debugging, add parameter |debug=true, e.g. {{#invoke:Science redirect|R|to scientific name|debug=true}} produces:

{{Redirect template
| name = To scientific name of an organism
| from = a vernacular ("common") name
| main category = Redirects to scientific names
| printworthy = yes
| to = the scientific name of an organism (or group of organisms)

Tracking categories[සංස්කරණය]


Science redirects[සංස්කරණය]

Plant redirects[සංස්කරණය]

Fish redirects[සංස්කරණය]

Fungus redirects[සංස්කරණය]

Spider redirects[සංස්කරණය]

Crustacean redirects[සංස්කරණය]

Reptile redirects[සංස්කරණය]

Insect redirects[සංස්කරණය]

Virus redirects[සංස්කරණය]

Invalid parameters[සංස්කරණය]

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, conf.templates[template].name, conf.templates[template].from, conf.templates[template].to, conf.templates[template].category, conf.templates[template].info, conf.templates[template].removeA)
	elseif template then
		return '<span class="error">The template '..template..'is not valid.</span>\n'
		return '<span class="error">No template specified</span>\n'

function p._main(frame, name, from, to, category, info, removeA)
	--initialize variables
	local args = frame:getParent().args
	local singleNoun, pluralNoun = '', ''
	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 singleNoun, pluralNoun = conf.cats[cat][1], conf.cats[cat][2] else
		singleNoun, pluralNoun = 'an organism'
		outStr = '[[Category:Redirects '..category..' using unknown values for parameter 1]]'
	--strip article from singleNoun if removeA is true
	if removeA == true then
		if singleNoun == 'an organism' then singleNoun = '' else singleNoun = (mw.ustring.match(singleNoun, '^an? (.*)$') or singleNoun) end
	--support alternative indications for printworthy
	if args[2] == 'unprintworthy' or args['unprintworthy'] == 'true' then args['printworthy'] = 'no' end
	--build template arguments
	local main_category = 'Redirects '..category
	if pluralNoun then main_category = main_category..' of '..pluralNoun end
	local outArgs = {
		name = mw.ustring.gsub(name, '$1', singleNoun),
		from = mw.ustring.gsub(mw.ustring.gsub(from, '$1', singleNoun), '$2', (pluralNoun or 'organisms')),
		to = mw.ustring.gsub(mw.ustring.gsub(to, '$1', singleNoun), '$2', (pluralNoun or 'organisms')),
		['main category'] = main_category,
		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'
		outStr = debugStr..'}}'..frame:extensionTag{ name = 'nowiki', content = outStr}
		outStr = frame:expandTemplate{ title = 'Redirect template', args = outArgs }..outStr
	return outStr

return p
"" වෙතින් සම්ප්‍රවේශනය කෙරිණි