Last modified: 2009-11-07 09:59:04 UTC
Created attachment 3959 [details]
adds IsBlockedFrom hook to User::isBlockedFrom
I have attempted to write a patch to add a hook to User::isBlockedFrom (needed for an extension I'm thinking of writing). Have I done it right?
* In general, hooks such as this would use the return value to determine whether or not to perform internal checking at all, i.e. a false return would indicate that the $blocked value is to be returned from the method
* This hook seems a little odd, given that we have hooks on Title::userCan() which should be just fine for most access control purposes
* "$this" is an object reference, and doesn't need the ampersand in front to pass by reference any more
1) Is it necessary to take into account the return value when the hook is after the core processing?
2) I was looking at userCan() and trying to use that, but it seems user rights and blocks are completely independent of each other (not an ideal situation - it would probably be best to do away with isBlocked() entirely and just use userCan(), but that's not the way things are set up at the moment). I'm trying to write an extension to (un)block users from individual pages. It's probably possible to do using a userCan() hook, but it's much easier with an isBlockedFrom() hook.
3) Thanks! I saw it was passed by reference in another hook, so thought it was best to follow suit. Good to know it isn't required any more.
What I meant with (1) was that the hook should be called *before* the core processing, and the default checking skipped if the hook returns false and sets a $blocked value.
Ah. For the extension I'm writing, it's easier if it's at the end, so that's where I put it. Having it at the beginning would probably be more useful in other cases, though, you're right. It should only make my extension a couple of lines longer, so I might as well move. I'll submit a new patch in a bit. Thanks for your help.
Created attachment 3963 [details]
adds IsBlockedFrom hook to *beginning* of User::isBlockedFrom
Was fixed in r57459.