Module:Copied: Difference between revisions

Content deleted Content added
fix crash
simply and clean up code
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 ""
Line 52 ⟶ 54:
 
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]
localif (afd =and args["afdmerge" .. i]) or ""then
text = text .. "\n*Merged"
else
text = text .. "\n*Copied"
end
 
text = text .. " [" .. tostring(mw.uri.fullUrl(from,{redirect="no"} )) .. " " .. from .. "]"
textlocal from = textargs["from" .. "i] (or ""
text = 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] or ""
if not (from_oldid == "") then
text = text .. "[" .. tostring(mw.uri.fullUrl(from, {oldid = from_oldid} )) .. " oldid], "
end
text = text .. "[" .. tostring(mw.uri.fullUrl(from,{action="history"} )) .. " history]"
textlocal to = text args["to".. ")i] or ""
text = text .. "[" .. tostring(mw.uri.fullUrl(from, {action = "history"} )) .. " history]) → [[" .. to .. "]]"
 
if not (diff == "") then
local fromdiff = args["fromdiff" .. i] or ""
local diffto_oldid = args["diffto_oldid" .. i] or ""
if not (diff == "") then
text = text .. "([" .. diff .. " diff])"
elseif not (to_oldid == "") then
local to_diff = args["to_diff".. i] or ""
text = text .. " ([" .. tostring(mw.uri.fullUrl(to, {diff=to_diff, oldid = to_oldid} )) .. " diff])"
end
 
if not (date == "") then
local to_diffdate = args["to_diffdate" .. i] or ""
if not (date == "") then
text = text .. " on " .. date
end
 
if not (afd == "") then
text = text .. " after being [["
if (not mw.ustring.match(afd, "Wikipedia:", 1 )) then
text = text .. "Wikipedia:Articles for deletion/"
end
text = text .. afd .. "|after being nominated for deletion]]"
end
return text
localreturn text
end
 
local function list(args)
local text = ""
local from1 = args["from1"] or ""
if not (from1 == "") then
text = text .. row(args, 1)
else
text = text .. row(args, "")
end
local i = 2
while i > 0 do
if (args["from" .. i]) then
text = text .. row(args, i)
i = i + 1
else
i = - 1
end
end
Line 115 ⟶ 119:
local function multiText(args)
local text = text"Text ..has been copied to or from 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 so long as the copies exist. For attribution and to access older versions of the copied text, please see the history links below. %s"
local collapse = args["collapse"] or ""
 
local currentTitle = mw.title.getCurrentTitle()
local pageType
local text = "Text has been copied to or from this"
if currentTitle(mw.title.getCurrentTitle():inNamespace(0)) then
textpageType = 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 (args["collapse"] == 'yes') then
textlocal collapsedText = text .. '<table style="width:100%%; background: transparent;" class="collapsible collapsed">\n<tr><th>Copied pages:</th></tr>\n<tr><td> %s </td></tr></table>'
end
historyList = string.format(collapsedText, historyList)
text = text .. list(args)
if collapse == 'yes' then
text = text .. '</td></tr></table>'
end
 
text = string.format(text, pageType, historyList)
return text
end
Line 136 ⟶ 140:
local function BannerText(args)
local text
local from2 = (args["from2"] or "")
if (from2 == "") then
text = singleText(args)
elseif not (from2 == "") then
text = multiText(args)
elseif (not (from2 == "") then
text = text .. listsingleText(args)
end
return text
Line 159 ⟶ 163:
local from_oldid = args["from_oldid"]
local text = "[[Category:Wikipedia pages using copied template]]"
if ((not from_oldid) or (not to_oldid)) then
text = text .. [[Category:Wikipedia pages using copied template without oldid]]
end
return text
end
 
function p.main(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
return renderBanner(args) .. categories(args)