Module:URL: Difference between revisions
Making extraction of URLs containing "=" actually work per edit request |
imported>Paine Ellsworth per edit request on talk page - update |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 54: | Line 54: | ||
-- If it's an HTTP[S] URL without the double slash, fix it. | -- If it's an HTTP[S] URL without the double slash, fix it. | ||
url = mw.ustring.gsub(url, '^[Hh][Tt][Tt][Pp]([Ss]?):(/?)([^/])', 'http%1://%3') | url = mw.ustring.gsub(url, '^[Hh][Tt][Tt][Pp]([Ss]?):(/?)([^/])', 'http%1://%3') | ||
local uri = safeUri(url) | local uri = safeUri(url) | ||
Line 116: | Line 113: | ||
local msg = templateArgs.msg or parentArgs.msg or 'no' | local msg = templateArgs.msg or parentArgs.msg or 'no' | ||
url = url or extractUrl(templateArgs) or extractUrl(parentArgs) or '' | url = url or extractUrl(templateArgs) or extractUrl(parentArgs) or '' | ||
-- if the url came from a Wikidata call, it might have a pen icon appended | |||
-- we want to keep that and add it back at the end. | |||
local u1, penicon = mw.ustring.match( url, "(.*)( <span class='penicon.*)" ) | |||
if penicon then url = u1 end | |||
-- strip out html tags and [ ] from url | -- strip out html tags and [ ] from url | ||
url = (url or ''):gsub("<[^>]*>", ""):gsub("[%[%]]", "") | url = (url or ''):gsub("<[^>]*>", ""):gsub("[%[%]]", "") | ||
-- truncate anything after a space | -- truncate anything after a space | ||
url = url:gsub("%%20", " "):gsub(" .*", "") | url = url:gsub("%%20", " "):gsub(" .*", "") | ||
return p._url(url, text, msg) | return (p._url(url, text, msg) or "") .. (penicon or "") | ||
end | end | ||
return p | return p |