Module:Copied: Difference between revisions

Content deleted Content added
test
Only apply wikilink escaping on automatically determined titles to avoid stacking colons onto manually escaped links
 
(48 intermediate revisions by 12 users not shown)
Line 1:
local MessageBox = require('Module:Message box')
 
local getArgs = require('Module:Arguments').getArgs
 
local p = {}
 
local function singleText(args)
local from_oldid = args["from_oldid"] or args["from_oldid1"] or ""
local from = args["from"] or args["from1"] or ""
local to_diff = args["to_diff"] or args["to_diff1"] or ""
local diff = args["diff"] or args["diff1"] or ""
local to_oldid = args["to_oldid"] or args["to_oldid1"] or ""
local to = args["to"] or args["to1"] or ""
local date = args["date"] or args["date1"] or ""
local afd = args["afd"] or args["afd1"] or ""
local merge = args["merge"] or args["merge1"] or ""
local textmergedFrom = args["mergedFrom"] or ""
local text
text = text .. "Text and/or other creative content from "
if (mergedFrom == 'yes') then
text = "The content of"
else
text = "Text and/or other creative content from"
end
if not (from_oldid == "") then
text = text .string.format("%s "[%s this version] of", ..text, tostring(mw.uri.fullUrl(from, {oldid=from_oldid} )) .. " this version] of ")
end
if from then
text = text .. "[[" .. from .."]]"
text = string.format("%s <span class='plainlinks'>[%s %s]</span>",text, tostring(mw.uri.fullUrl(from, {redirect="no"} )), from)
if (merge == "yes") or (not afd == "") then
else
text = text .. " was merged into "
text = text .. '[[]]'
else
end
text = text .. " was copied or moved into "
if (merge == "yes") or (mergedFrom == "yes") or not (afd == "") then
end
text = text .. " was [["Wikipedia:Merging|merged]] into"
if (merge == "yes") and to == "" then
text = text .. mw.title.getCurrentTitle().nsText .. ":" .. mw.title.getCurrentTitle().text
else
text = text .. to" was copied or moved into"
end
if (to == "") then -- If no target given assume current page is the target
text = text .. "]] "
to = ":" .. mw.title.getCurrentTitle().subjectPageTitle.fullText
if not (diff == "") then
end
text = text .. "with [" .. diff .. " this edit]"
text = string.format("%s [[%s]]", text, to)
elseif not (to_oldid == "") then
local diff = args["diff"] or args["diff1"]
text = text .. "with [" .. tostring(mw.uri.fullUrl(to,{diff=to_diff, oldid=to_oldid} )) .. " this edit]"
local to_diff = args["to_diff"] or args["to_diff1"]
local to_oldid = args["to_oldid"] or args["to_oldid1"]
if (diff) then
text = string.format("%s with [%s this edit]",text,diff)
elseif (to_oldid or to_diff) then
text = string.format("%s with [%s this edit]",text,tostring(mw.uri.fullUrl(to, {diff=to_diff or "next", oldid = to_oldid or "prev"} )))
end
if not (date == "") then
text = text string.. format("%s on %s" .. ,text,date)
end
if not (afd == "") then
if (mw.ustring.match(afd, "Wikipedia:", 1 )) then --If no venue is given add AfD prefix
text = text .. " after being [["
text = string.format("%s after being [[%s|nominated for deletion]]",text,afd)
if not mw.ustring.match(afd, "Wikipedia:", 1 ) then
else
text = text .. "Wikipedia:Articles for deletion/"
text = string.format("%s after being [[Wikipedia:Articles for deletion/%s|nominated for deletion]]",text,afd)
end
text = text .. afd .. "|nominated for deletion]]"
end
text = text .. "." The-- formerFinish page'sfirst "sentence
text = text string.. format("%s The former page's ["%s ..history] now serves to [[WP:Copying within Wikipedia|provide attribution]] for that content in the latter page, and it must not be deleted as long as the latter page exists.",text,tostring(mw.uri.fullUrl(from,{action="history"} )) ..or " history] "))
if (args["talk"] == 'yes' or (mergedFrom == 'yes' and args["talk"] ~= 'no')) then
text = text .. "now serves to [[WP:Copying within Wikipedia|provide attribution]] for that content in the latter page, and it must not be deleted so long as the latter page exists."
local fromPage = mw.title.new(from)
local fromTalk = fromPage and fromPage.talkPageTitle.fullText or "Talk:" .. from
text = string.format("%s For the discussion at that ___location, see its [[%s|talk page]].", text, fromTalk)
end
return text
end
 
