Misplaced Pages

Module:RfD: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
Browse history interactively← Previous editNext edit →Content deleted Content added
Revision as of 22:24, 20 June 2014 view sourceJackmcbarn (talk | contribs)31,380 edits let this do the subst part too← Previous edit Revision as of 22:25, 20 June 2014 view source Jackmcbarn (talk | contribs)31,380 edits fix error and use safesubstNext edit →
Line 38: Line 38:
-- called if the redirect up for discussion is being viewed -- called if the redirect up for discussion is being viewed
p = function(frame) p = function(frame)
return makeRfdNotice(frame.args) .. frame.args.content return makeRfdNotice(frame.args) .. frame.args
end end


local substText = '{{#invoke:RfD|<includeonly>1</includeonly>|name = %s|%s\n' local substText = '{{ {{{|safesubst:}}}#invoke:RfD|<includeonly>1</includeonly>|name = %s|%s\n'
.. '<!-- Do not use the "Rfd/core" template directly; the above line is generated by {{subst:Rfd}}. -->\n<!-- End of RFD message. Feel free to edit beyond this point. -->|\n%s\n}}' .. '<!-- Do not use the "Rfd/core" template directly; the above line is generated by {{subst:Rfd}}. -->\n<!-- End of RFD message. Feel free to edit beyond this point. -->|\n%s\n}}'



Revision as of 22:25, 20 June 2014

Module documentation[view] [edit] [history] [purge]
ProtectedThis module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
If you plan to make breaking changes to this module, move it, change scope, or nominate it for deletion or deprecation, please notify the Article Alerts project at Misplaced Pages talk:Article alerts as a courtesy, as this page is used by the AAlertBot bot to detect and report pages. Thank you!
Logo of Twinkle; Police ManAny breaking changes to this template, including moving it or nominating it for deletion, must be communicated in advance to Twinkle's users and maintainers at Misplaced Pages talk:Twinkle. The standard installation of Twinkle relies on this template. Thank you.

Background

Implements {{Redirect for discussion}}.

Usage

{{#invoke:RfD|function_name}}

The above documentation is transcluded from Module:RfD/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.

local p = {}

local getTargetFromText
local messageBox

local rfdText = "'''The purpose of this redirect is currently being discussed by the Misplaced Pages community."
	.. " The outcome of the discussion may result in a change of this page, or possibly its deletion in accordance with Misplaced Pages's ].''' <br />"
	.. " Please share your thoughts on the matter at ''']''' on the ] 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;]:]&#124;%s&#125;&#125; &#126;&#126;&#126;&#126;</code> on their talk page.</small>"
	
local function makeRfdNotice(args)
	local currentTitle = mw.title.getCurrentTitle()
	if not messageBox then
		messageBox = require('Module:Message box')
	end
	local discussionPage = args.name and mw.text.trim(args.name)
	if discussionPage == '' then
		discussionPage = nil
	end
	return string.format('%s<span id="delete-reason" style="display:none;">%%5B%%5BWikipedia%%3ARedirects+for+discussion%%5D%%5D+debate+closed+as+delete</span>%s',
		messageBox.main('mbox', {
			type = 'delete',
			image = 'none',
			text = string.format(rfdText, args.year, args.month, args.day, discussionPage or currentTitle.prefixedText, currentTitle.prefixedText)
		}),
		args.category or string.format(']', currentTitle.text)
	)
end

-- called if the redirect up for discussion is being transcluded
p = function(frame)
	if not getTargetFromText then
		getTargetFromText = require('Module:Redirect').getTargetFromText
	end
	return frame:getParent():preprocess(mw.title.new(getTargetFromText(frame.args)):getContent())
end

-- called if the redirect up for discussion is being viewed
p = function(frame)
	return makeRfdNotice(frame.args) .. frame.args
end

local substText = '{{ {{{|safesubst:}}}#invoke:RfD|<includeonly>1</includeonly>|name = %s|%s\n'
	.. '<!-- Do not use the "Rfd/core" template directly; the above line is generated by {{subst:Rfd}}. -->\n<!-- End of RFD message. Feel free to edit beyond this point. -->|\n%s\n}}'

-- called during subst when the template is initially placed on the page
function p.main(frame)
	local titleText
	if frame.args.name then
		titleText = mw.title.new(frame.args.name).prefixedText
	else
		titleText = mw.title.getCurrentTitle().prefixedText
	end
	local date = os.date('*t')
	local retval = string.format(substText, titleText, os.date('month = %B\n|day = %e\n|year = %Y\n|time = %R\n|timestamp = %Y%m%d%H%M%S'), frame.args)
	if mw.isSubsting() then
		return retval
	end
	return frame:expandTemplate{title = 'Template:Error:must be substituted', args = {'Rfd'}} .. frame:preprocess(retval)
end

return p
Categories: