Add all ResourceLoaderModules using supported hook

PersonalUrls hooks is not meant to be used to add RL modules,
its documentation says it's meant to "alter the user-specific
navigation links (e.g. "my page, * my talk page, my contributions" etc)."

Echo is already using BeforePageDisplay hook to add modules, let's
now register all our modules via that

Bug: T259872
Change-Id: I12616a9947ea0e574287443361e2180c42e48d4b
This commit is contained in:
Ammar Abdulhamid 2020-08-08 00:41:30 +01:00
parent 060ab77258
commit 95a0dff88c

View file

@ -845,7 +845,17 @@ class EchoHooks implements RecentChange_saveHook {
* @param Skin $skin Skin being used.
*/
public static function beforePageDisplay( $out, $skin ) {
if ( $out->getUser()->isLoggedIn() ) {
$user = $out->getUser();
if ( !$user->isLoggedIn() ) {
return;
}
if ( self::shouldDisplayTalkAlert( $user, $out->getTitle() ) ) {
// Load the module for the Orange alert
$out->addModuleStyles( 'ext.echo.styles.alert' );
}
// Load the module for the Notifications flyout
$out->addModules( [ 'ext.echo.init' ] );
// Load the styles for the Notifications badge
@ -854,7 +864,6 @@ class EchoHooks implements RecentChange_saveHook {
'oojs-ui.styles.icons-alerts'
] );
}
}
private static function processMarkAsRead( User $user, WebRequest $request, Title $title ) {
global $wgEchoCrossWikiNotifications;
@ -1130,15 +1139,20 @@ class EchoHooks implements RecentChange_saveHook {
// * User actually has new messages
// * User is not viewing their user talk page, as user_newtalk
// will not have been cleared yet. (bug T107655).
$userHasNewMessages = MediaWikiServices::getInstance()
->getTalkPageNotificationManager()->userHasNewMessages( $user );
if ( $userHasNewMessages && !$user->getTalkPage()->equals( $title ) ) {
if ( Hooks::run( 'BeforeDisplayOrangeAlert', [ $user, $title ] ) ) {
if ( self::shouldDisplayTalkAlert( $user, $title )
&& Hooks::run( 'BeforeDisplayOrangeAlert', [ $user, $title ] )
) {
$personal_urls['mytalk']['text'] = $sk->msg( 'echo-new-messages' )->text();
$personal_urls['mytalk']['class'] = [ 'mw-echo-alert' ];
$sk->getOutput()->addModuleStyles( 'ext.echo.styles.alert' );
}
}
private static function shouldDisplayTalkAlert( $user, $title ) {
$userHasNewMessages = MediaWikiServices::getInstance()
->getTalkPageNotificationManager()
->userHasNewMessages( $user );
return $userHasNewMessages && !$user->getTalkPage()->equals( $title );
}
/**