Module:Section link: Difference between revisions

m
14 revisions imported from templatewiki:Module:Section_link
m>Ahecht
(Detect anchors in page parameter, other code cleanup)
m (14 revisions imported from templatewiki:Module:Section_link)
 
(4 intermediate revisions by 3 users not shown)
Line 16: Line 16:
end
end


function p._main(page, sections, options, title, displaytitle)
function p._main(page, sections, options, title)
-- Validate input.
-- Validate input.
checkType('_main', 1, page, 'string', true)
checkType('_main', 1, page, 'string', true)
Line 48: Line 48:
if isShowingPage then
if isShowingPage then
page = page or title.prefixedText
page = page or title.prefixedText
if displaytitle and displaytitle ~= '' then
if options.display and options.display ~= '' then
if normalizeTitle(displaytitle) == normalizeTitle(page) then
if normalizeTitle(options.display) == normalizeTitle(page) then
display = displaytitle .. ' ' .. display
display = options.display .. ' ' .. display
else
else
error(string.format(
error(string.format(
'Display title "%s" was ignored since it is ' ..
'Display title "%s" was ignored since it is ' ..
"not equivalent to the page's actual title",
"not equivalent to the page's actual title",
displaytitle
options.display
), 0)
), 0)
end
end
Line 106: Line 106:


-- Sort the arguments.
-- Sort the arguments.
local page, displaytitle
local page
local sections, options = {}, {}
local sections, options = {}, {}
for k, v in pairs(args) do
for k, v in pairs(args) do
Line 112: Line 112:
-- Doing this in the loop because of a bug in [[Module:Arguments]]
-- Doing this in the loop because of a bug in [[Module:Arguments]]
-- when using pairs with deleted arguments.
-- when using pairs with deleted arguments.
page = v
page = mw.text.decode(v, decodeNamedEntities)
elseif type(k) == 'number' then
elseif type(k) == 'number' then
sections[k] = v
sections[k] = v
elseif k == 'display' then
displaytitle = v
else
else
options[k] = v
options[k] = v
Line 142: Line 140:
sections = compressArray(sections)
sections = compressArray(sections)


return p._main(page, sections, options, nil, displaytitle)
return p._main(page, sections, options)
end
end


return p
return p