模块:Featured article list
来自从零开始
更多操作
此模块的文档可以在模块:Featured article list/doc创建
local randoms = mw.loadData 'Module:Featured article list/randoms'
local dates = mw.loadData 'Module:Featured article list/dates'
local p = {}
function p.main(frame)
local lang = mw.language.getContentLanguage()
local year = lang:formatDate('Y', nil, true)
local month = lang:formatDate('n', nil, true)
local day = lang:formatDate('j', nil, true)
if dates[year] and dates[year][month] and dates[year][month][day] then
return frame:preprocess(dates[year][month][day])
elseif dates['any'] and dates['any'][month] and dates['any'][month][day] then
return frame:preprocess(dates['any'][month][day])
end
local edits = mw.site.stats.edits
local title = randoms[edits % randoms.length + 1]
return frame:expandTemplate {title = title}
end
function p.list(frame)
local node = mw.html.create ''
node:wikitext '共有以下页面可以显示'
node:newline()
local ul = node:tag 'ul'
for _, v in ipairs(randoms) do
ul:tag 'li'
:wikitext('[[' .. v .. ']]')
end
local edits = mw.site.stats.edits
local title = randoms[edits % randoms.length + 1]
node:wikitext('当前显示的页面名称为:[[' ..title .. ']]')
return node
end
function p.listRandoms(frame)
local node = mw.html.create ''
node:wikitext '本站随机展示的特色条目中共有以下内容:'
local ol = mw.html.create 'ol'
for _, v in ipairs(randoms) do
local li = ol:tag 'li'
li:wikitext(string.format('[[%s]]([[Special:EditPage/%s|编辑]])', v, v))
li:newline()
local successes, result = pcall(frame.expandTemplate, frame, {title = v})
li:wikitext('<div>' ..result.. '</div>')
end
return ol
end
return p