local function sandbox(args, s)
return args.sandbox and s.."-sand" or s
end
local function checkPortalExists(portal)
return not (mw.title.makeTitle(100, portal).id == 0)
end
if #portals < 1 then return '' end
-- Normalize arguments
args.sandbox = yesno(args.sandbox)
local args.redlinks = yesno(args.redlinks )▼
local nav = mw.html.create( 'div' )
:addClass(sandbox(args,'portal-bar'))
not isTrackedNamespace() or not isTrackedPagename() then
trackingEnabled = false
end
-- TODO: This used to say 'if no portals are specified', but we return early
-- above. Someone should check whether this is really 'portals[1]' or #portals < 0.
-- If the first portal is not specified,
-- display an error and add the page to a tracking category.
local nominimum = args.nominimum
local warning = mw.html.create()
if nominimum ~= 'yes' and nominimum ~= 'y' and nominimum ~= 'true' then
warning:tag('strong')
:addClass('error')
:wikitext('No portals specified: please specify at least one portal')
end
warning:wikitext('[[Category:Portal templates without a parameter]]') ▼
end
return tostring(warning)
end
-- scan for nonexistent portals, if they exist remove them from the portals
-- table. If redlinks=yes, then don't remove
local portallentrackingCats = #portals''
▲ if not portals[1]args.redlinks then
-- traverse the list backwards to ensure that no portals are missed
local existingPortals = {}
-- (table.remove also moves down the portals in the list, so that the next
for _, portal in ipairs(portals) do
-- portal isn't checked if going fowards. going backwards allows us to
local portalTitle = mw.title.new(portal,"Portal")
-- circumvent this issue
if portalTitle.exists then
for i=portallen,1,-1 do
table.insert(existingPortals,portal)
-- the use of pcall here catches any errors that may occour when
▲ if elseif trackingEnabled then
-- attempting to locate pages when the page name is invalid. if pcall
▲ warning:wikitext(' trackingCats = "[[Category:Portal templates withoutwith aredlinked parameterportals]] ')"
-- returns true, then rerun the function to find if the page exists
if not pcall(checkPortalExists, portals[i]) or not checkPortalExists(portals[i]) then
-- Getting here means a redlinked portal has been found
▲ local redlinks = args.redlinks
if redlinks == 'yes' or redlinks == 'y' or redlinks == 'true' or redlinks == 'include' then
-- if redlinks as been set to yes (or similar), add the cleanup
-- category and then break the loop before the portal is removed
-- from the list
if trackingEnabled then
nav:wikitext('[[Category:Portal templates with redlinked portals]]') ▼
end
-- TODO: This looks buggy given the comment above; we will always
-- break if redlinks are yes, whether or not tracking is enabled
break
end
-- remove the portal (this does not happen if redlinks=yes)
table.remove(portals,i)
end
if # portalsexistingPortals == 0 then ▼
end
▲ nav:wikitext('return trackingEnabled and "[[Category:Portal templates with all redlinked portals]] ')" or ""
-- if the length of the table is different, then rows were removed from the
-- table, so portals were removed. If this is the case add the cleanup category
if portallen ~= #portals then
if trackingEnabled then
return '[[Category:Portal templates with all redlinked portals]]'
else
return ""
end
end
if trackingEnabled then
nav:wikitext('[[Category:Portal templates with redlinked portals]]')
end
portals = existingPortals
end
return mw.getCurrentFrame():extensionTag{
name = 'templatestyles', args = { src = styleFile }
} .. tostring( nav ) .. trackingCats
end
|