ProfessionalWiki / chameleon

Provides a highly flexible and customizable skin using Bootstrap 4
https://www.mediawiki.org/wiki/Skin:Chameleon
Other
114 stars 62 forks source link

PHP Notice if using Toolbox in NavbarHorizontal #279

Closed stefahn closed 3 years ago

stefahn commented 3 years ago

I use this structure in my layout: ` ...

...

`

In MediaWiki 1.35.3 and Chameleon 3.3.0 this throws the following PHP Notice: Undefined index: id in /site/mediawiki/skins/chameleon/src/Components/NavbarHorizontal/Toolbox.php on line 96

This notice also appears if I use the "default" code for the Toolbox, that means <component type="Toolbox" />

Thanks for all your work on this great skin!

WouterRademaker commented 3 years ago

The error is not difficult to fix, but the question is more why is "$linkItem['id']" not defined there for you?

A fix is in "skins/chameleon/src/Components/NavbarHorizontal/Toolbox.php" change

            foreach ( $toolbox as $key => $linkItem ) {
                    if ( isset( $linkItem[ 'class' ] ) ) {
                            $linkItem[ 'class' ] .= ' nav-item';
                    } else {
                            $linkItem[ 'class' ] = 'nav-item';
                    }
                    $listItems[] = $this->indent() . $skinTemplate->makeListItem( $key, $linkItem,
                            [ 'link-class' => 'nav-link '.$linkItem['id'], 'tag' => 'div' ] );
            }

to

            foreach ( $toolbox as $key => $linkItem ) {
                    if ( isset( $linkItem[ 'class' ] ) ) {
                            $linkItem[ 'class' ] .= ' nav-item';
                    } else {
                            $linkItem[ 'class' ] = 'nav-item';
                    }
                    if ( isset( $linkItem[ 'id' ] ) ) {                        
                            $listItems[] = $this->indent() . $skinTemplate->makeListItem( $key, $linkItem,
                                   [ 'link-class' => 'nav-link '.$linkItem['id'], 'tag' => 'div' ] );
                     } else {
                            $listItems[] = $this->indent() . $skinTemplate->makeListItem( $key, $linkItem,
                                   [ 'link-class' => 'nav-link', 'tag' => 'div' ] );
                    }         
            }
malberts commented 3 years ago

Thanks for the fix @WouterRademaker. I'm going to add that to the upcoming 3.4. I'm not able to reproduce this with only Chameleon, but my guess is it's because of another extension. I think Echo also had an issue with the id logic in PersonalTools.

@stefahn Can you provide some more info on which other extensions you are using? Or at least which extensions are putting extra links in the Toolbox?

stefahn commented 3 years ago

Thanks a lot for the quick fix and your comments.

I run https://www.mediawiki.org/wiki/Extension:Contributors on my site, which adds a link in the toolbox. I disabled it and the notice disappeared.

However I'm glad that the Vector code will be able to handle this, starting with version 3.4. Thanks!

stefahn commented 3 years ago

Thanks a lot for the commit!

Is there an easy way to tell my MediaWiki to use the latest version from branch 3.x ? My require statement in composer.local.json is "mediawiki/chameleon-skin": "~3.0"

malberts commented 3 years ago

That is fine to get the latest 3.x release, but it won't get the current unreleased commits. Once I publish 3.4 (aiming for the weekend) that same line will get it when you update again.

Otherwise, if you want to get the latest 3.x dev code, use this: "mediawiki/chameleon-skin": "3.x-dev"

malberts commented 3 years ago

Chameleon 3.4 is now available.