local function row(args, i)
local text
local from_oldid = args["from_oldid"..i] or ""
local from = args["from"..i] or ""
local to_diff = args["to_diff"..i] or ""
local diff = args["diff"..i] or ""
local to_oldid = args["to_oldid"..i] or ""
local to = args["to"..i] or ""
local date = args["date"..i] or ""
local afd = args["afd"..i] or ""
local merge = args["merge"..i] or ""
local text = ""
iflocal not (afd == args["afd" and merge == "").. theni]
if (afd or args["merge" .. i] or args["mergedFrom"]) then
text = text .. "\n*Merged"
text = string.format("%s\n*Merged",text)
else
text = text string.. format("%s\n*Copied",text)
end
 
text = text .. " [" .. tostring(mw.uri.fullUrl(from,{redirect="no"} )) .. " " .. from .. "]"
textlocal from = textargs["from" .. "i] (or ""
text = string.format("%s [%s %s] (",text,tostring(mw.uri.fullUrl(from, {redirect = "no"} )),from)
if not from_oldid == "" then
 
text = text .. "[" .. tostring(mw.uri.fullUrl(from, {oldid=from_oldid} )) .. " oldid], "
local from_oldid = args["from_oldid" .. i]
if (from_oldid) then
text = string.format("%s[%s oldid], ",text,tostring(mw.uri.fullUrl(from, {oldid = from_oldid} )))
end
text = text .. "[" .. tostring(mw.uri.fullUrl(from,{action="history"} )) .. " history]"
textlocal talk = text args["talk".. ")i] or ""
if (talk == "yes" or (args["mergedFrom"] == 'yes' and talk ~= "no")) then
text = text .. "[[" .. to .. "]]"
local fromPage = mw.title.new(from)
if not (diff == "") then
local fromTalk = fromPage and fromPage.talkPageTitle.fullText or "Talk:" .. from
text = text .. "([" .. diff .. " diff])"
text = string.format("%s[[%s|talk]], ", text, fromTalk)
elseif not (to_oldid == "") then
text = text .. " ([" .. tostring(mw.uri.fullUrl(to,{diff=to_diff, oldid=to_oldid} )) .. " diff])"
end
if not (date == "") then
text local to = text args["to".. "i] onor " .. date"
if (to == "") then -- If no target given assume current page is the target
to = ":" .. mw.title.getCurrentTitle().subjectPageTitle.fullText
end
text = string.format("%s[%s history]) → [[%s]]",text,tostring(mw.uri.fullUrl(from, {action = "history"} )), to)
if not (afd == "") then
text = text .. " after being [["
local diff = args["diff" .. i]
if not mw.ustring.match(afd, "Wikipedia:", 1 ) then
if (diff) then
text = text .. "Wikipedia:Articles for deletion/"
text = string.format("%s ([%s diff])",text,diff)
elseif (args["to_oldid" .. i] or args["to_diff".. i]) then
local to_diff = args["to_diff".. i] or "next"
local to_oldid = args["to_oldid" .. i] or "prev"
text = string.format("%s ([%s diff])",text,tostring(mw.uri.fullUrl(to, {diff=to_diff, oldid = to_oldid} )))
end
local date = args["date" .. i]
if (date) then
text = string.format("%s on %s",text,date)
end
 
if (afd) then
if (mw.ustring.match(afd, "Wikipedia:", 1 )) then --If no venue is given add AfD prefix
text = string.format("%s after being [[%s|nominated for deletion]]",text,afd)
else
text = string.format("%s after being [[Wikipedia:Articles for deletion/%s|nominated for deletion]]",text,afd)
end
text = text .. afd .. "|after being nominated for deletion]]"
end
if (not (args["to_oldid" .. i] or args["to_diff".. i])) then
return text
if (args["mergedFrom"] == 'yes') then
text = string.format("%s[[Category:Wikipedia pages using merged-from template without oldid]]",text)
else
text = string.format("%s[[Category:Wikipedia pages using copied template without oldid]]",text)
end
end
return text
end
 
local function list(args)
local text = ""
local from1 = args["from1"] or ""
if (from1) then --Support from1 and from in case of multiple rows
if not from1 == "" then
text = text string.. format("%s%s",text,row(args, 1))
else
text = text string.. format("%s%s",text,row(args, ""))
end
local i = 2
while (args["from" .. i>0]) do
text = string.format("%s%s",text,row(args, i))
if args["from"..i] then
i = i + 1 --Check if from(i+1) exists
text = text .. row(args,i)
i = i+1
else
i = -1
end
end
return text
Line 115 ⟶ 141:
local function multiText(args)
local pageType
local collapse = args["collapse"] or ""
local currentTitle =if (mw.title.getCurrentTitle():inNamespace(1)) then
pageType = "article"
local text = "Text has been copied to or from this"
if currentTitle:inNamespace(0) then
text = text .. "article"
else
textpageType = text .. "page"
end
text = text .. "see the list below. The source pages now serve to [[WP:Copying within Wikipedia|provide attribution]] for the content in the destination pages and must not be deleted so long as the copies exist. For attribution and to access older versions of the copied text, please see the history links below."
local historyList = list(args)
if collapse == 'yes' then
if (args["collapse"] == 'yes') then
text = text .. '<table style="width:100%; background: transparent;" class="collapsible collapsed">\n<tr><th>Copied pages:</th></tr>\n<tr><td>'
local collapsedText
if (args["mergedFrom"] == 'yes') then
collapsedText = '<table style="width:100%%; background: transparent;" class="mw-collapsible mw-collapsed">\n<tr><th>Merged pages:</th></tr>\n<tr><td> %s </td></tr></table>'
else
collapsedText = '<table style="width:100%%; background: transparent;" class="mw-collapsible mw-collapsed">\n<tr><th>Copied pages:</th></tr>\n<tr><td> %s </td></tr></table>'
end
historyList = string.format(collapsedText, historyList)
end
text = text .. list(args)
local mergedFrom
if collapse == 'yes' then
local copies
text = text .. '</td></tr></table>'
if (args["mergedFrom"]) then
mergedFrom = "merged into"
copies = "this page"
else
mergedFrom = "copied to or from"
copies = "the copies"
end
local text = "Text has been %s this %s; see the list below. The source pages now serve to [[WP:Copying within Wikipedia|provide attribution]] for the content in the destination pages and must not be deleted as long as %s exist. For attribution and to access older versions of the copied text, please see the history links below. %s"
text = string.format(text, mergedFrom, pageType, copies, historyList)
return text
end
 
local function categories(args,multiUsed)
local to_oldid = args["to_oldid"] or args["to_diff"] or args["diff"] or args["to_oldid1"] or args["to_diff1"] or args["diff1"]
local from_oldid = args["from_oldid"] or args["from_oldid1"]
local text = "[[Category:Wikipedia pages using copied template]]"
if ((not from_oldid) or (not to_oldid)) and not multiUsed then
if (args["mergedFrom"] == 'yes') then
text = text .. "[[Category:Wikipedia pages using merged-from template without oldid]]"
else
text = text .. "[[Category:Wikipedia pages using copied template without oldid]]"
end
end
return text
Line 135 ⟶ 188:
 
local function BannerText(args)
--Checks if there are multiple rows
local text
local from2 = (args["from2"] or "")
if (from2 == "") then
text = singleTextmultiText(args) .. categories(args,true)
else
elseif not (from2 == "") then
text = multiTextsingleText(args) .. categories(args,false)
end
return text
Line 146 ⟶ 200:
 
local function renderBanner(args)
local image
if args.mergedFrom then
image = "[[Image:Mergefrom.svg|50px|alt=|link=]]"
else
image = '[[File:Splitsection.svg|frameless|upright=0.23|link=|alt=]]'
end
return MessageBox.main('tmbox', {
class = "copiednotice",
small = args["small"],
typeimage = 'notice'image,
image = '[[File:Splitsection.svg|50px]]',
smallimage = 'none',
text = BannerText(args)
})
Line 156 ⟶ 215:
 
function p.main(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
return renderBanner(args)