diff --git a/autoload.php b/autoload.php index 325b3086856..e4aae26ce61 100644 --- a/autoload.php +++ b/autoload.php @@ -1108,6 +1108,7 @@ $wgAutoloadLocalClasses = [ 'MediaWiki\\ProcOpenError' => __DIR__ . '/includes/exception/ProcOpenError.php', 'MediaWiki\\ShellDisabledError' => __DIR__ . '/includes/exception/ShellDisabledError.php', 'MediaWiki\\Skins\\Hook\\SkinAfterPortletHook' => __DIR__ . '/includes/skins/Hook/SkinAfterPortletHook.php', + 'MediaWiki\\Skins\\Hook\\SkinPageReadyConfigHook' => __DIR__ . '/includes/skins/Hook/SkinPageReadyConfigHook.php', 'MediaWiki\\Special\\SpecialPageFactory' => __DIR__ . '/includes/specialpage/SpecialPageFactory.php', 'MediaWiki\\Storage\\IncompleteRevisionException' => __DIR__ . '/includes/Revision/IncompleteRevisionException.php', 'MediaWiki\\Storage\\MutableRevisionRecord' => __DIR__ . '/includes/Revision/MutableRevisionRecord.php', diff --git a/includes/HookContainer/HookRunner.php b/includes/HookContainer/HookRunner.php index d0a4705fbc0..dc0222e27c4 100644 --- a/includes/HookContainer/HookRunner.php +++ b/includes/HookContainer/HookRunner.php @@ -511,6 +511,7 @@ class HookRunner implements \MediaWiki\Session\Hook\UserSetCookiesHook, \MediaWiki\Shell\Hook\WfShellWikiCmdHook, \MediaWiki\Skins\Hook\SkinAfterPortletHook, + \MediaWiki\Skins\Hook\SkinPageReadyConfigHook, \MediaWiki\SpecialPage\Hook\AuthChangeFormFieldsHook, \MediaWiki\SpecialPage\Hook\ChangeAuthenticationDataAuditHook, \MediaWiki\SpecialPage\Hook\ChangesListSpecialPageQueryHook, @@ -3512,6 +3513,16 @@ class HookRunner implements ); } + public function onSkinPageReadyConfig( ResourceLoaderContext $context, + array &$config + ) : void { + $this->container->run( + 'SkinPageReadyConfig', + [ $context, &$config ], + [ 'abortable' => false ] + ); + } + public function onSkinAddFooterLinks( Skin $skin, string $key, array &$footerItems ) { $this->container->run( 'SkinAddFooterLinks', diff --git a/includes/skins/Hook/SkinPageReadyConfigHook.php b/includes/skins/Hook/SkinPageReadyConfigHook.php new file mode 100644 index 00000000000..009d577d104 --- /dev/null +++ b/includes/skins/Hook/SkinPageReadyConfigHook.php @@ -0,0 +1,23 @@ + 'config.json', 'callback' => function ( + ResourceLoaderContext $context, + Config $config + ) { + $readyConfig = [ + 'collapsible' => true, + 'sortable' => true, + ]; + + Hooks::runner()->onSkinPageReadyConfig( $context, $readyConfig ); + return $readyConfig; + } ], ], 'dependencies' => [ 'mediawiki.util', diff --git a/resources/src/mediawiki.page.ready/ready.js b/resources/src/mediawiki.page.ready/ready.js index 9ae5fe86324..5882b837484 100644 --- a/resources/src/mediawiki.page.ready/ready.js +++ b/resources/src/mediawiki.page.ready/ready.js @@ -1,33 +1,41 @@ var checkboxShift = require( './checkboxShift.js' ); +var config = require( './config.json' ); + mw.hook( 'wikipage.content' ).add( function ( $content ) { - var $sortable, $collapsible, $sortableAndCollapsible, dependencies; + var $sortable, $collapsible, $sortableAndCollapsible, + dependencies = []; - $collapsible = $content.find( '.mw-collapsible' ); - $sortable = $content.find( 'table.sortable' ); - $sortableAndCollapsible = $content.find( 'table.sortable.mw-collapsible' ); - - // Both modules are preloaded by Skin::getDefaultModules() - dependencies = []; - if ( $collapsible.length ) { - dependencies.push( 'jquery.makeCollapsible' ); + if ( config.sortable && config.collapsible ) { + $sortableAndCollapsible = $content.find( 'table.sortable.mw-collapsible' ); } - if ( $sortable.length ) { - dependencies.push( 'jquery.tablesorter' ); - } - - mw.loader.using( dependencies ).then( function () { - // The two scripts only work correctly together when executed in this order (T64878) - if ( $sortableAndCollapsible.length ) { - $sortableAndCollapsible.tablesorter().makeCollapsible(); - } - // These are no-ops when executed on elements that were already handled above + if ( config.sortable ) { + $collapsible = $content.find( '.mw-collapsible' ); if ( $collapsible.length ) { - $collapsible.makeCollapsible(); + dependencies.push( 'jquery.makeCollapsible' ); } + } + if ( config.collapsible ) { + $sortable = $content.find( 'table.sortable' ); if ( $sortable.length ) { - $sortable.tablesorter(); + dependencies.push( 'jquery.tablesorter' ); } - } ); + } + if ( dependencies.length ) { + // Both modules are preloaded by Skin::getDefaultModules() + mw.loader.using( dependencies ).then( function () { + // The two scripts only work correctly together when executed in this order (T64878) + if ( $sortableAndCollapsible && $sortableAndCollapsible.length ) { + $sortableAndCollapsible.tablesorter().makeCollapsible(); + } + // These are no-ops when executed on elements that were already handled above + if ( $collapsible && $collapsible.length ) { + $collapsible.makeCollapsible(); + } + if ( $sortable && $sortable.length ) { + $sortable.tablesorter(); + } + } ); + } checkboxShift( $content.find( 'input[type="checkbox"]:not(.noshiftselect)' ) ); } );