Module:RpMainPage: Difference between revisions
Appearance
QA 25.09: заглавная страница графа на языке читателя |
QA 25.09: заглавная страница графа на языке читателя |
||
| Line 53: | Line 53: | ||
local m = msgs(code) | local m = msgs(code) | ||
local ch = chain(code) | local ch = chain(code) | ||
local n = function(ns) return | local lang = mw.language.new(code) | ||
local stats = (m.stats or 'Items: $1 · Properties: $2 · Lexemes: $3'):gsub('%$1', n(120)):gsub('%$2', n(122)):gsub('%$3', n(146)) | local n = function(ns) return lang:formatNum(mw.site.stats.pagesInNamespace(ns)) end | ||
local stats = (m.stats or 'Items: $1 · Properties: $2 · Lexemes: $3'):gsub('%$1', (n(120):gsub('%%','%%%%'))):gsub('%$2', (n(122):gsub('%%','%%%%'))):gsub('%$3', (n(146):gsub('%%','%%%%'))) | |||
local site = 'https://' .. code .. '.reincarnatiopedia.com/' | local site = 'https://' .. code .. '.reincarnatiopedia.com/' | ||
local out = { | local out = { | ||
Latest revision as of 22:10, 24 September 2026
Documentation for this module may be created at Module:RpMainPage/doc
-- Заглавная страница графа Реинкарнациопедии на языке читателя (QA 25.09.2026).
-- Строки: Module:RpMainPage/i18n (316 языков сайтов), ярлыки айтемов — из самого графа с цепочкой запасных языков.
local p = {}
local I18N = mw.loadData('Module:RpMainPage/i18n')
local CONCEPTS = {'Q2','Q3','Q4','Q96','Q82','Q83','Q14','Q98','Q99','Q81','Q6','Q5','Q101','Q9','Q40'}
local PEOPLE = {'Q86','Q85','Q1','Q12','Q13','Q34','Q21','Q24','Q47','Q17','Q38'}
local function chain(code)
local c = {code}
for _, f in ipairs(mw.language.getFallbacksFor(code)) do c[#c + 1] = f end
c[#c + 1] = 'mul'; c[#c + 1] = 'en'
return c
end
local function userlang(frame)
local code = frame:preprocess('{{USERLANGUAGE}}')
if not code or code == '' or code:find('{') then code = 'en' end
return code
end
local function msgs(code)
local out = {}
for _, c in ipairs(chain(code)) do
local t = I18N[c]
if t then for k, v in pairs(t) do if out[k] == nil then out[k] = v end end end
end
return out
end
local function label(id, ch)
for _, c in ipairs(ch) do
local l = mw.wikibase.getLabelByLang(id, c)
if l and l ~= '' then return l end
end
return id
end
local function list(ids, ch)
local r = {}
for _, id in ipairs(ids) do
r[#r + 1] = '* [[Item:' .. id .. '|' .. label(id, ch) .. ']] <small style="color:#72777d">' .. id .. '</small>'
end
return table.concat(r, '\n')
end
function p.title(frame)
return msgs(userlang(frame)).title or 'Reincarnatiopedia knowledge graph'
end
function p.main(frame)
local code = userlang(frame)
local m = msgs(code)
local ch = chain(code)
local lang = mw.language.new(code)
local n = function(ns) return lang:formatNum(mw.site.stats.pagesInNamespace(ns)) end
local stats = (m.stats or 'Items: $1 · Properties: $2 · Lexemes: $3'):gsub('%$1', (n(120):gsub('%%','%%%%'))):gsub('%$2', (n(122):gsub('%%','%%%%'))):gsub('%$3', (n(146):gsub('%%','%%%%')))
local site = 'https://' .. code .. '.reincarnatiopedia.com/'
local out = {
'<div class="rp-main" style="max-width:60em">',
'<p style="font-size:110%">' .. m.intro .. '</p>',
"<p>'''" .. stats .. "'''</p>",
'<div style="display:flex;flex-wrap:wrap;gap:0 2.5em">',
'<div style="flex:1 1 18em">\n=== ' .. m.concepts .. ' ===\n' .. list(CONCEPTS, ch) .. '\n</div>',
'<div style="flex:1 1 18em">\n=== ' .. m.people .. ' ===\n' .. list(PEOPLE, ch) .. '\n</div>',
'</div>',
'\n=== ' .. m.browse .. ' ===',
'* [{{fullurl:Special:AllPages|namespace=120}} ' .. m.allitems .. ']',
'* [{{fullurl:Special:AllPages|namespace=122}} ' .. m.allprops .. ']',
'* [{{fullurl:Special:AllPages|namespace=146}} ' .. m.alllexemes .. ']',
'* [[Special:Search|' .. m.search .. ']]',
'</div>',
}
return frame:preprocess(table.concat(out, '\n'))
end
return p