跳转到内容

模組:Al-iw

维基百科,自由的百科全书
文档图示 模块文档[创建]
require('strict')

local getArgs = require('Module:Arguments').getArgs
local p = {}

local qualityIcon = require('Module:Class/icon')._main
local importanceIcon = require('Module:Importance/icon2')._main

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
	local _icons = {}
	if c ~= nil then
		table.insert(_icons, qualityIcon{c})
	end
	if i ~= nil then
		table.insert(_icons, importanceIcon{i})
	end
	
	if #_icons >0  then
		ret = table.concat(_icons, '') .. ' '
	end
	
	
	-- Article link and note
	link = link or 'Special:RandomPage>隨機頁面'
	local _, _, target, text = link:find("^:?([^>]-)%s*>%s*(.+)$")
	if target then
		_ret = '[[:' .. target:gsub('_', ' ') .. '|' .. text .. ']]'
	else
		_ret = '[[:' .. link:gsub('_', ' ') .. ']]'
	end
	
	if linknote ~= nil then
		local note = ''
   		local _, _, mark, notetext = mw.ustring.find(linknote, '^(%S)%s+(.*)$')
		if mark then
			note = '<sup role="note" title="' .. notetext .. '">' .. mark .. '</sup>'
		else
			note = '<sup 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("^:?([^>]-)%s*>%s*(.+)$")
			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 = '<small>〔' .. _ret .. '〕</small>'
		
		ret = ret .. _ret
		_ret = ''
	end
	

	-- RETURN
    return ret
end

return p