Somehow, I’ve come to be responsible for administering two MediaWiki-powered wikis. The main burden is having to ban spammers, which sometimes sign up in batches of 20 at a time.
To help with process, I’ve put together the following browser userscript. On Firefox, you can easily set it up using the Greasemonkey extension. Opera and Chrome have their own facilities.
The script basically makes the default values on the user ban form sane, so I can just click through without fiddling with dropdown and checkboxes. Obviously, the ban has to be permanent. Obviously, I don’t want spammers emailing anyone.
// ==UserScript== // @name Blocker // @namespace https://userscripts.org/users/457667 // @include http://example.com/index.php/Special:Block/* // ==/UserScript== // Set default expiry to 'infinite' or 'indefinite', depending on MediaWiki version function makeExpiryInfinite () { "use strict"; // Get the element var elExpiry = document.getElementById('wpBlockExpiry'); if (!elExpiry) { elExpiry = document.getElementById('mw-input-wpExpiry'); } // Abort if element not found if (!elExpiry || !elExpiry.children) { return; } // Find the infinite option var expiryNodes = elExpiry.children; var index = 0; for (var i in expiryNodes) { if (expiryNodes[i].label && expiryNodes[i].label in {infinite:1, indefinite:1}) { index = i; } } // Set dropdown to the infinite option elExpiry.selectedIndex = index; } // Automatically prevent user from sending e-mail function preventEmail() { "use strict"; // Find check box var elEmailBan = document.getElementById('wpEmailBan'); if (!elEmailBan) { elEmailBan = document.getElementById('mw-input-wpDisableEmail'); } // Abort if it's not there if (!elEmailBan) { return; } // Check the box elEmailBan.checked = true; } // Automatically prevent user from sending e-mail function reallyBanThatIP() { "use strict"; // Find check box var elHardBlock = document.getElementById('mw-input-wpHardBlock'); if (!elHardBlock) { elHardBlock = document.getElementById('mw-input-wpHardBlock'); } // Abort if it's not there if (!elHardBlock) { return; } // Check the box elHardBlock.checked = true; } makeExpiryInfinite(); preventEmail(); reallyBanThatIP();
I’ve been hearing wonderful things about userscripts for years, but this is the first one I’ve put together for myself. It’s actually very easy to write these, assuming you know Javascript and have tools like Firefox’s Web Console and the Web Developer extension handy.
I’m planning to enhance it a little so that it handles the slightly different form for banning anonymous users, but I’m not sure if it makes sense to submit to any official repository. It helps with running small wikis that have open memberships, so there isn’t any one site I can identify it with. Obviously, it’s not suited for Wikipedia, as they have a very different set of problems.
Edit: Updated the script with better handling for banning anonymous users by IP address.
I had issues using this off the bat as & was transformed into & so if anyone else has issues just change:
to
and everything should work great! Thanks for this script!
LikeLike