Skip to content

Commit

Permalink
Minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
malberts committed Jul 29, 2024
1 parent ab5b9cc commit aaca110
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/Components/NavbarHorizontal/PersonalTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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();
}
Expand All @@ -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() );

Expand All @@ -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;
}

Expand All @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit aaca110

Please sign in to comment.