יחידה:תבנית מידע/אתר

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

ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:תבנית מידע/אתר/תיעוד

function site(frame)
	local templateArgs = frame.args

	if templateArgs[1] =='-' then return '' end
	
	if templateArgs[1]~= '' and  templateArgs[1]~= nil then
		return templateArgs[1]
	end
	local entityId = nil
	if (templateArgs['qid'] ~= nil and templateArgs['qid'] ~= '') then
		entityId = templateArgs['qid']
	else
		entityId = mw.wikibase.getEntityIdForCurrentPage()
	end	
	if entityId == nil then return '' end
	local sites = mw.wikibase.getBestStatements(entityId, 'P856')
	if #sites == 0 then return '' end

	-- TODO: consider to use qualifier to pick a different site. for simplification currently pick the first
	local siteForFormat = sites[1] and sites[1].mainsnak and sites[1].mainsnak.datavalue.value
	if siteForFormat==nil or siteForFormat=='' then return '' end
	
	local urlModule = require('Module:URL')
	if #siteForFormat<35 then
		return urlModule.url(frame:newChild{ title = title, args = { siteForFormat	} } )
	end
	return '[' .. siteForFormat ..' אתר רשמי]'
end

return 	{
	['אתר']=site,
	site=site
}