跳转到内容

模組:Copied

本页使用了标题或全文手工转换
被永久保护的模块
维基百科,自由的百科全书

local MessageBox = require('Module:Message box')


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 = 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 text = "页面中的文本或其他内容" 

	if not (from_oldid == "") then
		text = string.format("[%s 此版本]%s", tostring(mw.uri.fullUrl(from, {oldid=from_oldid} )), text)
	end
	text = string.format("[[%s]]的%s",from,text)

	local diff = args["diff"] or args["diff1"]
	local to_diff = args["to_diff"] or args["to_diff1"]
	local to_oldid = args["to_oldid"] or args["to_oldid1"] 

    if not (date == "") then
        if (diff) then
            text = string.format("%s在%s的[%s 这一编辑]中",text,date,diff)
        elseif (to_oldid or to_diff) then
            text = string.format("%s在%s的[%s 这一编辑]中",text,date,tostring(mw.uri.fullUrl(to, {diff=to_diff or "next", oldid = to_oldid or "prev"} )))
        else
            text = string.format("%s在%s",text,date)
        end
	end

    if (date == "") then
    	if (diff) then
    		text = string.format("%s在[%s 这一编辑]中",text,diff)
    	elseif (to_oldid or to_diff) then
    		text = string.format("%s在[%s 这一编辑]中",text,tostring(mw.uri.fullUrl(to, {diff=to_diff or "next", oldid = to_oldid or "prev"} )))
        end
	end

    if (merge == "是") or not (afd == "") then
		text = text .. "被合并到"
	else 
		text = text .. "被复制粘贴移动到"
	end 

	if (merge == "是") and (to == "") then
		text = string.format("%s[[%s:%s]]",text,mw.title.getCurrentTitle().nsText,mw.title.getCurrentTitle().text) --如果没有给出合并目标页面,则假定当前页面是目标。
	else 
		text = string.format("%s[[%s]]",text,to)
	end 

    if not (afd == "") then
		if (mw.ustring.match(afd, "Wikipedia:", 1 )) then --如果没有给出讨论链接,则添加“Wikipedia:頁面存廢討論”前缀
			text = string.format("经[[%s|提删讨论]],%s",afd,text)
		else
			text = string.format("经[[Wikipedia:頁面存廢討論/%s|提删讨论]],%s",afd,text)
		end
	end

	text = text .. "。" -- 第一句完成
	text = string.format("%s先前页面的[%s 历史]现[[Wikipedia:在维基百科内复制内容|归属于]]目标页面,且在目标页面删除前不得删除。",text,tostring(mw.uri.fullUrl(from,{action="history"}) or ""))
	return text
end

local function row(args, i)
	local text = ""
	local afd = args["afd" .. i]
	if (afd or args["merge" .. i]) then
		text = string.format("%s\n*合并",text)
	else 
		text = string.format("%s\n*复制",text)
	end

	local from = args["from" .. i] or ""
	text = string.format("%s [%s %s] (",text,tostring(mw.uri.fullUrl(from, {redirect = "no"} )),from)

	local from_oldid = args["from_oldid" .. i]
	if (from_oldid) then
		text = string.format("%s[%s 版本], ",text,tostring(mw.uri.fullUrl(from, {oldid = from_oldid} )))
	end
	
	local to = args["to".. i] or ""
	text = string.format("%s[%s 历史]) → [[%s]]",text,tostring(mw.uri.fullUrl(from, {action = "history"} )), to)
	
	local diff = args["diff" .. i]
	if (diff) then
		text = string.format("%s ([%s 差异])",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 差异])",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,-{zh-cn:操作;zh-tw:作業始}-于%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,[[%s|讨论见此]]",text,afd)
		else
			text = string.format("%s,[[Wikipedia:頁面存廢討論/%s|讨论见此]]",text,afd)
		end
	end
	if (not (args["to_oldid" .. i] or args["to_diff".. i])) then
		text = string.format("%s[[Category:未填写oldid的复制模板页面]]",text)
	end
	
	return text
end

local function list(args)
	local text = ""
	local from1 = args["from1"]
	if (from1) then --Support from1 and from in case of multiple rows
		text = string.format("%s%s",text,row(args, 1))
	else
		text = string.format("%s%s",text,row(args, ""))
	end
	local i = 2
	while i > 0 do
		if (args["from" .. i]) then 
			text = string.format("%s%s",text,row(args, i))
			i = i + 1 --Check if from(i+1) exist
		else
			i = - 1 --Break if fromi doesn't exist
		end
	end
	return text
end
	
local function multiText(args)
	local pageType
	if (mw.title.getCurrentTitle():inNamespace(1)) then
		pageType = "条目"
	else
		pageType = "页面"
	end
	
	local historyList = list(args)
	if (args["collapse"] == '是') then
		local collapsedText = '<table style="width:100%%; background: transparent;" class="collapsible collapsed">\n<tr><th>复制移动的页面:</th></tr>\n<tr><td> %s </td></tr></table>'
		historyList = string.format(collapsedText, historyList)
	end

	local text = "本%s中有文本从别处粘贴而来,亦或本%s的文本被复制到别处,详情参见下表。复制文本的来源页面现作为目标页面[[Wikipedia:在维基百科内复制内容|归属]],在目标页面删除前均不得删除。文本的来源版本及贡献情况已标注于表中。%s"
	text = string.format(text, pageType, pageType, 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:曾複製或移動內容的頁面]]" 
	if ((not from_oldid) or (not to_oldid)) and not multiUsed then
		text = text .. "[[Category:未填写oldid的复制模板页面]]"
	end
	return text
end

local function BannerText(args)
	--Checks if there are multiple rows
	local text
	local from2 = args["from2"]
	if (from2) then
		text = multiText(args) .. categories(args,true)
	else
		text = singleText(args) .. categories(args,false)
	end
	return text
end

local function renderBanner(args)
	return MessageBox.main('tmbox', {
		class = "copiednotice",
		small = args["small"],
		image = '[[File:Splitsection.svg|50px]]',
		text = BannerText(args)
	})
end

function p.main(frame)
	local getArgs = require('Module:Arguments').getArgs
	local args = getArgs(frame)
	return renderBanner(args)
end

return p