Module:Excerpt: Difference between revisions

Content deleted Content added
Reduce image obtained from infobox to thumb size for [[File:... syntax too
Check for non-free files, including a fix developed in sandbox by Evad37
Line 7:
if errors then error(text, 2) end
return ""
end
 
-- Check image for suitablity
local function checkimage(image)
local page = mw.ustring.match(image, "([Ff]ile%s*:[^|%]]*)") -- File:(name) ...
or mw.ustring.match(image, "([Ii]mage%s*:([^|%]]*)") -- or Image:(name) ...
if not page then return nil end
 
local title = mw.title.new(":" .. page) -- Read description page (for :File:Foo rather than File:Foo)
if not title then return nil end
 
local redir = mRedirect.getTarget(title)
if redir then title = mw.title.new(redir) end
 
local frame = mw.getCurrentFrame()
local desc = frame:preprocess("{{" .. title.prefixedText .. "}}")
return desc and desc ~= "" and not mw.ustring.match(desc, "[Nn]on%-free") -- hide non-free image
end
 
Line 94 ⟶ 111:
for _, v in pairs(options.paraflags) do
if v then allparas = false end -- if any para specifically requested, don't keep all
end
end
 
local maxfile = 0 -- for efficiency, stop checking images after this many have been found
if options.fileflags then
for k, v in pairs(options.fileflags) do
if v and k > maxfile then maxfile = k end
end
end
Line 109 ⟶ 133:
if inlead then -- keep comments and templates only within text body
t = t .. token
elseelseif files < maxfile then -- look for [[File:... embedded in an infobox etc. in the preamble
local image = parseimage(token, false) or argimage(token)
if image and checkimage(image) then -- keep comments and templates only within text body
image = mw.ustring.gsub(image, "|%s*frameless", "|thumb") -- excerpt needs a frame to flow around, even if infobox doesn't
files = files + 1
Line 120 ⟶ 144:
token = parseimage(text, true)
if token then
if files =< filesmaxfile and +checkimage(token) 1then
files = files + 1
if options.fileflags and options.fileflags[files] then t = t .. token end
end
else -- got a paragraph, which ends at a file, image, blank line or end of text
local afterend = mw.ustring.len(text) + 1