FANDOM


local Merge = {}
local HF = require('Module:HF')
local getArgs = require('Module:Arguments').getArgs
local M = require('Module:Message box')
local CH = require( 'Module:Category handler' ).main
 
-- Implements new {{Merge}}.
function Merge.main(frame)
	local args = getArgs(frame)
	return Merge._box(args)
end
 
function Merge._box(args)
    return ''
end
 
local separators = {
	dot = true,
	pipe = true,
	comma = true,
	['tpt-languages'] = true
}
 
local function getSeparator(sep)
	if type(sep) ~= 'string' then
		return nil
	end
	if separators[sep] then
		return mw.message.new(sep .. '-separator'):plain()
	else
		return sep
	end
end
 
local function generateLink(page, nspace, delim, endDelim)
	if not page then
		return nil
	end
	local pagename = mw.title.new(page)
	if not pagename then
		-- Default to the args we were passed if our page
		-- object was nil.
		pagename = page
	else
		pagename = pagename.text
	end
	delim = delim or ''
	endDelim = endDelim or delim
	nspace = nspace or mw.title.getCurrentTitle().nsText
	return string.format( 
		'%s[[:%s:%s|%s]]%s',
		delim, nspace, pagename, page, endDelim
	)
end
 
function Merge.Pagelist(frame)
	local origArgs = require('Module:Arguments').getArgs(frame, {
		trim = false,
		removeBlanks = false
	})
 
	-- Process integer args. Allow for explicit positional arguments that are
	-- specified out of order, e.g. {{br separated entries|3=entry3}}.
	-- After processing, the args can be accessed accurately from ipairs.
	local args = {}
	for k, v in pairs(origArgs) do
		if type(k) == 'number' and 
			k >= 1 and
			math.floor(k) == k and
			string.match(v, '%S') then -- Remove blank or whitespace values.
			table.insert(args, k)
		end
	end
	table.sort(args)
	for i, v in ipairs(args) do
		args[i] = origArgs[v]
		-- Trim whitespace.
		if type(args[i]) == 'string' then
			args[i] = mw.text.trim(args[i])
		end
	end
 
	-- Get old named args. We don't need to remove blank values
	-- as for the nspace and edelim parameters the behaviour is different
	-- depending on whether the parameters are blank or absent, and for
	-- the delim parameter the default should be the blank string anyway.
	args.delim = origArgs.delim
	args.edelim = origArgs.edelim
	args.nspace = origArgs.nspace
 
	-- Get new named args, "separator" and "conjunction", and strip blank values.
	if origArgs.separator and origArgs.separator ~= '' then
		args.separator = origArgs.separator
	end
	if origArgs.conjunction and origArgs.conjunction ~= '' then
		args.conjunction = origArgs.conjunction
	end
 
	return Merge._pagelist(args)
end
 
function Merge._pagelist(args)
	local t = {}
	local separator = getSeparator(args.separator)
	local conjunction = getSeparator(args.conjunction)
	for i, v in ipairs(args) do
		table.insert(t, generateLink(
			v, args.nspace, args.delim, args.edelim
		))
	end
	return mw.text.listToText(t, separator, conjunction)
end
 
-- Implements classic {{Merge}}
function Merge.Merge(frame)
    local args = getArgs(frame)
    assert(args[1], "No article was listed.")
    local category = CH{ all = '[[Category:Articles to be merged]]' }
    local boxtext = category .. "It has been suggested that this "
    if (args['section'] == 'section') then
        boxtext = boxtext .. 'section '
    else
        boxtext = boxtext .. 'article '
    end
    boxtext = boxtext .. 'be merged with '
    boxtext = boxtext .. Merge._pagelist( args )
    boxtext = boxtext .. '.'
    if args['talk'] then
        boxtext = boxtext .. " ([[" .. args['talk'] .. "|Discuss]])"
    end
    return M.main( 'mbox', {
        demospace = args['demospace'] or '',
        type = 'move',
        small = args['small'] or '',
        image = '[[File:Merge-arrows.svg|alt=|link=]]',
        text = boxtext,
    } )
end
 
