Moderator, Bürokraten, Checkuser-Berechtigte, developer, emailconfirmed, Oberflächenadministratoren, Oversighter, Administratoren
11.008
Bearbeitungen
(wird später noch gefüllt) |
Keine Bearbeitungszusammenfassung |
||
Zeile 1: | Zeile 1: | ||
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() | function renderAnzeige() | ||
return '' | 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 | end | ||
Bearbeitungen