diff --git a/resources/styles/Components/NavbarHorizontal.scss b/resources/styles/Components/NavbarHorizontal.scss
index 0798b080..b94d3867 100644
--- a/resources/styles/Components/NavbarHorizontal.scss
+++ b/resources/styles/Components/NavbarHorizontal.scss
@@ -155,4 +155,18 @@
a.navbar-more-tools, a.navbar-usernotloggedin, a.navbar-userloggedin, a.navbar-tool-link, a:visited.navbar-tool-link {
color: $navbar-light-color;
}
+
+ .navbar-tool.avatar {
+ background: white;
+ border-radius: 99px;
+ overflow: hidden;
+ }
+
+ a.navbar-userloggedin-avatar {
+ width: 41px;
+ height: 41px;
+ background-size: contain;
+ background-repeat: no-repeat;
+ background-position: center;
+ }
}
diff --git a/src/Components/NavbarHorizontal/PersonalTools.php b/src/Components/NavbarHorizontal/PersonalTools.php
index 4fd0c991..c79208e3 100644
--- a/src/Components/NavbarHorizontal/PersonalTools.php
+++ b/src/Components/NavbarHorizontal/PersonalTools.php
@@ -36,6 +36,7 @@
* 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
*/
@@ -54,6 +55,9 @@ class PersonalTools extends Component {
private const SHOW_USER_NAME_YES = 'yes';
private const ATTR_PROMOTE_LONE_ITEMS = 'promoteLoneItems';
+ /** @var avatarUrl */
+ protected $avatarUrl = null;
+
/**
* @return String
* @throws \FatalError
@@ -61,6 +65,8 @@ class PersonalTools extends Component {
*/
public function getHtml() {
$tools = $this->getSkinTemplate()->getPersonalTools();
+
+ $this->setUserAvatar();
// Flatten classes to avoid MW bug: https://phabricator.wikimedia.org/T262160
// NB: This bug is finally fixed in MW >=1.36.
@@ -99,7 +105,8 @@ public function getHtml() {
return $echoHtml .
$this->indent() . '' .
$this->indent() . '
' .
- $this->indent( 1 ) . \Html::rawElement( 'div', [ 'class' => 'navbar-tool dropdown' ],
+ $this->indent( 1 ) . \Html::rawElement( 'div',
+ [ 'class' => 'navbar-tool' . ( !$this->avatarUrl ? '' : ' avatar' ) . ' dropdown' ],
$this->getDropdownToggle() .
$this->indent( 1 ) . \Html::rawElement( 'div',
@@ -225,16 +232,14 @@ protected function getDropdownToggle(): string {
$user = $this->getSkinTemplate()->getSkin()->getUser();
if ( $user->isRegistered() ) {
-
- $toolsClass = 'navbar-userloggedin';
+ $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();
-
}
// TODO Rename '...LinkText' to '...LinkTitle' in both the hook and variable.
@@ -243,14 +248,23 @@ protected function getDropdownToggle(): string {
$newtalkNotifierHtml = $this->getNewtalkNotifier();
$userNameHtml = $this->getUserName();
+
MediaWikiServices::getInstance()->getHookContainer()->run( 'ChameleonNavbarHorizontalPersonalToolsLinkInnerHtml',
[ &$newtalkNotifierHtml, &$userNameHtml, $this ] );
$this->indent( 1 );
- $dropdownToggle = IdRegistry::getRegistry()->element( 'a', [ 'class' => $toolsClass,
+ $attr = [
+ 'class' => $toolsClass,
'href' => '#', 'data-toggle' => 'dropdown', 'data-boundary' => 'viewport',
- 'title' => $toolsLinkText ], $newtalkNotifierHtml . $userNameHtml,
+ 'title' => $toolsLinkText
+ ];
+
+ if ( $this->avatarUrl ) {
+ $attr['style'] = "background-image:url('$this->avatarUrl')";
+ }
+
+ $dropdownToggle = IdRegistry::getRegistry()->element( 'a', $attr, $newtalkNotifierHtml . $userNameHtml,
$this->indent() );
$this->indent( -1 );
@@ -258,6 +272,43 @@ protected function getDropdownToggle(): string {
return $dropdownToggle;
}
+ private function setUserAvatar() {
+ if ( !empty( $GLOBALS['chameleonDisableAvatar'] ) ) {
+ return;
+ }
+
+ $user = $this->getSkinTemplate()->getSkin()->getUser();
+ if ( ! $user->isRegistered() ) {
+ return;
+ }
+
+ // let users of the skin set an avatar url by some
+ // other criteria. e.g. SMW could use
+ // \SMW\DIProperty::newFromUserLabel( 'User image' )
+ if ( !MediaWikiServices::getInstance()->getHookContainer()->run( 'ChameleonNavbarHorizontalPersonalToolsAvatarUrl',
+ [ &$this->avatarUrl, $this->getSkin() ] ) ) {
+ return false;
+ }
+
+ // retrieve an image with the same name
+ // of the user with some common extension
+ $imageExt = [ 'png', 'jpg', 'jpeg' ];
+ $imagePage = null;
+ $username = $user->getName();
+ foreach ( $imageExt as $ext ) {
+ $title_ = \Title::makeTitleSafe( NS_FILE, "$username.$ext" );
+ if ( $title_ && $title_->isKnown() ) {
+ $imagePage = new \WikiFilePage( $title_ );
+ break;
+ }
+ }
+ if ( !$imagePage ) {
+ return;
+ }
+
+ $this->avatarUrl = $imagePage->getFile()->createThumb( 41, 41 );
+ }
+
/**
* @return string
*/