Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fork 2 or more mediawiki chameleon skins to be used in the same instance of mediawiki #428

Open
eurodomenii opened this issue May 15, 2024 · 0 comments

Comments

@eurodomenii
Copy link

My case is to use different css and fonts for admins, compared to anonymous users.

The first attempt was to conditionally load $egChameleonExternalStyleVariables and $egChameleonExternalStyleModules in LocalSettings.php, based on the cookie test, because the $user object cannot be loaded here, due to the premature access to service error

if (isset($_COOKIE[$wgDBname.'_session']) && isset($_COOKIE[$wgDBname.'UserName']) && $_COOKIE[$wgDBname.'UserName'] == "XXX" )

But the solution is not stable, because in some cases it enters the anonymous branch, even if there is a cookie set and it compromises the design.

Then, I thought of making one or more forks of the Chameleon theme, which admin users can switch from their preferences.

A concept of the project is posted at https://github.com/eurodomenii/mw_chameleon_fork

After copying the files, I ran two scripts

find . -type f -exec sed -i 's/chameleon/chameleon1/g' {} \; 
find . -type f -exec sed -i 's/Chameleon/Chameleon1/g' {} \;

And rename few files

skins/chameleon1/resources/styles/chameleon.scss
skins/chameleon1/src/Chameleon.php, 
skins/chameleon1/src/ChameleonTemplate.php 
skins/chameleon1/tests/phpunit/Unit/ChameleonTemplateTest.php

But the variables were overwritten and the styles messed up.

After x-debugging load.php

$resourceLoader->modules["zzz.ext.bootstrap.styles"]->variables
I realized they were overwriting each other here

$resourceLoader->modules["zzz.ext.bootstrap.styles"]->styles
Here the styles from both themes were added

I think that Chameleon's interconnection with Bootstrap was not designed for such a use case, because all variables, styles and scripts go in the 'zzz.ext.bootstrap.styles' module, for all forks

protected function registerSkinWithMW() {
		MediaWikiServices::getInstance()->getSkinFactory()->register( 'chameleon1', 'Chameleon1',
			function () {
				$styles = [
					'mediawiki.ui.button',
					'skins.chameleon1',
					'zzz.ext.bootstrap.styles',
				];

Finally, I found the workaround ext.bootstrap1.styles + ext.bootstrap1.scripts + new class BootstrapManager1.php workaround, see relevant details in the commit eurodomenii/mw_chameleon_fork@bb699af

I'm not convinced it's the best solution, it seems hackish, but it works!
See also https://github.com/eurodomenii/mw_chameleon_fork/blob/master/CommonSettings.php usage of new Chameleon1/2 variables.

The code below duplicates the scripts, but in a hurry, I preferred to simply comment it out, as I didn't need it.

protected function addResourceModules(): void {
        $GLOBALS[ 'wgResourceModules' ][ 'skin.chameleon1.sticky' ] = [
            'localBasePath'  => $GLOBALS[ 'chameleon1LocalPath' ] . '/resources/js',
            'remoteBasePath' => $GLOBALS[ 'chameleon1RemotePath' ] . '/resources/js',
            'group'          => 'skin.chameleon1',
            'skinScripts'    =>
                [ 'chameleon1' => [ 'hc-sticky/hc-sticky.js', 'Components/Modifications/sticky.js' ] ]
        ];

        $GLOBALS[ 'wgResourceModules' ][ 'skin.chameleon1.toc' ] = [
            'localBasePath'  => $GLOBALS[ 'chameleon1LocalPath' ] . '/resources',
            'remoteBasePath' => $GLOBALS[ 'chameleon1RemotePath' ] . '/resources',
            'group'          => 'skin.chameleon1',
            'skinScripts'    => [ 'chameleon1' => [ 'js/Components/toc.js' ] ]
        ];
    }

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant