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, | local function parseContent(title, args, optionsList) | ||
if | if 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 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 | ||
for _, options in next, optionsList do | |||
local list, parameter, default, articleOnly = unpack(options, 1, 4) | |||
if not articleOnly or title.namespace==0 then -- only check for templates if we should... | |||
local out = lookUpNamespaceArg(args, parameter) | |||
if type(out) == "string" or (out ~= false and default) then -- ...and if we actually have anything to say about them | |||
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 | 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, { | ||
{'softredirect', cfg.softRedirect, cfg.softRedirectDefault}, | |||
{'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) |