<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ar">
	<id>https://www.copticpedia.org/index.php?action=history&amp;feed=atom&amp;title=%D9%88%D8%AD%D8%AF%D8%A9%3AUrlToWiki</id>
	<title>وحدة:UrlToWiki - تاريخ المراجعة</title>
	<link rel="self" type="application/atom+xml" href="https://www.copticpedia.org/index.php?action=history&amp;feed=atom&amp;title=%D9%88%D8%AD%D8%AF%D8%A9%3AUrlToWiki"/>
	<link rel="alternate" type="text/html" href="https://www.copticpedia.org/index.php?title=%D9%88%D8%AD%D8%AF%D8%A9:UrlToWiki&amp;action=history"/>
	<updated>2026-05-18T04:24:01Z</updated>
	<subtitle>تاريخ التعديل لهذه الصفحة في الويكي</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://www.copticpedia.org/index.php?title=%D9%88%D8%AD%D8%AF%D8%A9:UrlToWiki&amp;diff=72923&amp;oldid=prev</id>
		<title>Gerges: مراجعة واحدة</title>
		<link rel="alternate" type="text/html" href="https://www.copticpedia.org/index.php?title=%D9%88%D8%AD%D8%AF%D8%A9:UrlToWiki&amp;diff=72923&amp;oldid=prev"/>
		<updated>2021-09-14T02:16:52Z</updated>

		<summary type="html">&lt;p&gt;مراجعة واحدة&lt;/p&gt;
&lt;p&gt;&lt;b&gt;صفحة جديدة&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;
p = {}&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&lt;br /&gt;
        error(&amp;quot;Non-string value for host name detected.&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    -- Find the entry for the host in the interwiki table.&lt;br /&gt;
    local id&lt;br /&gt;
    for k,v in pairs(interwiki_table) do&lt;br /&gt;
        if mw.ustring.match(host, interwiki_table[k].domain) then&lt;br /&gt;
            id = k&lt;br /&gt;
            break&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return id&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getInterwiki(host)&lt;br /&gt;
    -- This function returns the value of the interwiki prefix.&lt;br /&gt;
    if type(host) ~= &amp;quot;string&amp;quot; then&lt;br /&gt;
        error(&amp;quot;Non-string value for host name detected.&amp;quot;)&lt;br /&gt;
    end&lt;br /&gt;
    host = mw.language.getContentLanguage():lc(host)&lt;br /&gt;
    local host_id = getHostId(host)&lt;br /&gt;
    if not host_id then return end -- If the host isn't valid then the language and the interwiki are also invalid.&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;
    &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 nil, lang, host_id&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;
    -- Return the interwiki prefix, omitting the language or the project code if&lt;br /&gt;
    -- it is not necessary.&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;
        return project, lang, host_id&lt;br /&gt;
    elseif same_project then&lt;br /&gt;
        return lang, lang, host_id&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;
        return nil, nil, host_id&lt;br /&gt;
    else&lt;br /&gt;
        return project .. &amp;quot;:&amp;quot; .. lang, lang, host_id&lt;br /&gt;
    end   &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function _urlToWiki(args)&lt;br /&gt;
    local url = args[1] or error(&amp;quot;لم يتم تحديد رابط!&amp;quot;)&lt;br /&gt;
    url = mw.text.trim(url) -- Trim whitespace.&lt;br /&gt;
    url = mw.uri.new(url)&lt;br /&gt;
    local host = url.host -- Get the host name.&lt;br /&gt;
    -- Get the interwiki prefix. Lang and host_id are passed through so we don't have to work them out again.&lt;br /&gt;
    local interwiki, lang, host_id&lt;br /&gt;
    if host then&lt;br /&gt;
        interwiki, lang, host_id = getInterwiki(host)&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 -- Let users override the default.&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'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'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, return the URL and don't link it.&lt;br /&gt;
    elseif host and not host_id then&lt;br /&gt;
        link = false -- Don't use double square brackets for URLs.&lt;br /&gt;
        pagetitle = tostring(url)&lt;br /&gt;
    -- Otherwise, return whatever text we were passed and link it.&lt;br /&gt;
    else&lt;br /&gt;
        pagetitle = tostring(url)&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&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'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;
    -- 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 current_lang = mw.language.getContentLanguage()&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'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 not (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;
    -- Add the link&lt;br /&gt;
    if link then&lt;br /&gt;
        local display = args[2] -- The display text in piped links.&lt;br /&gt;
        if display then&lt;br /&gt;
            if type(display) ~= &amp;quot;string&amp;quot; then&lt;br /&gt;
                error(&amp;quot;Non-string display value detected&amp;quot;)&lt;br /&gt;
            end&lt;br /&gt;
            display = mw.text.trim(display) -- Trim whitespace.&lt;br /&gt;
            wikitext = wikitext .. &amp;quot;|&amp;quot; .. 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 origArgs&lt;br /&gt;
    if frame == mw.getCurrentFrame() then&lt;br /&gt;
        -- We're being called via #invoke. If the invoking template passed any args, use&lt;br /&gt;
        -- them. Otherwise, use the args that were passed into the template.&lt;br /&gt;
        origArgs = frame:getParent().args&lt;br /&gt;
        for k, v in pairs(frame.args) do&lt;br /&gt;
            origArgs = frame.args&lt;br /&gt;
            break&lt;br /&gt;
        end&lt;br /&gt;
    else&lt;br /&gt;
        -- We're being called from another module or from the debug console, so assume&lt;br /&gt;
        -- the args are passed in directly.&lt;br /&gt;
        origArgs = frame&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- ParserFunctions considers the empty string to be false, so to preserve the previous &lt;br /&gt;
    -- behavior of the template, change any empty arguments to nil, so Lua will consider&lt;br /&gt;
    -- them false too.&lt;br /&gt;
    local args = {}&lt;br /&gt;
    for k, v in pairs(origArgs) do&lt;br /&gt;
        if mw.ustring.match(v, '%S') then&lt;br /&gt;
            args[k] = v&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    return _urlToWiki(args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Gerges</name></author>
	</entry>
</feed>