MediaWiki master
MediaWiki\Revision\SlotRoleRegistry Class Reference

A registry service for SlotRoleHandlers, used to define which slot roles are available on which page. More...

Public Member Functions

 __construct (NameTableStore $roleNamesStore)
 
 defineRole (string $role, callable $instantiator)
 Defines a slot role.
 
 defineRoleWithModel (string $role, string $model, array $layout=[], bool $derived=false)
 Defines a slot role that allows only the given content model, and has no special behavior.
 
 getAllowedRoles (PageIdentity $page)
 Returns the list of roles allowed when creating a new revision on the given page.
 
 getDefinedRoles ()
 Returns the list of roles defined by calling defineRole().
 
 getKnownRoles ()
 Returns the list of known roles, including the ones returned by getDefinedRoles(), and roles that exist according to the NameTableStore provided to the constructor.
 
 getRequiredRoles (PageIdentity $page)
 Returns the list of roles required when creating a new revision on the given page.
 
 getRoleHandler (string $role)
 Gets the SlotRoleHandler that should be used when processing content of the given role.
 
 isDefinedRole (string $role)
 Whether the given role is defined, that is, it was defined by calling defineRole().
 
 isKnownRole (string $role)
 Whether the given role is known, that is, it's either defined or exist according to the NameTableStore provided to the constructor.
 

Detailed Description

A registry service for SlotRoleHandlers, used to define which slot roles are available on which page.

Extensions may use the SlotRoleRegistry to register the slots they define.

In the context of the SlotRoleRegistry, it is useful to distinguish between "defined" and "known" slot roles: A slot role is "defined" if defineRole() or defineRoleWithModel() was called for that role. A slot role is "known" if the NameTableStore provided to the constructor as the $roleNamesStore parameter has an ID associated with that role, which essentially means that the role at some point has been used on the wiki. Roles that are not "defined" but are "known" typically belong to extensions that used to be installed on the wiki, but no longer are. Such slots should be considered ok for display and administrative operations, but only "defined" slots should be supported for editing.

Since
1.33

Definition at line 48 of file SlotRoleRegistry.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Revision\SlotRoleRegistry::__construct ( NameTableStore $roleNamesStore)

Definition at line 56 of file SlotRoleRegistry.php.

Member Function Documentation

◆ defineRole()

MediaWiki\Revision\SlotRoleRegistry::defineRole ( string $role,
callable $instantiator )

Defines a slot role.

For use by extensions that wish to define roles beyond the main slot role.

See also
defineRoleWithModel()
Parameters
string$roleThe role name of the slot to define. This should follow the same convention as message keys:
callable$instantiatorcalled with $role as a parameter; Signature: function ( string $role ): SlotRoleHandler

Definition at line 72 of file SlotRoleRegistry.php.

◆ defineRoleWithModel()

MediaWiki\Revision\SlotRoleRegistry::defineRoleWithModel ( string $role,
string $model,
array $layout = [],
bool $derived = false )

Defines a slot role that allows only the given content model, and has no special behavior.

For use by extensions that wish to define roles beyond the main slot role, but have no need to implement any special behavior for that slot.

See also
defineRole()
Parameters
string$roleThe role name of the slot to define, see defineRole() for more information.
string$modelA content model name, see ContentHandler
array$layoutSee SlotRoleHandler getOutputLayoutHints
bool$derivedsee SlotRoleHandler constructor
Since
1.36 optional $derived parameter added

Definition at line 98 of file SlotRoleRegistry.php.

◆ getAllowedRoles()

MediaWiki\Revision\SlotRoleRegistry::getAllowedRoles ( PageIdentity $page)

Returns the list of roles allowed when creating a new revision on the given page.

The choice should not depend on external state, such as the page content. Note that existing revisions of that page are not guaranteed to comply with this list.

All implementations of this method are required to return at least all "required" roles.

Parameters
PageIdentity$page
Returns
string[]

Definition at line 162 of file SlotRoleRegistry.php.

◆ getDefinedRoles()

MediaWiki\Revision\SlotRoleRegistry::getDefinedRoles ( )

Returns the list of roles defined by calling defineRole().

This list should be used when enumerating slot roles that can be used for editing.

Returns
string[]

Definition at line 192 of file SlotRoleRegistry.php.

◆ getKnownRoles()

MediaWiki\Revision\SlotRoleRegistry::getKnownRoles ( )

Returns the list of known roles, including the ones returned by getDefinedRoles(), and roles that exist according to the NameTableStore provided to the constructor.

This list should be used when enumerating slot roles that can be used in queries or for display.

Returns
string[]

Definition at line 205 of file SlotRoleRegistry.php.

◆ getRequiredRoles()

MediaWiki\Revision\SlotRoleRegistry::getRequiredRoles ( PageIdentity $page)

Returns the list of roles required when creating a new revision on the given page.

The should not depend on external state, such as the page content. Note that existing revisions of that page are not guaranteed to comply with this list.

All required roles are implicitly considered "allowed", so any roles returned by this method will also be returned by getAllowedRoles().

Parameters
PageIdentity$page
Returns
string[]

Definition at line 180 of file SlotRoleRegistry.php.

◆ getRoleHandler()

MediaWiki\Revision\SlotRoleRegistry::getRoleHandler ( string $role)

Gets the SlotRoleHandler that should be used when processing content of the given role.

Parameters
string$role
Exceptions
InvalidArgumentExceptionIf $role is not a known slot role.
Returns
SlotRoleHandler The handler to be used for $role. This may be a FallbackSlotRoleHandler if the slot is "known" but not "defined".

Definition at line 121 of file SlotRoleRegistry.php.

References wfWarn().

◆ isDefinedRole()

MediaWiki\Revision\SlotRoleRegistry::isDefinedRole ( string $role)

Whether the given role is defined, that is, it was defined by calling defineRole().

Definition at line 215 of file SlotRoleRegistry.php.

◆ isKnownRole()

MediaWiki\Revision\SlotRoleRegistry::isKnownRole ( string $role)

Whether the given role is known, that is, it's either defined or exist according to the NameTableStore provided to the constructor.

Definition at line 224 of file SlotRoleRegistry.php.


The documentation for this class was generated from the following file: