MediaWiki:ArchiveBoards/code.js

// // Script Name: ArchiveBoards // Author: SuperSajuuk // Last Modified: 16th January 2015, 00:15 // // Disable posting rights in specific boards. // Useful for creating archive boards and // enforcing local policy / community consensus //

(function ($, mw) {	"use strict";       // These are the default values if not customised.        // For obvious reasons, we cannot define a default for        // boards because there is no "default" for them.        window.ArchiveBoards = window.ArchiveBoards || {};        var ArchiveBoards = $.extend({ boards: [], style: "width: 100%;text-align: center;border: 2px solid #f66;background-color: whitesmoke;margin: 0.8em 0px;padding: 0.5em 12px;color: black;", boardNotice: "Sorry, you may not create a new thread in this board. Please go back to the Forum Index to find an appropriate board.", threadNotice: "Sorry, you may not reply to this thread because it has been placed in a closed board.", groupCustom: [] }, window.ArchiveBoards);       // Default usergroups. We cannot allow these ones to be overwritten.        // If overwritten, this will violate Wikia TOU on customisation.        var groupDefaults = ["sysop","staff","vstf","helper"];        // Merge the group arrays to make a larger array.        // This allows checking custom groups and the defaults.        var groups = $.merge(ArchiveBoards.groupCustom, groupDefaults);        // Is the user in an "allowed" group?        function isAllowed(user, groups) {               for (var i = 0; i < groups.length; i++) {                      if (user.indexOf(groups[i]) > -1) {                             return true;                      }	       }	       return false;        }

// Viewing the forum namespace? if(mw.config.get('wgNamespaceNumber') === 2000) { // Replace spaces with underscores. wgTitle, by default, does // not include them. This makes for simplicity when users // configure the script var title = wgTitle.replace(" ","_"); // Check the array for a match. if($.inArray(title, ArchiveBoards.boards)) { $(".ForumNewMessage").remove; $(".board-description").after(" "); }       }        // Viewing the thread namespace? if(mw.config.get('wgNamespaceNumber') === 1201) { // Select the board name. var boardname = $("div.BreadCrumbs a:eq(1)").text.replace(/ board‎$/, ''); // Reconfigure the threads if they're in a matching board. if($.inArray(boardname, ArchiveBoards.boards)) { // Remove the New Reply block. $("li.new-reply").remove; // Add the notice. $("h4.related-topics-heading").before(" "); // Remove the buttons based on the array. Default is to exclude admins/Wikia Staff/VSTF. // Exclusion means local sysops and Wikia Staff can reopen threads that were accidentally // "closed" due to the script. if(isAllowed(wgUserGroups, groups) === false) { $("div.buttonswrapper").remove; }              }        } }(jQuery, mediaWiki));