Module:InfoboxImage: Difference between revisions

From Roses, Tulips, & Liberty
Content added Content deleted
(add a sanity check to help debug an intermittent error)
(add more asserts - this is still intermittently failing somewhere)
Line 92: Line 92:
-- change underscores to spaces
-- change underscores to spaces
image = mw.ustring.gsub(image, "_", " ");
image = mw.ustring.gsub(image, "_", " ");
assert(image ~= nil, 'mw.ustring.gsub must not return nil')
assert(image ~= nil, 'mw.ustring.gsub(image, "_", " ") must not return nil')
-- if image starts with [[ then remove that and anything after |
-- if image starts with [[ then remove that and anything after |
if mw.ustring.sub(image,1,2) == "[[" then
if mw.ustring.sub(image,1,2) == "[[" then
image = mw.ustring.sub(image,3);
image = mw.ustring.sub(image,3);
image = mw.ustring.gsub(image, "([^|]*)|.*", "%1");
image = mw.ustring.gsub(image, "([^|]*)|.*", "%1");
assert(image ~= nil, 'mw.ustring.gsub(image, "([^|]*)|.*", "%1") must not return nil')
end
end
-- Trim spaces
-- Trim spaces
image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');
image = mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1');
assert(image ~= nil, "mw.ustring.gsub(image, '^[ ]*(.-)[ ]*$', '%1') must not return nil")
-- remove prefix if exists
-- remove prefix if exists
local allNames = mw.site.namespaces[6].aliases
local allNames = mw.site.namespaces[6].aliases