<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://moasspedia.org/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AUrltowiki</id>
	<title>Module:Urltowiki - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://moasspedia.org/w/index.php?action=history&amp;feed=atom&amp;title=Module%3AUrltowiki"/>
	<link rel="alternate" type="text/html" href="https://moasspedia.org/w/index.php?title=Module:Urltowiki&amp;action=history"/>
	<updated>2026-04-14T12:34:52Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.37.2</generator>
	<entry>
		<id>https://moasspedia.org/w/index.php?title=Module:Urltowiki&amp;diff=3673&amp;oldid=prev</id>
		<title>Wikipedia&gt;Wugapodes: Wugapodes moved page Module:UrlToWiki to Module:Urltowiki without leaving a redirect: Per requested move Template_talk:Urltowiki#Requested_move_30_October_2019</title>
		<link rel="alternate" type="text/html" href="https://moasspedia.org/w/index.php?title=Module:Urltowiki&amp;diff=3673&amp;oldid=prev"/>
		<updated>2019-11-08T05:05:32Z</updated>

		<summary type="html">&lt;p&gt;Wugapodes moved page &lt;a href=&quot;/w/index.php?title=Module:UrlToWiki&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Module:UrlToWiki (page does not exist)&quot;&gt;Module:UrlToWiki&lt;/a&gt; to &lt;a href=&quot;/wiki/Module:Urltowiki&quot; title=&quot;Module:Urltowiki&quot;&gt;Module:Urltowiki&lt;/a&gt; without leaving a redirect: Per requested move &lt;a href=&quot;/w/index.php?title=Template_talk:Urltowiki&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Template talk:Urltowiki (page does not exist)&quot;&gt;Template_talk:Urltowiki#Requested_move_30_October_2019&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- This module takes a URL from a Wikimedia project and returns the equivalent wikitext. &lt;br /&gt;
