2019-07-12 03:06:13 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace MediaWiki\Minerva\Menu\Entries;
|
|
|
|
|
2023-08-19 04:23:00 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2021-12-17 17:16:49 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
2019-07-12 03:06:13 +00:00
|
|
|
|
2022-01-13 00:38:16 +00:00
|
|
|
/**
|
|
|
|
* Note this is used by Extension:GrowthExperiments
|
|
|
|
*/
|
2019-07-12 03:06:13 +00:00
|
|
|
final class ProfileMenuEntry implements IProfileMenuEntry {
|
2024-03-28 19:15:41 +00:00
|
|
|
private UserIdentity $user;
|
2019-07-12 03:06:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Code used to track clicks on the link to profile page
|
|
|
|
* @var string|null
|
|
|
|
*/
|
2024-03-28 19:15:41 +00:00
|
|
|
private ?string $profileTrackingCode = null;
|
2019-07-12 03:06:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom profile URL, can be used to override where the profile link href
|
|
|
|
* @var string|null
|
|
|
|
*/
|
2024-03-28 19:15:41 +00:00
|
|
|
private ?string $customProfileURL = null;
|
2019-07-12 03:06:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom profile label, can be used to override the profile label
|
|
|
|
* @var string|null
|
|
|
|
*/
|
2024-03-28 19:15:41 +00:00
|
|
|
private ?string $customProfileLabel = null;
|
2019-07-12 03:06:13 +00:00
|
|
|
|
|
|
|
/**
|
2021-12-17 17:16:49 +00:00
|
|
|
* @param UserIdentity $user Currently logged in user/anon
|
2019-07-12 03:06:13 +00:00
|
|
|
*/
|
2021-12-17 17:16:49 +00:00
|
|
|
public function __construct( UserIdentity $user ) {
|
2019-07-12 03:06:13 +00:00
|
|
|
$this->user = $user;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2024-03-28 19:15:41 +00:00
|
|
|
public function getName(): string {
|
2019-07-12 03:06:13 +00:00
|
|
|
return 'profile';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2024-03-28 19:15:41 +00:00
|
|
|
public function overrideProfileURL(
|
|
|
|
$customURL, $customLabel = null, $trackingCode = null
|
|
|
|
): self {
|
2019-07-12 03:06:13 +00:00
|
|
|
$this->customProfileURL = $customURL;
|
|
|
|
$this->customProfileLabel = $customLabel;
|
|
|
|
$this->profileTrackingCode = $trackingCode;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getCSSClasses(): array {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getComponents(): array {
|
|
|
|
$username = $this->user->getName();
|
|
|
|
return [ [
|
2023-08-08 23:33:28 +00:00
|
|
|
'data-icon' => [
|
2024-10-07 22:35:31 +00:00
|
|
|
'icon' => 'userAvatar',
|
2023-08-08 23:33:28 +00:00
|
|
|
],
|
|
|
|
'label' => $this->customProfileLabel ?? $username,
|
|
|
|
'array-attributes' => [
|
|
|
|
[
|
|
|
|
'key' => 'href',
|
|
|
|
'value' => $this->customProfileURL ?? Title::makeTitle( NS_USER, $username )->getLocalURL(),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'key' => 'data-event-name',
|
|
|
|
'value' => 'menu.' . (
|
|
|
|
$this->profileTrackingCode ?? self::DEFAULT_PROFILE_TRACKING_CODE
|
|
|
|
)
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'classes' => 'menu__item--user',
|
2019-07-12 03:06:13 +00:00
|
|
|
] ];
|
|
|
|
}
|
|
|
|
}
|