模块:Featured phrase list

求闻百科,共笔求闻

本模块用于展示主页的每日佳文列表。如需让你上传的佳文能够显示,请编辑对应的数据部分:

共有以下页面可以显示

当前显示的页面名称为:Qiuwen:每日佳文展示/8月7日
上述文档内容嵌入自Module:Featured phrase list/doc编辑 | 历史
编者可以在本模块的沙盒创建 | 镜像和测试样例创建页面进行实验。
请将模块自身所属的分类添加在文档中。本模块的子页面
--- 复制自:[[Module:Featured picture list]]
local randoms = mw.loadData 'Module:Featured phrase list/randoms'
local dates = mw.loadData 'Module:Featured phrase 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(result)
	end
	return ol
end

return p