Module:Science redirect
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 302,000 pages. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
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.
Usage
{{#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:
- To the scientific name of an organism: This is a redirect from a vernacular ("common") name to the scientific name of an organism (or group of organisms).
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 the 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 ( 13 )
- Category:Redirects from alternative scientific names ( 8,735 )
- Category:Redirects to scientific names ( 19,962 )
- Category:Redirects from scientific names ( 977 )
- Category:Redirects to monotypic taxa ( 3,585 )
- Category:Redirects from monotypic taxa ( 3,265 )
Script error: The function "list" does not exist.
Invalid parameters
- Category:Redirects from alternative scientific names using unknown values for parameter 1 ( 21 )
- Category:Redirects to scientific names using unknown values for parameter 1 ( 12 )
- Category:Redirects from scientific names using unknown values for parameter 1 ( 4 )
- Category:Redirects to monotypic taxa using unknown values for parameter 1 ( 15 )
- Category:Redirects from monotypic taxa using unknown values for parameter 1 ( 6 )
local p = {}
local conf = {
from_alternative_scientific_name = {
name = 'From alternative scientific name of $1',
from = 'an alternative scientific name of $1 (or group of $2)',
to = 'the accepted scientific name',
category = 'from alternative scientific names',
}, to_scientific_name = {
name = 'To the scientific name of $1',
from = 'a [[Common name|vernacular ("common") name]]',
to = 'the [[biological nomenclature|scientific name]] of $1 (or group of $2)',
category = 'to scientific names',
}, from_scientific_name = {
name = 'From a scientific name of $1',
from = 'a [[biological nomenclature|scientific name]] of $1 (or group of $2)',
to = 'a [[Common name|vernacular ("common") name]]',
category = 'from scientific names',
}, to_monotypic_taxon = {
name = 'To a monotypic taxon',
from = 'the only lower-ranking member of a monotypic $1 taxon',
to = 'its monotypic taxon',
category = 'to monotypic taxa',
info = "In a biology-related article, when for example a genus has only one species, the [[binomial name]] may be a redirect to the genus.\n** Use {{[[:Template:R from monotypic taxon|R from monotypic taxon]]}} when making a redirect ''from'' a monotypic taxon ''to'' its only member, for example, from a family name to its sole genus.",
removeA = true,
}, from_monotypic_taxon = {
name = 'From a monotypic taxon',
from = 'a monotypic $1 taxon',
to = 'its only lower-ranking member',
category = 'from monotypic taxa',
info = "In a biology-related article, when for example a family has only one genus, the family may be a redirect to the genus.\n** Use {{[[:Template:R to monotypic taxon|R to monotypic taxon]]}} when making a redirect ''to'' a monotypic taxon ''from'' its only member, for example, from a species to the genus of which it is the only member.",
removeA = true,
},
}
function p.R(frame)
local template = mw.ustring.gsub(frame.args[1], ' ', '_')
if conf[template] then
return p._main(frame, conf[template].name, conf[template].from, conf[template].to, conf[template].category, conf[template].info, conf[template].removeA)
elseif template then
return '<span class="error">The template '..template..'is not valid.</span>\n'
else
return '<span class="error">No template specified</span>\n'
end
end
local cats = { -- list entries minus any trailing 's'
plant = {'a plant', 'plants'},
fish = {'a fish', 'fish'},
fishe = {'a fish', 'fish'},
fungu = {'a fungus', 'fungi'},
fungi = {'a fungus', 'fungi'},
spider = {'a spider', 'spiders'},
crustacean = {'a crustacean', 'crustaceans'},
reptile = {'a reptile', 'reptiles'},
insect = {'an insect', 'insects'},
none = {'an organism'},
}
function p._main(frame, name, from, to, category, info, removeA)
--initialize variables
local args = frame:getParent().args
local singleNoun, pluralNoun = '', ''
local cat = mw.ustring.match(mw.ustring.lower(args[1] or 'none'), '^(.-)s?$')
local unknown = false;
--Check for valid category
if cats[cat] then singleNoun, pluralNoun = cats[cat][1], cats[cat][2] else
singleNoun, pluralNoun = 'an organism'
unknown = true
end
--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
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
local outStr = ''
if frame.args['debug'] == 'true' then
outStr = '{{Redirect template\n\n'
for k,v in pairs( outArgs ) do
outStr = outStr..'| '..k..' = '..v..'\n\n'
end
outStr = outStr..'}}'
else
outStr = frame:expandTemplate{ title = 'Redirect template', args = outArgs }
end
if unknown == true then outStr = outStr..'[[Category:Redirects '..category..' using unknown values for parameter 1]]' end
return outStr
end
return p