Add new 'toc' feature to ResourceLoaderSkinModule

The table of content styles will now be loaded on all pages rather than
just pages which have it. This will lead to less stylesheet fragmentation
across page views.

Skins in WMF production were updated long ago to automatically opt
into new features so will automatically gain this module:
I98b7e49b8a3bcba31284385d2f45e0164df2fbb4
I50afd035360ff2eccd5a934a02a218d093f9583d
I5b3920ae6e98111582b93e60a2b9950c478bff7d
If9283742a83ecfbe8c4246e3624022a56be8f161
If9ae25c41b91a8b47c154f0fd98984eac526654f

Skins that are using ResourceLoaderSkinModule with opt-in approach or
the existing mediawiki.skinning.interface, will automatically get these
new styles. Skins that are use neither of these mechanisms will need to
be modified if they wish to retain the collapsing functionality of the
table of contents. As of now, I am not aware of any such skins.

Note in a follow-up, the mediawiki.toc.styles module will be marked as
deprecated in 1.35. This is done separately to allow WMF caches
some time to roll over to the new code first.

Bug: T252774
Change-Id: Ie28b7e732664eb332be795d7e33cd9a227c21370
This commit is contained in:
jdlrobson 2020-08-18 11:06:28 -07:00 committed by Jdlrobson
parent 9c253febe2
commit db3c8ea16b
8 changed files with 19 additions and 16 deletions

View file

@ -121,9 +121,6 @@ class ApiHelp extends ApiBase {
'mediawiki.hlist',
'mediawiki.apipretty',
] );
if ( !empty( $options['toc'] ) ) {
$out->addModuleStyles( 'mediawiki.toc.styles' );
}
$out->setPageTitle( $context->msg( 'api-help-title' ) );
$services = MediaWikiServices::getInstance();

View file

@ -24,7 +24,7 @@
* @ingroup ResourceLoader
* @internal
*/
class ResourceLoaderSkinModule extends ResourceLoaderFileModule {
class ResourceLoaderSkinModule extends ResourceLoaderLessVarFileModule {
/**
* All skins are assumed to be compatible with mobile
*/
@ -80,6 +80,9 @@ class ResourceLoaderSkinModule extends ResourceLoaderFileModule {
* For backwards compatibility a legacy feature is provided.
* New skins should not use this if they can avoid doing so.
* This feature also contains all `i18n-` prefixed features.
*
* "toc"
* Styling rules for the table of contents.
*/
private const FEATURE_FILES = [
'logo' => [
@ -114,6 +117,11 @@ class ResourceLoaderSkinModule extends ResourceLoaderFileModule {
'i18n-headings' => [
'screen' => [ 'resources/src/mediawiki.skinning/i18n-headings.less' ],
],
'toc' => [
'all' => [ 'resources/src/mediawiki.skinning/toc/common.css' ],
'screen' => [ 'resources/src/mediawiki.skinning/toc/screen.less' ],
'print' => [ 'resources/src/mediawiki.skinning/toc/print.css' ],
],
];
/** @var string[] */
@ -129,6 +137,13 @@ class ResourceLoaderSkinModule extends ResourceLoaderFileModule {
'i18n-ordered-lists' => false,
'i18n-all-lists-margins' => false,
'i18n-headings' => false,
'toc' => true,
];
private const LESS_MESSAGES = [
// `toc` feature
'hidetoc',
'showtoc',
];
public function __construct(
@ -136,6 +151,7 @@ class ResourceLoaderSkinModule extends ResourceLoaderFileModule {
$localBasePath = null,
$remoteBasePath = null
) {
$options['lessMessages'] = self::LESS_MESSAGES;
parent::__construct( $options, $localBasePath, $remoteBasePath );
$features = $options['features'] ??
// For historic reasons if nothing is declared logo and legacy features are enabled.

View file

@ -266,7 +266,6 @@ abstract class Skin extends ContextSource {
if ( $out->isTOCEnabled() ) {
$modules['content'][] = 'mediawiki.toc';
$modules['styles']['content'][] = 'mediawiki.toc.styles';
}
$prefMgr = MediaWikiServices::getInstance()->getPermissionManager();

View file

@ -169,7 +169,6 @@ class SpecialEditWatchlist extends UnlistedSpecialPage {
$out->addReturnTo( SpecialPage::getTitleFor( 'Watchlist' ) );
} elseif ( $this->toc !== false ) {
$out->prependHTML( $this->toc );
$out->addModuleStyles( 'mediawiki.toc.styles' );
}
}

View file

@ -1000,20 +1000,12 @@ return [
],
'dependencies' => [
'mediawiki.cookie',
'mediawiki.toc.styles',
],
'targets' => [ 'desktop', 'mobile' ],
],
'mediawiki.toc.styles' => [
'class' => ResourceLoaderLessVarFileModule::class,
'lessMessages' => [ 'hidetoc', 'showtoc' ],
'styles' => [
'resources/src/mediawiki.toc.styles/common.css',
'resources/src/mediawiki.toc.styles/screen.less'
=> [ 'media' => 'screen' ],
'resources/src/mediawiki.toc.styles/print.css'
=> [ 'media' => 'print' ],
],
'class' => ResourceLoaderSkinModule::class,
'features' => [ 'toc' ],
'targets' => [ 'desktop', 'mobile' ],
],
'mediawiki.Uri' => [