Make talk page notification use link-class, id and don't set class

Before this commit, setting:

```
$wgVectorConsolidateUserLinks = [
  'logged_in' => true
];
```

would result in an orange talk notification that had missing or
incorrect attributes (`#ca-mytalk` instead of `#pt-mytalk` and missing
the `title` and `accesskey` attributes) when visiting modern Vector
with a talk notification visible. The notification's html looked like:

```
<li id="ca-mytalk" class="mw-echo-alert">
  <a href="/wiki/User_talk:Newuser5">You have a new Talk page message</a>
</li>
```

The `pt-mytalk` id is important for echo to remove the notification [1].
The title and accesskey are important for accessibility reasons.

This commit corrects that by setting a `link-class`, setting an explicit
`id`, and NOT setting a `class` key. This results in html that is
correct in both modern and legacy Vector:

```
<li id="pt-mytalk">
  <a href="/wiki/User_talk:Newuser5" class="mw-echo-alert" title="Your talk page [ctrl-option-n]" accesskey="n">You have a new Talk page message</a>
</li>
```

[1] 67bf58a489/modules/ext.echo.init.js (L172)

Bug: T274428
Change-Id: I5afc74992ad3153ac32df65ccf5fd03b469f05fb
This commit is contained in:
Nicholas Ray 2021-05-27 18:44:42 -06:00
parent 67bf58a489
commit 7880cc1895

View file

@ -1131,13 +1131,17 @@ class EchoHooks implements RecentChange_saveHook {
->getHookContainer()->run( 'BeforeDisplayOrangeAlert', [ $user, $title ] )
) {
// Move `mytalk` from `user-menu` to `notifications`.
$links['notifications']['mytalk'] = array_merge(
$links['user-menu']['mytalk'],
[
'text' => $skinTemplate->msg( 'echo-new-messages' )->text(),
'class' => [ 'mw-echo-alert' ]
]
);
$links['notifications']['mytalk'] = [
'href' => $links['user-menu']['mytalk']['href'],
'text' => $skinTemplate->msg( 'echo-new-messages' ),
'active' => $links['user-menu']['mytalk']['active'],
'exists' => $links['user-menu']['mytalk']['exists'],
'link-class' => [ 'mw-echo-alert' ],
// Id of `pt-mytalk` is important for Linker to set the `title` and
// `accesskey` attributes.
'id' => 'pt-mytalk',
];
unset( $links['user-menu']['mytalk'] );
}