Modul:Infobox

Aus Android Wiki

Dieses Modul hilft bei der Erstellung der Vorlage Infobox.

  • renderAnzeige - Erstellt aus den drei Informations-Eigenschaften Bildschirmdiagonale (d:Property:P10), Bildschirmauflösung (Menge) (d:Property:P35) und Pixeldichte (d:Property:P37) eine Komma-separierte Liste an formatierten Werten für den Informationspunkt Anzeige

Skriptfehler: Interner Lua-Fehler: Der Interpreter beendet sich mit dem Status 127.

lang = mw.getContentLanguage()
function needsWhitespace(unit)
	--[=====[ 
	hacky workaround, because I don't know how to easily check, if the unit
	is a superscript, which shouldn't have a whitespace between the value
	and the unit itself. Therefore: Here's a list of units I remember.
	--]=====]
	local unitsWithoutWhitespace = {
		["″"] = true,
		["°"] = true,
		["′"] = true,
		["″"] = true,
	}
	if unitsWithoutWhitespace[unit] then
		return false
	else
		return true
	end
end

function getValueWithUnit(prop)
	local result = ''
	local propValue = prop.mainsnak and prop.mainsnak.datavalue
	if propValue and propValue.value and propValue.value.amount then
		result = result .. lang:formatNum(tonumber(propValue.value.amount))
		if propValue.value.unit then
			local unit = mw.wikibase.label(propValue.value.unit:match('Q%d+$'))
			if needsWhitespace(unit) then
				result = result .. " "
			end
			result = result .. unit
		end
	end
	return result
end

function getValue(prop)
	local result = ''
	local propValue = prop.mainsnak and prop.mainsnak.datavalue
	if propValue and propValue.value and propValue.value.amount then
		result = result .. lang:formatNum(tonumber(propValue.value.amount))
	end
	return result
end

function getScreenSize(property)
	local result = ''
	local needToClose = false
	if property then
		for key, prop in pairs(property) do
			if key == 1 then
				result = result .. getValueWithUnit(prop) .. " "
			elseif key == 2 then
				needToClose = true
				result = result .. "(" .. getValueWithUnit(prop)
			else
				result = result .. getValueWithUnit(prop)
			end
		end
		if needToClose then
			result = result .. ")"
		end
	end
	return result
end

function getScreenResolution(property)
	local result = ''
	if property then
		if property[2] then
			result = getValue(property[1]) .. " x " .. getValueWithUnit(property[2])
		else
			result = getValueWithUnit(property[1])
		end
	end
	return result
end

function getScreenPpi(property)
	return getValueWithUnit(property[1])
end

function renderAnzeige()
	local entity = mw.wikibase.getEntityObject()
	local result = ''
	if not entity or not entity.claims then return end --the entity doesnt exist or have no claims
    local screenSize = getScreenSize(entity.claims['P10'])
    local screenResolution = getScreenResolution(entity.claims['P35'])
    local screenPpi = getScreenPpi(entity.claims['P37'])
    if screenSize then
    	result = result .. screenSize
	end
	if screenResolution then
		if result ~= "" then
			result = result .. ", "
		end
		result = result .. screenResolution
	end
	if screenPpi then
		if result ~= "" then
			result = result .. ", "
		end
		result = result .. screenPpi
	end
	return result
end

return {
    renderAnzeige = renderAnzeige
}