Debian Codegraph @

skins/MinervaNeue/includes/Menu/Entries/ProfileMenuEntry.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 namespace MediaWiki\Minerva\Menu\Entries;
19
20 use MediaWiki\Title\Title;
21 use MediaWiki\User\UserIdentity;
22
23 /**
24 * Note this is used by Extension:GrowthExperiments
25 */
26 final class ProfileMenuEntry implements IProfileMenuEntry {
27 private UserIdentity $user;
28
29 /**
30 * Code used to track clicks on the link to profile page
31 * @var string|null
32 */
33 private ?string $profileTrackingCode = null;
34
35 /**
36 * Custom profile URL, can be used to override where the profile link href
37 * @var string|null
38 */
39 private ?string $customProfileURL = null;
40
41 /**
42 * Custom profile label, can be used to override the profile label
43 * @var string|null
44 */
45 private ?string $customProfileLabel = null;
46
47 /**
48 * @param UserIdentity $user Currently logged in user/anon
49 */
50 public function __construct( UserIdentity $user ) {
51 $this->user = $user;
52 }
53
54 /**
55 * @inheritDoc
56 */
57 public function getName(): string {
58 return 'profile';
59 }
60
61 /**
62 * @inheritDoc
63 */
64 public function overrideProfileURL(
65 $customURL, $customLabel = null, $trackingCode = null
66 ): self {
67 $this->customProfileURL = $customURL;
68 $this->customProfileLabel = $customLabel;
69 $this->profileTrackingCode = $trackingCode;
70 return $this;
71 }
72
73 /**
74 * @inheritDoc
75 */
76 public function getCSSClasses(): array {
77 return [];
78 }
79
80 /**
81 * @inheritDoc
82 */
83 public function getComponents(): array {
84 $username = $this->user->getName();
85 return [ [
86 'data-icon' => [
87 'icon' => 'userAvatar',
88 ],
89 'label' => $this->customProfileLabel ?? $username,
90 'array-attributes' => [
91 [
92 'key' => 'href',
93 'value' => $this->customProfileURL ?? Title::makeTitle( NS_USER, $username )->getLocalURL(),
94 ],
95 [
96 'key' => 'data-event-name',
97 'value' => 'menu.' . (
98 $this->profileTrackingCode ?? self::DEFAULT_PROFILE_TRACKING_CODE
99 )
100 ],
101 ],
102 'classes' => 'menu__item--user',
103 ] ];
104 }
105 }