Content deleted Content added
sync |
clean for readability |
||
Line 3:
require('Module:No globals')
local getImageName = require( 'Module:Portal' ).image▼
local yesno = require( 'Module:Yesno' )▼
local p = {}
local function checkPortalExists(portal)
return
end
▲local getImageName = require( 'Module:Portal' ).image
▲local yesno = require( 'Module:Yesno' )
local trackingEnabled = true▼
-- Check whether to do tracking in this namespace
-- Returns true unless the page is one of the banned namespaces
local function
local
end
Line 37 ⟶ 31:
-- Returns false if the page title matches one of the banned strings
-- Otherwise returns true
local function
local
local match = string.match
▲ if (string.match(thisPageLC, "/doc") ~= nil) then
▲ if (string.match(thisPageLC, "/test") ~= nil) then
end
-- Builds the portal bar used by {{portal bar}}.
function p._main( portals, args )
if #portals < 1 then return '' end
local nav = mw.html.create( 'div' )
Line 74 ⟶ 61:
end
▲ local trackingEnabled = true
if (args.tracking == 'no') or (args.tracking == 'n') or (args.tracking == 'false') then▼
local tracking = args.tracking
not isTrackedNamespace() or not isTrackedPagename() then
trackingEnabled = false
end
-- TODO: This used to say 'if no portals are specified', but we return early
-- If no portals have been specified, display an error and add the page to a tracking category.▼
-- above. Someone should check whether this is really 'portals[1]' or #portals < 0.
-- If the first portal is not specified,
if not portals[1] then
root:tag('strong')
:addClass('error')
end
if
root:wikitext('[[Category:Portal templates without a parameter]]')
end
Line 98 ⟶ 85:
end
-- scan for nonexistent portals, if they exist remove them from the portals
-- table. If redlinks=yes, then don't remove local portallen = #portals
-- traverse the list backwards to ensure that no portals are missed
-- (table.remove also moves down the portals in the list, so that the next -- portal isn't checked if going fowards. going backwards allows us to --
for i=portallen,1,-1 do
-- the use of pcall here catches any errors that may occour when
-- attempting to locate pages when the page name is invalid. if pcall --
if not pcall(checkPortalExists, portals[i]) or not checkPortalExists(portals[i]) then
-- Getting here means a redlinked portal has been found
if redlinks == 'yes' -- 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
Line 119 ⟶ 115:
end
-- 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 not
if #portals == 0 then
if trackingEnabled then
Line 139 ⟶ 136:
:tag( 'li' )
:css( 'display', 'inline' )
:css( 'white-space', 'nowrap' )
:css( '
:
'[[File:
) )
'[[Portal:%s|%s portal]]', portal, portal ▲ ) )
end
Line 157 ⟶ 156:
-- Processes external arguments and sends them to the other functions.
function p.main( frame )
-- If called via #invoke, use the args passed into the invoking template, or
--
--
local origArgs
if type( frame.getParent ) == 'function' then
Line 171 ⟶ 169:
origArgs = frame
end
-- Process the args to make an array of portal names that can be used with
-- ipairs. We need to use ipairs because we want to list all the portals in --
-- to deal with positional arguments passed explicitly, for example --
-- are present, so we need to make sure they are all removed.
local portals, args = {}, {}
for k, v in pairs( origArgs ) do
if type( k ) == 'number' and type( v ) == 'string' then
if mw.ustring.find( v, '%S' ) then -- Remove blank values.
table.insert( portals, k )
Line 190 ⟶ 191:
table.sort( portals )
for i, v in ipairs( portals ) do
portals[ i ] = mw.text.trim( origArgs[ v ] )
end
return p._main( portals, args )
|