Jump to content

手册:封禁抽象层

From mediawiki.org
This page is a translated version of the page Manual:Block abstraction layer and the translation is 100% complete.

封禁”是一种限制,它会与尝试执行操作的用户相匹配,并且可能会阻止这些操作。 MediaWiki 核心定义了一些类型的封禁(有关这些封禁的更多信息,请参见 Manual:封禁与解除封禁 ),但允许扩展定义自己的封禁。

类层次结构

MediaWiki中的封禁由AbstractBlock类表示。 (存在一个Block接口,但实际上这两者之间并没有区分。) 在MediaWiki核心中,有三种类型的封禁:

与封禁交互

There are three ways to interact with blocks in the code:

  • Via PermissionManager or equivalent mechanisms (such as the permission-related methods of User or Authority): block checks are integrated into permission checks so calling e.g. PermissionManager::getPermissionErrors() or Authority::authorizeWrite() will return the appropriate error message if the user is blocked, so usually no explicit interaction is needed. The Authority methods provide a PermissionStatus, which also exposes the block object.
    Note that probablyCan and equivalent checks intentionally ignore blocks: the presence of UX elements for most actions should not depend on whether the user is blocked from performing that action at the moment.
  • Via BlockManager and especially its getUserBlock() method.
  • Via block-related User (and Authority) methods such as User::getBlock(). These get cached within the User object.

与全域封禁交互

For historical reasons, global blocks aren't fully integrated with the block system. Using the permissions system will work, the other two approaches won't. Global blocks can be retrieved with User::getGlobalBlock() instead. Note that the only existing implementation of global blocks (Extension:全域封禁 ) is quite buggy, most of the methods on the block object won't work properly (T315644).

管理封禁

Managing blocks (such as blocking and unblocking users, or listing active blocks) is not part of the abstraction layer; each extension has its own mechanisms and interfaces for that.

扩展封禁系统

Extensions providing a new type of block need to use the GetUserBlock hook to return a block whenever the conditions for the user being blocked. (There is also a UserIsBlockedGlobally hook for global blocks, but there is not much point in using it; the handling of global blocks is somewhat erratic, and there is no real meaning to being "global" – nothing prevents a GetUserBlock extension from using cross-wiki logic.)

Block management (such as blocking, unblocking, listing active blocks, showing a block log) needs to be implemented from scratch. The OtherBlockLogLink and OtherAutoblockLogLink hooks can be used to expose custom logging-related special pages from the standard ones.