תבנית לטבלת מיון לבעלי חיים, צמחים וכו'.


דוגמאות שימוש

דוגמה תוצאה
{{מיון
|שם=אריה אסייתי
|תמונה=Adult Asiatic Lion.jpg
|ממלכה=[[בעלי חיים]]
|מערכה=[[מיתרניים]]
|מחלקה=[[יונקים]]
|סדרה=[[טורפים]]
|משפחה=[[חתוליים]]
|סוג=[[פנתר]]
|מין=[[אריה]]
|תת-מין=אריה אסייתי
|שם מדעי=Panthera leo persica
}}
קריאת טבלת מיוןאריה אסייתי
מיון מדעי
ממלכה: בעלי חיים
מערכה: מיתרניים
מחלקה: יונקים
סדרה: טורפים
משפחה: חתוליים
סוג: פנתר
מין: אריה
תת־מין: אריה אסייתי
שם מדעי
Panthera leo persica
{{מיון
|שם=אריה אסייתי
|תמונה=[[קובץ:Adult Asiatic Lion.jpg|250px]]
|ממלכה=[[בעלי חיים]]
|מערכה=[[מיתרניים]]
|מחלקה=[[יונקים]]
|סדרה=[[טורפים]]
|משפחה=[[חתוליים]]
|סוג=[[פנתר]]
|מין=[[אריה]]
|תת-מין=אריה אסייתי
|שם מדעי=Panthera leo persica
}}
קריאת טבלת מיוןאריה אסייתי
מיון מדעי
ממלכה: בעלי חיים
מערכה: מיתרניים
מחלקה: יונקים
סדרה: טורפים
משפחה: חתוליים
סוג: פנתר
מין: אריה
תת־מין: אריה אסייתי
שם מדעי
Panthera leo persica

local p={}
local l = {} -- local functions
local wikidataTreeCache = nil
local wikidataTaxonomicRanks = {
    	--[146481]= 'על-ממלכה',
        [36732]= 'ממלכה',
        --[2752679]= 'תת-ממלכה',
        [38348] = 'מערכה',
        [334460] = 'מערכה', -- division
        [3504061] = 'על-מחלקה',
        [37517] = 'מחלקה',
        [36602] = 'סדרה',
        [5867959] = 'תת-סדרה',
        --[2136103] = 'על-משפחה',
        [35409] = 'משפחה',
        [2455704] = 'תת-משפחה',
        [34740] = 'סוג',
        [7432] = 'מין'
    }
local wikidataTaxonomicLevels = {
	['ממלכה']=1,
	['מערכה']=1,
	['על-מחלקה']=1,
	['מחלקה']=1,
	['סדרה']=1,
	['תת-סדרה']=1,
	['משפחה']=1,
	['תת-משפחה']=1,
	['סוג']=1,
	['מין']=1
}

local wikidataTaxonProperties = {
	[ "שם מדעי"] = 'P225',
	[ "שנת תיאור הטקסון" ] = 'P574',
	[ "שימור"] = 'P141',
	[ "תפוצה"] = 'P181',
	[ "מופע של"] = 'P31',
	[ "מתאר הטקסון"] = 'P405'
}

--taxon items
local Q_RECOMBINATION = 'Q14594740'

function p.header( kingdom, title )
     if not p.color then
        local colors = {
            [ "חיידקים אמיתיים" ] = "#D3D3D3",
            [ "חיידקים קדומים" ] = "#E0E0F3",
            [ "חיידקים" ] = "#D3D3D3",
            [ "בעלי חיים"]="#f4dda1",
            [ "פטריות"]="#ADD8E6",
            [ "איקריוטיים"]="#CE9EF2",
            [ "אוקריוטיים"]="#CE9EF2",
            [ "צומח"]="#90EE90",
            [ "צמחים"]="#90EE90"
        }        
        local colorKingdom = colors[kingdom]
        if not colorKingdom and kingdom then --pattern search - usefull for links...
            for k,v in pairs( colors ) do
                if string.find( kingdom,k ) then
                    colorKingdom = v
                    break
                end
            end
        end
        p.color = colorKingdom or "#CE9EF2"
    end
    return "! colspan=\"2\" style=\"text-align: center; background-color: " .. p.color .. ";\" | " .. title
end

--return true if claim exist in property of qualifiers
function l.isClaimExist(qualifiers, property, claimId)
	local claims = {}
	if qualifiers and qualifiers[property] then
		for _,claim in pairs(qualifiers[property]) do
			if claim.datavalue.value['id'] == claimId then
				return true
			end
		end
	end
	return false