-- Implements classic {{Merge to}}
function Merge.MergeTo(frame)
    local args = getArgs(frame)
    assert(args[1], "No article was listed.")
    local category = CH{ all = '[[Category:Articles to be merged]]' }
    local boxtext = category .. "It has been suggested that this "
    if (args['section'] == 'section') then
        boxtext = boxtext .. 'section '
    else
        boxtext = boxtext .. 'article '
    end
    boxtext = boxtext .. 'be merged into '
    boxtext = boxtext .. Merge._pagelist( args )
    boxtext = boxtext .. '.'
    if args['talk'] then
        boxtext = boxtext .. " ([[" .. args['talk'] .. "|Discuss]])"
    end
    return M.main( 'mbox', {
        demospace = args['demospace'] or '',
        type = 'move',
        small = args['small'] or '',
        image = '[[File:Merge-arrow.svg|alt=|link=]]',
        text = boxtext,
    } )
end
 
-- Implements classic {{Merge from}}
function Merge.MergeFrom(frame)
    local args = getArgs(frame)
    local category = CH{ all = '[[Category:Articles to be merged]]' }
    local boxtext = category .. 'It has been suggested that '
    if (args['multiplesections'] == 'yes') then
        boxtext = boxtext .. 'multiple sections of '
    end
    if not args[1] then args[1] = 'an article' end
    boxtext = boxtext .. Merge._pagelist( args )
    boxtext = boxtext .. ' be merged into this '
    if (args['section'] == 'section') then
        boxtext = boxtext .. 'section.'
    else
        boxtext = boxtext .. 'article.'
    end
    if args['talk'] then
        boxtext = boxtext .. " ([[" .. args['talk'] .. "|Discuss]])"
    end
    return M.main( 'mbox', {
        demospace = args['demospace'] or '',
        type = 'move',
        small = args['small'] or '',
        image = '[[Image:Mergefrom.svg|50px|alt=|link=]]',
        text = boxtext,
    } )
end
 
-- Implements classic {{Move portions}}
function Merge.MovePortions(frame)
    local args = getArgs(frame)
    assert(args[1], "No article was listed.")
    local category = CH{ all = '[[Category:Articles to be merged]]' }
    local boxtext = category .. "It has been suggested that "
    if (args['section'] == 'section') then
        boxtext = boxtext .. 'this section '
    else
        boxtext = boxtext .. 'portions of this article '
    end
    boxtext = boxtext .. "be moved or incorporated into ''[["..args[1].."]]'' "
    if args['talk'] then
        boxtext = boxtext .. " ([[" .. args['talk'] .. "|Discuss]])"
    end
    return M.main( 'ambox', {
        demospace = args['demospace'] or '',
        type = 'move',
        small = args['small'] or '',
        image = '[[File:Merge-arrow.svg|alt=|link=]]',
        text = boxtext,
    } )
end
 
-- Implements classic {{Move portions from}}
function Merge.MovePortionsFrom(frame)
    local args = getArgs(frame)
    assert(args[1], "No article was listed.")
    local category = CH{ all = '[[Category:Articles to be merged]]' }
    local boxtext = category .. "It has been suggested that portions of ''[["..args[1].."]]'' "
    if args[2] then boxtext = boxtext .. " (" .. args[2] .. ") " end
    boxtext = boxtext .. "be moved or incorporated into this "
    if (args['section'] == 'section') then
        boxtext = boxtext .. 'section.'
    else
        boxtext = boxtext .. 'article.'
    end
    if args['talk'] then
        boxtext = boxtext .. " ([[" .. args['talk'] .. "|Discuss]])"
    end
    return M.main( 'ambox', {
        demospace = args['demospace'] or '',
        type = 'move',
        small = args['small'] or '',
        image = '[[Image:Mergefrom.svg|50px|alt=|link=]]',
        text = boxtext,
    } )
end
 
-- Implements classic {{Move section portions}}
function Merge.MoveSectionPortions(frame)
    local args = getArgs(frame)
    assert(args[1], "No article was listed.")
    local category = CH{ all = '[[Category:Articles to be merged]]' }
    local boxtext = category .. "It has been suggested that portions of this section "
    boxtext = boxtext .. "be moved or incorporated into ''[["..args[1].."]]'' "
    if args['talk'] then
        boxtext = boxtext .. " ([[" .. args['talk'] .. "|Discuss]])"
    end
    return M.main( 'ambox', {
        demospace = args['demospace'] or '',
        type = 'move',
        small = 'left',
        image = '[[File:Merge-arrow.svg|alt=|link=]]',
        text = boxtext,
    } )
end
 
return Merge

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.