Content deleted Content added
BrokenSegue (talk | contribs) frame:expandTemplate |
Tom.Reding (talk | contribs) m Improve readability of long, compound if-statements |
||
(8 intermediate revisions by 4 users not shown) | |||
Line 37:
if i then
-- year
parts[index] = tonumber(mw.ustring.gsub(dateStr:sub(ptr, i-1), "^
if parts[index] == -0 then
Line 87:
if aY < bY then
return true
end▼
▲ if aY > bY then
return false
end▼
▲ if aM < bM then
return true
end▼
▲ if aM > bM then
return false
end▼
▲ if aD < bD then
return true
end
Line 116 ⟶ 108:
end
local pointInTime = pointsInTime[1]
if pointInTime and
pointInTime['datavalue'] and pointInTime['datavalue']['value'] and pointInTime['datavalue']['value']['time'] then return parseDate(pointInTime['datavalue']['value']['time'])
end
Line 180 ⟶ 176:
end
if not qid then
error("No qid found for page. Please make a Wikidata item for this article")▼
return e
end
local e = mw.wikibase.getEntity(qid)
if not e then▼
▲ error("No such item found: " .. qid)
return e
end
Line 194 ⟶ 189:
if #chanIds == 1 then
local chan = chanIds[1]
if chan and
chan["mainsnak"] and chan["mainsnak"]["datavalue"] and chan["mainsnak"]["datavalue"]["value"] then return chan["mainsnak"]["datavalue"]["value"]
end
Line 208 ⟶ 207:
function p.date( frame )
local e = getEntity(frame)
local chanId = getBestYtChanId(e)
if not chanId then▼
▲ error("Could not find a single best YouTube channel ID for this item. Add a YouTube channel ID or set the rank of one channel ID to be preferred")
local s = newestMatching(e, SUB_COUNT_PID, YT_CHAN_ID_PID, chanId)
if s then
Line 227 ⟶ 225:
--end
end
return
end
error("Could not find a date for YouTube subscriber information. Is there a social media followers statement (P8687) qualified with good values for P585 and P2397?")
function p.dateNice( frame )
local status, obj = pcall(p.date, frame)
return obj
else
return returnError(frame, obj)
▲ end
end
-- the most up to date number of subscribers
function p.subCount( frame )
local subCount = nil
local e = getEntity(frame)
▲ if not e then
▲ local subCount = nil
subCount = -424
return tonumber(subCount)
▲ end
local chanId = getBestYtChanId(e)
if chanId then
local s = newestMatching(e, SUB_COUNT_PID, YT_CHAN_ID_PID, chanId)
if s and
s["mainsnak"] and
s['mainsnak']["datavalue"] and
s['mainsnak']["datavalue"]["value"] and
s['mainsnak']["datavalue"]['value']['amount']
then
subCount = s['mainsnak']["datavalue"]['value']['amount']
end
else
subCount = -404
end
if subCount then
return tonumber(subCount)
else
subCount = -412
return tonumber(subCount)
end
end
Line 255 ⟶ 272:
local status, obj = pcall(p.subCount, frame)
if status then
if obj >= 0 then
return frame:expandTemplate{title="Format price", args = {obj}}
else
return obj
else
return returnError(frame, obj)
|