Module:RfD: Difference between revisions

Content deleted Content added
Jackmcbarn (talk | contribs)
handle an edge case and document what needs to happen if we ever get grandparent frame access
NOINDEX only if actually displaying the RfD notice
 
(60 intermediate revisions by 23 users not shown)
Line 1:
require('strict')
 
local p = {}
 
local getTargetFromText = require('Module:Redirect').getTargetFromText
local messageBox
 
local mboxText = "'''The purpose of this redirect is currently being discussed by the Wikipedia community."
.. " The outcome of the discussion may result in a change of this page, or possibly its deletion in accordance with Wikipedia's [[Wikipedia:Deletion policy|deletion policy]].''' <br />"
.. " Please share your thoughts on the matter at '''[[Wikipedia:Redirects for discussion/Log/%s %s %s#%s|this redirect's entry]]''' on the [[Wikipedia:Redirects for discussion|Redirectsredirects for discussion]] page.<br />"
.. " '''Click on the link below''' to go to the current destination page.<br />"
.. "<small>Please notify the good-faith creator and any main contributors of the redirect by placing <code>&#123;&#123;[[Wikipedia:Substitution|subst]]:[[Template:RFDNoteRfd notice|RFDNoteRfd notice]]&#124;%s&#125;&#125; &#126;&#126;&#126;&#126;</code> on their talk page.</small>__EXPECTUNUSEDTEMPLATE__"
local deleteReason = '[[Wikipedia:Redirects for discussion]] debate closed as delete'
local messageOnTransclusionsStandard = '&lsaquo;The template below is included via a redirect'
.. ' (%s) that is under discussion. See [[Wikipedia:Redirects for discussion/Log/%s %s %s#%s|redirects for discussion]]'
.. ' to help reach a consensus.&rsaquo;'
local messageOnTransclusionsTiny = '&lsaquo;[[Wikipedia:Redirects for discussion/Log/%s %s %s#%s|See RfD]]&rsaquo;'
 
local function makeTransclusionTag(args, redirect)
local discussionPage = args[1] and mw.text.trim(args[1])
if not discussionPage or discussionPage == '' then
discussionPage = redirect
end
local visClasses = {
['autoconfirmed']='autoconfirmed-show',
['extendedconfirmed']='extendedconfirmed-show sysop-show'
} -- More can be added if justified by situation
local sizeAttrs = {
['standard'] = {
['tags'] = {'<div ', '</div>'},
['style'] = ' border-bottom: 1px solid #AAAAAA;',
['message'] = messageOnTransclusionsStandard:format(redirect, args.year, args.month, args.day, discussionPage)
},
['tiny'] = {
['tags'] = {'<span ', '</span> '},
['style'] = '',
['message'] = messageOnTransclusionsTiny:format(args.year, args.month, args.day, discussionPage)
},
}
local size = sizeAttrs[args.showontransclusion] and args.showontransclusion or 'standard'
local tags = sizeAttrs[size]['tags']
local visibility = visClasses[args.transclusiontagvisibility] or ''
local classes = 'class="boilerplate metadata plainlinks ' .. visibility .. '" '
local id = 'id="rfd-t" '
local style = 'style="font-size: 85%; text-align: left;' .. sizeAttrs[size]['style'] .. '" '
return tags[1] .. classes .. id .. style .. '>' .. sizeAttrs[size]['message'] .. tags[2]
end
 
