Modul:Infobox: Unterschied zwischen den Versionen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 21: | Zeile 21: | ||
function getValueWithUnit(prop) | function getValueWithUnit(prop) | ||
local result = '' | local result = '' | ||
local propValue = prop.mainsnak and prop.mainsnak.datavalue | local propValue = prop.mainsnak and prop.mainsnak.datavalue or prop.datavalue | ||
if propValue and propValue.value and propValue.value.amount then | if propValue and propValue.value and propValue.value.amount then | ||
result = result .. lang:formatNum(tonumber(propValue.value.amount)) | result = result .. lang:formatNum(tonumber(propValue.value.amount)) | ||
Zeile 102: | Zeile 102: | ||
end | end | ||
result = result .. screenPpi | result = result .. screenPpi | ||
end | |||
return result | |||
end | |||
function dump(o) | |||
if type(o) == 'table' then | |||
local s = '{ ' | |||
for k,v in pairs(o) do | |||
if type(k) ~= 'number' then k = '"'..k..'"' end | |||
s = s .. '['..k..'] = ' .. dump(v) .. ',' | |||
end | |||
return s .. '} ' | |||
else | |||
return tostring(o) | |||
end | |||
end | |||
function getValueLabel(propValue) | |||
if propValue['type'] == 'wikibase-entityid' then | |||
local linkTarget = mw.wikibase.sitelink( "Q" .. propValue.value['numeric-id'] ) | |||
local linkTitle = mw.wikibase.label( "Q" ..propValue.value['numeric-id'] ) | |||
return linkTarget and linkTitle and mw.ustring.format( "[[%s|%s]]", linkTarget, linkTitle ) | |||
or linkTitle | |||
elseif propValue and propValue['type'] == 'string' then | |||
return propValue.value | |||
end | |||
end | |||
function renderCPU() | |||
local entity = mw.wikibase.getEntityObject() | |||
result = '' | |||
if not entity or not entity.claims then return end --the entity doesnt exist or have no claims | |||
local property = entity.claims['P28'] | |||
if property then | |||
local linkRenderer = require( "Modul:PropertyLink" ) | |||
result = result .. linkRenderer.property({ args = { "P28" } }) | |||
if property and property[1] and property[1].mainsnak and property[1].mainsnak.datavalue and property[1].mainsnak.datavalue.value and property[1].mainsnak.datavalue.value["numeric-id"] then | |||
local processorObjectId = "Q" .. property[1].mainsnak.datavalue.value["numeric-id"] | |||
local processorObject = mw.wikibase.getEntityObject(processorObjectId) | |||
if not processorObject or not processorObject.claims then | |||
return result | |||
end | |||
local p2 = processorObject.claims["P2"] | |||
if p2 and p2[1] and p2[1].mainsnak and p2[1].mainsnak.datavalue then | |||
local label = getValueLabel(p2[1].mainsnak.datavalue) | |||
result = label .. " " .. result | |||
end | |||
if property[1].qualifiers['P30'] then | |||
p30 = property[1].qualifiers['P30'][1] | |||
result = result .. ", " .. getValueWithUnit(p30) | |||
end | |||
local p31 = processorObject.claims["P31"] | |||
for key, prop in pairs(p31) do | |||
if prop and prop.mainsnak and prop.mainsnak.datavalue then | |||
local propValue = prop.mainsnak.datavalue | |||
result = result .. ", " .. getValue(prop) .. "-Kern"; | |||
if prop.qualifiers["P32"] and prop.qualifiers["P32"][1] and prop.qualifiers["P32"][1].datavalue then | |||
result = result .. " " .. getValueLabel(prop.qualifiers["P32"][1].datavalue) .. " CPU" | |||
end | |||
end | |||
end | |||
end | |||
end | end | ||
return result | return result | ||
Zeile 107: | Zeile 169: | ||
return { | return { | ||
renderAnzeige = renderAnzeige | renderAnzeige = renderAnzeige, | ||
renderCPU = renderCPU | |||
} | } |
Version vom 29. Mai 2016, 17:39 Uhr
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 or prop.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
function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
function getValueLabel(propValue)
if propValue['type'] == 'wikibase-entityid' then
local linkTarget = mw.wikibase.sitelink( "Q" .. propValue.value['numeric-id'] )
local linkTitle = mw.wikibase.label( "Q" ..propValue.value['numeric-id'] )
return linkTarget and linkTitle and mw.ustring.format( "[[%s|%s]]", linkTarget, linkTitle )
or linkTitle
elseif propValue and propValue['type'] == 'string' then
return propValue.value
end
end
function renderCPU()
local entity = mw.wikibase.getEntityObject()
result = ''
if not entity or not entity.claims then return end --the entity doesnt exist or have no claims
local property = entity.claims['P28']
if property then
local linkRenderer = require( "Modul:PropertyLink" )
result = result .. linkRenderer.property({ args = { "P28" } })
if property and property[1] and property[1].mainsnak and property[1].mainsnak.datavalue and property[1].mainsnak.datavalue.value and property[1].mainsnak.datavalue.value["numeric-id"] then
local processorObjectId = "Q" .. property[1].mainsnak.datavalue.value["numeric-id"]
local processorObject = mw.wikibase.getEntityObject(processorObjectId)
if not processorObject or not processorObject.claims then
return result
end
local p2 = processorObject.claims["P2"]
if p2 and p2[1] and p2[1].mainsnak and p2[1].mainsnak.datavalue then
local label = getValueLabel(p2[1].mainsnak.datavalue)
result = label .. " " .. result
end
if property[1].qualifiers['P30'] then
p30 = property[1].qualifiers['P30'][1]
result = result .. ", " .. getValueWithUnit(p30)
end
local p31 = processorObject.claims["P31"]
for key, prop in pairs(p31) do
if prop and prop.mainsnak and prop.mainsnak.datavalue then
local propValue = prop.mainsnak.datavalue
result = result .. ", " .. getValue(prop) .. "-Kern";
if prop.qualifiers["P32"] and prop.qualifiers["P32"][1] and prop.qualifiers["P32"][1].datavalue then
result = result .. " " .. getValueLabel(prop.qualifiers["P32"][1].datavalue) .. " CPU"
end
end
end
end
end
return result
end
return {
renderAnzeige = renderAnzeige,
renderCPU = renderCPU
}