-- Any actions such as edit, history, etc., are stripped, and percent-encoded characters &lt;br /&gt;
-- are converted to normal text.&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
local current_lang = mw.language.getContentLanguage()&lt;br /&gt;
&lt;br /&gt;
local interwiki_table = mw.loadData(&amp;quot;Module:InterwikiTable&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
local function getHostId(host)&lt;br /&gt;
	if type(host) ~= &amp;quot;string&amp;quot; then return end&lt;br /&gt;
	for id, t in pairs(interwiki_table) do&lt;br /&gt;
		if mw.ustring.match(host, t.domain) and t.domain_primary then -- Match partial domains (e.g. &amp;quot;www.foo.org&amp;quot; and &amp;quot;foo.org&amp;quot;) but don&amp;#039;t match non-primary domains.&lt;br /&gt;
			return id&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getInterwiki(host)&lt;br /&gt;
	-- This function returns a table with information about the interwiki prefix of the specified host.&lt;br /&gt;
	local ret = {}&lt;br /&gt;
&lt;br /&gt;
	-- Return a blank table for invalid input.&lt;br /&gt;
	if type(host) ~= &amp;quot;string&amp;quot; then&lt;br /&gt;
		return ret&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Get the host ID.&lt;br /&gt;
	host = mw.ustring.lower(host)&lt;br /&gt;
	local host_id = getHostId(host)&lt;br /&gt;
	if not host_id then&lt;br /&gt;
		return ret&lt;br /&gt;
	end&lt;br /&gt;
	ret.host_id = host_id&lt;br /&gt;
&lt;br /&gt;
	-- Find the language in the interwiki prefix, if applicable.&lt;br /&gt;
	local lang = mw.ustring.match(host, &amp;quot;^(.-)%.&amp;quot;) -- Find the text before the first period.&lt;br /&gt;
	if not lang or not mw.language.isSupportedLanguage(lang) then -- Check if lang is a valid language code.&lt;br /&gt;
		lang = false&lt;br /&gt;
	end&lt;br /&gt;
	-- A language prefix is not necessary if there is already a language prefix for the host in the interwiki table.&lt;br /&gt;
	local domain_lang = mw.ustring.match(interwiki_table[host_id].domain, &amp;quot;^(.-)%.&amp;quot;) -- Find the text before the first period.&lt;br /&gt;
	if  mw.language.isSupportedLanguage(domain_lang) then&lt;br /&gt;
		lang = false&lt;br /&gt;
	end&lt;br /&gt;
	ret.lang = lang&lt;br /&gt;
&lt;br /&gt;
	-- No need for an interwiki link if we are on the same site as the URL.&lt;br /&gt;
	local current_host = mw.uri.new(mw.title.getCurrentTitle():fullUrl()).host -- Get the host portion of the current page URL.&lt;br /&gt;
	if host == current_host then&lt;br /&gt;
		return ret&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Check if the URL language is the same as the current language.&lt;br /&gt;
	local same_lang&lt;br /&gt;
	if lang and lang == mw.ustring.match(current_host, &amp;quot;^(.-)%.&amp;quot;) then&lt;br /&gt;
		same_lang = true&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Check if the project is the same as the current project (but a different language).&lt;br /&gt;
	local current_host_id = getHostId(current_host)&lt;br /&gt;
	local same_project&lt;br /&gt;
	if current_host_id == host_id then&lt;br /&gt;
		same_project = true&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Find the interwiki prefix.&lt;br /&gt;
	local interwiki&lt;br /&gt;
	local project = interwiki_table[host_id].iw_prefix[1]&lt;br /&gt;
	if same_lang or ( not lang and interwiki_table[host_id].takes_lang_prefix == false ) then&lt;br /&gt;
		interwiki = project&lt;br /&gt;
	elseif same_project then&lt;br /&gt;
		interwiki = lang&lt;br /&gt;
	elseif not lang then -- If the language code is bad but the rest of the host name is ok.&lt;br /&gt;
		interwiki = nil&lt;br /&gt;
	else&lt;br /&gt;
		interwiki = project .. &amp;quot;:&amp;quot; .. lang&lt;br /&gt;
	end   &lt;br /&gt;
	ret.interwiki = interwiki&lt;br /&gt;
&lt;br /&gt;
	return ret&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p._urlToWiki(args)&lt;br /&gt;
	-- Check the input is valid.&lt;br /&gt;
&lt;br /&gt;
	local input = args[1] or args.url&lt;br /&gt;
	if type(input) ~= &amp;quot;string&amp;quot; then&lt;br /&gt;
		if args.error ~= &amp;quot;no&amp;quot; then&lt;br /&gt;
			if type(input) == &amp;quot;nil&amp;quot; then&lt;br /&gt;
				error(&amp;quot;No URL specified&amp;quot;, 2)&lt;br /&gt;
			else&lt;br /&gt;
				error(&amp;quot;The URL must be a string value&amp;quot;, 2)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			return &amp;quot;&amp;quot;&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	input = mw.text.trim(input)&lt;br /&gt;
&lt;br /&gt;
	-- Get the URI object.&lt;br /&gt;
	url = mw.uri.new(input)&lt;br /&gt;
	local host = url.host&lt;br /&gt;
&lt;br /&gt;
	-- Get the interwiki prefix.&lt;br /&gt;
	local interwiki, lang, host_id&lt;br /&gt;
	if host then&lt;br /&gt;
		local iw_data = getInterwiki(host)&lt;br /&gt;
		interwiki, lang, host_id = iw_data.interwiki, iw_data.lang, iw_data.host_id&lt;br /&gt;
	end&lt;br /&gt;
	local link = true -- This decides whether the resulting wikitext will be linked or not. Default is yes.&lt;br /&gt;
	if args.link == &amp;quot;no&amp;quot; then&lt;br /&gt;
		link = false&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Get the page title.&lt;br /&gt;
	local pagetitle, title_prefix&lt;br /&gt;
	if host_id and not ( interwiki_table[host_id].takes_lang_prefix == true and not lang ) then&lt;br /&gt;
		title_prefix = interwiki_table[host_id].title_prefix&lt;br /&gt;
	end&lt;br /&gt;
	-- If the URL path starts with the title prefix in the interwiki table, use that to get the title.&lt;br /&gt;
	if title_prefix and mw.ustring.sub(url.path, 1, mw.ustring.len(title_prefix)) == title_prefix then&lt;br /&gt;
		pagetitle = mw.ustring.sub(url.path, mw.ustring.len(title_prefix) + 1, -1)&lt;br /&gt;
		-- Else, if the URL is a history &amp;quot;index.php&amp;quot;, use url.query.title. Check for host_id&lt;br /&gt;
		-- in case the URL isn&amp;#039;t of a Wikimedia site.&lt;br /&gt;
	elseif host_id and mw.ustring.match(url.path, &amp;quot;index%.php&amp;quot;) and url.query.title then&lt;br /&gt;
		pagetitle = url.query.title&lt;br /&gt;
		-- Special case for Bugzilla.&lt;br /&gt;
	elseif host_id == &amp;quot;bugzilla&amp;quot; and url.query.id then&lt;br /&gt;
		pagetitle = url.query.id&lt;br /&gt;
	elseif host_id == &amp;quot;bugzilla&amp;quot; and not url.query.id then&lt;br /&gt;
		interwiki = false -- disable the interwiki prefix as we are returning a full URL.&lt;br /&gt;
		link = false -- don&amp;#039;t use double square brackets for URLs.&lt;br /&gt;
		pagetitle = tostring(url)&lt;br /&gt;
		-- If the URL is valid but not a recognised interwiki, use the URL and don&amp;#039;t link it.&lt;br /&gt;
	elseif host and not host_id then&lt;br /&gt;
		link = false -- Don&amp;#039;t use double square brackets for URLs.&lt;br /&gt;
		pagetitle = tostring(url)&lt;br /&gt;
		-- Otherwise, use our original input minus any fragment&lt;br /&gt;
	else&lt;br /&gt;
		pagetitle = mw.ustring.match(input, &amp;quot;^(.-)#&amp;quot;) or input&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Get the fragment and pre-process percent-encoded characters.&lt;br /&gt;
	local fragment = url.fragment -- This also works for non-urls like &amp;quot;Foo#Bar&amp;quot;.&lt;br /&gt;
	if fragment then&lt;br /&gt;
		fragment = mw.ustring.gsub(fragment, &amp;quot;%.([0-9A-F][0-9A-F])&amp;quot;, &amp;quot;%%%1&amp;quot;)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Assemble the wikilink.&lt;br /&gt;
	local wikitext = pagetitle&lt;br /&gt;
	if interwiki then&lt;br /&gt;
		wikitext = interwiki .. &amp;quot;:&amp;quot; .. wikitext&lt;br /&gt;
	end&lt;br /&gt;
	if fragment and not (args.section == &amp;quot;no&amp;quot;) then&lt;br /&gt;
		wikitext = wikitext .. &amp;quot;#&amp;quot; .. fragment&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Decode percent-encoded characters and convert underscores to spaces.&lt;br /&gt;
	wikitext = mw.uri.decode(wikitext, &amp;quot;WIKI&amp;quot;)&lt;br /&gt;
	-- If the wikitext is to be linked, re-encode illegal characters. Don&amp;#039;t re-encode &lt;br /&gt;
	-- characters from invalid URLs to make the default [[{{{1}}}]] display correctly.&lt;br /&gt;
	if link and host then&lt;br /&gt;
		wikitext = mw.ustring.gsub(wikitext, &amp;quot;[&amp;lt;&amp;gt;%[%]|{}%c\n]&amp;quot;, mw.uri.encode)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Find the display value&lt;br /&gt;
	local display&lt;br /&gt;
	if link then&lt;br /&gt;
		display = args[2] or args.display -- The display text in piped links.&lt;br /&gt;
		if (display and type(display) ~= &amp;quot;string&amp;quot;) then&lt;br /&gt;
			if args.error ~= &amp;quot;no&amp;quot; then&lt;br /&gt;
				error(&amp;quot;Non-string display value detected&amp;quot;)&lt;br /&gt;
			else&lt;br /&gt;
				display = nil&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
		if display then&lt;br /&gt;
			display = mw.text.trim(display) -- Trim whitespace.&lt;br /&gt;
			-- If the page name is the same as the display value, don&amp;#039;t pipe&lt;br /&gt;
			-- the link.&lt;br /&gt;
			if current_lang:lcfirst(wikitext) == display then&lt;br /&gt;
				wikitext = display&lt;br /&gt;
				display = nil&lt;br /&gt;
			elseif wikitext == display then&lt;br /&gt;
				display = nil&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Use the [[Help:Colon trick]] with categories, interwikis, and files.&lt;br /&gt;
	local colon_prefix = mw.ustring.match(wikitext, &amp;quot;^(.-):.*$&amp;quot;) or &amp;quot;&amp;quot; -- Get the text before the first colon.&lt;br /&gt;
	local ns = mw.site.namespaces&lt;br /&gt;
	local need_colon_trick&lt;br /&gt;
	if mw.language.isSupportedLanguage(colon_prefix) -- Check for interwiki links.&lt;br /&gt;
		or current_lang:lc(ns[6].name) == current_lang:lc(colon_prefix) -- Check for files.&lt;br /&gt;
		or current_lang:lc(ns[14].name) == current_lang:lc(colon_prefix) then -- Check for categories.&lt;br /&gt;
		need_colon_trick = true&lt;br /&gt;
	end&lt;br /&gt;
	for i,v in ipairs(ns[6].aliases) do -- Check for file namespace aliases.&lt;br /&gt;
		if current_lang:lc(v) == current_lang:lc(colon_prefix) then&lt;br /&gt;
			need_colon_trick = true&lt;br /&gt;
			break&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	for i,v in ipairs(ns[14].aliases) do -- Check for category namespace aliases.&lt;br /&gt;
		if current_lang:lc(v) == current_lang:lc(colon_prefix) then&lt;br /&gt;
			need_colon_trick = true&lt;br /&gt;
			break&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	-- Don&amp;#039;t use the colon trick if the user says so or if we are not linking&lt;br /&gt;
	-- (due to [[bugzilla:12974]]).&lt;br /&gt;
	if need_colon_trick and link and args.colontrick ~= &amp;quot;no&amp;quot; then&lt;br /&gt;
		wikitext = &amp;quot;:&amp;quot; .. wikitext&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Make the link&lt;br /&gt;
	if link then&lt;br /&gt;
		if display then&lt;br /&gt;
			wikitext = wikitext .. &amp;#039;|&amp;#039; .. display&lt;br /&gt;
		end&lt;br /&gt;
		wikitext = &amp;quot;[[&amp;quot; .. wikitext .. &amp;quot;]]&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return wikitext&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.urlToWiki(frame)&lt;br /&gt;
	local args = require(&amp;#039;Module:Arguments&amp;#039;).getArgs(frame, {&lt;br /&gt;
		wrappers = {&amp;#039;Template:Urltowiki&amp;#039;,&amp;#039;Template:Urltowiki/sandbox&amp;#039;}&lt;br /&gt;
	})&lt;br /&gt;
	return p._urlToWiki(args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Wikipedia&gt;Wugapodes</name></author>
	</entry>
</feed>