local function makeRfdNotice(args)
Line 20 ⟶ 56:
discussionPage = nil
end
local target = getTargetFromText(args.content)
return string.format('%s<span id="delete-reason" style="display:none;">%s</span>%s',
local isError = not target or not mw.title.new(target)
local category
if args.category then
category = args.category
elseif args.timestamp then
-- Extract stable year and month from timestamp; args.month and args.year can change if the discussion is relisted (see [[Special:Diff/896302321]])
local lang = mw.language.getContentLanguage()
local catMonth = lang:formatDate('F', args.timestamp)
local catYear = lang:formatDate('Y', args.timestamp)
category = string.format('[[Category:Redirects for discussion from %s %s|%s]][[Category:All redirects for discussion|%s]]', catMonth, catYear, currentTitle.text, currentTitle.text)
else
category = string.format('[[Category:Redirects for discussion|%s]][[Category:All redirects for discussion|%s]]', currentTitle.text, currentTitle.text)
end
if category then category = category..'[[Category:Temporary maintenance holdings/RFD]]' end
local noindex = mw.getCurrentFrame():expandTemplate{title="NOINDEX"}
return string.format('%s%s<span id="delete-reason" style="display: none;">%s</span>%s%s',
noindex,
messageBox.main('mbox', {
type = 'delete',
name = 'RfD',
image = 'none',
text = string.format(mboxText, args.year, args.month, args.day, discussionPage or currentTitle.prefixedText, mw.text.nowiki(currentTitle.prefixedText))
}),
mw.uri.encode(deleteReason),
category,
args.category or string.format('[[Category:Redirects for discussion|%s]]', currentTitle.text)
isError and '[[Category:RfD errors]]' or ''
)
end
 
p[''] = function(frame)
-- called if the redirect up for discussion is being transcluded
p['1'] local args = function(frame).args
if not getTargetFromTextargs.content or mw.text.trim(args.content) == '' then
return '<span class="error">Error: No content was provided. The original text of the page (the #REDIRECT line and any templates) must be placed inside of the content parameter.[[Category:RfD errors]]</span>'
getTargetFromText = require('Module:Redirect').getTargetFromText
end
local targetpframe = getTargetFromText(frame.args.content:getParent()
if pframe:preprocess('<includeonly>1</includeonly>') == '1' then
if target then
-- We're being transcluded, so display the content of our target.
target = mw.title.new(target)
local target = getTargetFromText(args.content)
if target then
target = mw.title.new(target)
end
local redirect = pframe:getTitle()
if target and not target.isRedirect and target ~= redirect then
-- We should actually be calling expandTemplate on the grandparent rather than on the parent, but we can't do that yet
-- Since we don't have grandparent access, though, it means the thing we're calling doesn't either, so it doesn't really matter yet
local parsedTarget = pframe:expandTemplate{title = ':' .. target.prefixedText, args = pframe.args}
local showontransclusion = frame.args.showontransclusion
showontransclusion = require('Module:Yesno')(showontransclusion, showontransclusion)
if showontransclusion and not (showontransclusion == '' or mw.isSubsting()) then
return makeTransclusionTag(args, redirect) .. parsedTarget
end
return parsedTarget
end
end
-- We're not being transcluded, or we can't figure out how to display our target.
if target and not target.isRedirect and target ~= mw.title.getCurrentTitle() then
-- Check if we can find the target.
local pframe = frame:getParent()
local target = getTargetFromText(args.content)
-- We should actually be calling newChild on the grandparent rather than on the parent, but we can't do that yet
messageBox = require('Module:Message box')
-- Since we don't have grandparent access, though, it means the thing we're calling doesn't either, so it doesn't really matter yet
local redirbox
return pframe:newChild{title = target.prefixedText, args = pframe.args}:preprocess(target:getContent())
if target then -- target isn't nil
local firstChar = string.sub(target, 1, 1)
if firstChar ~= ":" then
target = ":" .. target
end
redirbox = messageBox.main('mbox', {
type = 'notice',
name = 'RedirectBox',
image = '[[File:Symbol redirect blue.svg|40px]]',
text = "'''This title is currently a redirect ''' to [[" .. target .. "]]; click there to go to the current target. The full content of this redirect page, including all [[Wikipedia:Categorizing redirects|redirect categories]], is displayed below."
})
else
redirbox = messageBox.main('mbox', {
return p[''](frame)
type = 'notice',
name = 'RedirectBox',
image = '[[File:Symbol redirect vote 4.svg|40px]]',
text = "'''This redirect's target could not be determined.''' This page may be a [[Wikipedia:Soft redirect|soft redirect]], or not a redirect at all. The content of the page is displayed below."
})
end
-- Display the RfD banner.
return makeRfdNotice(frame.args) .. '\n' .. redirbox .. frame.args.content
end
 
local substText = "{{<includeonly>safesubst:</includeonly>#invoke:RfD||%s%s|%s%s\n"
-- called if the redirect up for discussion is being viewed
.. "<!-- The above content is generated by {{subst:Rfd}}. -->\n<!-- End of RFD message. Don't edit anything above here. Feel free to edit below here, but do NOT change the redirect's target. -->|content=\n%s\n"
p[''] = function(frame)
.. "<!-- Don't add anything after this line unless you're drafting a disambiguation page or article to replace the redirect. -->\n}}"
return makeRfdNotice(frame.args) .. '\n' .. frame.args.content
end
 
local substText = "{{ {{{|safesubst:}}}#invoke:RfD|<includeonly>1</includeonly>|%s|%s%s\n"
.. "<!-- The above content is generated by {{subst:rfd}}. -->\n<!-- End of RFD message. Don't edit anything above here, but feel free to edit below here. -->|content=\n%s\n"
.. "<!-- Don't add anything after this line. -->\n}}"
local dateText = 'month = %B\n|day = %e\n|year = %Y\n|time = %R\n|timestamp = %Y%m%d%H%M%S'
 
-- called during subst when the template is initially placed on the page
function p.main(frame)
local titleText
local pframe = frame:getParent()
local pargs = pframe.args
local Date
local retval = string.format(substText, pargs.FULLPAGENAME or pargs[1] or '', os.date(dateText), pframe:getTitle() == mw.title.getCurrentTitle().prefixedText and '|category=' or '', pargs.content or '')
if pargs.days then
Date = os.date(dateText, os.time() - 86400*pargs.days)
else
Date = os.date(dateText)
end
local retval = string.format(substText, pargs.FULLPAGENAME or pargs[1] or '', pargs.showontransclusion and '|showontransclusion=1' or '', Date, pframe:getTitle() == mw.title.getCurrentTitle().prefixedText and '|category=' or '', pargs.content or '')
if mw.isSubsting() then
return retval