Bước tới nội dung

Mô đun:Portal-inline

Bách khoa toàn thư mở Wikipedia

-- determine whether we're being called from a sandboxlocal isSandbox = mw.getCurrentFrame():getTitle():find('sandbox', 1, true)local sandbox = isSandbox and '/sandbox' or ''local getArgs = require('Module:Arguments').getArgslocal yesno = require('Module:Yesno')local portalModule = require('Module:Portal'..sandbox)local getImageName = portalModule._imagelocal checkPortals = portalModule._checkPortalslocal processPortalArgs = portalModule._processPortalArgslocal p = {}-- Function to format error message and tracking category-- Arguments:--   errMsg: string, or nil/false if no error--   trackingCat: string for tracking category (or empty string)local function formatError(errMsg, trackingCat)	local result = trackingCat or ''	if errMsg then		local errTag = mw.html.create('span')		errTag:addClass("error")		errTag:css("font-size",'100%')		errTag:wikitext("Lỗi: "..errMsg)		result = tostring(errTag)..result	end	return resultendlocal function image(portal, args)	local size = args.size == "tiny" and "16x16px" or "32x28px"	return string.format('[[Tập tin:%s|class=noviewer|%s]]',getImageName(portal,true), size)endlocal function link(portal, args)	local displayName = ""	if not (args.text == "" or args.text == nil) then		displayName = args.text	elseif args.short then		displayName = portal	else		displayName = "Cổng thông tin&#32;" .. portal	end	return string.format('[[Cổng thông tin:%s|%s]]',portal,displayName)endfunction p._main(portals, args)	mw.logObject(args)		-- Normalize all arguments	if args.redlinks == 'include' then args.redlinks = true end	for key, default in pairs({tracking=true,redlinks=false,short=false}) do		if args[key] == nil then args[key] = default end		args[key] = yesno(args[key], default)	end		local trackingCat = ''	local errMsg = nil		-- Check for existing categories, drop if not. 	-- Possible generate tracking category & error message if needed	args.minPortals = args.minPortals or 1	args.maxPortals = args.maxPortals or 1	portals, trackingCat, errMsg = checkPortals(portals,args)	-- use more specific tracking cat for inline portal	trackingCat = mw.ustring.gsub(trackingCat,"Bản mẫu cổng thông tin","Bản mẫu Portal-inline")	-- either too many/few portals, or no portals left after filtering, then return	if errMsg or #portals == 0 then		return formatError(errMsg, trackingCat)	end	return mw.ustring.format('<span class="nowrap">%s </span>%s%s',		image(portals[1],args),link(portals[1],args),(trackingCat or ''))endfunction p.main(frame)	local origArgs = getArgs(frame)	local portals, args = processPortalArgs(origArgs)	return p._main(portals, args)endreturn p