Jump to content

Module:Split article

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Chlod (talk | contribs) at 10:06, 11 August 2022 (saving progress). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local MessageBox = require('Module:Message box')
local yesno = require("Module:Yesno")

local p = {}

local function showWarning(text)
	mw.addWarning(text)
	return "[[Category:Wikipedia pages with split article warnings]]"
end

local function showError(text)
	return string.format(
		"[[Category:Wikipedia pages with split article warnings]] %s %s",
		tostring(
			mw.html.create("span")
				:css("color", "red")
				:css("font-weight", "bold")
				:wikitext("Error:")
		),
		text
	)
end

local function singleText(args)
	local text = ""
	-- from1 also included in case someone filed the template improperly
	local from = args["from"] or args["from1"] or mw.title.getCurrentTitle().subjectPageTitle.prefixedText
	if args["from1"] then
		text = text .. showWarning(
			"<code>from</code> is not a row-based parameter. Use <code>from</code> instead of <code>from1</code>."
		)
	end

	if args["from_oldid1"] then
		text = text .. showWarning(
			"<code>from_oldid</code> is not a row-based parameter. Use <code>from_oldid</code> instead of <code>from_oldid1</code>."
		)
	end
	
	-- Row-based parameters
	local to = args["to"] or args["to1"]
    if to == nil then
    	return showError("Target page was not specified with <code>to</code>.")
	end
	
	local toTalk = mw.title.new(to).subjectPageTitle.prefixedText
	local diff = args["diff"] or args["diff1"] or ""
	local date = args["date"] or args["date1"]
	if date == nil then
		return showError("Split date was not specified with <code>date</code>.")
	end
	
	text = string.format("Material from [[%s]] was split to [[%s]] on %s", from, to, date)
	local from_oldid = args["from_oldid"] or args["from_oldid1"]
	if from_oldid ~= nil then
		if from_oldid:match("^%d+$") then
			text = string.format("%s from [[Special:Diff/%s|this version]]", text, from_oldid)
		else
			text = string.format("%s from [%s this version]", text, from_oldid)
		end
	end
	text = string.format(
		"%s. The former page's [[Special:PageHistory/%s|history]] now serves to "..
		"[[Wikipedia: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. Please leave this template in place to link the article histories "..
		"and preserve this attribution. The former page's talk page can be accessed at [[%s]]", 
		text, from, toTalk
	)
	
	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


function p.renderBanner(args)
	return MessageBox.main('tmbox', {
		name = "split-article",
		small = args["small"],
		image = '[[File:Split-arrows.svg|50px]]',
		text = bannerText(args)
	})
end

function p.main(frame)
	local getArgs = require('Module:Arguments').getArgs
	local args = getArgs(frame, {
		trim = true,
		removeBlanks = true
	})
	return p.renderBanner(args)
end

return p