end

--Get the Wikidata taxonom in localized form.
--@return [[first last|last]], date
local function createTaxonAuthorsStr(entity, pTaxonName)
	local taxonom
	local wikidataTaxonName = mw.wikibase.getAllStatements( entity, pTaxonName )
	local wikidataAuthorsName = wikidataTaxonName and wikidataTaxonName[1] and wikidataTaxonName[1].qualifiers and wikidataTaxonName[1].qualifiers[wikidataTaxonProperties["מתאר הטקסון"]]
	local localizeWikidataAuthorsName = {}
	local missingTaxonomLocalization = false
	if wikidataAuthorsName then
		for k,v in pairs(wikidataAuthorsName) do
			local formattedValue = mw.wikibase.renderSnak(v)
			
			if v and v.datavalue and v.datavalue.value and v.datavalue.value.id then
				_, langLabel = mw.wikibase.getLabelWithLang( v.datavalue.value.id )
				if langLabel~='he' then
					missingTaxonomLocalization = true
				end
			end

			-- Link to author page in format: [[firstName lastName|lastName]]
			formattedValue = mw.ustring.gsub( formattedValue , '(.+ )(.*)', "[[%1 %2|%2]]")
			table.insert(localizeWikidataAuthorsName, formattedValue)
		end
		if #localizeWikidataAuthorsName > 0 then
			if missingTaxonomLocalization then
				taxonom = table.concat(localizeWikidataAuthorsName, ' & ')
				taxonom = taxonom .. '[[קטגוריה:ויקינתונים:ערכים_חסרי_תווית_בעברית: מתאר הטקסון]][[קטגוריה:ויקינתונים:ערכים_חסרי_תווית_בעברית]]'
			else
				taxonom = table.concat(localizeWikidataAuthorsName, ' ו')
			end
		end
	end
	local wikidataProp = require("יחידה:PropertyLink")
    local wikidataTaxonomYear = wikidataProp.getPropertyQualifier( pTaxonName, wikidataTaxonProperties["שנת תיאור הטקסון"])

	-- Append authority year
	if wikidataTaxonomYear then
   		taxonom = (taxonom and (taxonom .. ', '))   -- append comma seperator if author name exist
   		taxonom = (taxonom or '') .. wikidataTaxonomYear
	end
	
	-- parentheses needed if instance-of is a recombination
	if wikidataTaxonName and wikidataTaxonName[1] and l.isClaimExist(wikidataTaxonName[1].qualifiers, wikidataTaxonProperties["מופע של"], Q_RECOMBINATION) then
		taxonom = '(' .. taxonom .. ')'
	end
	
	return taxonom
end

--[[
    Fetch recursively the taxonomic data from wikidata
    -- @param {string} highestRank highest taxonomic rank to fetch for early termination
]]
function p.wikidataTaxonTree(highestRank, entity)
	if wikidataTreeCache~=nil then
		return wikidataTreeCache[highestRank]
	end
    local currentEntityId = entity or mw.wikibase.getEntityIdForCurrentPage()
    local taxonomicTree= {}
    local parentTaxonProperty = 'P171'
    local taxonomicRankproperty = 'P105'
    local parents= {}
    local currentPageTitle = mw.title.getCurrentTitle().text
    while currentEntityId ~= nil do
		mw.log('Access to entity: ' .. currentEntityId)
        local taxLevel = mw.wikibase.getBestStatements( currentEntityId, taxonomicRankproperty )
        taxLevel = taxLevel and taxLevel[1] and taxLevel[1].mainsnak
        taxLevel = taxLevel and taxLevel.datavalue and taxLevel.datavalue.value['numeric-id']
		
		local linkTarget = mw.wikibase.getSitelink( currentEntityId )
        local linkTitle, linkLang = mw.wikibase.getLabelWithLang( currentEntityId ) 
        if not linkTitle or linkLang~='he' then
        	linkTitle = mw.wikibase.getBestStatements(currentEntityId, 'P225')
        	linkTitle = linkTitle and linkTitle[1] and linkTitle[1].mainsnak and mw.wikibase.renderSnak(linkTitle[1].mainsnak)
        	if wikidataTaxonomicRanks[taxLevel]=='סוג' or  wikidataTaxonomicRanks[taxLevel]=='מין' then
        		linkTitle = mw.ustring.format('\'\'%s\'\'', linkTitle)
        	end
      	end
        if wikidataTaxonomicRanks[taxLevel] and linkTitle then
        	local taxValue
        	if linkTarget==nil then
        		taxValue = linkTitle
        	elseif currentPageTitle==linkTarget then
        		taxValue = mw.ustring.format('\'\'\'%s\'\'\'', linkTarget)
        	elseif linkTarget  then
        		taxValue = mw.ustring.format( "[[%s|%s]]", linkTarget, linkTitle )
        	end
        		-- dont override claim if already filled
        		if taxonomicTree[wikidataTaxonomicRanks[taxLevel]] == nil then
                	taxonomicTree[wikidataTaxonomicRanks[taxLevel]] = taxValue
                end
        end
		local parentTaxon = nil
		if highestRank~=wikidataTaxonomicRanks[taxLevel] then
		        parentTaxon = mw.wikibase.getBestStatements( currentEntityId, parentTaxonProperty )
		        parentTaxon = parentTaxon and parentTaxon[1] and parentTaxon[1].mainsnak
		        parentTaxon = parentTaxon and parentTaxon.datavalue
		        parentTaxon = parentTaxon and parentTaxon.value['numeric-id']
		end
        if parentTaxon and not parents[parentTaxon] then
    		parents[parentTaxon]=1
			currentEntityId = 'Q'..parentTaxon
        else 
			currentEntityId = nil
        end
    end
	wikidataTreeCache = taxonomicTree
    return taxonomicTree[highestRank]
