mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue
synced 2024-12-19 17:21:07 +00:00
98521bbb68
Following the migration to Codex, icons do not need suffixes for their icons. If we merge this now, we don't need to worry about caching when working on Bug T266361. Bug: T266361 Change-Id: Iafeb21858c89df1af35660eb63889fa5335e2b34
106 lines
2.6 KiB
PHP
106 lines
2.6 KiB
PHP
<?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;
|
|
|
|
use MediaWiki\Title\Title;
|
|
use MediaWiki\User\UserIdentity;
|
|
|
|
/**
|
|
* Note this is used by Extension:GrowthExperiments
|
|
*/
|
|
final class ProfileMenuEntry implements IProfileMenuEntry {
|
|
private UserIdentity $user;
|
|
|
|
/**
|
|
* Code used to track clicks on the link to profile page
|
|
* @var string|null
|
|
*/
|
|
private ?string $profileTrackingCode = null;
|
|
|
|
/**
|
|
* Custom profile URL, can be used to override where the profile link href
|
|
* @var string|null
|
|
*/
|
|
private ?string $customProfileURL = null;
|
|
|
|
/**
|
|
* Custom profile label, can be used to override the profile label
|
|
* @var string|null
|
|
*/
|
|
private ?string $customProfileLabel = null;
|
|
|
|
/**
|
|
* @param UserIdentity $user Currently logged in user/anon
|
|
*/
|
|
public function __construct( UserIdentity $user ) {
|
|
$this->user = $user;
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function getName(): string {
|
|
return 'profile';
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function overrideProfileURL(
|
|
$customURL, $customLabel = null, $trackingCode = null
|
|
): self {
|
|
$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 [ [
|
|
'data-icon' => [
|
|
'icon' => 'userAvatar',
|
|
],
|
|
'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',
|
|
] ];
|
|
}
|
|
}
|