Merge skin option modules into a single ResourceLoader module and move enabled logic to client

It's presumed that skin options will eventually become the default or be removed from the skin.
While they are not the default, it would be helpful to package them in one single module - as ResourceLoader
modules are costly bloating the dependency graph in the MediaWiki startup module.

In T167713 we talked about grouping our entry points by page rather than feature, which this seems consistent
with. A page with special options enabled is different from a page without.

Change-Id: Id948f913d4743532ba3442d2059a03c122419ff2
This commit is contained in:
jdlrobson 2018-09-26 16:03:20 -07:00
parent e2b4c024c7
commit cbad0bd363
8 changed files with 42 additions and 34 deletions

View file

@ -120,6 +120,19 @@ class SkinMinerva extends SkinTemplate {
return $this->skinOptions[$key]; return $this->skinOptions[$key];
} }
/**
* Return whether any of the skin options have been set
* @return bool
*/
public function hasSkinOptions() {
foreach ( $this->skinOptions as $key => $val ) {
if ( $val ) {
return true;
}
}
return false;
}
/** /**
* initialize various variables and generate the template * initialize various variables and generate the template
* @return QuickTemplate * @return QuickTemplate
@ -1245,6 +1258,7 @@ class SkinMinerva extends SkinTemplate {
return $data; return $data;
} }
/** /**
* Returns array of config variables that should be added only to this skin * Returns array of config variables that should be added only to this skin
* for use in JavaScript. * for use in JavaScript.
@ -1256,6 +1270,7 @@ class SkinMinerva extends SkinTemplate {
$out = $this->getOutput(); $out = $this->getOutput();
$vars = [ $vars = [
'wgMinervaFeatures' => $this->skinOptions,
'wgMinervaDownloadNamespaces' => $this->getConfig()->get( 'MinervaDownloadNamespaces' ), 'wgMinervaDownloadNamespaces' => $this->getConfig()->get( 'MinervaDownloadNamespaces' ),
'wgMinervaMenuData' => $this->getMenuData(), 'wgMinervaMenuData' => $this->getMenuData(),
'wgMFDescription' => $out->getProperty( 'wgMFDescription' ), 'wgMFDescription' => $out->getProperty( 'wgMFDescription' ),
@ -1326,12 +1341,8 @@ class SkinMinerva extends SkinTemplate {
$modules[] = 'skins.minerva.talk'; $modules[] = 'skins.minerva.talk';
} }
if ( $this->hasCategoryLinks() ) { if ( $this->hasSkinOptions() ) {
$modules[] = 'skins.minerva.categories'; $modules[] = 'skins.minerva.options';
}
if ( $this->getSkinOption( self::OPTION_BACK_TO_TOP ) ) {
$modules[] = 'skins.minerva.backtotop';
} }
return $modules; return $modules;

View file

@ -13,7 +13,7 @@
OO.mfExtend( BackToTopOverlay, View, { OO.mfExtend( BackToTopOverlay, View, {
className: 'backtotop', className: 'backtotop',
template: mw.template.get( 'skins.minerva.backtotop', 'BackToTopOverlay.hogan' ), template: mw.template.get( 'skins.minerva.options', 'BackToTopOverlay.hogan' ),
events: $.extend( {}, View.prototype.events, { events: $.extend( {}, View.prototype.events, {
click: 'onBackToTopClick' click: 'onBackToTopClick'
} ), } ),
@ -47,6 +47,6 @@
} }
} ); } );
M.define( 'skins.minerva.backtotop/BackToTopOverlay', BackToTopOverlay ); M.define( 'skins.minerva.options/BackToTopOverlay', BackToTopOverlay );
}( mw.mobileFrontend, jQuery ) ); }( mw.mobileFrontend, jQuery ) );

View file

@ -1,10 +1,11 @@
( function ( M, $ ) { ( function ( M, $ ) {
var BackToTopOverlay = M.require( 'skins.minerva.backtotop/BackToTopOverlay' ), var BackToTopOverlay = M.require( 'skins.minerva.options/BackToTopOverlay' ),
backtotop = new BackToTopOverlay(), backtotop = new BackToTopOverlay(),
features = mw.config.get( 'wgMinervaFeatures', {} ),
browser = M.require( 'mobile.startup/Browser' ).getSingleton(); browser = M.require( 'mobile.startup/Browser' ).getSingleton();
// check if browser user agent is iOS (T141598) // check if browser user agent is iOS (T141598)
if ( browser.isIos() ) { if ( browser.isIos() || !features.backToTop ) {
return; return;
} }

View file

@ -1,9 +1,15 @@
( function ( M, $ ) { ( function ( M, $ ) {
var loader = M.require( 'mobile.startup/rlModuleLoader' ), var loader = M.require( 'mobile.startup/rlModuleLoader' ),
features = mw.config.get( 'wgMinervaFeatures', {} ),
overlayManager = M.require( 'skins.minerva.scripts/overlayManager' ), overlayManager = M.require( 'skins.minerva.scripts/overlayManager' ),
user = M.require( 'mobile.startup/user' ); user = M.require( 'mobile.startup/user' );
// check the categories feature has been turned on
if ( !features.categories ) {
return;
}
// categories overlay // categories overlay
overlayManager.add( /^\/categories$/, function () { overlayManager.add( /^\/categories$/, function () {
return loader.loadModule( 'mobile.categories.overlays', true ).then( function ( loadingOverlay ) { return loader.loadModule( 'mobile.categories.overlays', true ).then( function ( loadingOverlay ) {

View file

@ -516,37 +516,26 @@
"resources/skins.minerva.editor/init.js" "resources/skins.minerva.editor/init.js"
] ]
}, },
"skins.minerva.backtotop": { "skins.minerva.options": {
"targets": [
"mobile",
"desktop"
],
"dependencies": [
"mobile.toggle",
"mobile.startup"
],
"templates": {
"BackToTopOverlay.hogan": "resources/skins.minerva.backtotop/BackToTopOverlay.hogan"
},
"styles": [
"resources/skins.minerva.backtotop/backtotop.less"
],
"scripts": [
"resources/skins.minerva.backtotop/BackToTopOverlay.js",
"resources/skins.minerva.backtotop/init.js"
]
},
"skins.minerva.categories": {
"targets": [ "targets": [
"mobile", "mobile",
"desktop" "desktop"
], ],
"dependencies": [ "dependencies": [
"skins.minerva.scripts", "skins.minerva.scripts",
"mobile.toggle",
"mobile.startup" "mobile.startup"
], ],
"templates": {
"BackToTopOverlay.hogan": "resources/skins.minerva.options/BackToTopOverlay.hogan"
},
"styles": [
"resources/skins.minerva.options/backtotop.less"
],
"scripts": [ "scripts": [
"resources/skins.minerva.categories/init.js" "resources/skins.minerva.options/BackToTopOverlay.js",
"resources/skins.minerva.options/backtotop.js",
"resources/skins.minerva.options/categories.js"
] ]
}, },
"skins.minerva.talk": { "skins.minerva.talk": {

View file

@ -39,6 +39,7 @@ class EchoNotifUser {
* @group MinervaNeue * @group MinervaNeue
*/ */
class SkinMinervaTest extends MediaWikiTestCase { class SkinMinervaTest extends MediaWikiTestCase {
const OPTIONS_MODULE = 'skins.minerva.options';
/** /**
* @covers ::addToBodyAttributes * @covers ::addToBodyAttributes
@ -190,8 +191,8 @@ class SkinMinervaTest extends MediaWikiTestCase {
public function provideGetContextSpecificModules() { public function provideGetContextSpecificModules() {
return [ return [
[ true, 'skins.minerva.backtotop', true ], [ true, self::OPTIONS_MODULE, true ],
[ false, 'skins.minerva.backtotop', false ], [ false, self::OPTIONS_MODULE, false ],
]; ];
} }