Documentation icon Dokumentacija modula[predogled] [uredi] [zgodovina] [osveži]

This module implements Template:Portal-inline. This module excepts one unnamed parameter which is the portal to link to and several named parameters:

  • size— optional; Specify |size=tiny to show a 16×16 image instead of the usual size.
  • text— optional; Specify |text=(name) for a different associated name to appear.
  • short— optional; Specify |short=anything to remove portal from the output.
  • redlinks— optional; Specify |redlinks=yes to show the portal if it is redlinked.

-- determine whether we're being called from a sandbox
local isSandbox = mw.getCurrentFrame():getTitle():find('sandbox', 1, true)
local sandbox = isSandbox and '/sandbox' or ''

local getArgs = require('Modul:Arguments').getArgs
local yesno = require('Modul:Yesno')
local portalModule = require('Modul:Portal'..sandbox)
local getImageName = portalModule._image
local checkPortals = portalModule._checkPortals
local processPortalArgs = portalModule._processPortalArgs

local 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:wikitext("Napaka: "..errMsg)
		result = tostring(errTag)..result
	return result

local function image(portal, args)
	local size = args.size == "tiny" and "16x16px" or "32x28px"
	return string.format('[[Slika:%s|class=noviewer|%s]]',getImageName(portal,true), size)

local function link(portal, args)
	local displayName = ""
	if not (args.text == "" or args.text == nil) then
		displayName = args.text
	elseif args.short then
		displayName = portal
		displayName = "Portal " .. portal
	return string.format('[[Portal:%s|%s]]',portal,displayName)

function p._main(portals, 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)
	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,"Predloge za portale Wikipedije","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)
	return image(portals[1],args)..' '[1],args)..(trackingCat or '')

function p.main(frame)
	local origArgs = getArgs(frame)
	local portals, args = processPortalArgs(origArgs)
	return p._main(portals, args)

return p