Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Module:Sandbox/Jc86035/3

From Wikipedia, the free encyclopedia
require('strict')


local infobox = require('Module:Infobox').infobox

local p = {}

local function getProperty(entity, property, value)
	if entity and entity.claims then
		local claims = entity.claims[property]
		if claims and claims[1] then
			if value == 'string' then
				return claims[1].mainsnak.datavalue.value, claims[1].qualifiers
			end
			return claims[1].mainsnak.datavalue.value.id, claims[1].qualifiers
		end
	end
end

local function getQualifier(qualifiers, property, value)
	local claims = qualifiers[property]
	if claims and claims[1] then
		if value == 'string' then
			return claims[1].datavalue.value
		end
		return claims[1].datavalue.value.id
	end
end

function p.test(frame)
	local args = frame.args
	local entity = mw.wikibase.getEntity(args.qid)
	local data = {
		title = 'Title',
		aboveclass = 'summary',
		
		label3 = 'Language', data3 = args.language,
		
		label10 = 'Artist', data10 = args.artist,
		
		label20 = 'ISWC', data20 = (args.ISWC or args.iswc or getProperty(entity, 'P1827', 'string')),
		
		label21 = 'ISRC', data21 = (args.ISRC or args.isrc),
	}
	
	local recording
	
	if not data.data10 or not data.data21 then
		local artist, qualifiers = getProperty(entity, 'P175')
		if artist then data.data10 = data.data10 or mw.wikibase.getLabel(artist) end
		local subject_of = getQualifier(qualifiers, 'P805')
		if subject_of then
			recording = mw.wikibase.getEntity(subject_of)
			local isrc = getProperty(recording, 'P1243', 'string')
			data.data21 = data.data21 or isrc
		end
	end
	
	return infobox(data)
end

return p