模組:WikipediaHonors
外观
local data = require('Module:WikipediaHonor/data')
local yesno = require('Module:Yesno')
local function error (text)
return require('Module:Error').error{[1] = text}
end
local z = {}
function typelist(type)
local typelist = {
["pagename"] = "頁面",
["section"] = "章節",
["honor"] = "榮譽"
}
if typelist[type] == nil then
return "Unknow type <code>" .. type .. '</code>'
end
return typelist[type]
end
function extractAliases(item)
allnames = {item['code']}
for j, alias in ipairs(item['aliases']) do
table.insert(allnames, alias)
end
return allnames
end
function z.data(frame)
local wt = [=[
{|class="wikitable
|-
!資料類型!!編碼!!可使用的代碼!!名稱!!英文全名!!頒發原因及描述!!章節!!對應模板!!對應分類
]=]
for i, item in ipairs(data) do
allnames = extractAliases(item)
wt = wt .. string.format([=[
|-
|%s
|%s
|
* %s
|%s
|%s
|style="width:200px;"|
* %s
|%s
|%s
|%s
]=],
typelist(item['type']),
item['code'],
mw.text.listToText(allnames, '\n* ', '\n* '),
item['name'],
item['fullname'],
((item['reason'] and item['reason'] .. '\n* ') or '') .. ((item['description'] and item['description']:gsub(',', '\n* '):gsub('及', ' + '):gsub('或', ' / ')) or ''),
((item['section'] and '[[WP:WPH#' .. item['section'] .. ']]') or ''),
((item['template'] and '[[:Template:' .. item['template'] .. ']]') or ''),
((item['category'] and '[[:Category:' .. item['category'] .. ']]') or '')
)
end
wt = wt .. '|}'
return frame:preprocess(wt)
end
function main(arg,itemarg)
map = {}
for i, item in ipairs(data) do
map[item['code']:lower()] = i
for j, alias in ipairs(item['aliases']) do
map[alias:lower()] = i
end
end
if arg ~= nil then
if arg and map[mw.text.trim(arg:lower())] then
arg = data[map[mw.text.trim(arg:lower())]]
return arg[itemarg]
elseif arg and mw.text.trim(arg) ~= '' then
return 'error'
end
else
return nil
end
end
function z.getlevel(frame)
if frame.args.parent then
args = frame:getParent().args
else
args = frame.args
end
local item = main(args[1],'code')
if item == nil then
return error('[[Module:WikipediaHonor]]錯誤:沒有參數<code>1</code>')
elseif item == 'error' then
return error('未知榮譽類型:<code>' .. args[1] .. '</code>')
elseif yesno(args['nolink']) then
return main(args[1],'name')
else
return '[[WP:WPH#' .. (main(args[1],'section') or '') .. '|' .. main(args[1],'name') .. ']]'
end
end
function z.getnewrequest(frame)
local args = frame.args
local item = main(args[1],'code')
if item == nil then
return error('[[Module:WikipediaHonor]]錯誤:沒有參數<code>1</code>')
elseif item == 'error' then
return error('未知榮譽類型:<code>' .. args[1] .. '</code>')
else
local arglist = {
['title'] = 'Wikipedia:維基榮譽/申請與變更/申請區',
['paid'] = 'action=edit§ion=new&preload=Template:HonorsApplication/preload2&preloadparams[]=' .. main(args[1],'section'),
['text'] = '點此申請'
}
return frame:expandTemplate{title = "Anchor",args = {[1] = main(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
return z