Module:Taxonbar
- Afrikaans
- Ænglisc
- العربية
- مصرى
- Asturianu
- Azərbaycanca
- تۆرکجه
- Basa Bali
- Беларуская (тарашкевіца)
- Betawi
- Banjar
- ပအိုဝ်ႏဘာႏသာႏ
- বাংলা
- Bosanski
- 閩東語 / Mìng-dĕ̤ng-ngṳ̄
- کوردی
- Čeština
- Cymraeg
- Dansk
- Kadazandusun
- فارسی
- Suomi
- Gaeilge
- Galego
- ગુજરાતી
- 客家語 / Hak-kâ-ngî
- हिन्दी
- Magyar
- Հայերեն
- Jaku Iban
- Bahasa Indonesia
- Ilokano
- 日本語
- Qaraqalpaqsha
- ភាសាខ្មែរ
- ಕನ್ನಡ
- 한국어
- मैथिली
- Minangkabau
- Македонски
- മലയാളം
- Bahasa Melayu
- Malti
- မြန်မာဘာသာ
- مازِرونی
- नेपाली
- Nederlands
- ଓଡ଼ିଆ
- ਪੰਜਾਬੀ
- Kapampangan
- Português
- Română
- ᱥᱟᱱᱛᱟᱲᱤ
- Scots
- سنڌي
- Srpskohrvatski / српскохрватски
- တႆး
- සිංහල
- Simple English
- Slovenčina
- Slovenščina
- Српски / srpski
- தமிழ்
- ᥖᥭᥰ ᥖᥬᥲ ᥑᥨᥒᥰ
- తెలుగు
- ไทย
- Türkmençe
- Türkçe
- Українська
- Oʻzbekcha / ўзбекча
- Tiếng Việt
- Yorùbá
- Vahcuengh
- 閩南語 / Bân-lâm-gí
- 粵語
- 中文
Appearance
From Wikipedia, the free encyclopedia
{{Taxonbar}} (edit talk history links # /subpages /doc /doc edit /sbox /sbox diff /test)
Warning This Lua module is used on approximately 502,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.
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 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.
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.
Main page: Template:Taxonbar
This module uses one or more Wikidata properties; see § Taxon identifiers for details.
This module depends on the following other modules:
| Related pages |
|---|
This module contains the code of {{Taxonbar }}. To use Taxonbar, follow instructions at Template:Taxonbar/doc.
Configuration
Parameters and databases are set by Module:Taxonbar/conf.
Taxon identifiers
Further information: Template:Taxonbar/doc § Taxon identifiers
Testcases
See also: Template:Taxonbar/testcases and Module:Taxonbar/sandbox
For testcases use: {{Taxonbar | from=QID}}
Peach (Prunus persica)
Dog (Canis lupus familiaris)
Eastern bluebird (Sialia sialis)
Honey bee (Apis)
Western honey bee (Apis mellifera)
Clipper butterfly (Parthenos sylvia )
Turkey tail (Trametes versicolor )
Button/portobello mushroom (Agaricus bisporus)
Module editing — to-do list
Further information: Template:Taxonbar/doc § Module editing — to-do list
See also
- Module:Taxonbar/conf – the configuration module to add/remove/edit sources
- {{Taxonbar/exists }} – tests for {{Taxonbar }} existence
- {{Taxonbar/candidate }} – categorize highly-likely and potentially-likely {{Taxonbar }} candidates
- Module:Authority control – a {{Taxonbar }}-like module for unique subjects
- gl:Módulo:Taxonbar – original code source for this module
The above documentation is transcluded from Module:Taxonbar/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
require('strict') localconf=require('Module:Taxonbar/conf')--configuration module localTaxonItalics=require('Module:TaxonItalics')--use a function to conditionally italicize taxon names --[[==========================================================================]] --[[ Local functions ]] --[[==========================================================================]] localfunctionisNilOrEmpty(thing) ifthing==nilorthing==''then returntrue end returnnil end localfunctiongetIdFromWikidata(item,property) localid=nil ifproperty=='PWikispecies:1ドル'then localsiteLinks=item.sitelinks ifsiteLinksthen localspeciesWiki=item.sitelinks.specieswiki ifspeciesWikithen id=speciesWiki.title end end returnid elseifitem.claims[property]==nilthen returnid end --[[ this code picks up deprecated values on wikidata; better to use getBestStatements for _, statement in pairs( item.claims[property] ) do if statement.mainsnak.datavalue then id = statement.mainsnak.datavalue.value break end end ]] localstatements=item:getBestStatements(property)[1] ifstatementsand statements.mainsnakand statements.mainsnak.datavalueand statements.mainsnak.datavalue.value then id=statements.mainsnak.datavalue.value end returnid end localfunctiongetLink(property,db,val) locallink,returnVal='',{} returnVal.isError=false ifmw.ustring.find(val,'//')then link=val else iftype(property)=='number'andproperty>0then localentityObject=mw.wikibase.getEntity('P'..property) localdataType ifentityObjectthendataType=entityObject.datatype elsereturnVal.isError=trueend ifdataType=='external-id'then localformatterURL=nil ifproperty==3746or--Wildflowers of Israel property==3795or--Flora of Israel Online property==5397--Tierstimmenarchiv then formatterURL=entityObject:getBestStatements('P1630')[2]--use 2nd formatterURL for English version end ifformatterURL==nilthenformatterURL=entityObject:getBestStatements('P1630')[1]end--default to [1] ifformatterURLthen ifformatterURL.mainsnak.datavalueandformatterURL.mainsnak.datavalue.valuethen--nil check for ABA link=formatterURL.mainsnak.datavalue.value end end ifdb=='bow'then-- for birds of world which uses eBird identifier link='https://birdsoftheworld.org/bow/species/1ドル' elseifdb=='speciesfungorum'then-- SpeciesFungorum uses Index Fungorum identifier link='https://www.speciesfungorum.org/Names/NamesRecord.asp?RecordID=1ドル' elseifdb=='fossilworks'then link='https://paleobiodb.org/classic/basicTaxonInfo?taxon_no=1ドル' end elseifdataType=='url'then localsubjectItem=entityObject:getBestStatements('P1629')[1] ifsubjectItemthen localofficialWebsite=mw.wikibase.getEntity(subjectItem.mainsnak.datavalue.value.id):getBestStatements('P856')[1] ifofficialWebsitethenlink=officialWebsite.mainsnak.datavalue.valueend end elseifdataType=='string'then localformatterURL=entityObject:getBestStatements('P1630')[1] ifformatterURLthen link=formatterURL.mainsnak.datavalue.value else localsubjectItem=entityObject:getBestStatements('P1629')[1] ifsubjectItemthen localofficialWebsite=mw.wikibase.getEntity(subjectItem.mainsnak.datavalue.value.id):getBestStatements('P856')[1] ifofficialWebsitethenlink=officialWebsite.mainsnak.datavalue.valueend end end else returnVal.isError=true end elseiftype(property)=='string'then link=property end --local valurl = val localvalurl=mw.uri.encode(val,'PATH') valurl=string.gsub(valurl,'%%2F','/')--escape '/' (e.g. issue with P5354); see wikidata T128078 and https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Wikibase/+/664820/3/lib/includes/PropertyInfoSnakUrlExpander.php iftype(property)=='number'then --doublecheck language for Wildflowers of Israel ID ifproperty==3746thenlink=mw.ustring.gsub(link,'/hebrew/','/english/')end --format spaces in PfaF binomials, e.g. "Elaeagnus x ebbingei" ifproperty==4301thenvalurl=mw.ustring.gsub(valurl,'%%20','+')end end valurl=mw.ustring.gsub(valurl,'%%','%%%%') link=mw.ustring.gsub(link,'1ドル',valurl) end link=mw.ustring.gsub(link,'^[Hh][Tt][Tt][Pp]([Ss]?)://','http%1://')--fix wikidata URL val=mw.ustring.match(val,'([^=/]*)/?$')--get display name from end of URL ifmw.ustring.find(link,'//')then returnVal.text='['..link..' '..mw.text.encode(mw.uri.decode(val,'PATH'),'%[%]')..']' elseiflink==''then returnVal.text=val else returnVal.text='<span class="external">[['..link..'|'..val..']]</span>' end returnreturnVal end localfunctioncreateRow(id,label,rawValue,link,withUid) iflinkthen localoutStr='*<span style="white-space:nowrap;">'..label..' <span' ifwithUidthenoutStr=outStr..' class="uid"'end returnoutStr..'>'..link..'</span></span>\n' else return'* '..mw.text.tag('span',{class='error'},'The identifier '..id..' '..rawValue..' is not valid.')..'\n' end end localfunctioncopyTable(inTable) iftype(inTable)~='table'thenreturninTableend localoutTable=setmetatable({},getmetatable(inTable)) forkey,valueinpairs(inTable)dooutTable[copyTable(key)]=copyTable(value)end returnoutTable end localp={} --[[==========================================================================]] --[[ Main ]] --[[==========================================================================]] functionp.authorityControlTaxon(frame) localresolveEntity=require('Module:ResolveEntityId') localwhitelist=require('Module:Taxonbar/whitelist').whitelist--to create acceptableInstanceOf_Strict & acceptableInstanceOf_All localparentArgs=copyTable(frame:getParent().args) localcurrentTitle=mw.title.getCurrentTitle() localcurrentEntityId=mw.wikibase.getEntityIdForCurrentPage() localstringArgs=false localfromTitleCount,firstRow,rowCount=1,0,0 localoutString,errors='','' localiFroms=0--integer size of tFroms, b/c Lua localtFroms={}--non-sequential table of unique froms localtCats={ '[[Category:Taxonbars without from parameter]]', '[[Category:Taxonbars desynced from Wikidata]]', '',-- [3] placeholder for [[Category:Taxonbar pages requiring a Wikidata item]] '',-- [4] placeholder for [[Category:Taxonbars on possible non-taxon pages]] '',-- [5] placeholder for [[Category:Taxonbars with invalid from parameters]] '',-- [6] placeholder for [[Category:Taxonbars with duplicate from parameters]] '',-- [7] placeholder for [[Category:Taxonbars with from2 matching article title]] '',-- [8] placeholder for [[Category:Taxonbars with from2 matching article title & QID]] '',-- [9] placeholder for [[Category:Taxonbars with manual taxon IDs]] '',--[10] placeholder for [[Category:Taxonbars with manual taxon IDs identical to Wikidata]] '',--[11] placeholder for [[Category:Taxonbars with manual taxon IDs differing from Wikidata]] '',--[12] placeholder for [[Category:Taxonbars with unknown parameters]] '',--[13] placeholder for [[Category:Taxonbars with unnamed parameters]] '',--[14] placeholder for [[Category:Taxonbars with multiple manual Wikidata items]] '',--[15] placeholder for [[Category:Taxonbars with automatically added basionyms]] '',--[16] placeholder for [[Category:Taxonbars with automatically added original combinations]] '',--[17] placeholder for [[Category:Taxonbars with automatically added monotypic species]] '',--[18] placeholder for [[Category:Taxonbars with automatically added monotypic genera]] '',--[19] placeholder for [[Category:Taxonbars of monotypic species missing genera on Wikidata]] '',--[20] placeholder for [[Category:Taxonbars of monotypic genera missing species on Wikidata]] '',--[21] placeholder for [[Category:Taxonbars without primary Wikidata taxon IDs]] '',--[22] placeholder for [[Category:Taxonbars without secondary Wikidata taxon IDs]] '',--[23] placeholder for [[Category:Taxonbars with 20–24 taxon IDs]] '',--[24] placeholder for [[Category:Taxonbars with 25–29 taxon IDs]] '',--[25] placeholder for [[Category:Taxonbars with 30–34 taxon IDs]] '',--[26] placeholder for [[Category:Taxonbars with 35–39 taxon IDs]] '',--[27] placeholder for [[Category:Taxonbars with 40–44 taxon IDs]] '',--[28] placeholder for [[Category:Taxonbars with 45+ taxon IDs]] '',--[29] placeholder for [[Category:Taxonbars of monotypic species missing genera on Wikipedia]] '',--[30] placeholder for [[Category:Taxonbars of monotypic genera missing species on Wikipedia]] } localacceptableInstanceOf_Strict=whitelist{args={'strict'}} localacceptableInstanceOf_All=whitelist{args={'all'}} --monotypic flags for WP-side check localmono=nil localmonoWPok=nil localmonoGenus=nil localmonoSpecies=nil localmonoParent=nil--parent taxon name --Assess the page's relationship with Wikidata localcurrentItem=nil ifcurrentTitle.namespace==10then--i.e. Module:Taxonbar/sandbox, Template:Taxonbar/doc, etc. ifresolveEntity._id(parentArgs['from'])then currentItem=mw.wikibase.getEntity(parentArgs['from']) end ifcurrentItem==nilthen ifresolveEntity._id(parentArgs['from1'])then currentItem=mw.wikibase.getEntity(parentArgs['from1']) end end elseifresolveEntity._id(currentEntityId)then currentItem=mw.wikibase.getEntity(currentEntityId) else--currentEntityId == nil/unresolvable tCats[3]='[[Category:Taxonbar pages requiring a Wikidata item]]' end ifcurrentItemthen tCats[4]='[[Category:Taxonbars on possible non-taxon pages]]'--unset if acceptable found for_,instanceOfStateinpairs(currentItem:getBestStatements('P31'))do--instance of localinstanceOf=instanceOfState.mainsnak.datavalue.value.id ifacceptableInstanceOf_All[instanceOf]then tCats[4]='' break end end end --Cleanup args fork,vinpairs(frame:getParent().args)do iftype(k)=='string'then --make args case insensitive locallowerk=mw.ustring.lower(k) ifisNilOrEmpty(parentArgs[lowerk])then parentArgs[k]=nil parentArgs[lowerk]=v end --remap abc to abc1 ifmw.ustring.find(lowerk,'%d$')==nilthen--if no number at end of param ifisNilOrEmpty(parentArgs[lowerk..'1'])then parentArgs[lowerk]=nil lowerk=lowerk..'1' parentArgs[lowerk]=v end end ifvandv~=''then --remap 'for' to 'title' ifmw.ustring.sub(lowerk,1,3)=='for'then localforTitle=mw.ustring.gsub(lowerk,'^for','title',1) ifisNilOrEmpty(parentArgs[forTitle])then parentArgs[lowerk]=nil lowerk=forTitle parentArgs[lowerk]=v end end --find highest from or title param ifmw.ustring.sub(lowerk,1,4)=='from'then localfromNumber=tonumber(mw.ustring.sub(lowerk,5,-1)) iffromNumberandfromNumber>=fromTitleCountthenfromTitleCount=fromNumberend --look for duplicate froms while we're here ifmw.ustring.find(v,'^Q%d')then iftFroms[v]then tCats[6]='[[Category:Taxonbars with duplicate from parameters]]' tFroms[v]=tFroms[v]+1 else tFroms[v]=1 iFroms=iFroms+1 end ifiFroms==2then tCats[14]='[[Category:Taxonbars with multiple manual Wikidata items]]' end end elseifmw.ustring.sub(lowerk,1,5)=='title'then localtitleNumber=tonumber(mw.ustring.sub(lowerk,4,-1)) iftitleNumberandtitleNumber>=fromTitleCountthenfromTitleCount=titleNumberend elseifmw.ustring.lower(v)~='no'andmw.ustring.lower(v)~='yes'then stringArgs=true tCats[9]='[[Category:Taxonbars with manual taxon IDs]]' end end end--if type(k) == 'string' end--for --Check for unknown parameters --create knowns list localacceptableArgs={from=true,}--master list of l/c acceptable args for_,dinpairs(conf.databases)do ifd[1]~='Wikidata'then--made obsolete by from acceptableArgs[mw.ustring.lower(d[1])]=true end end for_,ainpairs(conf.aliases)do acceptableArgs[mw.ustring.lower(a[1])]=true end --create trimmed parents list localbaseParentArgs={}--condensed list of l/c parent args w/o trailing #s fork,_inpairs(parentArgs)do iftype(k)=='string'then locallowerk=mw.ustring.lower(k) localbase=mw.ustring.gsub(lowerk,'[%d]*$','') baseParentArgs[base]=true elseiftype(k)=='number'then tCats[13]='[[Category:Taxonbars with unnamed parameters|'..k..']]' end end --compare lists and spit out unknowns localunknownParams={} fork,_inpairs(baseParentArgs)do ifacceptableArgs[k]==nilthen tCats[12]='[[Category:Taxonbars with unknown parameters|'..k..']]' unknownParams[#unknownParams+1]=k end end --warn if unknown(s) present if#unknownParams>0then localplural='s' localitthem='them' if#unknownParams==1then plural='' itthem='it' end errors=errors..require('Module:If preview')._warning({ mw.ustring.format( 'Unknown parameter%s <code>%s</code>. Please correct %s or consider adding %s to Wikidata.', plural, table.concat(unknownParams,'</code>, <code>'), itthem, itthem ) }) end --Append basionym to arg list, if not already provided ifcurrentItemthen localcurrentBasState=currentItem:getBestStatements('P566')[1]--basionym ifcurrentBasStatethen localdatavalue=currentBasState.mainsnak.datavalue localbasionymId=datavalueanddatavalue.value.id ifbasionymIdandresolveEntity._id(basionymId)andtFroms[basionymId]==nilthen --check that basionym is a strict instance of taxon localbasionymItem=mw.wikibase.getEntity(basionymId) ifbasionymItemthen for_,instanceOfStateinpairs(basionymItem:getBestStatements('P31'))do--instance of localinstanceOf=instanceOfState.mainsnak.datavalue.value.id ifacceptableInstanceOf_Strict[instanceOf]then --housekeeping tFroms[basionymId]=1 iFroms=iFroms+1 fromTitleCount=fromTitleCount+1 --append basionym & track parentArgs['from'..fromTitleCount]=basionymId tCats[15]='[[Category:Taxonbars with automatically added basionyms]]' break endendendendendend --Append original combination to arg list, if not already provided ifcurrentItemthen localcurrentOCState=currentItem:getBestStatements('P1403')[1]--original combination ifcurrentOCStatethen localorcoId=currentOCState.mainsnak.datavalue.value.id iforcoIdandresolveEntity._id(orcoId)andtFroms[orcoId]==nilthen --check that orco is a strict instance of taxon localorcoItem=mw.wikibase.getEntity(orcoId) iforcoItemthen for_,instanceOfStateinpairs(orcoItem:getBestStatements('P31'))do--instance of localinstanceOf=instanceOfState.mainsnak.datavalue.value.id ifacceptableInstanceOf_Strict[instanceOf]then --housekeeping tFroms[orcoId]=1 iFroms=iFroms+1 fromTitleCount=fromTitleCount+1 --append orco & track parentArgs['from'..fromTitleCount]=orcoId tCats[16]='[[Category:Taxonbars with automatically added original combinations]]' break endendendendendend --Append monotypic genus/species to arg list of monotypic species/genus, if not already provided ifcurrentItemthen for_,instanceOfStateinpairs(currentItem:getBestStatements('P31'))do--instance of localtaxonRank=nil localparentItem=nil localparentTaxon=nil localparentTaxonRank=nil localparentMonoGenus=nil--holy grail/tbd localchildItem=nil localchildTaxon=nil localchildTaxonRank=nil localchildMonoSpecies=nil--holy grail/tbd localinstanceOf=instanceOfState.mainsnak.datavalue.value.id ifinstanceOfand(instanceOf=='Q310890'orinstanceOf=='Q47487597')then--monotypic/fossil taxon --find & save monoParent for future WP-side check ifmonoParent==nilthen mono=true locallabel=nil localtaxonName=currentItem:getBestStatements('P225')[1]--taxon name iftaxonNamethen localdatavalue=taxonName.mainsnak.datavalue ifdatavaluethen label=datavalue.value end end label=labelorcurrentItem:getLabel() iflabelthen monoParent=mw.ustring.gsub(label,' .+','') end end localmissingP171orP427sortkey='*' localtaxonRankState=currentItem:getBestStatements('P105')[1]--taxon rank iftaxonRankStatethentaxonRank=taxonRankState.mainsnak.datavalue.value.idend iftaxonRankandtaxonRank=='Q7432'then--species --is monotypic species; add genus monoSpecies=true localparentTaxonState=currentItem:getBestStatements('P171')[1]--parent taxon ifparentTaxonStatethen parentTaxon=parentTaxonState.mainsnak.datavalue.value.id else tCats[19]='[[Category:Taxonbars of monotypic species missing genera on Wikidata|'..missingP171orP427sortkey..']]' break end --confirm parent taxon rank == genus & monotypic ifparentTaxonandresolveEntity._id(parentTaxon)then parentItem=mw.wikibase.getEntity(parentTaxon) ifparentItemthen localparentTaxonRankState=parentItem:getBestStatements('P105')[1]--taxon rank ifparentTaxonRankStatethenparentTaxonRank=parentTaxonRankState.mainsnak.datavalue.value.idend ifparentTaxonRankandparentTaxonRank=='Q34740'then--parent == genus for_,parentInstanceOfStateinpairs(parentItem:getBestStatements('P31'))do--instance of localparentInstanceOf=parentInstanceOfState.mainsnak.datavalue.value.id ifparentInstanceOfand (parentInstanceOf=='Q310890'orparentInstanceOf=='Q47487597')then--monotypic/fossil taxon parentMonoGenus=parentTaxon--confirmed break end end ifparentMonoGenusandtFroms[parentMonoGenus]==nilthen --housekeeping tFroms[parentMonoGenus]=1 iFroms=iFroms+1 fromTitleCount=fromTitleCount+1 --append monotypic genus & track parentArgs['from'..fromTitleCount]=parentMonoGenus tCats[18]='[[Category:Taxonbars with automatically added monotypic genera]]' break endendendend ifparentMonoGenus==nilortFroms[parentMonoGenus]==nilthen tCats[19]='[[Category:Taxonbars of monotypic species missing genera on Wikidata]]' break end elseiftaxonRankandtaxonRank=='Q34740'then--genus --is monotypic genus; add species --(https://www.wikidata.org/wiki/Wikidata:Property_proposal/child_monotypic_taxon unnecessary thanks to P427!) monoGenus=true localchildTaxonState=currentItem:getBestStatements('P427')[1]--taxonomic type ifchildTaxonStatethen childTaxon=childTaxonState.mainsnak.datavalue.value.id else tCats[20]='[[Category:Taxonbars of monotypic genera missing species on Wikidata|'..missingP171orP427sortkey..']]' break end --confirm child taxon rank == species & monotypic ifchildTaxonandresolveEntity._id(childTaxon)then childItem=mw.wikibase.getEntity(childTaxon) ifchildItemthen localchildTaxonRankState=childItem:getBestStatements('P105')[1]--taxon rank ifchildTaxonRankStatethenchildTaxonRank=childTaxonRankState.mainsnak.datavalue.value.idend ifchildTaxonRankandchildTaxonRank=='Q7432'then--child == species for_,childInstanceOfStateinpairs(childItem:getBestStatements('P31'))do--instance of localchildInstanceOf=childInstanceOfState.mainsnak.datavalue.value.id ifchildInstanceOfand (childInstanceOf=='Q310890'orchildInstanceOf=='Q47487597')then--monotypic/fossil taxon childMonoSpecies=childTaxon--confirmed break end end ifchildMonoSpeciesandtFroms[childMonoSpecies]==nilthen --housekeeping tFroms[childMonoSpecies]=1 iFroms=iFroms+1 fromTitleCount=fromTitleCount+1 --append monotypic species & track parentArgs['from'..fromTitleCount]=childMonoSpecies tCats[17]='[[Category:Taxonbars with automatically added monotypic species]]' break endendendend ifchildMonoSpecies==nilortFroms[childMonoSpecies]==nilthen tCats[20]='[[Category:Taxonbars of monotypic genera missing species on Wikidata]]' break end end--monotype searches end--monotype handling end--for end--if currentItem --Setup navbox localnavboxParams={ name='Taxonbar', bodyclass='hlist', listclass='', groupstyle='text-align: left;', } forf=1,fromTitleCount,1 do localelements,title={},nil --cleanup parameters ifparentArgs['from'..f]==''thenparentArgs['from'..f]=nilend ifparentArgs['title'..f]==''thenparentArgs['title'..f]=nilend --remap aliases for_,ainpairs(conf.aliases)do localalias,name=mw.ustring.lower(a[1]),mw.ustring.lower(a[2]) ifparentArgs[alias..f]andparentArgs[name..f]==nilthen parentArgs[name..f]=parentArgs[alias..f] parentArgs[alias..f]=nil end end --Fetch Wikidata item localfrom=resolveEntity._id(parentArgs['from'..f]) localitem=mw.wikibase.getEntity(from) locallabel=nil iftype(item)=='table'then localstatements=item:getBestStatements('P225')[1]--taxon name ifstatementsthen localdatavalue=statements.mainsnak.datavalue ifdatavaluethen label=datavalue.value end end label=labeloritem:getLabel() else ifparentArgs['from'..f]then tCats[1]='' tCats[5]='[[Category:Taxonbars with invalid from parameters]]' errors=errors..mw.text.tag('strong',{class='error'},'Error: "'.. parentArgs['from'..f]..'" is not a valid Wikidata entity ID.<br />') end end iflabelandlabel~=''then title=mw.title.new(label) end iftitle==nilandparentArgs['title'..f]then title=mw.title.new(parentArgs['title'..f]) end iftitle==nilandf==1then title=currentTitle end iftitlethen ifisNilOrEmpty(parentArgs['wikidata'..f])and (title.namespace==0)then ifparentArgs['from'..f]then parentArgs['wikidata'..f]=parentArgs['from'..f] elseifitemthen parentArgs['wikidata'..f]=item.id end end iftitle.namespace==0orstringArgsthen--only in mainspace or if manual overrides exist localsourceCount=0 for_,paramsinpairs(conf.databases)do params[1]=mw.ustring.lower(params[1]) localpropId=params[3] --Wikidata fallback if requested if(itemanditem.claims)and (type(propId)=='string'or(type(propId)=='number'andpropId>0)) then localwikidataId=getIdFromWikidata(item,'P'..propId) localv=parentArgs[params[1]..f] ifwikidataIdthen ifisNilOrEmpty(v)then parentArgs[params[1]..f]=wikidataId else ifvandv~='no'andv~=wikidataIdthen tCats[11]='[[Category:Taxonbars with manual taxon IDs differing from Wikidata]]' elseifvandv==wikidataIdthen tCats[10]='[[Category:Taxonbars with manual taxon IDs identical to Wikidata]]' end end end end if(itemanditem.claims)and ((type(propId)=='number'andpropId<0)) then localwikidataId=getIdFromWikidata(item,'P'..-propId) --mw.addWarning ("propId=" .. tostring(propId) .. "; wikidata=" .. tostring(wikidataId)) localv=parentArgs[params[1]..f] ifv=='yes'then ifwikidataIdthen parentArgs[params[1]..f]=wikidataId else parentArgs[params[1]..f]=nil-- don't want to use 'yes' as id end end end localval=parentArgs[params[1]..f] ifvalandval~=''andmw.ustring.lower(val)~='no'then iftype(propId)=='number'then ifpropId<0thenpropId=-propIdend--allow link ifpropId>0then--link table.insert(elements,createRow(params[1],params[2]..':',val,getLink(propId,params[1],val).text,true)) ifparams[1]=='fossilworks'then-- fossilworks being use to link to PBDB ifelements[#elements]==elements[#elements-1]then-- check if identical PBDB entry already set --mw.addWarning("item has both Fossilworks and PBDB identifers:" .. val) elements[#elements]=nil end end else--propId == 0; no link table.insert(elements,createRow(params[1],params[2]..':',val,val,true)) end else table.insert(elements,createRow(params[1],params[2]..':',val,getLink(propId,params[1],val).text,true)) end ifparams[1]~='wikidata'andparams[1]~='wikispecies'then sourceCount=sourceCount+1 end end end--for _, params in pairs( conf.databases ) do ifsourceCount>=45thentCats[28]='[[Category:Taxonbars with 45+ taxon IDs]]' elseifsourceCount>=40thentCats[27]='[[Category:Taxonbars with 40–44 taxon IDs]]'--endashes elseifsourceCount>=35thentCats[26]='[[Category:Taxonbars with 35–39 taxon IDs]]' elseifsourceCount>=30thentCats[25]='[[Category:Taxonbars with 30–34 taxon IDs]]' elseifsourceCount>=25thentCats[24]='[[Category:Taxonbars with 25–29 taxon IDs]]' elseifsourceCount>=20thentCats[23]='[[Category:Taxonbars with 20–24 taxon IDs]]' end --Generate navbox title ifsourceCount>0then rowCount=rowCount+1 iffirstRow==0thenfirstRow=fend --set title from wikidata if it doesn't exist ifisNilOrEmpty(parentArgs['title'..f])then parentArgs['noTitle'..f]=true parentArgs['title'..f]=title.text end --if it exists now, set row heading to title ifnotisNilOrEmpty(parentArgs['title'..f])then navboxParams['group'..f]=TaxonItalics.italicizeTaxonName(parentArgs['title'..f],false) else navboxParams['group'..f]='' end navboxParams['list'..f]=table.concat(elements) elseifcurrentEntityIdand(currentEntityId==parentArgs['from'..f]orfromTitleCount==1)then tCats[21]='[[Category:Taxonbars without primary Wikidata taxon IDs]]' else tCats[22]='[[Category:Taxonbars without secondary Wikidata taxon IDs]]' end --Tracking cats ifnotisNilOrEmpty(parentArgs['from'..f])then tCats[1]=''--blank "missing from" if 'from' exists ifparentArgs['from'..f]==currentEntityIdthen tCats[2]=''--blank "desynced" if 'from' matches current page end end iftCats[1]~=''then tCats[2]=''--cannot be "desynced" if no 'from' params end ifmonoandmonoWPok==nilthen ifmonoSpeciesthen ifmonoParent==labelthen monoWPok=true tCats[29]='' else tCats[29]='[[Category:Taxonbars of monotypic species missing genera on Wikipedia]]' end end ifmonoGenusthen locallabelGenus=mw.ustring.gsub(label,' .+','') locallabelIsBinomial=mw.ustring.match(label,'^[A-Z][a-z]+ [a-z]+') iflabelIsBinomialandmonoParent==labelGenusthen monoWPok=true tCats[30]='' else tCats[30]='[[Category:Taxonbars of monotypic genera missing species on Wikipedia]]' end end end end--if title.namespace == 0 or stringArgs end--if title end--for f = 1, fromTitleCount, 1 ifrowCount>0then localNavbox=require('Module:Navbox') ifrowCount>1then --remove duplicates and don't bother moving page title to top localrowIDs={} forf=1,fromTitleCount,1 do ifnotisNilOrEmpty(parentArgs['title'..f])then ifrowIDs[parentArgs['wikidata'..f]]then--remove duplicate navboxParams['group'..f]=nil navboxParams['list'..f]=nil else rowIDs[parentArgs['wikidata'..f]]=true end end end ifparentArgs['title'..2]andparentArgs['title'..2]==currentTitle.textthen ifcurrentItemandparentArgs['from'..2]==currentItem['id']then tCats[8]='[[Category:Taxonbars with from2 matching article title & QID]]' else tCats[7]='[[Category:Taxonbars with from2 matching article title]]' end end --adjust navbox for number of rows navboxParams['title']='[[Help:Taxon identifiers|Taxon identifiers]]' ifrowCount>=4then navboxParams['navbar']='plain' else navboxParams['state']='off' navboxParams['navbar']='off' end elseifparentArgs['noTitle'..firstRow]then--show title & taxon for 1-row taxonbars, per talk navboxParams['title']='[[Help:Taxon identifiers|Taxon identifiers]]' navboxParams['state']='off' navboxParams['navbar']='off' else navboxParams['group'..firstRow]='[[Help:Taxon identifiers|Taxon identifiers]]<br />'..navboxParams['group'..firstRow] end --return navbox outString=Navbox._navbox(navboxParams) end--if rowCount > 0 --Add categories ifstring.sub(currentTitle.subpageText,1,9)=='testcases'thenparentArgs['demo']=trueend ifnotisNilOrEmpty(parentArgs['demo'])then outString=outString..mw.text.nowiki(table.concat(tCats))..'<br />' elseifcurrentTitle.namespace==0then outString=outString..table.concat(tCats) end returnoutString..errors end functionp.taxonbar(frame)returnp.authorityControlTaxon(frame:newChild{title=frame:getTitle()})end returnp