Skip to content

Commit

Permalink
Add showUserAvatar parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
malberts committed Jul 30, 2024
1 parent cf7bde0 commit 0f2dfee
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 10 deletions.
21 changes: 21 additions & 0 deletions docs/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion layouts/clean.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
@since 1.1
@ingroup Skins
-->
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng">
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.7/layout.rng">

<component type="NavbarHorizontal" >
<modification type="ShowOnlyFor" permission="edit"/>
Expand Down
2 changes: 1 addition & 1 deletion layouts/fixedhead.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
@since 1.0
@ingroup Skins
-->
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng">
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.7/layout.rng">

<component type="NavbarHorizontal">
<modification type="Sticky"/>
Expand Down
10 changes: 8 additions & 2 deletions layouts/layout.rng
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
<grammar
xmlns="http://relaxng.org/ns/structure/1.0"
xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
ns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng"
ns="https://ProfessionalWiki.github.io/chameleon/schema/3.7/layout.rng"
datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
>

<a:documentation>
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)
</a:documentation>
Expand Down Expand Up @@ -419,6 +419,12 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
<data type="string"/>
</attribute>
</optional>

<optional>
<attribute name="showUserAvatar" a:defaultValue="no">
<ref name="BoolValues"/>
</attribute>
</optional>
</define>

<define name="Component" combine="choice">
Expand Down
2 changes: 1 addition & 1 deletion layouts/navhead.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
@since 1.0
@ingroup Skins
-->
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng">
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.7/layout.rng">
<component type="NavbarHorizontal">
<component type="Logo" position="head"/>
<component type="NavMenu" flatten="navigation" />
Expand Down
2 changes: 1 addition & 1 deletion layouts/standard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
@since 1.0
@ingroup Skins
-->
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng">
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.7/layout.rng">
<grid class="flex-fill">
<row>
<cell class="flex-grow-0">
Expand Down
2 changes: 1 addition & 1 deletion layouts/stickyhead.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
@since 1.0
@ingroup Skins
-->
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.6/layout.rng">
<structure xmlns="https://ProfessionalWiki.github.io/chameleon/schema/3.7/layout.rng">

<component type="NavbarHorizontal" class="small bg-darker">
<component type="Menu" message="secondary-menu"/>
Expand Down
2 changes: 1 addition & 1 deletion maintenance/validateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
7 changes: 6 additions & 1 deletion src/Components/NavbarHorizontal/PersonalTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -270,7 +271,7 @@ protected function getDropdownToggle(): string {
}

private function setUserAvatar(): void {
if ( !empty( $GLOBALS['chameleonDisableAvatar'] ) ) {
if ( !$this->shouldShowUserAvatar() ) {
return;
}

Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 0f2dfee

Please sign in to comment.