Skip to content

Commit

Permalink
Add style loading compatibility for 1.35
Browse files Browse the repository at this point in the history
Using wgVersion determine the current version of MediaWiki.
In the case of < 1.35 use initPage (has been around since 1.31)
instead of setupSkinUserCss (deprecated since 1.31)

For > 1.35 use skin styles registration via options in
SetupAfterCache.

When support is dropped for < 1.35 all the version guarded
code can be dropped.

Fixes: #202
Fixes: #110
  • Loading branch information
jdlrobson authored and JeroenDeDauw committed Dec 31, 2020
1 parent 64284f4 commit 40a60c9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
10 changes: 10 additions & 0 deletions skin.json
Expand Up @@ -33,6 +33,16 @@
"value": true
}
},
"ResourceModules": {
"skins.chameleon": {
"class": "ResourceLoaderSkinModule",
"features": [ "elements", "content", "legacy" ],
"targets": [
"desktop",
"mobile"
]
}
},
"callback": "Skins\\Chameleon\\Chameleon::init",
"load_composer_autoloader": true,
"manifest_version": 2
Expand Down
43 changes: 10 additions & 33 deletions src/Chameleon.php
Expand Up @@ -98,54 +98,31 @@ public static function init() {
* @return array Array of modules
*/
public function getDefaultModules() {
$modules = parent::getDefaultModules();

if ( array_key_exists( 'styles', $modules ) ) {
global $wgVersion;

// FIXME: Remove when MW 1.31 is dropped
$this->stylesHaveBeenProcessed = true;
$modules = parent::getDefaultModules();

if ( version_compare( $wgVersion, '1.35', '<' ) ) {
// Not necessary in 1.35 (see #110)
$modulePos = array_search( 'mediawiki.legacy.shared', $modules[ 'styles' ][ 'core' ] );

if ( $modulePos !== false ) {
// we have our own version of these styles
unset( $modules[ 'styles' ][ 'core' ][ $modulePos ] );
}

// These are added in SetupAfterCache::registerSkinWithMW in >= 1.35
$modules[ 'styles' ][ 'content' ][] = 'mediawiki.skinning.content';
$modules[ 'styles' ][ 'content' ][] = 'mediawiki.ui.button';
$modules[ 'styles' ][ 'content' ][] = 'zzz.ext.bootstrap.styles';

}

return $modules;
}

/**
* Hook point for adding style modules to OutputPage.
*
*
* @deprecated since 1.32 Kept here for compat with 1.31
*
* @fixme Remove this method completely when MW 1.31 compatibility is dropped.
*
* @param OutputPage $out Legacy parameter, identical to $this->getOutput()
*/
public function setupSkinUserCss( OutputPage $out ) {
if ( $this->stylesHaveBeenProcessed === false ) {

$moduleStyles = [
'mediawiki.skinning.content',
'mediawiki.legacy.commonPrint',
'mediawiki.ui.button',
'zzz.ext.bootstrap.styles'
];
$modules[ 'styles' ][ 'content' ][] = 'mediawiki.legacy.commonPrint';

if ( $out->isSyndicated() ) {
$moduleStyles[] = 'mediawiki.feedlink';
$modules[ 'styles' ][ 'content' ][] = 'mediawiki.feedlink';
}

$out->addModuleStyles( $moduleStyles );
}

return $modules;
}

/**
Expand Down
9 changes: 8 additions & 1 deletion src/Hooks/SetupAfterCache.php
Expand Up @@ -260,7 +260,14 @@ protected function setLayoutFile() {
protected function registerSkinWithMW() {
MediaWikiServices::getInstance()->getSkinFactory()->register( 'chameleon', 'Chameleon',
function () {
return new Chameleon();
return new Chameleon( [
'name' => 'chameleon',
'styles' => [
'mediawiki.ui.button',
'skins.chameleon',
'zzz.ext.bootstrap.styles',
]
] );
} );
}

Expand Down

0 comments on commit 40a60c9

Please sign in to comment.