3 * This file is part of MediaWiki.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 namespace MediaWiki\Revision
;
25 use MediaWiki\Linker\LinkTarget
;
28 * SlotRoleHandler instances are used to declare the existence and behavior of slot roles.
29 * Most importantly, they control which content model can be used for the slot, and how it is
30 * represented in the rendered verswion of page content.
34 class SlotRoleHandler
{
43 * @see getOutputLayoutHints
46 'display' => 'section', // use 'none' to suppress
48 'placement' => 'append'
54 private $contentModel;
57 * @param string $role The name of the slot role defined by this SlotRoleHandler. See
58 * SlotRoleRegistry::defineRole for more information.
59 * @param string $contentModel The default content model for this slot. As per the default
60 * implementation of isAllowedModel(), also the only content model allowed for the
61 * slot. Subclasses may however handle default and allowed models differently.
62 * @param array $layout Layout hints, for use by RevisionRenderer. See getOutputLayoutHints.
64 public function __construct( $role, $contentModel, $layout = [] ) {
66 $this->contentModel
= $contentModel;
67 $this->layout
= array_merge( $this->layout
, $layout );
71 * @return string The role this SlotRoleHandler applies to
73 public function getRole() {
78 * Layout hints for use while laying out the combined output of all slots, typically by
79 * RevisionRenderer. The layout hints are given as an associative array. Well-known keys
82 * * "display": how the output of this slot should be represented. Supported values:
83 * - "section": show as a top level section of the region.
84 * - "none": do not show at all
85 * Further values that may be supported in the future include "box" and "banner".
86 * * "region": in which region of the page the output should be placed. Supported values:
87 * - "center": the central content area.
88 * Further values that may be supported in the future include "top" and "bottom", "left"
89 * and "right", "header" and "footer".
90 * * "placement": placement relative to other content of the same area.
91 * - "append": place at the end, after any output processed previously.
92 * Further values that may be supported in the future include "prepend". A "weight" key
93 * may be introduced for more fine grained control.
95 * @return array an associative array of hints
97 public function getOutputLayoutHints() {
102 * The message key for the translation of the slot name.
106 public function getNameMessageKey() {
107 return 'slot-name-' . $this->role
;
111 * Determines the content model to use per default for this slot on the given page.
113 * The default implementation always returns the content model provided to the constructor.
114 * Subclasses may base the choice on default model on the page title or namespace.
115 * The choice should not depend on external state, such as the page content.
117 * @param LinkTarget $page
121 public function getDefaultModel( LinkTarget
$page ) {
122 return $this->contentModel
;
126 * Determines whether the given model can be used on this slot on the given page.
128 * The default implementation checks whether $model is the content model provided to the
129 * constructor. Subclasses may allow other models and may base the decision on the page title
130 * or namespace. The choice should not depend on external state, such as the page content.
132 * @note This should be checked when creating new revisions. Existing revisions
133 * are not guaranteed to comply with the return value.
135 * @param string $model
136 * @param LinkTarget $page
140 public function isAllowedModel( $model, LinkTarget
$page ) {
141 return ( $model === $this->contentModel
);
145 * Whether this slot should be considered when determining whether a page should be counted
146 * as an "article" in the site statistics.
148 * For a page to be considered countable, one of the page's slots must return true from this
149 * method, and Content::isCountable() must return true for the content of that slot.
151 * The default implementation always returns false.
155 public function supportsArticleCount() {