From aaca1100c2f5801d322c567acc8c36402bc5d293 Mon Sep 17 00:00:00 2001 From: Morne Alberts Date: Mon, 29 Jul 2024 22:22:28 +0200 Subject: [PATCH] Minor code cleanup --- .../NavbarHorizontal/PersonalTools.php | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/Components/NavbarHorizontal/PersonalTools.php b/src/Components/NavbarHorizontal/PersonalTools.php index c79208e3..60ef9c68 100644 --- a/src/Components/NavbarHorizontal/PersonalTools.php +++ b/src/Components/NavbarHorizontal/PersonalTools.php @@ -36,7 +36,6 @@ * Provides a PersonalTools component to be included in a NavbarHorizontal component. * * @author Stephan Gambke - * @reviewer thomas-topway-it - user-avatar (for KM-A) * @since 1.6 * @ingroup Skins */ @@ -55,8 +54,7 @@ class PersonalTools extends Component { private const SHOW_USER_NAME_YES = 'yes'; private const ATTR_PROMOTE_LONE_ITEMS = 'promoteLoneItems'; - /** @var avatarUrl */ - protected $avatarUrl = null; + protected ?string $avatarUrl = null; /** * @return String @@ -65,7 +63,7 @@ class PersonalTools extends Component { */ public function getHtml() { $tools = $this->getSkinTemplate()->getPersonalTools(); - + $this->setUserAvatar(); // Flatten classes to avoid MW bug: https://phabricator.wikimedia.org/T262160 @@ -232,12 +230,11 @@ protected function getDropdownToggle(): string { $user = $this->getSkinTemplate()->getSkin()->getUser(); if ( $user->isRegistered() ) { - $toolsClass = 'navbar-userloggedin' - . ( !$this->avatarUrl ? '' : '-avatar' ); + $toolsClass = 'navbar-userloggedin' . ( !$this->avatarUrl ? '' : '-avatar' ); $toolsLinkText = $this->getSkinTemplate()->getMsg( 'chameleon-loggedin' )-> params( $user->getName() )->text(); - } else { + } else { $toolsClass = 'navbar-usernotloggedin'; $toolsLinkText = $this->getSkinTemplate()->getMsg( 'chameleon-notloggedin' )->text(); } @@ -259,11 +256,11 @@ protected function getDropdownToggle(): string { 'href' => '#', 'data-toggle' => 'dropdown', 'data-boundary' => 'viewport', 'title' => $toolsLinkText ]; - + if ( $this->avatarUrl ) { $attr['style'] = "background-image:url('$this->avatarUrl')"; } - + $dropdownToggle = IdRegistry::getRegistry()->element( 'a', $attr, $newtalkNotifierHtml . $userNameHtml, $this->indent() ); @@ -272,13 +269,13 @@ protected function getDropdownToggle(): string { return $dropdownToggle; } - private function setUserAvatar() { + private function setUserAvatar(): void { if ( !empty( $GLOBALS['chameleonDisableAvatar'] ) ) { return; } $user = $this->getSkinTemplate()->getSkin()->getUser(); - if ( ! $user->isRegistered() ) { + if ( !$user->isRegistered() ) { return; } @@ -287,7 +284,7 @@ private function setUserAvatar() { // \SMW\DIProperty::newFromUserLabel( 'User image' ) if ( !MediaWikiServices::getInstance()->getHookContainer()->run( 'ChameleonNavbarHorizontalPersonalToolsAvatarUrl', [ &$this->avatarUrl, $this->getSkin() ] ) ) { - return false; + return; } // retrieve an image with the same name @@ -296,7 +293,7 @@ private function setUserAvatar() { $imagePage = null; $username = $user->getName(); foreach ( $imageExt as $ext ) { - $title_ = \Title::makeTitleSafe( NS_FILE, "$username.$ext" ); + $title_ = \Title::makeTitleSafe( NS_FILE, "$username.$ext" ); if ( $title_ && $title_->isKnown() ) { $imagePage = new \WikiFilePage( $title_ ); break;