Module:Delink: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
sync from sandbox per WP:VPT discussion;
m (Protected "Module:Delink": Highly visible template: 55,000+ mainspace transclusions ([Edit=Allow only template editors and admins] (indefinite) [Move=Allow only template editors and admins] (indefinite)))
(sync from sandbox per WP:VPT discussion;)
Line 36:
end
 
local function delinkWikilink_tgt(s) -- return wikilink target |wikilinks=target
local function delinkWikilink(s)
local result = s
-- Deal with the reverse pipe trick.
Line 48:
-- Check for bad titles. To do this we need to find the
-- title area of the link, i.e. the part before any pipes.
local titleareatarget_area
if result:match("|") then -- Find if we're dealing with a piped link.
titleareatarget_area = result:match("^%[%[(.-)|.*%]%]")
else
titleareatarget_area = result:match("^%[%[(.-)%]%]")
end
-- Check for bad characters.
if mw.ustring.match(titleareatarget_area, "[%[%]<>{}%%%c\n]") then
return s
end
return target_area
end
 
local function delinkWikilink(s)
local result = s
-- Deal with the reverse pipe trick.
if result:match("%[%[|") then
return delinkReversePipeTrick(result)
end
result = mw.uri.decode(result, "PATH") -- decode percent-encoded entities. Leave underscores and plus signs.
result = mw.text.decode(result, true) -- decode HTML entities.
-- Check for bad titles. To do this we need to find the
-- title area of the link, i.e. the part before any pipes.
local target_area
if result:match("|") then -- Find if we're dealing with a piped link.
target_area = result:match("^%[%[(.-)|.*%]%]")
else
target_area = result:match("^%[%[(.-)%]%]")
end
-- Check for bad characters.
if mw.ustring.match(target_area, "[%[%]<>{}%%%c\n]") then
return s
end
 
-- Check for categories, interwikis, and files.
local colonprefix = result:match("%[%[(.-):.*%]%]") or "" -- Get the text before the first colon.
Line 156 ⟶ 182:
text = text:gsub("<!%-%-.-%-%->", "") -- Remove html comments.
end
if not (args.wikilinks == "no") and 'target' ~= args.wikilinks then
text = delinkLinkClass(text, "^%[%[.-%]%]", delinkWikilink) -- De-link wikilinks and return the label portion of the wikilink.
elseif 'target' == args.wikilinks then
end
text = delinkLinkClass(text, "^%[%[.-%]%]", delinkWikilink_tgt) -- De-link wikilinks and return the target portions of the wilikink
end
if not (args.urls == "no") then
text = delinkLinkClass(text, "^%[.-%]", delinkURL) -- De-link URLs.
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu