模組:Al-iw
外观
require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local p = {}
local yesno = require('Module:Yesno')
local function tl(title, args)
return mw.getCurrentFrame():expandTemplate{ title = title, args = args }
end
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
function p._main(args)
local ret, _ret = '', ''
-- preparation
local c, i = args.c, args.i
local link, linknote = args[1], args.note
local iw = {}
for i = 1, 10 do
local item = args['iw'..i]
if item ~= nil then table.insert(iw, item) end
end
if args.iw ~= nil then table.insert(iw, args.iw) end
-- Class and importance icons
if c ~= nil then
_ret = _ret .. tl('Class/icon', {c})
end
if i ~= nil then
_ret = _ret .. tl('importance/icon', {i}) -- Though {{importance/icon}} doesn't work well...
end
if _ret ~= '' then
ret = _ret .. ' '
_ret = ''
end
-- Article link and note
_ret = '[[' .. link:gsub('_', ' ') .. ']]'
if linknote ~= nil then
local note = ''
local _, _, mark, notetext = mw.ustring.find(linknote, '^(%S)%s+(.*)$')
if mark then
note = '<sup style="user-select: none;" role="note" title="' .. notetext .. '">' .. mark .. '</sup>'
else
note = '<sup style="user-select: none;" role="note">' .. linknote .. '</sup>'
end
_ret = _ret .. note
end
ret = ret .. _ret
_ret = ''
-- Interwikis
if #iw > 0 then
local _iw = {}
for i = 1, #iw do
local _, _, link, text = iw[i]:find("^:?([^>]+)>(.+)$")
if text == nil then
_, _, link = iw[i]:find("^:?(.+)$")
_, _, text = iw[i]:find("^:?([^:]+):.+$")
end
table.insert(_iw, '[[:' .. link:gsub('_', ' ') .. '|' .. text .. ']]')
end
_ret = table.concat(_iw, ' · ')
_ret = '<span style="user-select: none; font-size: smaller;">[' .. _ret .. ']</span>'
ret = ret .. _ret
_ret = ''
end
-- RETURN
return ret
end
return p