MediaWiki master
MediaWiki\Revision\SlotRoleHandler Class Reference

SlotRoleHandler instances are used to declare the existence and behavior of slot roles. More...

Inherited by MediaWiki\Revision\FallbackSlotRoleHandler, and MediaWiki\Revision\MainSlotRoleHandler.

Public Member Functions

 __construct ( $role, $contentModel, $layout=[], bool $derived=false)
 
 getDefaultModel ( $page)
 Determines the content model to use by default for this slot on the given page.
 
 getNameMessageKey ()
 The message key for the translation of the slot name.
 
 getOutputLayoutHints ()
 Layout hints for use while laying out the combined output of all slots, typically by RevisionRenderer.
 
 getRole ()
 
 isAllowedModel ( $model, PageIdentity $page)
 Determines whether the given model can be used on this slot on the given page.
 
 isDerived ()
 
 supportsArticleCount ()
 Whether this slot should be considered when determining whether a page should be counted as an "article" in the site statistics.
 

Detailed Description

SlotRoleHandler instances are used to declare the existence and behavior of slot roles.

Most importantly, they control which content model can be used for the slot, and how it is represented in the rendered version of page content.

Stability: stable
to extend
Since
1.33

Definition at line 37 of file SlotRoleHandler.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Revision\SlotRoleHandler::__construct ( $role,
$contentModel,
$layout = [],
bool $derived = false )
Stability: stable
to call
Parameters
string$roleThe name of the slot role defined by this SlotRoleHandler. See SlotRoleRegistry::defineRole for more information.
string$contentModelThe default content model for this slot. As per the default implementation of isAllowedModel(), also the only content model allowed for the slot. Subclasses may however handle default and allowed models differently.
string[]$layoutLayout hints, for use by RevisionRenderer. See getOutputLayoutHints.
bool$derivedIs this handler for a derived slot? Derived slots allow information that is derived from the content of a page to be stored even if it is generated asynchronously or updated later. Their size is not included in the revision size, their hash does not contribute to the revision hash, and updates are not included in revision history.
Since
1.36 optional $derived parameter added

Definition at line 80 of file SlotRoleHandler.php.

Member Function Documentation

◆ getDefaultModel()

MediaWiki\Revision\SlotRoleHandler::getDefaultModel ( $page)

Determines the content model to use by default for this slot on the given page.

The default implementation always returns the content model provided to the constructor. Subclasses may base the choice on default model on the page title or namespace. The choice should not depend on external state, such as the page content.

Stability: stable
to override
Parameters
LinkTarget | PageIdentity$page
Returns
string

Reimplemented in MediaWiki\Revision\MainSlotRoleHandler.

Definition at line 150 of file SlotRoleHandler.php.

◆ getNameMessageKey()

MediaWiki\Revision\SlotRoleHandler::getNameMessageKey ( )

The message key for the translation of the slot name.

Stability: stable
to override
Returns
string

Definition at line 133 of file SlotRoleHandler.php.

◆ getOutputLayoutHints()

MediaWiki\Revision\SlotRoleHandler::getOutputLayoutHints ( )

Layout hints for use while laying out the combined output of all slots, typically by RevisionRenderer.

The layout hints are given as an associative array. Well-known keys to use:

  • "display": how the output of this slot should be represented. Supported values:
    • "section": show as a top level section of the region.
    • "none": do not show at all Further values that may be supported in the future include "box" and "banner".
  • "region": in which region of the page the output should be placed. Supported values:
    • "center": the central content area. Further values that may be supported in the future include "top" and "bottom", "left" and "right", "header" and "footer".
  • "placement": placement relative to other content of the same area.
    • "append": place at the end, after any output processed previously. Further values that may be supported in the future include "prepend". A "weight" key may be introduced for more fine grained control.
Stability: stable
to override
Returns
string[] an associative array of hints

Reimplemented in MediaWiki\Revision\FallbackSlotRoleHandler.

Definition at line 115 of file SlotRoleHandler.php.

◆ getRole()

MediaWiki\Revision\SlotRoleHandler::getRole ( )
Returns
string The role this SlotRoleHandler applies to

Definition at line 90 of file SlotRoleHandler.php.

◆ isAllowedModel()

MediaWiki\Revision\SlotRoleHandler::isAllowedModel ( $model,
PageIdentity $page )

Determines whether the given model can be used on this slot on the given page.

The default implementation checks whether $model is the content model provided to the constructor. Subclasses may allow other models and may base the decision on the page title or namespace. The choice should not depend on external state, such as the page content.

Stability: stable
to override
Note
This should be checked when creating new revisions. Existing revisions are not guaranteed to comply with the return value.
Parameters
string$model
PageIdentity$page
Returns
bool

Reimplemented in MediaWiki\Revision\FallbackSlotRoleHandler, and MediaWiki\Revision\MainSlotRoleHandler.

Definition at line 171 of file SlotRoleHandler.php.

◆ isDerived()

MediaWiki\Revision\SlotRoleHandler::isDerived ( )
Returns
bool Is this a handler for a derived slot?
Since
1.36

Definition at line 123 of file SlotRoleHandler.php.

◆ supportsArticleCount()

MediaWiki\Revision\SlotRoleHandler::supportsArticleCount ( )

Whether this slot should be considered when determining whether a page should be counted as an "article" in the site statistics.

For a page to be considered countable, one of the page's slots must return true from this method, and Content::isCountable() must return true for the content of that slot.

The default implementation always returns false.

Stability: stable
to override
Returns
bool

Reimplemented in MediaWiki\Revision\MainSlotRoleHandler.

Definition at line 188 of file SlotRoleHandler.php.


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