Page MenuHomePhabricator

add hook to User::isBlockedFrom
Closed, ResolvedPublic

Description

Author: thomas.dalton

Description:
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?


Version: unspecified
Severity: enhancement

attachment isBlockedFromhook.patch ignored as obsolete

Details

Reference
bz10764

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:49 PM
bzimport set Reference to bz10764.
bzimport added a subscriber: Unknown Object (MLST).

robchur wrote:

  • 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

thomas.dalton wrote:

  1. Is it necessary to take into account the return value when the hook is after the core processing?
  1. 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.
  1. 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.

robchur wrote:

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.

thomas.dalton wrote:

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.

thomas.dalton wrote:

adds IsBlockedFrom hook to *beginning* of User::isBlockedFrom

Attached: