User:Barrylb/Usercan Hook

You can restrict access to certain MediaWiki features without modifying the core files using the userCan hook available since version 1.6.0. Tested and working on version 1.6.7 and 1.7.1.

Note the 'userCan' hook for 'edit' actions acts in addition to any other security checks so if you have this  in your LocalSettings.php then it will act in addition, and disable anonymous editing entirely.

Put one the following in your LocalSettings.php file depending on your needs:

Limit non-logged-in users to editing talk pages only
function fnMyUserCan($title, $user, $action, $result) {	if ($action == 'edit') {		if (!$title->isTalkPage && !$user->isLoggedIn) $result = false; } }

$wgHooks['userCan'][] = 'fnMyUserCan';

Any user can edit talk pages. Only Sysop can edit other pages
function fnMyUserCan($title, $user, $action, $result) {	if ($action == 'edit') {		if (!$title->isTalkPage && !$user->isSysop) $result = false; } }

$wgHooks['userCan'][] = 'fnMyUserCan';

Non-logged-in users can view source but not edit
function fnMyUserCan($title, $user, $action, $result) { if (($action == 'edit') && !$user->isLoggedIn) $result = false; } $wgHooks['userCan'][] = 'fnMyUserCan';

Last change 22:23, 16 July 2006 (UTC)