Jump to content

Module:Requested move

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 07:11, 17 February 2014 (Save progress on a replacement for Template:Move-multi. It doesn't output anything apart from error messages yet.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

-- This module implements {{move-multi}}.

local getArgs = require('Module:Arguments').getArgs
local tableTools = require('Module:TableTools')

local p = {}

--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------

local function err(msg)
	-- Generates a wikitext error message
	return string.format('<strong class="error">%s</strong>', msg)
end

--------------------------------------------------------------------------------
-- Main functions
--------------------------------------------------------------------------------

function p.main(frame)
	local args = getArgs(frame)
	
	-- Subst check
	if not mw.isSubsting() then
		local msg = 'This template must be [[Wikipedia:Template substitution|substituted]].'
			.. mw.text.nowiki(' Replace {{move-multi}} with {{subst:move-multi}}')
		return err(msg)
	end
	
	-- Check namespaces
	local title = mw.title.getCurrentTitle()
	local namespace = title.namespace
	local subjectSpace = mw.site.namespaces[namespace].subject.id
	if not title.isTalkPage then
		local msg = '[[Template:Move-multi]] must be used in a TALKSPACE, e.g., [[%s:%s]]'
		msg = string.format(msg, mw.site.namespaces[namespace].talk.name, title.text)
		return err(msg)
	elseif subjectSpace == 14 then -- Category
		local msg = '[[Template:Move-multi]] is not for categories,'
			.. ' see [[Wikipedia:Categories for discussion]]'
		return err(msg)
	elseif subjectSpace == 6 then -- File
		local msg = '[[Template:Move-multi]] is not for files;'
			.. ' see [[Wikipedia:Moving a page#Moving a file page]]'
			.. ' (use [[Template:Rename media]] instead)'
		return err(msg)
	elseif subjectSpace == 2 then -- User
		local msg = '[[Template:Move-multi]] is not for moves from user space;'
			.. ' see [[Wikipedia:Articles for creation]]'
			.. ' (use '
			.. mw.text.nowiki('{{')
			.. '[[Wikipedia:Substitution|subst]]:[[Template:Submit|submit]]'
			.. mw.text.nowiki('}}')
			.. ' instead),'
			.. ' or [[Help:How to move a page|move it yourself]]'
		return err(msg)
	end
	
	local subjectTitle = title.subjectPageTitle
	if not subjectTitle.exists then
		local msg = 'Must create [['
			.. subjectTitle.prefixedText
			.. ']] before requesting that it be moved'
		return err(msg)
	end
	
	--[[
	-- With the numArgs table we reorganise the numerical data so that it can
	-- be easily iterated over. A template invocation like:
	-- {{move-multi|current1=Page 1|new1=New page 1|current2=Page 2|new2 = New page 2}}
	-- would be converted to a table like
	-- { [1] = {current = 'Page 1', new = 'New page 1'}, [2] = {current = 'Page 2', new = 'New page 2'} }
	--]]
	local numArgs = tableTools.numData(args)
end

return p