יחידה:קישור

יחידה זו מיועדת לפונקציות שימושיות לקישורים.

בדיקות

עריכה

local linkUtilities = {}


function linkUtilities.checkIsDismabig( targetPage )
	local targetQid = mw.wikibase.getEntityIdForTitle(targetPage)
	local WIKIDATA_DISAMBIG_QID = 'Q4167410'
	
	if targetQid == nil then
		return false -- target page doesnt have wikidata entity -> hence cant query if disambig
	end
	
	local targetType = mw.wikibase.getBestStatements(targetQid, 'P31')
	for _, v in pairs(targetType) do
		if v.mainsnak and v.mainsnak.datavalue  and v.mainsnak.datavalue.value and v.mainsnak.datavalue.value.id == WIKIDATA_DISAMBIG_QID then
			return true
		end
	end
	return false
end


-- check if target is disambig page
function linkUtilities.isDismabig( frame )
	local targetPage = frame.args['1']
	if targetPage == '' or targetPage == nil then
		targetPage = frame:getTitle()
	end
	return linkUtilities.checkIsDismabig(targetPage)
end

return linkUtilities