<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.limswiki.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ADelink</id>
	<title>Module:Delink - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.limswiki.org/index.php?action=history&amp;feed=atom&amp;title=Module%3ADelink"/>
	<link rel="alternate" type="text/html" href="https://www.limswiki.org/index.php?title=Module:Delink&amp;action=history"/>
	<updated>2026-04-04T17:08:13Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.36.1</generator>
	<entry>
		<id>https://www.limswiki.org/index.php?title=Module:Delink&amp;diff=38207&amp;oldid=prev</id>
		<title>Shawndouglas: Protected &quot;Module:Delink&quot; ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))</title>
		<link rel="alternate" type="text/html" href="https://www.limswiki.org/index.php?title=Module:Delink&amp;diff=38207&amp;oldid=prev"/>
		<updated>2020-03-10T17:14:40Z</updated>

		<summary type="html">&lt;p&gt;Protected &amp;quot;&lt;a href=&quot;/index.php/Module:Delink&quot; title=&quot;Module:Delink&quot;&gt;Module:Delink&lt;/a&gt;&amp;quot; ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 17:14, 10 March 2020&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Shawndouglas</name></author>
	</entry>
	<entry>
		<id>https://www.limswiki.org/index.php?title=Module:Delink&amp;diff=38206&amp;oldid=prev</id>
		<title>Shawndouglas: Created as needed.</title>
		<link rel="alternate" type="text/html" href="https://www.limswiki.org/index.php?title=Module:Delink&amp;diff=38206&amp;oldid=prev"/>
		<updated>2020-03-10T17:14:32Z</updated>

		<summary type="html">&lt;p&gt;Created as needed.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- This module de-links most wikitext.&lt;br /&gt;
