Content deleted Content added
Remove imagemap |
Parse "File:" within templates within preamble (testcase: Man Utd). Strip citation/disambiguation needed templates. Declare functions as local. |
||
Line 2:
local mRedirect = require('Module:Redirect')
local errors
-- Attempt to parse [[File:...]] or [[Image:...]], either anywhere or at the start
local startre = ""
if start then startre = "^" end -- a true flag restricts search to start of string
or mw.ustring.match(text, startre .. "%[%[%s*[Ii]mage%s*:.*") -- or [[Image: ...
if image then
end▼
end
-- Return blank text, or an error message if requested▼
local function err(text, options)
if errors then error(text, 2) end▼
return ""
end
-- Entry point for Lua callers
Line 8 ⟶ 26:
errors = options.errors
if not pagenames or #pagenames < 1 then return
local pagename
Line 27 ⟶ 45:
if pagename and pagename ~= "" then
local title = mw.title.new(pagename) -- Find the lead section of the named page
if not title then return
local redir = mRedirect.getTarget(title)
if redir then title = mw.title.new(redir) end
Line 37 ⟶ 55:
pagecount = pagecount - 1 -- ensure that we exit the loop eventually
end
if not text then return
text = mw.ustring.gsub(text, "%c%s*==.*","") -- remove first heading and everything after it
Line 44 ⟶ 62:
text = mw.ustring.gsub(text, "<%s*ref.->.-<%s*/%s*ref%s*>", "") -- remove refs
text = mw.ustring.gsub(text, "<%s*imagemap.->.-<%s*/%s*imagemap%s*>", "") -- remove imagemaps
for _, t in pairs {"[Ee]fn", "[Ee]fn-la", "[Ee]l[mn]", "[Rr]p?", "[Ss]fn[bp]", "[Ss]f[bn]", "NoteTag", "#[Tt]ag:%s*[Rr]ef"
"[CcDd]n", "Citation needed", "Disambiguation needed"} do
text = mw.ustring.gsub(text, "{{%s*" .. t .. "%s*|.-}}", "") -- remove ref and footnote templates
end
Line 67 ⟶ 86:
or mw.ustring.match(text, "^%b{}%s*") or false -- or {{Template}}
if token then
t = t .. token
else -- look for [[File:... embedded in an infobox etc. in the preamble
local image = parseimage(token, false)
if image then -- keep comments and templates only within text body
image = mw.ustring.gsub(image, "|%s*frameless", "|frame") -- excerpt needs a frame to flow around, even if infobox doesn't
files = files + 1
if options.fileflags and options.fileflags[files] then t = t .. image .. "\n" end
end
end
else
token =
▲ or mw.ustring.match(text, "^%[%[%s*[Ii]mage%s*:") -- or [[Image: ...
if token then
▲ token = mw.ustring.match(text, "^%b[]%s*") -- match [[...]] to handle nesting
files = files + 1
if options.fileflags and options.fileflags[files] then t = t .. token end
Line 99 ⟶ 125:
if options.more then text = text .. " '''[[" .. pagename .. "|" .. options.more .. "]]'''" end
return text
▲end
▲-- Return blank text, or an error message if requested
▲function p.err(text, options)
▲ if errors then error(text, 2) end
▲ return ""
end
-- Convert a comma-separated list of numbers or min-max ranges into a list of booleans, e.g. "1,3-5" → {1=true,2=false,3=true,4=true,5=true}
local function
local ranges = mw.text.split(str, ",") -- parse ranges, e.g. "1,3-5" → {"1","3-5"}
local flags = {}
Line 122 ⟶ 142:
-- Shared template invocation code for lead and random functions
local function
-- args = { 1,2,... = page names, paragraphs = list e.g. "1,3-5", files = list, more = text}
local args = frame.args -- from calling module
Line 139 ⟶ 159:
local options = {}
options.paraflags =
options.fileflags =
options.more = args["more"] or pargs["more"]
if options.more and options.more == "" then options.more = "Read more..." end -- more= is short for this default text
Line 150 ⟶ 170:
-- Entry points for template callers using #invoke:
function p.lead(frame) return
function p.random(frame) return
return p
|