Module:Excerpt: Difference between revisions

Content deleted Content added
m Accept selected= as a string with a numeric value, e.g. "3"
Supporting named article keys in Transclude selected excerpt. Dispose of Efn-ua templates.
Line 68:
 
local function striptemplate(t)
local unwanted = {"[Ee]fn", "[Ee]fn%-la[lu]a", "[Ee]l[mn]", "[Rr]p?", "[Ss]fn[bp]", "[Ss]f[bn]", "NoteTag", "#[Tt]ag:%s*[Rr]ef", "[Rr]efn?",
"[CcDd]n", "[Cc]itation needed", "[Dd]isambiguation needed"}
for _, u in pairs(unwanted) do
Line 215:
 
-- Shared template invocation code for lead and random functions
local function invoke(frame, articlenumberarticlekey)
-- args = { 1,2,... = page names, paragraphs = list e.g. "1,3-5", files = list, more = text}
local args = {} -- args[k] = frame.args[k] or frame:getParent().args[k] for all k in either (numeric or not)
Line 223:
local pagenames = {}
local articlecount = #args
if articlekey then -- 1 for lead template; "selected" for selected template
if articlecount < 1 then err("No articles provided") end
articlekey = tonumber(articlekey) or args[articlekey]
if articlenumber then
if tonumber(articlekey) then
articlenumber = tonumber(articlenumber) or tonumber(args[articlenumber])
-- normalise selected article number into the range 1..#args
if articlecount < 1 then err("No articles provided") end
articlenumber = articlenumber % articlecount
if articlenumber articlekey == 0articlekey then articlenumber =% articlecount end
if articlekey == 0 then articlekey = articlecount end
pagenames = { args[articlenumber] } -- For lead, ignore all but the first unnamed argument
end
pagenames = { args[articlekey] }
else
-- For random, accept any number of page names. If more than one, we'll pick one randomly
if articlecount < 1 then err("No articles provided") end
for i, p in pairs(args) do
if p and type(i) == 'number' then table.insert(pagenames, p) end