end

function p.taxbox( frame )
    local realParams={}
    for i,j in pairs( frame:getParent().args ) do
        if string.len(j)>0 then
            realParams[i]=j
        end
    end
    frame.args=realParams
    
    local wikidataProp = require("יחידה:PropertyLink")
    local classificationParam = {
        "על-ממלכה",
        "קבוצה_1",
        "ממלכה",
        "תת-ממלכה",
        "קבוצה_2",
        "על-מערכה",
        "קבוצה_3",
        "מערכה",
        "קבוצה_4",
        "תת-מערכה",
        "קבוצה",
        "על-מחלקה",
        "קבוצה_5",
        "מחלקה",
        "קבוצה_6",
        "תת-מחלקה",
        "קבוצה_7",
        "אינפרא-מחלקה",
        "על-סדרה",
        "קבוצה_8",
        "סדרה",
        "קבוצה_9",
        "תת-סדרה",
        "קבוצה_10",
        "אינפרא-סדרה",
        "על-משפחה",
        "משפחה",
        "קבוצה_11",
        "תת-משפחה",
        "שבט",
        "תת-שבט",
        "סוג",
        "תת-סוג",
        "מין",
        "תת-מין"
    }

    local classifiedUnderParams = {
        "מחלקות",
        "סדרות",
        "משפחות",
        "תת-משפחות",
        "סוגים",
        "מינים",
        "תת-מינים"
    }
    local taxonomicNameToCode = {
	['ללא חשש'] = 'שימור LC',
	['מין קרוב לאיום'] = 'שימור NT',
	['מין תלוי שימור'] = 'שימור CD',
	['מין פגיע'] = 'שימור VU',
	['מינים בסכנת הכחדה'] = 'שימור EN',
	['מין בסכנת הכחדה חמורה'] = 'שימור CR',
	['מינים שנכחדו בטבע'] = 'שימור EW',
	['נכחד'] = 'שימור EX',
    ['אין מספיק נתונים'] = 'שימור DD',
    ['תלוי שימור'] = 'שימור CD'
	}
	
    local currTitle = tostring( mw.title.getCurrentTitle() )
    local wikidataEntity = frame.args["qid"] or mw.wikibase.getEntityIdForCurrentPage()
    local title = frame.args[ "שם"] or mw.ustring.gsub(currTitle, '%(.+%)', '')
    local headerKingdom = frame.args[ "ממלכה"] or frame.args[ "על-ממלכה"] or p.wikidataTaxonTree("ממלכה", wikidataEntity)
    local mainHeader = p.header( headerKingdom, '<span style="float:left; font-size:70%;">[[קובץ:Information-silk.svg|קישור=עזרה:קריאת טבלת מיון|קריאת טבלת מיון]]</span>' .. title )
    local wikidataEdit = '[[File:Wikidata-logo S.svg|20px|לעריכה בוויקינתונים שמשמש מקור לחלק מהמידע בתבנית|link=' ..((wikidataEntity and 'd:' .. wikidataEntity) or '//www.wikidata.org/wiki/Special:NewItem?label='..mw.uri.encode( currTitle )) .. ']]'

    local imageArea = frame.args[ 'תמונה' ]
    if not imageArea then
    	 imageArea = wikidataProp.getImageLink() 
    elseif not mw.ustring.match(imageArea, '^ *%[%[') and not  mw.ustring.match(imageArea, '^ *<') then
	   	local imageDesc = frame.args['כיתוב']
	   	local imgSuffix
	   	if imageDesc~=nil and #imageDesc>0 then
	   		imgSuffix = mw.ustring.format('|220px|%s]]', imageDesc)
	   	else
	   		imgSuffix = '|220px]]'
	   	end
		if mw.ustring.match(imageArea, '^[Ff]ile:') or 
			mw.ustring.match(imageArea, '^[Ii]mage:') or
			mw.ustring.match(imageArea, '^קובץ:') or
			mw.ustring.match(imageArea, '^תמונה:') then
			imageArea = '[[' .. imageArea .. imgSuffix
		else
			imageArea = '[[File:' .. imageArea .. imgSuffix
			end
	end
    
    imageArea = imageArea and string.format([[
|-
| colspan="2" style="text-align:center;" | %s
]], imageArea )
    if frame.args['כיתוב']  and imageArea then
        imageArea = imageArea .. '<div style="clear: both;"></div>' .. frame.args['כיתוב']
    end

    local distributionMap = frame.args['תפוצה'] or wikidataProp.getImageLink( wikidataTaxonProperties["תפוצה"] ) 
    distributionMap = distributionMap and string.format([[
|-
%s
|-
| colspan="2" style="text-align:center;" | %s
]],p.header( headerKingdom,'[[תחום תפוצה]]'), distributionMap )
    
    if frame.args['כיתוב תפוצה'] and distributionMap then  
        distributionMap = distributionMap ..frame.args['כיתוב תפוצה'] 
    end

    local floweringSeason = frame.args['עונת פריחה']
    floweringSeason = floweringSeason and string.format([[
|-
%s
|-
| colspan="2" style="text-align:center;" | %s
]],p.header( headerKingdom,'עונת פריחה'), floweringSeason )
    
    local synoyms = frame.args[ "שמות נוספים"]
    synoyms = synoyms and string.format([[
|-
%s
|- 
|colspan="2" style="font-size:90%%;text-align:center" |
%s
]],p.header( headerKingdom,'שמות נוספים'), synoyms )
    
    local period = frame.args[ "תקופה"] 
    period = period and string.format([[
|-
%s
|-
| colspan="2" style="text-align:center;" | %s
]],p.header( headerKingdom,'[[יחידת זמן גאולוגית|תקופה]]'), frame.args[ "תקופה"])

    local conservationNote = frame.args[ "הערת שימור"] 
    local iucnStatus = frame.args[ "שימור"] or frame.args[ "מצב שימור"] 
    local wikidataIucnStatus = wikidataProp.getLabel( wikidataTaxonProperties[ "שימור"] )
    if wikidataIucnStatus and taxonomicNameToCode[wikidataIucnStatus] then
        wikidataIucnStatus=taxonomicNameToCode[wikidataIucnStatus]
    end
    local iucnStatusWarn=''
    iucnStatus = iucnStatus or wikidataIucnStatus
    if mw.title.getCurrentTitle():inNamespaces(0, 118) and (iucnStatus ~= 'שימור DO') and (wikidataIucnStatus ~= iucnStatus) then
    	iucnStatusWarn = '[[קטגוריה:דפים עם מצב שימור שאינו תואם את ויקינתונים]]'
    end
    if iucnStatus then
        iucnStatus = frame:expandTemplate{ title = iucnStatus }
        if wikidataEntity then
            local icunStatement = mw.wikibase.getBestStatements(wikidataEntity, wikidataTaxonProperties[ "שימור"])
            icunStatement = icunStatement and icunStatement[1]
            if icunStatement and icunStatement.references and icunStatement.references[1] and icunStatement.references[1].snaks['P627'] then
                local iucnRef = mw.wikibase.renderSnak(icunStatement.references[1].snaks['P627'][1])
                iucnRef = mw.ustring.format('<span dir="rtl">[https://apiv3.iucnredlist.org/api/v3/taxonredirect/%s %s] באתר הרשימה האדומה של [[IUCN]]</span>', iucnRef, title)
                iucnRef = frame:extensionTag{ name = 'ref', content = iucnRef, args = { name = 'IucnRedList', dir = 'rtl' } }
                iucnStatus = iucnStatus..iucnRef
            end
        end
     elseif conservationNote then
          iucnStatus=''
     end
     if iucnStatus or conservationNote then
     	conservationNote = conservationNote or ''
        iucnStatus=iucnStatus..conservationNote..iucnStatusWarn
        iucnStatus = string.format([[
|-
%s
|-
| colspan="2" style="text-align:center;" |
%s
]],p.header( headerKingdom,'[[מצב שימור]]'), iucnStatus )
    end
    
    local classifictionSection = ''
    local taxonRank
    local usesWikidataParam = false
    for i,j in ipairs( classificationParam ) do
        local taxonVal = frame.args[j]
        local taxonHeader = j
        if not taxonVal and wikidataTaxonomicLevels[j] then
            taxonVal = p.wikidataTaxonTree(j, wikidataEntity)
            -- virus are different - avoid using the standard Kingdom terminology
            if taxonVal == '[[נגיף|נגיף]]' and taxonHeader == 'ממלכה' then
            	taxonHeader = 'קבוצה'
            end
            if taxonVal then
                usesWikidataParam = true
            end
        end
        if taxonVal then
            taxonHeader = mw.ustring.gsub( taxonHeader, 'קבוצה_.+','קבוצה')
            taxonRank = j
            if taxonHeader==j then
                local taxonHeaderDisplay = string.gsub( taxonHeader,'-','־')
                if ( mw.title.new( j .. ' (טקסונומיה)', 0 ).id >0) then
                    taxonHeader='[['..taxonHeader..' (טקסונומיה)|'..taxonHeaderDisplay..']]'
                else
                    taxonHeader = taxonHeaderDisplay
                end
            end        
            
            classifictionSection = classifictionSection..'\n|-\n| style="text-align:center;" | '..taxonHeader..': || style="text-align:center;" | '..((currTitle==taxonVal and "'''"..taxonVal.."'''") or taxonVal)
        end
    end
    
    if not taxonRank then --there is no classification either by parameter or by wikidata
        classifictionSection = '\n|-\n| colspan="2" | '..wikidataEdit
    end
    
    local classificationSectionHeader = '[[טקסונומיה (ביולוגיה)|מיון מדעי]]'
    classifictionSection = ('|-\n' .. p.header( headerKingdom, classificationSectionHeader ).. classifictionSection)
    
    
    local underClassification
    for i,j in ipairs( classifiedUnderParams ) do
        if frame.args[j] then
            underClassification='|-\n'..p.header( headerKingdom,j )..'\n|-\n| colspan="2" style="text-align:center;" |\n'..frame.args[j]
            break
        end
    end
    
    local taxonomicName = frame.args[ "שם מדעי"] or wikidataProp.getProperty( wikidataTaxonProperties[ "שם מדעי"])  
    if taxonomicName then
        local taxonomicDisplay = ((not string.find(taxonomicName,"''")) and ( taxonRank=="מין" or taxonRank=="סוג" or taxonRank=="תת-מין") and "''"..taxonomicName.."''" ) or taxonomicName
        local taxonom = frame.args[ "טקסונום"]
        if wikidataEntity and not taxonom then
			taxonom = createTaxonAuthorsStr(wikidataEntity, wikidataTaxonProperties[ "שם מדעי"])
        end

        taxonomicName = '|-\n'..p.header( headerKingdom,"[[שם מדעי]]")..'\n|-\n| colspan="2" style="text-align:center" | [[קובץ:Wikispecies-logo.svg|21px|קישור=ויקימינים]] [[wikispecies:'..taxonomicName..'|'..taxonomicDisplay..']]'
        if taxonom then
            taxonom = '<br /><small>&rlm;'..taxonom..'</small>'
            taxonomicName = taxonomicName..taxonom
        end
    end
    local taxonSections = { imageArea or "", period or "" ,iucnStatus or "", classifictionSection or "", underClassification or "", taxonomicName or "", distributionMap or "", synoyms or "", floweringSeason or "" }
    if usesWikidataParam then
        table.insert(taxonSections, '|-\n| colspan="2" style="text-align:left;" | <span class="editsection">'..wikidataEdit..'</span>' )
    end
    local realSections = {}
    for i,j in ipairs( taxonSections ) do
        if string.len( j )>0 then table.insert( realSections,j ) end
    end
    
    taxonSections = table.concat( realSections, "\n")
    result = string.format([[

{| class="infobox taxobox" style="margin-right: 0.5em; text-align: center;padding:2.5px;max-width:250px;"
|-
%s
%s
|}]], mainHeader,taxonSections )

    return result
end

return p