Content deleted Content added
Adding HTML comment with transclusion in error messages to make it easier to fix errors rather than rewriting the whole request from scratch |
m simplify some code (should be a no-op; if there are any errors no discussion is needed before reverting (WP:TPEDISPUTE)) |
||
(23 intermediate revisions by 7 users not shown) | |||
Line 5:
local tableTools = require('Module:TableTools')
local yesno = require('Module:Yesno')
local mRedirect = require('Module:Redirect')
-- Set static values
Line 14 ⟶ 15:
-- Helper functions
--------------------------------------------------------------------------------
local function err(msg, numargs, reason, count)
-- Generates a wikitext error message
Line 23 ⟶ 24:
commented = commented .. numargs[1]['new']
for i = 2,count do
commented = commented .. string.format('|current
commented = commented .. string.format('|new
end
if reason then
Line 90 ⟶ 91:
if not validTitle then
-- If invalid, the second parameter is the error message.
end
return 'yes'
end
--------------------------------------------------------------------------------
-- Confirm protection levels (used at [[Template:Requested move/dated]])
--------------------------------------------------------------------------------
function p.protected(frame)
local args = getArgs(frame, {parentOnly = true})
if args.protected then
local levels = mw.title.new(args.protected).protectionLevels
local levelMove = levels['move'] and levels['move'][1]
local levelEdit = levels['edit'] and levels['edit'][1]
local levelCreate = levels['create'] and levels['create'][1]
if levelMove == 'sysop'
or levelEdit == 'sysop'
or levelEdit == 'editprotected'
or levelCreate == 'sysop' then
return 'sysop'
elseif levelMove == 'templateeditor'
or levelEdit == 'templateeditor'
or levelCreate == 'templateeditor' then
return 'templateeditor'
end
end
end
Line 122 ⟶ 146:
-- The current1 parameter is a special case, as it does not need to be
-- specified. To avoid clashes with later current parameters, we need to
-- add it to the args table manually.
--
-- Also, we allow the first positional parameter to be an alias for the
Line 135 ⟶ 157:
-- true.
--]]
if not args.current1 then
args.current1 = title.subjectPageTitle.prefixedText end
-- Find the first new page title, if specified, and keep a record of the
Line 168 ⟶ 192:
-- multiple nomination.
local argsByNumCount = #argsByNum
local multi = (argsByNumCount >= 2)
--[[
-- Validate new params.
Line 194 ⟶ 213:
end
end
----------------------------------------------------------------------------
-- Error checks
Line 270 ⟶ 289:
.. '<br>If you cannot move it yourself, see [[Wikipedia:Requested moves#Requesting technical moves|Requesting technical moves]].'
return err(msg, argsByNum, args.reason, argsByNumCount)
end
-- Request to move a single page must be placed on that page's talk, or the page it redirects to
if not multi and args.current1 ~= title.subjectPageTitle.prefixedText then
local idealpage = mw.title.new(args.current1).talkPageTitle
local rtarget = mRedirect.getTarget(idealpage)
if rtarget == title.prefixedText then
multi = true
else
local msg = 'Request to move a single page must be placed on that page\'s talk or the page its talk redirects to'
return err(msg, argsByNum, args.reason, argsByNumCount)
end
end
Line 322 ⟶ 353:
newDupes[newPrefixedText] = true
end
end
end
----------------------------------------------------------------------------
-- Check for page protection
----------------------------------------------------------------------------
local highestProtection = ''
local protectedTitle = ''
-- Checking page protection requires use of .protectionLevels(), one of the
-- "expensive" parser functions, which stop working after 500 uses total.
-- Without some limit set, this starts breaking near 250 distinct titles.
local titleLimit = 80
local titlesChecked = 0
local titles = {}
-- Consolidate duplicate titles (i.e., when moving A to B and B to C)
for i = 1,argsByNumCount do
titles[mw.title.new(argsByNum[i]['current'])] = true
titles[mw.title.new(argsByNum[i]['new'])] = true
end
-- Check each title t, while ignoring the "true" value
for t, _ in pairs(titles) do
if titlesChecked < titleLimit then
local levels = t.protectionLevels
titlesChecked = titlesChecked + 1
local levelMove = levels['move'] and levels['move'][1]
local levelEdit = levels['edit'] and levels['edit'][1]
local levelCreate = levels['create'] and levels['create'][1]
if levelMove == 'sysop'
or levelEdit == 'sysop'
or levelEdit == 'editprotected'
or levelCreate == 'sysop' then
highestProtection = 'sysop'
protectedTitle = tostring(t)
break
elseif levelMove == 'templateeditor'
or levelEdit == 'templateeditor'
or levelCreate == 'templateeditor' then
highestProtection = 'templateeditor'
protectedTitle = tostring(t)
end
else
-- End the "for" loop if the titleLimit is reached
break
end
end
Line 364 ⟶ 440:
rmd[#rmd + 1] = '|' .. new1param .. argsByNum[1].new
-- Add
if multi then
for i = 2, argsByNumCount do
Line 374 ⟶ 450:
rmd[#rmd + 1] = '|new' .. numString .. '=' .. new
end
end
-- Highest page protection (if admin or template-editor)
if highestProtection == 'sysop' or highestProtection == 'templateeditor' then
rmd[#rmd + 1] = '|protected=' .. protectedTitle
end
-- Pass through demo=yes to the
if args.demo ~= nil then
rmd[#rmd + 1] = '|demo='
rmd[#rmd + 1] = args.demo
end
-- The old multi template always has a bar before the closing curly
-- braces, so we will do that too.
if multi then
rmd[#rmd + 1] = '|'
end
Line 390 ⟶ 480:
local current = t.current
local new = t.new
local msg = '\n%s[[:%s]] → '
if new ~= defaultNewPagename then
msg = msg .. '{{no redirect|%s}}'
else
msg = msg .. '%s'
end
local item = string.format(
msg,
multi and '* ' or '', -- Don't make a list for single page moves.
current,
Line 407 ⟶ 503:
local reason = args.reason or args[2] or 'Please place your rationale for the proposed move here.'
reason = '– ' .. reason
if yesno(args.sign
reason = reason .. ' ~~~~'
end
-- Talk blurb
local talk = ''
if yesno(args.talk, true) then
talk = frame:expandTemplate{title = 'Requested move/talk'}
end
|