Anonymous user
Module:Delink: Difference between revisions
sync from sandbox per WP:VPT discussion;
Johnrdorazio (talk | contribs) m (1 revision imported) |
(sync from sandbox per WP:VPT discussion;) |
||
Line 34: | Line 34: | ||
end | end | ||
return s | return s | ||
end | |||
local function delinkWikilink_tgt(s) -- return wikilink target |wikilinks=target | |||
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 | |||
return target_area | |||
end | end | ||
Line 48: | Line 74: | ||
-- Check for bad titles. To do this we need to find the | -- Check for bad titles. To do this we need to find the | ||
-- title area of the link, i.e. the part before any pipes. | -- title area of the link, i.e. the part before any pipes. | ||
local | local target_area | ||
if result:match("|") then -- Find if we're dealing with a piped link. | if result:match("|") then -- Find if we're dealing with a piped link. | ||
target_area = result:match("^%[%[(.-)|.*%]%]") | |||
else | else | ||
target_area = result:match("^%[%[(.-)%]%]") | |||
end | end | ||
-- Check for bad characters. | -- Check for bad characters. | ||
if mw.ustring.match( | if mw.ustring.match(target_area, "[%[%]<>{}%%%c\n]") then | ||
return s | return s | ||
end | end | ||
-- Check for categories, interwikis, and files. | -- Check for categories, interwikis, and files. | ||
local colonprefix = result:match("%[%[(.-):.*%]%]") or "" -- Get the text before the first colon. | local colonprefix = result:match("%[%[(.-):.*%]%]") or "" -- Get the text before the first colon. | ||
Line 156: | Line 182: | ||
text = text:gsub("<!%-%-.-%-%->", "") -- Remove html comments. | text = text:gsub("<!%-%-.-%-%->", "") -- Remove html comments. | ||
end | 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 | |||
text = delinkLinkClass(text, "^%[%[.-%]%]", delinkWikilink_tgt) -- De-link wikilinks and return the target portions of the wilikink | |||
end | |||
if not (args.urls == "no") then | if not (args.urls == "no") then | ||
text = delinkLinkClass(text, "^%[.-%]", delinkURL) -- De-link URLs. | text = delinkLinkClass(text, "^%[.-%]", delinkURL) -- De-link URLs. |