Tchanders added a comment.

  In T207893#5251961 <https://phabricator.wikimedia.org/T207893#5251961>, 
@dbarratt wrote:
  
  > In T207893#5250838 <https://phabricator.wikimedia.org/T207893#5250838>, 
@Addshore wrote:
  >
  > > So I guess we use BlockManager to get the blocks of a user?
  >
  >
  > You can use either `User::getBlock()` or `BlockManager::getUserBlock()`. 
They are //slightly// different, but for your purposes, it should always return 
the same result.
  
  
  You should use User::getBlock, since that will call 
BlockManager::getUserBlock and run the hooks too.
  
  (BlockManager::getUserBlock should be treated as internal and only be called 
by User::getBlockedStatus (as documented). Eventually, the blocks logic should 
be taken out of User, as part of the wider effort to untangle such 
dependencies, at which point the way to get a block will be via the 
BlockManager, but we're not there yet.)
  
  >> And then check the blocks to see if they apply to the namespace we are 
creating in?
  > 
  > Yes. :)
  
  Yes, so somethig like:
  
    $block = $user->getBlock();
    if ( $block && $block->appliesToNamespace( $ns ) ) { ... }
  
  
  
  >> Blockmanager::getUserBlock only returns one block ("the most relevant 
one"), what happens in the situation when a user has 2 block for different 
namespaces?
  > 
  > You will get a `CompositeBlock` object which will extend from 
`AbstractBlock` class and have all of the same methods. MediaWiki has, up until 
this week, always returned a single, most-relevant block anyways. Starting 
soon, you'll get a `CompositeBlock` which can be used the same way.
  
  A few things to add here:
  
  - Two blocks can't be stored against exactly the same target, but a user can 
be affected by more than one block if there are blocks against their account 
and IP address, or against some ranges that cover their IP address
  - "the most relevant one" is a not-terribly-helpful way of saying the most 
"specific" one, meaning that a user account block is chosen over an IP block, 
which is chosen over an IP range block (and narrower IP range blocks are 
favoured over wider ones). Thanks for pointing this out, will improve the docs.
  - AHT should be merging this soon: 
https://gerrit.wikimedia.org/r/#/c/mediawiki/core/+/497668/ After this, if 
BlockManager::getUserBlock finds more than one block, then instead of choosing 
just one, it will return a composite block combining the strictest features of 
all the blocks. So if there are blocks that apply to different namespaces, this 
composite block will apply to all of them.
  
  >> Is there a way to get all blocks of a user? Or a way to see if any of a 
users blocks apply to a namespace?
  > 
  > We could probably build that into `CompositeBlock` if you really need them, 
but calling `::appliesToNamespace()` on the `AbstractBlock` returned from 
`User::getBlock()` or `BlockManager::getUserBlock()` should be what you want.
  > 
  >> Maybe we need a User::isBlockedFromNamespace, or rather 
PermissionManager::isBlockedFromNamespace() ?
  > 
  > I think the best way would be to determine if the `AbstractBlock` applies 
to the namespace with `AbstractBlock::appliesToNamespace()`.
  
  After the above patch is merged, doing `$user->getBlock()` and 
`$block->appliesToNamespace( $ns )` as shown above will do all of this.

TASK DETAIL
  https://phabricator.wikimedia.org/T207893

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: Tchanders
Cc: Tchanders, Niharika, Lydia_Pintscher, WMDE-leszek, TBolliger, 
Lucas_Werkmeister_WMDE, Addshore, Aklapper, dbarratt, MGChecker, darthmon_wmde, 
Nandana, Lahi, Gq86, GoranSMilovanovic, QZanden, LawExplorer, _jensen, 
rosalieper, Jonas, Wikidata-bugs, aude, Mbch331
_______________________________________________
Wikidata-bugs mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikidata-bugs

Reply via email to