跳转到内容

模組:WikipediaHonors/sandbox

维基百科,自由的百科全书
local yesno = require('Module:Yesno')
local parse = require('Module:WikipediaHonors/parse').new()
local p = {}

local getArgs = require('Module:Arguments').getArgs

local function makeInvokeFunc(funcName)
	return function (frame)
		local args = getArgs(frame, {
			parentFirst = true
		})
		return p[funcName](args)
	end
end

p.data = makeInvokeFunc('_data')

function p._data(args) 
	return parse:getDataTable()
end

p.getlevel = makeInvokeFunc('_getlevel')

function p._getlevel(args) 
	return parse:check(args[1], 1, (function()
		if yesno(args['nolink']) then
			return parse:getItemVal(args[1],'name')
		else
			return '[[WP:WPH#' .. (parse:getItemVal(args[1], 'section') or '') .. '|' .. parse:getItemVal(args[1],'name') .. ']]'
		end
	end), (function()
		if string.gsub(mw.text.trim(args[1]:lower()), '((%d{1,2}[級级]|)([维維]基|)[创創]作[奖獎]|produce)', '') == mw.text.trim(args[1]:lower()) then
			return false
		else
			return error('檢測到維基創作獎')
		end
	end))
end

p.getnewrequest = makeInvokeFunc('_getnewrequest')

function p._getnewrequest(args)
	return parse:check(args[1], 1, (function()
		local arglist = {
			['title'] = 'Wikipedia:維基榮譽/申請與變更/申請區',
			['paid'] = 'action=edit&section=new&preload=Template:HonorsApplication/preload2&preloadparams[]=' .. parse:getItemVal(args[1], 'section'),
			['text'] = '點此申請'
		}
		return parse.frame:expandTemplate{ title = "Anchor", args = {[1] = parse:getItemVal(args[1], 'section') } }
		.. '<span class="mw-editsection"><span class="mw-editsection-bracket">[</span>' .. require('Module:Fullurl')._fullurl(arglist) .. '<span class="mw-editsection-bracket">]</span></span>'
	end))
end

-- getleveltemplate

p.getcatlink = makeInvokeFunc('_getcatlink')

function p._getcatlink(args)
	return parse:check(args[1], 1, (function()
		return '[[:Category:' .. parse:getItemVal(args[1],'category') .. '|' .. item(args[1],'name') .. ']]'
	end))
end

return p