Fandom

Wikia Developers Wiki

LockForums

847pages on
this wiki
Add New Page
Talk35 Share
LockForums disables the replying field on threads that haven't been commented on in the past 30 days, effectively allowing them to be automatically archived over time. There are many configuration options, including the ability to set a warning period prior to locking, displaying a banner at the top of the page, and more. See Configuration for more details.

Note: This script is for the forum boards i.e. forums in the Thread: namespace.

Installation

Add this JavaScript on your wiki:

Site-wide
MediaWiki:Common.js
importArticles({
    type: "script",
    articles: [
        "u:dev:LockForums/code.js"
    ]
});
importArticles — Best Practices for installing JavaScript on Fandom
The importArticles statement is designed to combine multiple HTTP requests into a single data transfer, allowing multiple scripts to load and execute faster. If you've been installing several different scripts, your JavaScript file has probably accumulated unnecessary import statements. Click "Expand" to learn how to efficiently batch import scripts to speed up performance and make your code look cleaner. One other approach is by using the MediaWiki:ImportJS.
If your JavaScript file has several lines of code that say importScript, importScriptPage, or importArticles, you may be able to combine them! By batch importing a collection of scripts with a single import, your JavaScript code will load faster and look cleaner. Consider the example below. On the left is an example of what your JavaScript file might currently look like. On the right is how you could improve that code.
Multiple imports — messy and slow One import — clean and efficient
importScriptPage('AjaxRC/code.js','dev');
 
importScript('MediaWiki:localScript.js');
 
importArticle({
  type: 'script',
  article: 'u:dev:FloatingToc/code.js'
});
 
importScriptPage('page1.js', 'wikiname');
 
importScriptPage('page2.js', 'wikiname');
importArticles({
    type: 'script',
    articles: [
        'u:dev:AjaxRC/code.js',
        'MediaWiki:localScript.js',
        'u:dev:FloatingToc/code.js',
        'u:wikiname:page1.js',
        'u:wikiname:page2.js'
    ]
});
Note: In this example, pay close attention to the placement of commas and other punctuation. For people who aren't familiar with programming (and even those who are!), a common mistake when writing code is to accidentally delete, forget, or misplace critical symbols like commas or quotation marks. This can cause a syntax error that breaks the code. Carefully follow the convention shown here when using importArticles.
But there's much more to importArticles than just this! For more examples and advanced usage, see the help page at Help:Including additional JavaScript and CSS.


Configuration

There are some custom configuration options that you can use if you want to:

