local p = {}
local messageBox = require('Module:Message box')
local dateModule = require('Module:Date')._Date
local listModule = require('Module:List').horizontal
-- Create variables used in other functions
local pageType
if (mw.title.getCurrentTitle():inNamespace(1)) then
pageType = "article"
else
pageType = "page"
end
-- TODO: find the most optimal way to do this (is making the html in code better than just plopping it in a string?)
local function makeTable(list, text)
local collapseTable = mw.html.create("table")
collapseTable
:attr({
class = "mw-collapsible mw-collapsed",
cellspacing = 0,
cellpadding = 0
})
:css({
width = "100%",
background = "transparent",
margin = 0,
padding = "0.5em 0 0"
})
:tag("tr"):tag("th"):wikitext(text):cssText("text-align: left"):tag("tr"):tag("td"):wikitext("\n" .. list)
return collapseTable
end
-- I'm not sure if we actually need custom text for when it's just one entry
-- Old moves doesn't do this, and it would make things simpler to just have one function for generating text
local function singleText(args)
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 dateformat = args["dateformat"] or "dmy"
local text = ""
if (date ~= "") then
if dateModule(date) then
date = dateModule(date):text(dateformat)
end
text = string.format("On %s, it was proposed that this %s be [[Wikipedia:Requested moves|moved]]", date, pageType)
else
text = string.format("It has previously been proposed that this %s be [[Wikipedia:Requested moves|moved]]", pageType)
end
if (from ~= "") then
text = string.format("%s from [%s %s]", text, tostring(mw.uri.fullUrl(from, {redirect = "no"} )), from)
end
if (to ~= "") then
text = string.format("%s to [[%s]]", text, to)
end
text = string.format("%s.", text)
if (result ~= "") then
if (link ~= "") then
text = string.format("%s The result of [[%s|the discussion]] was '''%s'''.", text, link, result)
else
text = string.format("%s The result of the discussion was '''%s'''.", text, result)
end
elseif (link ~= "") then
text = string.format("%s See [[%s|discussion]].", text, link)
end
return text
end
local function row(args, i)
local date = args["date" .. i] or ""
local from = args["from" .. i] or ""
local dateformat = args["dateformat"] or "dmy"
local to = args["destination" .. i] or args["to" .. i] or ""
local result = mw.language.getContentLanguage():ucfirst(args["result" .. i]) or ""
local link = args["link" .. i] or ""
local rowText = string.format("\n*'''%s'''", result)
if (date ~= "") then
if dateModule(date) then
date = dateModule(date):text(dateformat)
end
rowText = string.format("%s, %s", rowText, date)
end
if (from ~= "") then
rowText = string.format("%s, from [%s %s]", rowText, tostring(mw.uri.fullUrl(from, {redirect = "no"} )), from)
if (to ~= "") then
rowText = string.format("%s to [[%s]]", rowText, to)
end
elseif (to ~= "") then
rowText = string.format("%s, to [[%s]]", rowText, to)
end
if (link ~= "") then
rowText = string.format("%s, see [[%s|discussion]]", rowText, link)
end
rowText = rowText .. "."
return rowText
end
local function list(args)
local text = ""
local multiple = args["result1"] or ""
if (multiple ~= "") 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 (args["result" .. i]) do
text = string.format("%s%s", text, row(args, i))
i = i + 1 -- Check if to(i+1) exist
end
return text
end
local function manualList(args)
local manualListText = ""
if (args["list"]) then
if (args["result"] or args["result1"]) then
manualListText = string.format("%s\n'''Other discussions: '''\n%s", manualListText, args["list"])
elseif (args["collapse"] or args["collapsed"]) then
manualListText = string.format("%s\n%s", manualListText, args["list"])
else
manualListText = string.format("%s\n'''Discussions: '''\n%s", manualListText, args["list"])
end
end
if (args["oldlist"]) then
if (args["collapse"] or args["collapsed"]) then
manualListText = string.format("%s\n'''Older discussions: '''\n%s", manualListText, tostring(args["oldlist"]))
else
manualListText = string.format("%s\n%s", manualListText, tostring(makeTable(args["oldlist"], "Older discussions:")))
end
end
return manualListText
end
local function showLogs(args)
local logList, i = {}, 1
while (args["title" .. i]) do
local uri = mw.uri.encode(args["title" .. i], "QUERY")
if (i == 1) then -- Hacky way to make the hlist go after "move logs"
table.insert(logList, string.format("\n'''Move logs: '''[https://en.wikipedia.org/w/index.php?title=Special:Log&page=%s&type=move %s]", uri, args["title" .. i]))
else
table.insert(logList, string.format("[https://en.wikipedia.org/w/index.php?title=Special:Log&page=%s&type=move %s]", uri, args["title" .. i]))
end
i = i + 1
end
logList["style"] = "padding-top: 0.5em;"
return listModule(logList)
end
local function evaluate(args)
local text = ""
-- COMPAAAAAAAREEEEEEEEE
-- This makes sure we don't show the single version when there's a log or manual list, bit ugly
if (args["result"]) then
if (args["title"] ~= true and args["title"] ~= true) then
if (args["list"] or args["oldlist"]) then
text = string.format("%s\n'''Discussions: '''\n%s", text, list(args))
else
text = singleText(args)
end
end
end
if (args["title"] or args["title1"]) then
text = string.format("%s%s", text, showLogs(args))
end
if (args["result2"]) then -- Do we have multiple rows?
text = string.format("%s\n'''Discussions: '''\n%s", text, list(args))
end
if (args["list"] or args["oldlist"]) then
text = string.format("%s%s", text, manualList(args))
end
return text
end
local function bannerText(args)
local blurb = string.format("This %s has previously been nominated to be moved.", pageType)
local list = ""
if (args["collapse"] or args["collapsed"]) then
if (args["title"] or args["title1"]) then
list = string.format("%s%s", blurb, tostring(makeTable(evaluate(args), "Logs and discussions:")))
else
list = string.format("%s%s", blurb, tostring(makeTable(evaluate(args), "Discussions:")))
end
else
list = string.format("%s%s", blurb, evaluate(args))
end
return list
end
local function renderBanner(args)
return messageBox.main('tmbox', {
small = args["small"],
type = 'move',
text = bannerText(args)
})
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame)
return renderBanner(args)
end
return p