Jump to content

Module:Old moves

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Trialpears (talk | contribs) at 14:51, 12 December 2020 (Test). 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 p = {}

local function singleText(args)
	local datemodule = require('Module:Date')._Date
	local pageType
	if (mw.title.getCurrentTitle():inNamespace(1)) then
		pageType = "article"
	else
		pageType = "page"
	end
	local date = args["date"] or args["date1"] or ""
	local from = args["from"] or args["from1"] or ""
	local to = args["destination"] or args["destination1"] or args["to1"] or args["to"] or ""
	local result = args["result"] or args["result1"] or ""
	local link = args["link"] or args["link1"] or ""
	local text = ""
	if not (date == "") then
		date = (datemodule(date) or date)
		if not (link == "") then
			text = string.format("On  [[%s|%s]], it was proposed that this %s be [[Wikipedia:Requested moves|moved]]",link,date,pageType) 
		else
			text = string.format("On %s, it was proposed that this %s be [[Wikipedia:Requested moves|moved]]",date,pageType) 
		end
	else
		if not (link == "") then
			text = string.format("*It has [[%s|previously been proposed]] that this %s be moved",link,pageType)
		else
			text = string.format("It has previously been proposed that this %s be moved",pageType) 
		end
	end
	if not (from == "") then 
		text = string.format("%s from [%s %s]",text,tostring(mw.uri.fullUrl(from, {redirect = "no"} )), from)
	end
	if not (to == "") then 
		text = string.format("%s to [%s %s]",text,tostring(mw.uri.fullUrl(to, {redirect = "no"} )), to)
	end
	text = string.format("%s.",text)
	if not (result == "") then 
		text = string.format("%s The result of the proposal was '''%s'''.",text,result)
	end
	return text
end

local function row(args, i)
	local pageType
	if (mw.title.getCurrentTitle():inNamespace(1)) then
		 pageType = "article"
	else
		 pageType = "page"
	end
	local date = args["date" .. i] or ""
	local from = args["from" .. i] or ""
	local to = args["destination" .. i] or args["to" .. i] or ""
	local result = args["result" .. i] or ""
	local link = args["link" .. i] or ""
	local text = ""
	
	if not (date == "") then
	date = datemodule(date):text('mdy')  
		if not (link == "") then
			text = string.format("\n*On  [[%s|%s]], it was proposed that this %s be [[Wikipedia:Requested moves|moved]]",link,date,pageType) 
		else
			text = string.format("\n*On %s, it was proposed that this %s be [[Wikipedia:Requested moves|moved]]",date,pageType) 
		end
	else
		if not (link == "") then
			text = string.format("\n*It has [[%s|previously been proposed]] that this %s be moved",link,pageType)
		else
			text = string.format("\n*It has previously been proposed that this %s be moved",pageType) 
		end
	end
	if not (from == "") then 
		text = string.format("%s from [%s %s]",text,tostring(mw.uri.fullUrl(from, {redirect = "no"} )), from)
	end
	if not (to == "") then 
		text = string.format("%s to [%s %s]",text,tostring(mw.uri.fullUrl(to, {redirect = "no"} )), to)
	end
	text = string.format("%s.",text)
	if not (result == "") then 
		text = string.format("%s The result of the proposal was '''%s'''.",text,result)
	end
	return text
end

local function list(args)
	local text = ""
	local to1 = args["to1"]
	if (to1) then --Support to1 and to 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["to" .. i]) then 
			text = string.format("%s%s",text,row(args, i))
			i = i + 1 --Check if to(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(0)) then
		pageType = "article"
	else
		pageType = "page"
	end
	
	local historyList = list(args)

	local text = string.format("This %s has previously been nominated to be moved.", pageType)
	text = string.format("%s\n%s", text, historyList)
	return text
end
local function listText(args)
	local pageType
	if (mw.title.getCurrentTitle():inNamespace(0)) then
		pageType = "article"
	else
		pageType = "page"
	end

	local text = string.format("This %s has previously been nominated to be moved. \n%s", pageType, args["list"])

end

local function BannerText(args)
	--Checks if there are multiple rows
	local text
	local multiple = args["to2"] or args["to2"] or args["date2"] or ""
	if not (multiple == "") then
		text = multiText(args)
	elseif args["list"] then
		text = listText(args)
	else
		text = singleText(args)
	end
	return text
end

local function renderBanner(args)
	return MessageBox.main('tmbox', {
		small = args["small"],
		type = 'move',
		text = BannerText(args)
	})
end

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

return p