Variable name Variable type Description Default value
expiryDays Number The number of days after which a forum post should be archived. 30
expiryMessage String The message that should be displayed to the user if commenting has been locked on the forum post. "This forum hasn\'t been commented on for over <expiryDays> days. There is no need to comment."
warningDays Number The number of days after which a forum post should display a warning that the thread is old and should only be replied to if necessary. Messages older than both <warningDays> and <expiryDays> will be locked and display the <expiryMessage>. 0 (disabled)
warningMessage String The message that should be displayed to the user if commenting is about to be locked on the forum post. "This forum hasn\'t been commented on for over <warningDays> days. Please reply ONLY if a response is really needed."
disableOn String Array Array of thread numbers to disable this script completely. []
ignoreDeletes Boolean Causes the code to ignore deleted messages when calculating the age of the post. The default behavior uses the time of the most recent post, whether or not it has been deleted. false
banners Boolean If enabled, causes a banner to appear at the top of the page for both warnings and expired messages. false
expiryBannerMessage String The message that will be displayed at the top of the page for expired messages (if banners are enabled). "Note: This topic has been unedited for <actualDays> days. It is considered archived - the discussion is over. If you feel this forum needs additional information, contact an administrator."
warningBannerMessage String The message that will be displayed at the top of the page for soon-to-be-expiring messages (if banners are enabled). "Note: This topic has been unedited for <actualDays> days. It is considered archived - the discussion is over. Do not add to unless it really needs a response."
expiryBannerStyle String or Object The configurable CSS style(s) of the expiry banner. Define this parameter as "stylesheet" in order to use your local CSS stylesheet (div#forum-warning-banner.warning-banner-expired). Otherwise you can use a key-value pair object to override the default style ({'tag1': 'value1', 'tag2': 'value2'}). {'border': '2px solid #f66', 'background-color': 'whitesmoke', 'margin': '0.8em 0px', 'padding': '0.5em 12px', 'color': 'black'}
warningBannerStyle String or Object The configurable CSS style(s) of the warning banner. Define this parameter as "stylesheet" in order to use your local CSS stylesheet (div#forum-warning-banner.warning-banner-expired-warning). Otherwise you can use a key-value pair object to override the default style ({'tag1': 'value1', 'tag2': 'value2'}). {'border': '2px solid #f66', 'background-color': 'whitesmoke', 'margin': '0.8em 0px', 'padding': '0.5em 12px', 'color': 'black'}
warningPopup Boolean If enabled, will cause a popup confirmation dialog to appear when someone attempts to post on a forum that has a warning message displayed. Canceling this confirmation dialog will cancel the post. false
warningPopupMessage String The text of the warning popup dialog message. "This forum has not had a response for over <actualDays> days; are you sure you want to reply?"
boxHeight Number The height (in pixels) of the comment box. 50
forumName String The name of your Forum board as seen in your wiki's MediaWiki:Forum-forum-title. "Forum"

The syntax for using these configuration options goes like this:

window.LockForums = {
    expiryDays: number,
    expiryMessage: string,
    warningDays: number,
    warningMessage: string,
    disableOn: array,
    ignoreDeletes: boolean,
    banners: boolean,
    expiryBannerMessage: string,
    expiryBannerStyle: object (or "stylesheet"),
    warningBannerMessage: string,
    warningBannerStyle: object (or "stylesheet"),
    warningPopup: boolean,
    warningPopupMessage: string,
    boxHeight: number,
    forumName: string
};

Note that you only need to define the fields you wish to change from the defaults, and they may be defined in any order. However, this definition must precede the importArticles() call!

Example 1

Let's say you want to do the following:

  • Old forums should be locked from commenting after 60 days
  • The message should say This forum is considered archived because it hasn't been commented on in over 60 days, please don't bump this forum!
  • Your wiki's MediaWiki:Forum-forum-title has been customized to Forum Board

Here's the code you would put in your MediaWiki:Common.js with those configuration options:

window.LockForums = {
    expiryDays: 60,
    expiryMessage: "This forum is considered archived because it hasn\'t been commented on in over <expiryDays> days, please don\'t bump this forum!",
    forumName: "Forum Board" 
};
 
importArticles({
    type: "script",
    articles: [
        "w:c:dev:LockForums/code.js"
    ]
});

Example 2

Let's say you want to do the following:

  • Old forums should be locked from commenting after 180 days
  • However, after 30 days, you want to warn people that they shouldn't be commenting unless absolutely necessary.
  • The expiry message should say This forum has been automatically archived because its most recent comment is over 180 days old.
  • The warning message should say This forum is now [current days] old; out of courtesy to your fellow Wikians, please do not comment unless it is absolutely necessary. This forum will archive automatically when the last comment is 180 days old.
  • A banner at the top of the page should clearly mark the expired and warned threads. The default text is fine.
  • You would like to ignore deleted messages when calculating the age of the most recent thread.
  • You would like a confirmation dialog to pop up for people posting on forums older than 30 days.
  • This popup message should read By posting on an old forum you may be filling up the e-mail boxes of many people who are still following this post. Are you sure you want to do this?
  • Disable on Thread:12345 and Thread:67890

Here's the code you would put in your MediaWiki:Common.js with those configuration options:

window.LockForums = {
    expiryDays: 180,
    expiryMessage: "This forum has been automatically archived because its most recent comment is over <expiryDays> days old.",
    warningDays: 30,
    warningMessage: "This forum is now <actualDays> days old; out of courtesy to your fellow Wikians, please do not comment unless it is absolutely necessary. This forum will archive automatically when the last comment is <expiryDays> days old.",
    banners: true,
    ignoreDeletes: true,
    warningPopup: true,
    warningPopupMessage: "By posting on an old forum you may be filling up the e-mail boxes of many people who are still following this topic. Are you sure you want to do this?",
    disableOn: ["12345", "67890"]
};
 
importArticles({
    type: "script",
    articles: [
        "w:c:dev:LockForums/code.js"
    ]
});

If the banner is used it will look like this (as a default):

Note: This topic has been unedited for 143 days. It is considered archived - the discussion is over. If you feel this forum needs additional information, contact an administrator.

Notes

  • Inside of the expiryMessage, warningMessage, expiryBannerMessage, warningBannerMessage and warningPopupMessage strings, The apostrophe character ' must be replaced with \' and the quote character " must be replaced with \". This is called an "escape character" in JavaScript.
  • Inside of these strings, you can (if you want to) use the <expiryDays> tag which will automatically be replaced with the expiryDays variable, which is 60 in this example. You may also use <warningDays> for the warningDays variable, and actualDays for the actual time elapsed since the most recent post.
  • Important reminder: Note that the importArticles() call comes after the configuration options!

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.