Jump to content

Module:Template invocation and Module:Template invocation/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
Update name call to fix a few edge cases per request
 
typo
 
Line 20: Line 20:
if type(title) == 'string' then
if type(title) == 'string' then
title = mw.title.new(title)
title = mw.title.new(title)
if not title or #title.prefixedText == 0 or #title.interwiki > 0 then
if not title then
error("invalid title in parameter #1 of function 'name'", 2)
error("invalid title in parameter #1 of function 'name'", 2)
end
end
Line 27: Line 27:
end
end
if title.namespace == 10 then
if title.namespace == 10 then
local text = title.text
return title.text
local check = mw.title.new(text, 10)
-- Exclude the prefix, unless we have something like "Template:Category:Foo", which can't be abbreviated to "Category:Foo".
return check and mw.title.equals(title, check) and text or title.prefixedText
elseif title.namespace == 0 then
elseif title.namespace == 0 then
return ':' .. title.prefixedText
return ':' .. title.prefixedText
Line 37: Line 34:
end
end
end
end

------------------------------------------------------------------------
------------------------------------------------------------------------
-- Name: p.invocation
-- Name: p.invocation