Content deleted Content added
Bug fix: display title correctly where only part of the bold text is in italics, e.g. '''Foo ''Bar''''' or '''''Foo'' Bar''' |
Prefer image= to [[File:... when extracting an image from an infobox with multiple images. Accept non-standard argument names such as Ship image= and Ship caption=. Refactor to use matchany(). |
||
Line 7:
if errors then error(text, 2) end
return ""
end
-- In text, match pre..list[1]..post or pre..list[2]..post or ...
local function matchany(text, pre, list, post)
local match
for i = 1, #list do
if match then return match end
end
return nil
end
-- Check image for suitability
local function checkimage(image)
local page =
if not page then return false end
-- Limit to image types: .gif, .jpg, .jpeg, .png, .svg, .tiff, .xcf (exclude .ogg audio etc.)
if not
return false
end
and not mw.ustring.match(page, "%.[Pp][Nn][Gg]%s*$")▼
local title = mw.title.new(":" .. page) -- Read description page (for :File:Foo rather than File:Foo)
Line 38 ⟶ 44:
local startre = ""
if start then startre = "^" end -- a true flag restricts search to start of string
local image =
if image then
image = mw.ustring.match(image, "%b[]%s*") -- matching [[...]] to handle wikilinks nested in caption
Line 50 ⟶ 55:
local token = nil
if mw.ustring.match(text, "{{%s*[Ii]nfobox") then
local image =
or mw.ustring.match(text, "|%s*PD_image%s*=%s*([^}|]-)") -- or its known alternatives such as...▼
if image then -- add in relevant optional parameters: caption, alt text and image size
token =
if not
image
token =
if not matchany(image, "^", {"[Ff]ile", "[Ii]mage"}, "%s*:") then
end
token = token .. image
local caption =
if caption then token = token .. "|" .. caption end▼
▲ local
if image_size then token = token .. "|" .. image_size end
end
token = mw.ustring.gsub(token, "\n","") ..
▲ local caption = mw.ustring.match(text, "|%s*[Cc]aption%s*=%s*([^}|]*)")
▲ if caption then token = token .. "|" .. caption end
▲ local alt = mw.ustring.match(text, "|%s*alt%s*=%s*([^}|]*)")
▲ if alt then token = token .. "|alt=" .. alt end
▲ if image_size then token = token .. "|" .. image_size end
▲ token = mw.ustring.gsub(token, "\n","") .. "]]\n"
end
end
Line 157 ⟶ 164:
t = t .. token
elseif files < maxfile then -- discard template, but if we are still collecting images...
local image =
if image and checkimage(image) then -- if image is found and qualifies (not a sound file, non-free, etc.)
files = files + 1 -- count the file, whether displaying it or not
Line 163 ⟶ 170:
image = mw.ustring.gsub(image, "|%s*frameless%s*%f[|%]]", "") -- make image a thumbnail, not frameless etc.
image = mw.ustring.gsub(image, "|%s*framed?%s*%f[|%]]", "")
if not
image = mw.ustring.gsub(image, "(%]%]%s*)$", "|thumb%1")
end
|