Bu modul uchun Modul:Wikidata/url/doc nomli hujjat sahifasini yaratishingiz mumkin

local p = {}

local function formatLangRefs( options )
	local langRefs = ''
	if ( options.qualifiers and options.qualifiers.P407 ) then
		for i, qualifier in pairs( options.qualifiers.P407 ) do
			if ( qualifier
					and qualifier.datavalue
					and qualifier.datavalue.type == 'wikibase-entityid' ) then
				local wbStatus, langRefEntity = pcall( mw.wikibase.getEntityObject, qualifier.datavalue.value.id )
				if ( langRefEntity and langRefEntity.claims ) then
					local WDS = require( 'Module:WikidataSelectors' );
					local langRefCodeClaims = WDS.filter( langRefEntity.claims, 'P218' )
					if langRefCodeClaims then
						for _, claim in pairs( langRefCodeClaims ) do
							if ( claim.mainsnak
									and claim.mainsnak
									and claim.mainsnak.datavalue
									and claim.mainsnak.datavalue.type == 'string' ) then
								local langRefCode = claim.mainsnak.datavalue.value
								langRefs = langRefs .. '​' .. options.frame:expandTemplate{ title = 'ref-' ..langRefCode }
							end
						end
					end
				end
			end
		end
	end

	return langRefs
end

function p.formatUrlValue( context, options, value )
	local moduleUrl = require( 'Module:URL' )
	local langRefs = formatLangRefs( options )
	if not options.length or options.length == '' then
		options.length = math.max( 18, 25 - #langRefs )
	end
	return moduleUrl.formatUrlSingle( context, options, value ) .. langRefs
end

return p