Module:Pagetype: Difference between revisions

Jump to navigation Jump to search
performance improvements and bug fix by User:Aidan9382
m (1 revision imported)
Template:Track listing>MSGJ
(performance improvements and bug fix by User:Aidan9382)
Line 110: Line 110:
end
end


local function parseContent(title, args, list, parameter, default, articleOnly)
local function parseContent(title, args, optionsList)
if articleOnly and title.namespace~=0 -- only detect in mainspace
if title.namespace==828 and title.subpageText~='doc' -- don't detect modules
or title.namespace==828 and title.subpageText~='doc' -- don't detect modules
or not title.exists -- can't check unless page exists
or not title.exists -- can't check unless page exists
then
then
return nil
return nil
end
end
local templates = mw.loadData('Module:Pagetype/' .. list)
local content = title:getContent()
local content = title:getContent()
if content == nil then
if content == nil then
return nil
return nil
end
end
content = require('Module:Wikitext Parsing').PrepareText(content) -- disregard templates which do not have any affect  
local templates -- lazily evaluated
local templateNames = {}
for _, options in next, optionsList do
local templateFound = false
local list, parameter, default, articleOnly = unpack(options, 1, 4)
for template in string.gmatch(content, "{{%s*([^|}]-)%s*[|}]") do
if not articleOnly or title.namespace==0 then -- only check for templates if we should...
if templates[capitalize(template)] then
local out = lookUpNamespaceArg(args, parameter)
templateFound = true
if type(out) == "string" or (out ~= false and default) then -- ...and if we actually have anything to say about them
break
if not templates then
templates = {} -- do our delayed evaluation now that we are required to
content = require('Module:Wikitext Parsing').PrepareText(content) -- disregard templates which do not have any affect
for template in string.gmatch(content, "{{%s*([^|}]-)%s*[|}]") do
templates[#templates+1] = capitalize(template)
end
end
local wantedTemplates = mw.loadData('Module:Pagetype/' .. list)
local templateFound = false
for _, template in next, templates do
if wantedTemplates[template] then
templateFound = true
break
end
end
if templateFound then
if type(out)=='string' then
return out
elseif out ~= false and default then
return default
end
end
end
end
end
end
local out = lookUpNamespaceArg(args, parameter)
if not templateFound then
return nil
elseif type(out)=='string' then
return out
else
return default
end
end
end
end
Line 225: Line 237:
return (
return (
detectRedirects(title, args, cfg)
detectRedirects(title, args, cfg)
or parseContent(title, args, 'softredirect', cfg.softRedirect, cfg.softRedirectDefault)
or parseContent(title, args, {
or parseContent(title, args, 'setindex', cfg.sia, cfg.siaDefault, true)
{'softredirect', cfg.softRedirect, cfg.softRedirectDefault},
or parseContent(title, args, 'disambiguation', cfg.dab, cfg.dabDefault, true)
{'setindex', cfg.sia, cfg.siaDefault, true},
{'disambiguation', cfg.dab, cfg.dabDefault, true},
})
or getMainNamespaceClassPageType(title, args, cfg)
or getMainNamespaceClassPageType(title, args, cfg)
or getNamespaceArgPageType(title, args, cfg)
or getNamespaceArgPageType(title, args, cfg)

Navigation menu