跳转到内容

模組:Al-iw

维基百科,自由的百科全书

这是本页的一个历史版本,由Lopullinen留言 | 贡献2022年6月27日 (一) 13:24编辑。这可能和当前版本存在着巨大的差异。

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, '&thinsp;·&thinsp;')
		_ret = '<span style="user-select: none; font-size: smaller;">[' .. _ret .. ']</span>'
		
		ret = ret .. _ret
		_ret = ''
	end
	

	-- RETURN
    return ret
end

return p