Extension:NoViewOnBlock

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.svg
NoViewOnBlock

Release status:Extension status experimental

ImplementationTemplate:Extension#type User rights
DescriptionTemplate:Extension#description Blocked users can't view the wiki
Author(s)Template:Extension#username Jacob Myers (spaztalk)
Latest versionTemplate:Extension#version 0.1
MediaWikiTemplate:Extension#mediawiki Tested on 1.10.
LicenseTemplate:Extension#license CC0 waiver (public domain)
Download this page
Hooks usedTemplate:Extension#hook
userCanManual:Hooks/userCan

Translate the NoViewOnBlock extension if it is available at translatewiki.net

Check usage and version matrix.

Description[edit]

This extension prevents blocked users from viewing the wiki

Installation[edit]

Copy this into extensions/NoBlockedUserView.php:

extensions/NoBlockedUserView.php[edit]

<?php
$wgHooks['userCan'][] = 'CheckUserBlocked';

function CheckUserBlocked( $title, $user, $action, &$result ) {
    global $wgUser;

    if( $wgUser->isBlocked() && $action == 'read' ) {
        $result = false;
        return false;
    } else {
        $result = null;
        return true;
    }
}

Now add this to your LocalSettings.php file:

LocalSettings.php[edit]

require_once("$IP/extensions/NoBlockedUserView.php");

Status[edit]

Note: I no longer mainain this due to time concerns and having moved on to greener pastures. Anyone else is welcome to adopt it. :)

This module works very well, however there are some limitations and a minor bug:

  • Blocked users will be turned away with "The action you have requested is limited to users in one of the groups *, user." This may not be the message you want to send. Patches welcome to fix it. In the meantime, you can simply edit MediaWiki:Badaccess-groups, and change the contents to something even more generic (I.E., You can't perform that action).
  • All blocked users will be turned away, keep this in mind.