From 1517f8abe664560a4f0651c8ede437fe2398602b Mon Sep 17 00:00:00 2001 From: Morne Alberts Date: Tue, 30 Jul 2024 16:22:19 +0200 Subject: [PATCH] Add showUserAvatar parameter --- docs/components.md | 21 +++++++++++++++++++ docs/release-notes.md | 2 +- layouts/clean.xml | 2 +- layouts/fixedhead.xml | 2 +- layouts/layout.rng | 10 +++++++-- layouts/navhead.xml | 2 +- layouts/standard.xml | 2 +- layouts/stickyhead.xml | 2 +- maintenance/validateLayout.php | 2 +- .../NavbarHorizontal/PersonalTools.php | 7 ++++++- 10 files changed, 42 insertions(+), 10 deletions(-) diff --git a/docs/components.md b/docs/components.md index 68aadc31..884cb380 100644 --- a/docs/components.md +++ b/docs/components.md @@ -996,6 +996,27 @@ applicable. This attribute applies only when used inside the [NavbarHorizontal](#component-navbarhorizontal) component. +* `showUserAvatar`: + * Since Chameleon 4.4.0 + * Allowed values: Boolean (`yes`|`no`) + * Default: `no` + * Optional. + + Whether to show a user avatar instead of a generic icon for the dropdown. This will look for an image file on the + wiki with a title matching `USERNAME.EXTENSION`. The supported extensions are: `png`, `jpg`, `jpeg`. + + Alternatively, the avatar URL can be provided by implementing the `ChameleonNavbarHorizontalPersonalToolsAvatarUrl` + hook. Example: + ```php + $wgHooks['ChameleonNavbarHorizontalPersonalToolsAvatarUrl'][] = function ( &$avatarUrl, $skin ) { + avatarUrl = 'https://upload.wikimedia.org/wikipedia/mediawiki/thumb/3/31/Chameleon.svg/170px-Chameleon.svg.png'; + return false; + }; + ``` + + This attribute applies only when used inside the + [NavbarHorizontal](#component-navbarhorizontal) component. + #### Allowed Parent Elements: * [Structure](#structure) * [Cell](#cell) diff --git a/docs/release-notes.md b/docs/release-notes.md index cd559dd8..60e74e8a 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -14,7 +14,7 @@ Under development. Under development. * Added experimental Table of Contents component `Toc` (thanks @malberts, and @DanielWTQ for bug fixes) -* Added user avatar support in `PersonalTools` component (thanks @thomas-topway-it) +* Added `showUserAvatar` parameter for showing a user avatar in the `PersonalTools` component (thanks @thomas-topway-it) * Translation updates for system messages (thanks @translatewiki and its translator community) ### Chameleon 4.3.0 diff --git a/layouts/clean.xml b/layouts/clean.xml index dc9250f1..aee75a4b 100644 --- a/layouts/clean.xml +++ b/layouts/clean.xml @@ -23,7 +23,7 @@ with this program. If not, see . @since 1.1 @ingroup Skins --> - + diff --git a/layouts/fixedhead.xml b/layouts/fixedhead.xml index 3ac21816..158bc96c 100644 --- a/layouts/fixedhead.xml +++ b/layouts/fixedhead.xml @@ -23,7 +23,7 @@ with this program. If not, see . @since 1.0 @ingroup Skins --> - + diff --git a/layouts/layout.rng b/layouts/layout.rng index 381c72f9..ae1375f9 100644 --- a/layouts/layout.rng +++ b/layouts/layout.rng @@ -25,13 +25,13 @@ with this program. If not, see . Schema for Chameleon layout files - Version 3.6 + Version 3.7 Copyright 2013 - 2021, Stephan Gambke GNU General Public License, version 3 (or any later version) @@ -419,6 +419,12 @@ with this program. If not, see . + + + + + + diff --git a/layouts/navhead.xml b/layouts/navhead.xml index 1e7ba6ac..868d48f0 100644 --- a/layouts/navhead.xml +++ b/layouts/navhead.xml @@ -23,7 +23,7 @@ with this program. If not, see . @since 1.0 @ingroup Skins --> - + diff --git a/layouts/standard.xml b/layouts/standard.xml index 0b50c156..facbcdb7 100644 --- a/layouts/standard.xml +++ b/layouts/standard.xml @@ -23,7 +23,7 @@ with this program. If not, see . @since 1.0 @ingroup Skins --> - + diff --git a/layouts/stickyhead.xml b/layouts/stickyhead.xml index 17007099..5cc49605 100644 --- a/layouts/stickyhead.xml +++ b/layouts/stickyhead.xml @@ -23,7 +23,7 @@ with this program. If not, see . @since 1.0 @ingroup Skins --> - + diff --git a/maintenance/validateLayout.php b/maintenance/validateLayout.php index bca2a9fe..5fca1e8a 100644 --- a/maintenance/validateLayout.php +++ b/maintenance/validateLayout.php @@ -79,7 +79,7 @@ function validateFile( $filename ) { $xml = new DOMDocument(); $xml->load( $filename ); - if ( !$xml->relaxNGValidate( 'https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng' ) ) { + if ( !$xml->relaxNGValidate( 'https://ProfessionalWiki.github.io/chameleon/schema/3.7/layout.rng' ) ) { libxml_display_errors(); } else { print "Ok!\n"; diff --git a/src/Components/NavbarHorizontal/PersonalTools.php b/src/Components/NavbarHorizontal/PersonalTools.php index e09f2b96..ce1ca19c 100644 --- a/src/Components/NavbarHorizontal/PersonalTools.php +++ b/src/Components/NavbarHorizontal/PersonalTools.php @@ -53,6 +53,7 @@ class PersonalTools extends Component { private const SHOW_USER_NAME_NO = 'no'; private const SHOW_USER_NAME_YES = 'yes'; private const ATTR_PROMOTE_LONE_ITEMS = 'promoteLoneItems'; + private const ATTR_SHOW_USER_AVATAR = 'showUserAvatar'; protected ?string $avatarUrl = null; @@ -270,7 +271,7 @@ protected function getDropdownToggle(): string { } private function setUserAvatar(): void { - if ( !empty( $GLOBALS['chameleonDisableAvatar'] ) ) { + if ( !$this->shouldShowUserAvatar() ) { return; } @@ -306,6 +307,10 @@ private function setUserAvatar(): void { $this->avatarUrl = $imagePage->getFile()->createThumb( 41, 41 ); } + private function shouldShowUserAvatar(): bool { + return filter_var( $this->getAttribute( self::ATTR_SHOW_USER_AVATAR ), FILTER_VALIDATE_BOOLEAN ); + } + /** * @return string */