Global Lua Modules/BlockMessages

BlockMessages is a module that generates block messages for corresponding reasons listed in a wiki's local MediaWiki:Ipbreason-dropdown.
This module is intended to be used in conjunction with a site-wide installation of MessageBlock; although the module can be used independently.
== Installation ==
== Configuration ==
=== Step 1: Configuring MessageBlock for messages ===
After installation of this module and installation of MessageBlock, in MediaWiki:Common.js before the import statements paste the following configuration object for MessageBlock:
var MessageBlock = {
 title : 'Blocked',
 message : '{'+'{subst:#invoke:BlockMessages|main|reason=$1|expiry=$2}'+'}',
 autocheck : true // set to false, if automatic block messages are not desired
};
=== Step 2: Prepping block reasons ===
Before creating block messages, any, and all, colons (:) present in MediaWiki:Ipbreason-dropdown must be replaced with &#58; (even within wikilinks).
This may be done automatically by replacing all content in MediaWiki:Ipbreason-dropdown with the following:
{{subst:#invoke:BlockMessages|prep}}
=== Step 3: Creating block messages ===
Next, block messages corresponding to the various offenses listed in MediaWiki:Ipbreason-dropdown need to be made in MediaWiki:Custom-Ipbreason-messages.
# Copy verbatim an offense listed in MediaWiki:Ipbreason-dropdown, and paste it into a new line in MediaWiki:Custom-Ipbreason-messages.
# Prepend a semicolon (;) to the beginning of this line.
# On new lines after this, create a block message for this offense while beginning every single line (including blank lines) in the message with a colon (:). Use $1 to replace for the block reason, and $2 for the block expiry/duration.
# Repeat this process (1-3 above) for every offense you want a custom block message for.
# Create a default message for "generic" blocks. Begin a line with ;__DEFAULT__ and perform substep #3 above.
# Publish the page, and you're done!
Update the page in the future when any changes to MediaWiki:Ipbreason-dropdown is made.
=== Example configuration ===
:For a full MediaWiki:Custom-Ipbreason-messages example, see /Example messages.
The following is an example configuration message:
;Inserting false information
:Hello,
:
:You have been blocked from the for inserting blatantly false or controversial information in our articles. You have been blocked for $2.
:
:(Blocking administrator's comment:  $1)
==== Source ====
;Inserting false information
:Hello,
:
:You have been blocked from the {{SITENAME}} for inserting blatantly false or controversial information in our articles. You have been blocked for $2.
:
:(Blocking administrator's comment:  $1)