Модуль:Wikidata/url

Материал из wikixw
Перейти к навигации Перейти к поиску

Модуль используется для форматирования значений свойств с типом «url» из Викиданных.

Методы[править]

formatUrlValue[править]

  • Используется в свойствах:
    • Ошибка Lua в Модуль:WD на строке 450: attempt to index field 'wikibase' (a nil value).
  • Формат возвращаемого значения:
    <url>[' ('<язык>')']
    
  • Примеры:

formatLangRefs[править]

  • Используется в квалификаторах:
    • Ошибка Lua в Модуль:WD на строке 450: attempt to index field 'wikibase' (a nil value).
  • Формат возвращаемого значения:
    ('<язык>')
    
  • Примеры:
    • (англ.)

local p = {}

local function formatLangRefs( options )
	local langRefs = {}
	if options.qualifiers and options.qualifiers.P407 then
		for _, qualifier in ipairs( options.qualifiers.P407 ) do
			if ( qualifier
					and qualifier.datavalue
					and qualifier.datavalue.type == 'wikibase-entityid' ) then
				local qualifierId = qualifier.datavalue.value.id
				local wbStatus, langRefCodeClaims = pcall( mw.wikibase.getBestStatements, qualifierId, 'P218' )
				if wbStatus and langRefCodeClaims then
					for _, claim in ipairs( langRefCodeClaims ) do
						if ( claim.mainsnak
								and claim.mainsnak.datavalue
								and claim.mainsnak.datavalue.type == 'string' ) then
							local langRefCode = claim.mainsnak.datavalue.value
							table.insert( langRefs, options.frame:expandTemplate{ title = 'ref-' .. langRefCode } )
						end
					end
				end
			end
		end
	end

	return table.concat( langRefs, '&#8203;' )
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