User talk:Barrylb/Usercan Hook

isSysop is deprecated
As much as I would love to use the original userCan hook, anything I try to use with isSysop results in the rather pretty chunk of errors to be spewed upon my screen: MediaWiki internal error.

Original exception: exception 'MWException' with message 'Call to deprecated (v1.7) User::isSysop method ' in C:\Apache22\htdocs\sandbox\includes\User.php:1206 Stack trace:
 * 0 C:\Apache22\htdocs\sandbox\LocalSettings.php(152): User->isSysop
 * 1) 1 [internal function]: fnMyUserCan(Object(Title), Object(User), 'edit', NULL)
 * 2 C:\Apache22\htdocs\sandbox\includes\Hooks.php(114): call_user_func_array('fnMyUserCan', Array)
 * 3 C:\Apache22\htdocs\sandbox\includes\Title.php(1023): wfRunHooks('userCan', Array)
 * 4 C:\Apache22\htdocs\sandbox\includes\Title.php(1092): Title->userCan('edit')
 * 5 C:\Apache22\htdocs\sandbox\includes\ParserCache.php(38): Title->userCanEdit
 * 6 C:\Apache22\htdocs\sandbox\includes\ParserCache.php(51): ParserCache->getKey(Object(Article), Object(User))
 * 7 C:\Apache22\htdocs\sandbox\includes\Article.php(671): ParserCache->getETag(Object(Article), Object(User))
 * 8 C:\Apache22\htdocs\sandbox\includes\Wiki.php(327): Article->view
 * 9 C:\Apache22\htdocs\sandbox\includes\Wiki.php(50): MediaWiki->performAction(Object(OutputPage), Object(Article), Object(Title), Object(User), Object(WebRequest))
 * 1) 10 C:\Apache22\htdocs\sandbox\index.php(123): MediaWiki->initialize(Object(Title), Object(OutputPage), Object(User), Object(WebRequest))
 * 2) 11 {main}

So I can't use that.

I'm trying to accomplish several things here.
 * 1) Anonymous users should not be able to edit any page at all
 * 2) *Easily accomplished through $wgGroupPermissions['*']['edit'] = false;
 * 3) Logged in users cannot edit articles, but can edit Talk pages
 * 4) Sysops rights should remain untouched

I managed to accomplish what I set out to do with the following code.

function fnMyUserCan($title, $wgUser, $action, $result) {	if ($action == 'edit') {		if (!$title->isTalkPage && !in_array("sysop", $wgUser->mGroups)) $result = false; } }

$wgHooks['userCan'][] = 'fnMyUserCan'; //disable editing of everything but Talk pages for logged in users

Johann 18:30, 2 November 2006 (UTC)

Thanks for your notes, Barrylb. I found these helpful in developing my own userCan extension at work. Richardkmiller 01:33, 20 March 2008 (UTC)