User talk:Barrylb/Usercan Hook
Add topicisSysop() is deprecated
[edit]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 [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)) #10 C:\Apache22\htdocs\sandbox\index.php(123): MediaWiki->initialize(Object(Title), Object(OutputPage), Object(User), Object(WebRequest)) #11 {main}
So I can't use that.
I'm trying to accomplish several things here.
- Anonymous users should not be able to edit any page at all
- Easily accomplished through $wgGroupPermissions['*']['edit'] = false;
- Logged in users cannot edit articles, but can edit Talk pages
- 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)
Internal error
[edit]I get the following error when I try to use this. It looks like it got crufty and doesn't work anymore. =( Sy Ali 19:25, 12 May 2008 (UTC)
---
Internal error
Detected bug in an extension! Hook fnMyUserCan failed to return a value; should return true to continue hook processing or false to abort.
Backtrace:
#0 /var/www/vhosts/jrandomhacker.info/httpdocs/includes/Title.php(1264): wfRunHooks() #1 /var/www/vhosts/jrandomhacker.info/httpdocs/includes/Wiki.php(133): Title->userCanRead('userCan', Array) #2 /var/www/vhosts/jrandomhacker.info/httpdocs/includes/Wiki.php(43): MediaWiki->preliminaryChecks() #3 /var/www/vhosts/jrandomhacker.info/httpdocs/index.php(89): MediaWiki->initialize(Object(Title), Object(StubObject), Object(WebRequest)) #4 {main}
Code no longer works
[edit]Hi guys. Apologies, I am not knowledgeable about PHP. I have tried adapting the code found on this talk page and in the original article without much luck. I get php errors from my mediawiki 1.12.0 install. Please can someone kindly provide me with code here so that:
Anonymous users cannot edit any page except for the article talk pages.
Thanks in advance: James Hatton
Thanks
[edit]Thank you so much for this! It's a blessing on Zelda Wiki since we used to have so many vandals. I'm thinking about using it on my private wiki, but we'll see how it turns out.Neo of ZW 15:48, 6 February 2010 (UTC)