mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-12-02 03:07:13 +00:00
24055a6752
* Leverage the infrastructure around feature management to handle the page tools pinning and persistence * Make pinnableHeader.js leverage features.js if the data-feature-name attribute is set * Sets tests/.eslintrc.json ecmaVersion to 2018 to enable destructuring in test files. * Adds a isPinned helper method to pinnableElement * Add a logged in requirement so that the pinned feature is disabled for anon users. Bug: T322051 Change-Id: Ib86282216882fa94e37b7088a3f4bd0c1bcf6cd4
82 lines
2.4 KiB
PHP
82 lines
2.4 KiB
PHP
<?php
|
|
namespace MediaWiki\Skins\Vector\Components;
|
|
|
|
use MessageLocalizer;
|
|
|
|
/**
|
|
* VectorComponentPinnableHeader component
|
|
*/
|
|
class VectorComponentPinnableHeader implements VectorComponent {
|
|
/** @var MessageLocalizer */
|
|
private $localizer;
|
|
/** @var bool */
|
|
private $pinned;
|
|
/** @var string */
|
|
private $name;
|
|
/** @var string|null */
|
|
private $featureName;
|
|
/**
|
|
* @var bool
|
|
* Flag controlling if the pinnable element should be automatically moved in the DOM when pinned/unpinned
|
|
*/
|
|
private $moveElement;
|
|
/**
|
|
* @var string
|
|
*/
|
|
private $labelTagName;
|
|
|
|
/**
|
|
* @param MessageLocalizer $localizer
|
|
* @param bool $pinned
|
|
* @param string $name By convention, this should include the `vector-`
|
|
* prefix e.g. `vector-page-tools` or `vector-toc`.
|
|
* @param string|null $featureName If set, pinned and unpinned states will
|
|
* persist for logged-in users by leveraging features.js to manage the user
|
|
* preference storage and the toggling of the body class. This name should NOT
|
|
* contain the "vector-" prefix.
|
|
* @param bool|null $moveElement
|
|
* @param string|null $labelTagName Element type of the label. Either a 'div' or a 'h2'
|
|
* in the case of the pinnable ToC.
|
|
*/
|
|
public function __construct(
|
|
MessageLocalizer $localizer,
|
|
bool $pinned,
|
|
string $name,
|
|
?string $featureName,
|
|
?bool $moveElement = true,
|
|
?string $labelTagName = 'div'
|
|
) {
|
|
$this->localizer = $localizer;
|
|
$this->pinned = $pinned;
|
|
$this->name = $name;
|
|
$this->featureName = $featureName;
|
|
$this->moveElement = $moveElement;
|
|
$this->labelTagName = $labelTagName;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function getTemplateData(): array {
|
|
$messageLocalizer = $this->localizer;
|
|
$data = [
|
|
'is-pinned' => $this->pinned,
|
|
'label' => $messageLocalizer->msg( $this->name . '-label' ),
|
|
'label-tag-name' => $this->labelTagName,
|
|
'pin-label' => $messageLocalizer->msg( 'vector-pin-element-label' ),
|
|
'unpin-label' => $messageLocalizer->msg( 'vector-unpin-element-label' ),
|
|
'data-name' => $this->name,
|
|
'data-feature-name' => $this->featureName
|
|
];
|
|
if ( $this->moveElement ) {
|
|
// Assumes consistent naming standard for pinnable elements and their containers
|
|
$data = array_merge( $data, [
|
|
'data-pinnable-element-id' => $this->name . '-pinnable-element',
|
|
'data-unpinned-container-id' => $this->name . '-unpinned-container',
|
|
'data-pinned-container-id' => $this->name . '-pinned-container',
|
|
] );
|
|
}
|
|
return $data;
|
|
}
|
|
}
|