יחידה:תבנית מידע/טבלת ניווט

מתוך ויקיפדיה, האנציקלופדיה החופשית

יחידה זו מיועדת להוספה של ניווט בתבניות מידע.

אופן השימוש[עריכת קוד מקור]

פרמטרים:

  1. 1 - הערך הקודם בסדרה. אם לא מצוין יגיע מוויקינתונים כd:Property:P155
  2. 2 - הערך הבא בסדרה. אם לא מצוין יגיע מוויקינתונים כd:Property:P155
  3. מקוצר - כאשר מציינים "כן" מקצר את הקישור להבא/הקודם ומשאיר רק שנה. למשל פורמולה 1 עונת 2016 => 2016
  4. סדרה - כאשר הנתון נשאב מוויקינתונים וצפוי להופיע כסדרה יש לציין את שם המאפיין בוויקינתונים. לדוגמה בערכים על סדרות ספורט ‏עונת ספורט של‏ (P3450)
  5. qid - מזהה היישות בוויקינתונים. אם לא מצוין יילקח משם הדף הנוכחי.

דוגמאות[עריכת קוד מקור]

קוד: {{#invoke:תבנית מידע/טבלת ניווט|render|סדרה=P3450|qid=Q20755615|מקוצר=כן}}
תוצאה:
2016
2018
קוד: {{#invoke:תבנית מידע/טבלת ניווט|render|סדרה=P3450|qid=Q255767}}

תוצאה:


local p = {}
local WikidataCrossValidation = require('Module:WikidataCrossValidation')
local PropertyLink = require('Module:PropertyLink')

local function getWikidataValue(entity, property, series, yearsOnly)
	if entity == nil or property==nil then return end
	local res = nil
    local propertyVals
    if series ~= nil then
    	propertyVals = mw.wikibase.getBestStatements( entity, series )
    	if propertyVals and #propertyVals>0 then
    		local seriesId = propertyVals[1] and propertyVals[1].mainsnak and propertyVals[1].mainsnak.datavalue
    		seriesId = seriesId and seriesId.value and seriesId.value.id
    		if seriesId==nil then return end
    		local qualifierVal = propertyVals[1].qualifiers and propertyVals[1].qualifiers[property] and propertyVals[1].qualifiers[property][1]
    		qualifierVal = qualifierVal and qualifierVal.datavalue  and qualifierVal.datavalue.value and qualifierVal.datavalue.value.id
    		if qualifierVal == nil then return end
			--local seriesLabel = mw.wikibase.label(propertyVals[1].mainsnak.datavalue.value.id)
			res = PropertyLink.formatEntity(qualifierVal)
    	end
    else
    	res = PropertyLink.getPropertyByOptions(property, entity)
    end
    
    if yearsOnly and res then
    	if mw.ustring.match(res, '%[%[.+%|.+') then
    		res = mw.ustring.gsub(res, '%[%[(.+)%|.+ ([0-9]+)%]%]', '[[%1|%2]]')
    	else
    		if mw.ustring.match(res, '%[%[(.+ )([0-9]+)%]%]') then
    			res = mw.ustring.gsub(res, '%[%[(.+ )([0-9]+)%]%]', '[[%1%2|%2]]')
    		else
    			res = mw.ustring.gsub(res, '%[%[(.+ )([0-9]+/[0-9]+)([^0-9]-)%]%]', '[[%1%2%3|%2]]')
    		end
    	end
    end
    return res
end

function p.render(frame)
	local Arguments = require('Module:Arguments')
	local templateArgs = Arguments.getArgs(frame)
	local seriesProperty = templateArgs['סדרה']
	local yearsOnly = templateArgs['מקוצר'] == 'כן'
	local maintainceCats = ''
	local entityId = templateArgs['qid'] or mw.wikibase.getEntityIdForCurrentPage()
	local prevLink = frame.args[1]
	if prevLink == nil or prevLink=='' then
		prevLink=getWikidataValue(entityId, 'P155', seriesProperty, yearsOnly)
	else
		local wikidataLink = getWikidataValue(entityId, 'P155', seriesProperty, yearsOnly)
		if wikidataLink==prevLink then
			maintainceCats = maintainceCats .. WikidataCrossValidation.maintainceCategory(WikidataCrossValidation.CrossValidateResult.COMPATIBLE, 'P155')
		end
	end
	local nextLink = frame.args[2]
	
	if nextLink == nil or nextLink=='' then
		nextLink=getWikidataValue(entityId, 'P156', seriesProperty, yearsOnly)
	else
		local wikidataLink = getWikidataValue(entityId, 'P156', seriesProperty, yearsOnly)
		if wikidataLink==nextLink then
			maintainceCats = maintainceCats .. WikidataCrossValidation.maintainceCategory(WikidataCrossValidation.CrossValidateResult.COMPATIBLE, 'P156')
		end
	end	
	if prevLink==nil and nextLink==nil then
		return ''
	end
	local result = ''
	if prevLink~=nil then
		result = result .. '<div style="float:right;">→ '..prevLink..'</div>'
	end
	if nextLink~=nil then
		result = result .. '<div style="float:left;">'..nextLink ..' ←</div>'
	end
	if result ~= '' then
		result = '<div style="font-size:smaller;">'..result ..'</div>'
	end
	return result .. maintainceCats
end

return p