Module:Portal bar/sandbox: Difference between revisions

Content deleted Content added
use main Module:Portal
factor more code into Module:Portal
Line 3:
require('Module:No globals')
 
local portalModule = require('Module:Portal/sandbox')
local getImageName = portalModule.image
local checkTracking = portalModule._checkTracking
local checkExists = portalModule._checkExists
local processPortalArgs = portalModule._processPortalArgs
local yesno = require( 'Module:Yesno' )
Line 17 ⟶ 18:
-- Builds the portal bar used by {{portal bar}}.
function p._main( portals, args )
-- Don't display a blank navbox if no portals were specified.
if (not portals) or (#portals < 1) then return '' end
-- check for sensible args
Line 37 ⟶ 35:
:addClass(sandbox(args,args.border and 'portal-bar-bordered' or 'portal-bar-unbordered'))
local trackingEnabledargs.tracking = args.tracking and checkTracking()
args.nominimum = true
portals, trackingCats = checkExists(portals, args)
if #portals == 0 then
local return trackingCats = ''
end
 
-- scan for nonexistent portals, if they exist remove them from the portals
-- table. If redlinks=yes, then don't remove
local trackingCats = ''
if not args.redlinks or trackingEnabled then
local existingPortals = {}
for _, portal in ipairs(portals) do
local portalTitle = mw.title.new(portal,"Portal")
if portalTitle and portalTitle.exists then
table.insert(existingPortals,portal)
elseif trackingEnabled then
trackingCats = "[[Category:Portal templates with redlinked portals]]"
end
end
portals = args.redlinks and portals or existingPortals
if #portals == 0 then
return trackingEnabled and "[[Category:Portal templates with all redlinked portals]]" or ""
end
end
local header = nav:tag('span')
header:addClass(sandbox(args,'portal-bar-header'))