יחידה:NUMBEROF – הבדלי גרסאות

מ. רובין (שיחה | תרומות)
אין תקציר עריכה
מ. רובין (שיחה | תרומות)
אין תקציר עריכה
 
(גרסת ביניים אחת של אותו משתמש אינה מוצגת)
שורה 37: שורה 37:
local function getIfLocal(site, action)
local function getIfLocal(site, action)
local localSite = string.match(mw.site.server, 'https?://(.-)%.com$')
local localSite = string.match(mw.site.server, 'https?://(.-)%.com$')
or string.match(mw.site.server, 'https?://(.-)%.co%.il$')
              or string.match(mw.site.server, 'https?://(.-)%.co%.il$')
if site == localSite then
if site == localSite then
if action == 'activeusers' then
if action == 'activeusers' then
שורה 47: שורה 47:


function p.main(frame)
function p.main(frame)
local args = frame:getParent().args
local args = frame.args or frame:getParent().args
local action = trimArg(args[1], 1) -- כמו "articles"
local action = trimArg(args[1], 1) -- articles, edits, etc.
if not action then return -1 end
if not action then return -1 end


שורה 55: שורה 55:
end
end


local site = trimArg(args[2], 2) or 'chabadpedia.co.il'
local site = trimArg(args[2], 2) or ''
if not site:find('.', 1, true) then
if site ~= 'total' and not site:find('.', 1, true) then
site = site .. '.chabadpedia'
site = site .. '.chabadpedia'
end
end


local wantComma = trimArg(args[3])
local wantComma = trimArg(args[3])
-- בדיקה אם מדובר באתר המקומי
local result = getIfLocal(site, action)
local result = getIfLocal(site, action)


-- אם לא נמצא מקומית – ננסה מהקובץ data
if not result then
if not result then
local data = mw.loadData('Module:NUMBEROF/data')
local data = mw.loadData('Module:NUMBEROF/data')
local map = data.map
local map = data.map
data = data.data
data = data.data
local siteData = data[site]
result = data[site]
if siteData then
if result then
result = getValue(siteData, action, map)
result = getValue(result, action, map)
end
end
end
end
שורה 91: שורה 88:
local base = trimArg(args[2]) or 'chabadpedia'
local base = trimArg(args[2]) or 'chabadpedia'
local wantComma = trimArg(args[3])
local wantComma = trimArg(args[3])
local data = mw.loadData('Module:NUMBEROF/' .. (base == 'chabadpedia' and 'rank' or 'other'))
local data = mw.loadData('Module:NUMBEROF/' .. (base == 'chabadpedia' and 'rank' or 'other'))
data = data[base]
data = data[base]
if data then
if data then
local result
local result
שורה 100: שורה 99:
else
else
result = data.rankBySite[parm]
result = data.rankBySite[parm]
if result and wantComma then
result = mw.getContentLanguage():formatNum(result)
end
end
end
if result and wantComma then
if result then
result = mw.getContentLanguage():formatNum(result)
return result
end
end
return result or -1
end
end
return -1
return -1
end
end


return p
return p