跳转到内容

模組:ProduceEncouragement

被永久保护的模块
维基百科,自由的百科全书

这是本页的一个历史版本,由SunAfterRain留言 | 贡献2024年5月27日 (一) 07:55 建立内容为“local p = {} function p._get_level(level, count) return count and math.floor(count / 5) or level end local category_suffix = '级维基创作奖' function p._get_category_name(level) if level < 10 then return tostring(level) .. category_suffix end -- level = f_level * (10 ^ n_level), 1 <= f_level < 10 (未對f_level執行無條件捨去前) local n_level = math.floor(math.log(level) / math.log(10)) local f_level = math.floor(…”的新页面)编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)
local p = {}

function p._get_level(level, count)
	return count
		and math.floor(count / 5)
		or level
end

local category_suffix = '级维基创作奖'

function p._get_category_name(level)
	if level < 10 then
		return tostring(level) .. category_suffix
	end
	-- level = f_level * (10 ^ n_level), 1 <= f_level < 10 (未對f_level執行無條件捨去前)
	local n_level = math.floor(math.log(level) / math.log(10))
	local f_level = math.floor(level / math.pow(10, n_level))
	return tostring(f_level) .. ('0'):rep(n_level) .. '—' .. tostring(f_level) .. ('9'):rep(n_level) .. category_suffix
end

function p._get_category_index(level)
	-- 2024 -> 024
	return tostring(level):sub(2)
end

local function _arg_to_level(args)
	return p._get_level(tonumber(args['1']) or 1, tonumber(args['count']))
end

-- //// ---

function p.get_level(frame)
	return tostring(_arg_to_level(frame.args))
end

function p.get_category(frame)
	local level = _arg_to_level(frame.args)
	return '[[Category:' .. p._get_category_name(level) .. '|' .. p._get_category_index(level) .. ']]'
end

return p