Allow skins to override mediawiki.page.ready initialisation
Add 'ready.config.json' to resource Add 'collapsible', 'sortable' field to be possible override via hook. In order to override setting, new hook ResourceLoaderPageReadyConfigHook has been introduced. A new config field for search will follow. Bug: T250851 Change-Id: I041d4a4b9114f1190f28e0283d96cd33b81f9850
This commit is contained in:
parent
6c90c2758b
commit
ae3104c46d
5 changed files with 77 additions and 22 deletions
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
23
includes/skins/Hook/SkinPageReadyConfigHook.php
Normal file
23
includes/skins/Hook/SkinPageReadyConfigHook.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Skins\Hook;
|
||||
|
||||
use ResourceLoaderContext;
|
||||
|
||||
/**
|
||||
* @stable for implementation
|
||||
*/
|
||||
interface SkinPageReadyConfigHook {
|
||||
/**
|
||||
* Allows skins to change the `mediawiki.page.ready` module configuration.
|
||||
*
|
||||
* @since 1.36
|
||||
* @param ResourceLoaderContext $context
|
||||
* @param mixed[] &$config Associative array of configurable options
|
||||
* @return void This hook must not abort, it must return no value
|
||||
*/
|
||||
public function onSkinPageReadyConfig(
|
||||
ResourceLoaderContext $context,
|
||||
array &$config
|
||||
) : void;
|
||||
}
|
||||
|
|
@ -1471,6 +1471,18 @@ return [
|
|||
'ready.js',
|
||||
'checkboxShift.js',
|
||||
'checkboxHack.js',
|
||||
[ 'name' => 'config.json', 'callback' => function (
|
||||
ResourceLoaderContext $context,
|
||||
Config $config
|
||||
) {
|
||||
$readyConfig = [
|
||||
'collapsible' => true,
|
||||
'sortable' => true,
|
||||
];
|
||||
|
||||
Hooks::runner()->onSkinPageReadyConfig( $context, $readyConfig );
|
||||
return $readyConfig;
|
||||
} ],
|
||||
],
|
||||
'dependencies' => [
|
||||
'mediawiki.util',
|
||||
|
|
|
|||
|
|
@ -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)' ) );
|
||||
} );
|
||||
|
|
|
|||
Loading…
Reference in a new issue