&lt;br /&gt;
require('Module:No globals')&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
local getArgs&lt;br /&gt;
&lt;br /&gt;
local function delinkReversePipeTrick(s)&lt;br /&gt;
    if s:match(&amp;quot;^%[%[|.*[|\n]&amp;quot;) then -- Check for newlines or multiple pipes.&lt;br /&gt;
        return s&lt;br /&gt;
    else&lt;br /&gt;
        return s:match(&amp;quot;%[%[|(.*)%]%]&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function delinkPipeTrick(s)&lt;br /&gt;
    local linkarea, display = &amp;quot;&amp;quot;, &amp;quot;&amp;quot;&lt;br /&gt;
    -- We need to deal with colons, brackets, and commas, per [[Help:Pipe trick]].&lt;br /&gt;
    &lt;br /&gt;
    -- First, remove the text before the first colon, if any.&lt;br /&gt;
    if s:match(&amp;quot;:&amp;quot;) then&lt;br /&gt;
        s = s:match(&amp;quot;%[%[.-:(.*)|%]%]&amp;quot;)&lt;br /&gt;
    -- If there are no colons, grab all of the text apart from the square brackets and the pipe.&lt;br /&gt;
    else&lt;br /&gt;
        s = s:match(&amp;quot;%[%[(.*)|%]%]&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- Next up, brackets and commas.&lt;br /&gt;
    if s:match(&amp;quot;%(.-%)$&amp;quot;) then -- Brackets trump commas.&lt;br /&gt;
        s = s:match(&amp;quot;(.-) ?%(.-%)$&amp;quot;)&lt;br /&gt;
    elseif s:match(&amp;quot;,&amp;quot;) then -- If there are no brackets, display only the text before the first comma.&lt;br /&gt;
        s = s:match(&amp;quot;(.-),.*$&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    return s&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function delinkWikilink(s)&lt;br /&gt;
    local result = s&lt;br /&gt;
    -- Deal with the reverse pipe trick.&lt;br /&gt;
    if result:match(&amp;quot;%[%[|&amp;quot;) then&lt;br /&gt;
        return delinkReversePipeTrick(result)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    result = mw.uri.decode(result, &amp;quot;PATH&amp;quot;) -- decode percent-encoded entities. Leave underscores and plus signs.&lt;br /&gt;
    result = mw.text.decode(result, true) -- decode HTML entities.&lt;br /&gt;
    &lt;br /&gt;
    -- Check for bad titles. To do this we need to find the&lt;br /&gt;
    -- title area of the link, i.e. the part before any pipes.&lt;br /&gt;
    local titlearea&lt;br /&gt;
    if result:match(&amp;quot;|&amp;quot;) then -- Find if we're dealing with a piped link.&lt;br /&gt;
        titlearea = result:match(&amp;quot;^%[%[(.-)|.*%]%]&amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
        titlearea = result:match(&amp;quot;^%[%[(.-)%]%]&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    -- Check for bad characters.&lt;br /&gt;
    if mw.ustring.match(titlearea, &amp;quot;[%[%]&amp;lt;&amp;gt;{}%%%c\n]&amp;quot;) then&lt;br /&gt;
        return s&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- Check for categories, interwikis, and files.&lt;br /&gt;
    local colonprefix = result:match(&amp;quot;%[%[(.-):.*%]%]&amp;quot;) or &amp;quot;&amp;quot; -- Get the text before the first colon.&lt;br /&gt;
    local ns = mw.site.namespaces[colonprefix] -- see if this is a known namespace&lt;br /&gt;
    if mw.language.isKnownLanguageTag(colonprefix)&lt;br /&gt;
    or ( ns and ( ns.canonicalName == &amp;quot;File&amp;quot; or ns.canonicalName == &amp;quot;Category&amp;quot; ) ) then&lt;br /&gt;
        return &amp;quot;&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- Remove the colon if the link is using the [[Help:Colon trick]].&lt;br /&gt;
    if result:match(&amp;quot;%[%[:&amp;quot;) then&lt;br /&gt;
        result = &amp;quot;[[&amp;quot; .. result:match(&amp;quot;%[%[:(.*%]%])&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- Deal with links using the [[Help:Pipe trick]].&lt;br /&gt;
    if mw.ustring.match(result, &amp;quot;^%[%[[^|]*|%]%]&amp;quot;) then&lt;br /&gt;
        return delinkPipeTrick(result)&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- Find the display area of the wikilink&lt;br /&gt;
    if result:match(&amp;quot;|&amp;quot;) then -- Find if we're dealing with a piped link.&lt;br /&gt;
        result = result:match(&amp;quot;^%[%[.-|(.+)%]%]&amp;quot;)&lt;br /&gt;
        -- Remove new lines from the display of multiline piped links,&lt;br /&gt;
        -- where the pipe is before the first new line.&lt;br /&gt;
        result = result:gsub(&amp;quot;\n&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
        result = result:match(&amp;quot;^%[%[(.-)%]%]&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function delinkURL(s)&lt;br /&gt;
    -- Assume we have already delinked internal wikilinks, and that&lt;br /&gt;
    -- we have been passed some text between two square brackets [foo].&lt;br /&gt;
    &lt;br /&gt;
    -- If the text contains a line break it is not formatted as a URL, regardless of other content.&lt;br /&gt;
    if s:match(&amp;quot;\n&amp;quot;) then&lt;br /&gt;
        return s&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- Check if the text has a valid URL prefix and at least one valid URL character.&lt;br /&gt;
    local valid_url_prefixes = {&amp;quot;//&amp;quot;, &amp;quot;http://&amp;quot;, &amp;quot;https://&amp;quot;, &amp;quot;ftp://&amp;quot;, &amp;quot;gopher://&amp;quot;, &amp;quot;mailto:&amp;quot;, &amp;quot;news:&amp;quot;, &amp;quot;irc://&amp;quot;} &lt;br /&gt;
    local url_prefix&lt;br /&gt;
    for i,v in ipairs(valid_url_prefixes) do&lt;br /&gt;
        if mw.ustring.match(s, '^%[' .. v ..'[^&amp;quot;%s].*%]' ) then&lt;br /&gt;
            url_prefix = v&lt;br /&gt;
            break&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- Get display text&lt;br /&gt;
    if not url_prefix then&lt;br /&gt;
        return s&lt;br /&gt;
    end&lt;br /&gt;
    s = s:match(&amp;quot;^%[&amp;quot; .. url_prefix .. &amp;quot;(.*)%]&amp;quot;) -- Grab all of the text after the URL prefix and before the final square bracket.&lt;br /&gt;
    s = s:match('^.-([&amp;quot;&amp;lt;&amp;gt; ].*)') or &amp;quot;&amp;quot; -- Grab all of the text after the first URL separator character (&amp;quot;&amp;lt;&amp;gt; ).&lt;br /&gt;
    s = mw.ustring.match(s, &amp;quot;^%s*(%S.*)$&amp;quot;) or &amp;quot;&amp;quot; -- If the separating character was a space, trim it off.&lt;br /&gt;
    &lt;br /&gt;
    local s_decoded = mw.text.decode(s, true)&lt;br /&gt;
    if mw.ustring.match(s_decoded, &amp;quot;%c&amp;quot;) then&lt;br /&gt;
        return s&lt;br /&gt;
    else    &lt;br /&gt;
        return s_decoded&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function delinkLinkClass(s, pattern, delinkFunction)&lt;br /&gt;
    if not type(s) == &amp;quot;string&amp;quot; then&lt;br /&gt;
        error(&amp;quot;Attempt to de-link non-string input.&amp;quot;, 2)&lt;br /&gt;
    end&lt;br /&gt;
    if not ( type(pattern) == &amp;quot;string&amp;quot; and mw.ustring.sub(pattern, 1, 1) == &amp;quot;^&amp;quot; ) then&lt;br /&gt;
        error('Invalid pattern detected. Patterns must begin with &amp;quot;^&amp;quot;.', 2)&lt;br /&gt;
    end&lt;br /&gt;
    -- Iterate over the text string, and replace any matched text. using the &lt;br /&gt;
    -- delink function. We need to iterate character by character rather &lt;br /&gt;
    -- than just use gsub, otherwise nested links aren't detected properly.&lt;br /&gt;
    local result = &amp;quot;&amp;quot;&lt;br /&gt;
    while s ~= '' do&lt;br /&gt;
        -- Replace text using one iteration of gsub.&lt;br /&gt;
        s = mw.ustring.gsub(s, pattern, delinkFunction, 1)&lt;br /&gt;
        -- Append the left-most character to the result string.&lt;br /&gt;
        result = result .. mw.ustring.sub(s, 1, 1)&lt;br /&gt;
        s = mw.ustring.sub(s, 2, -1)&lt;br /&gt;
    end&lt;br /&gt;
    return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._delink(args)&lt;br /&gt;
    local text = args[1] or &amp;quot;&amp;quot;&lt;br /&gt;
    if args.refs == &amp;quot;yes&amp;quot; then&lt;br /&gt;
        -- Remove any [[Help:Strip markers]] representing ref tags. In most situations &lt;br /&gt;
        -- this is not a good idea - only use it if you know what you are doing!&lt;br /&gt;
        text = mw.ustring.gsub(text, &amp;quot;UNIQ%w*%-ref%-%d*%-QINU&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    if not (args.comments == &amp;quot;no&amp;quot;) then&lt;br /&gt;
        text = text:gsub(&amp;quot;&amp;lt;!%-%-.-%-%-&amp;gt;&amp;quot;, &amp;quot;&amp;quot;) -- Remove html comments.&lt;br /&gt;
    end&lt;br /&gt;
    if not (args.wikilinks == &amp;quot;no&amp;quot;) then&lt;br /&gt;
        text = delinkLinkClass(text, &amp;quot;^%[%[.-%]%]&amp;quot;, delinkWikilink) -- De-link wikilinks.&lt;br /&gt;
    end&lt;br /&gt;
    if not (args.urls == &amp;quot;no&amp;quot;) then&lt;br /&gt;
        text = delinkLinkClass(text, &amp;quot;^%[.-%]&amp;quot;, delinkURL) -- De-link URLs.&lt;br /&gt;
    end&lt;br /&gt;
    if not (args.whitespace == &amp;quot;no&amp;quot;) then&lt;br /&gt;
        -- Replace single new lines with a single space, but leave double new lines&lt;br /&gt;
        -- and new lines only containing spaces or tabs before a second new line.&lt;br /&gt;
        text = mw.ustring.gsub(text, &amp;quot;([^\n \t][ \t]*)\n([ \t]*[^\n \t])&amp;quot;, &amp;quot;%1 %2&amp;quot;)&lt;br /&gt;
        text = text:gsub(&amp;quot;[ \t]+&amp;quot;, &amp;quot; &amp;quot;) -- Remove extra tabs and spaces.&lt;br /&gt;
    end&lt;br /&gt;
    return text&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.delink(frame)&lt;br /&gt;
    if not getArgs then&lt;br /&gt;
    	getArgs = require('Module:Arguments').getArgs&lt;br /&gt;
    end&lt;br /&gt;
    return p._delink(getArgs(frame, {wrappers = 'Template:Delink'}))&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Shawndouglas</name></author>
	</entry>
</feed>