Aktuelle Version |
Dein Text |
Zeile 1: |
Zeile 1: |
| lang = mw.getContentLanguage()
| | function getValue(prop) |
| TBD = "tbd"
| | 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 renderList(claimIdentifier) | | function renderList(claimIdentifier) |
| local totalReviewCount = 0
| | local entity = mw.wikibase.getEntityObject('Q294') |
| local totalWithReview = 0
| |
| local totalReview = 0
| |
| local entity = mw.wikibase.getEntityObject() | |
| result = '' | | result = '' |
| if not entity or not entity.claims then return end --the entity doesnt exist or have no claims | | if not entity or not entity.claims then return end --the entity doesnt exist or have no claims |
Zeile 13: |
Zeile 16: |
| for key, prop in pairs(property) do | | for key, prop in pairs(property) do |
| if prop and prop.mainsnak and prop.mainsnak.datavalue then | | if prop and prop.mainsnak and prop.mainsnak.datavalue then |
| local reviewNumber
| | result = result .. "\n* " .. getValueLabel(prop.mainsnak.datavalue) |
| local reviewString
| |
| if prop.qualifiers['P76'] then
| |
| totalReviewCount = totalReviewCount + 1
| |
| reviewNumber = tonumber(prop.qualifiers['P76'][1].datavalue.value.amount)
| |
| reviewString = lang:formatNum(reviewNumber)
| |
| totalReview = totalReview + reviewNumber
| |
| totalWithReview = totalWithReview + 1
| |
| else
| |
| reviewNumber = TBD
| |
| reviewString = reviewNumber
| |
| end
| |
| result = result .. '<hr><span style="' .. reviewStyle(reviewNumber) .. '>' .. reviewString .. '</span> ' .. getValueLabel(prop) .. '<br>' .. getConclusion(prop) | |
| end | | end |
| end | | end |
| end | | end |
| local reviewNumber
| |
| local reviewString
| |
| if totalWithReview >= (totalReviewCount / 2) then
| |
| reviewNumber = tonumber(string.format("%.1f", totalReview / totalReviewCount))
| |
| reviewString = lang:formatNum(reviewNumber)
| |
| else
| |
| reviewNumber = TBD
| |
| reviewString = reviewNumber
| |
| end
| |
| result = 'Durchschnittliche Bewertung: <span style="' .. reviewStyle(reviewNumber) .. '">' .. reviewString .. '</span><span style="height: 14px;width: 14px;position: absolute;margin-top: -4px;margin-left: 4px;">[[Datei:Baseline-help outline-24px.svg|14px|link=Hilfe:Rezensionen]]</span>\n' .. result
| |
| return result | | return result |
| end
| |
|
| |
| function reviewStyle(reviewNumber)
| |
| local baseStyle = 'padding:0.25em;border-radius:5px;display:inline-block;font-size:24px;color:white;font-weight:bold;height: 1.5em;width: 1.5em;text-align: center;'
| |
| if reviewNumber == TBD then
| |
| return baseStyle .. "background:#a1a5a1;"
| |
| elseif reviewNumber >= 8 then
| |
| return baseStyle .. "background:#1d1;"
| |
| elseif reviewNumber < 8 and reviewNumber >= 4 then
| |
| return baseStyle .. "background:#FFAA00;"
| |
| else
| |
| return baseStyle .. "background:#B22222;"
| |
| end
| |
| end
| |
|
| |
| function getValueLabel(prop)
| |
| local propValue = prop.mainsnak.datavalue
| |
| local linkLabel
| |
| 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'] )
| |
| linkLabel = linkTarget and linkTitle and mw.ustring.format( "[[%s|%s]]", linkTarget, linkTitle )
| |
| or linkTitle
| |
| elseif propValue and propValue['type'] == 'string' then
| |
| linkLabel = propValue.value
| |
| else
| |
| return ""
| |
| end
| |
| if prop.references and prop.references[1] and prop.references[1].snaks['P18'] and prop.references[1].snaks['P18'][1] then
| |
| return "'''Bewertung von:''' [" .. prop.references[1].snaks['P18'][1].datavalue.value .. " " .. linkLabel .. "]"
| |
| end
| |
| return linkLabel
| |
| end
| |
|
| |
| function getConclusion(prop)
| |
| return "'''Positive Erwähnungen:''' " .. prop.qualifiers['P77'][1].datavalue.value ..
| |
| "<br>" ..
| |
| "'''Negative Erwähnungen:''' " .. prop.qualifiers['P78'][1].datavalue.value
| |
| 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 | | end |
|
| |
|