Jump to content
Wikipedia The Free Encyclopedia

Module:Science redirect

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
Page template-protected This module is currently protected from editing.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
Warning This Lua module is used on approximately 311,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:

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
| id = R_to_scientific_name
| printworthy = yes
| main category = Redirects to scientific names
| to = the scientific name of an organism (or group of organisms)
}}

Tracking categories

Science redirects ( 13 )

Virus redirects ( 5 )

Mammal redirects ( 5 )

Plant redirects ( 6 )

Fish redirects ( 5 )

Bird redirects ( 5 )

Fungus redirects ( 5 )

Insect redirects ( 6 )

Alga redirects ( 5 )

Spider redirects ( 5 )

Animal redirects ( 11 )

Invalid parameters

The above documentation is transcluded from Module:Science redirect/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.

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

 localp={}

 functionp.R(frame)
 localtemplate=mw.ustring.gsub(frame.args[1],' ','_')
 ifconf.templates[template]then
 returnp._main(frame,'R_'..template,conf.templates[template].name,conf.templates[template].from,conf.templates[template].to,conf.templates[template].category,conf.templates[template].info,conf.templates[template].removeA)
 elseiftemplatethen
 return'<span class="error">The template '..template..'is not valid.</span>\n'
 else
 return'<span class="error">No template specified</span>\n'
 end
 end

 functionp.list(frame)
 localoutstr=""
 localocats={}

 fork,vinpairs(conf.cats)do
 if(v[2])then
 ocats[v[2]]=v[1]
 end
 end

 fork,vinpairs(ocats)do
 localh=mw.ustring.match(v,".*%s(.*)")
 localcatTitle=mw.title.new((h.." redirects"),14):getContent()and(h.." redirects")or(k.." redirects")
 outstr=outstr.."\n=== "..frame:expandTemplate{title='cl',args={catTitle,(mw.language.getContentLanguage():ucfirst(catTitle)),count="yes"}}.." ===\n"
 forkk,vvinpairs(conf.templates)do
 outstr=outstr.."*"..frame:expandTemplate{title='cl',args={("Redirects "..vv.category.." of "..k),count="yes"}}.."\n"
 end
 end

 returnoutstr
 end

 functionp._main(frame,id,name,from,to,category,info,removeA)
 --initialize variables
 localargs=frame:getParent().args
 localsingleNoun,pluralNoun='',''
 localoutStr=''

 --Check for known parameter 1
 localcat=mw.ustring.match(mw.ustring.lower(args[1]or'none'),'^(.-)s?$')
 ifconf.cats[cat]thensingleNoun,pluralNoun=conf.cats[cat][1],conf.cats[cat][2]else
 singleNoun,pluralNoun='an organism'
 outStr='[[Category:Redirects '..category..' using unknown values for parameter 1]]'
 end

 --strip article from singleNoun if removeA is true
 ifremoveA==truethen
 ifsingleNoun=='an organism'thensingleNoun=''elsesingleNoun=(mw.ustring.match(singleNoun,'^an? (.*)$')orsingleNoun)end
 end

 --support alternative indications for printworthy
 ifargs[2]=='unprintworthy'orargs['unprintworthy']=='true'thenargs['printworthy']='no'end

 --build template arguments
 localmain_category='Redirects '..category
 ifpluralNounthenmain_category=main_category..' of '..pluralNounend
 localoutArgs={
 id=id,
 name=mw.ustring.gsub(name,'1ドル',singleNoun),
 from=mw.ustring.gsub(mw.ustring.gsub(from,'1ドル',singleNoun),'2ドル',(pluralNounor'organisms')),
 to=mw.ustring.gsub(mw.ustring.gsub(to,'1ドル',singleNoun),'2ドル',(pluralNounor'organisms')),
 ['main category']=main_category,
 printworthy=(args['printworthy']or'yes'),
 info=info,
 }

 --build output string
 ifframe.args['debug']=='true'then
 localdebugStr='{{Redirect template<br />\n'
 fork,vinpairs(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

 returnoutStr
 end

 returnp

AltStyle によって変換されたページ (->オリジナル) /