Jump to content
החלפת מצב תפריט
שינוי מצב תפריט ההעדפות
החלפת מצב תפריט אישי
לא בחשבון
כתובת ה־IP שלך תהיה גלויה לציבור אם תעשה עריכות כלשהן.

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

מתוך ויקיפדיה, האנציקלופדיה החופשית
גרסה מ־05:36, 10 באוגוסט 2026 מאת Admin (שיחה | תרומות) (Pinkas: guard mw.wikibase via local stub (self-contained; no Wikidata/Commons fetch))
(הבדל) → הגרסה הקודמת | הגרסה האחרונה (הבדל) | הגרסה הבאה ← (הבדל)

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

-- [Pinkas] Wikibase Client is not installed; route mw.wikibase through a local no-op stub
-- so Wikidata-backed fields degrade to nil/empty instead of raising Lua errors. No external
-- data is ever fetched. See [[Module:Wikibase-stub]].
if not mw.wikibase then mw.wikibase = require( 'Module:Wikibase-stub' ) end
function extractQualifier(claim, qualifier, ignoredValue)
	local values = {}
	if claim.qualifiers and claim.qualifiers[qualifier] then 
		for _,v in pairs(claim.qualifiers[qualifier]) do
			if v.datavalue == nil then
				table.insert(values,  'skip')
			elseif mw.wikibase.label(v.datavalue.value.id) ~= ignoredValue then
				table.insert(values,  mw.wikibase.label(v.datavalue.value.id))
			end
		end
	end
	return values
end

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 ws = mw.wikibase.getBestStatements(entityId, 'P856')
	if #ws == 0 then return '' end

	local siteForFormat = ''
	local languageQualifier = 'P407'
	local countryQualifier = 'P17'
	local endTimeQualifier = 'P582'
	local earliestEndDateQualifier = 'P8554'
	
	for k,v in pairs(ws) do
		if v.mainsnak.datavalue then
			if not preferredOnly and v.rank == 'normal' or v.rank == 'preferred' then 
				-- TODO: this condition fails when we get normal ranked values prior to a preferred ranked value
				preferredOnly = preferredOnly or (v.rank == 'preferred')
				local lang = extractQualifier(v, languageQualifier)
				local countries = extractQualifier(v, countryQualifier)
				local isThereEndTime = extractQualifier(v, endTimeQualifier)
				local isThereEarliestEndDate = extractQualifier(v, earliestEndDateQualifier)
				local url = v.mainsnak.datavalue.value
				
				if (#isThereEndTime == 0 and #isThereEarliestEndDate == 0) then
					siteForFormat = url
				end
			end
		end
	end
	
	-- TODO: consider to use qualifier to pick a different site. for simplification currently pick the first
	
	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
}